Class: GraphQLSchema::TypeDefinition

Inherits:
Type
  • Object
show all
Defined in:
lib/graphql_schema.rb

Constant Summary

Constants inherited from Type

GraphQLSchema::Type::BUILTIN

Instance Method Summary collapse

Methods inherited from Type

#builtin?, #enum?, #initialize, #input_object?, #interface?, #kind, #list?, #object?, #scalar?, #union?

Methods included from NamedHash

#camelize_name, #classify_name, #description, #name, #to_h, #upcase_name

Constructor Details

This class inherits a constructor from GraphQLSchema::Type

Instance Method Details

#enum_values(include_deprecated: false) ⇒ Object



280
281
282
283
# File 'lib/graphql_schema.rb', line 280

def enum_values(include_deprecated: false)
  @enum_values ||= @hash.fetch('enumValues').map{ |value_hash| EnumValue.new(value_hash) }.sort_by(&:name)
  include_deprecated ? @enum_values : @enum_values.reject(&:deprecated?)
end

#fields(include_deprecated: false) ⇒ Object



246
247
248
249
250
# File 'lib/graphql_schema.rb', line 246

def fields(include_deprecated: false)
  return unless @hash.fetch('fields')
  @fields ||= @hash.fetch('fields').map{ |field_hash| Field.new(field_hash) }
  include_deprecated ? @fields : @fields.reject(&:deprecated?)
end

#fields_by_nameObject



252
253
254
# File 'lib/graphql_schema.rb', line 252

def fields_by_name
  @fields_by_name ||= fields(include_deprecated: true).map{ |field| [field.name, field]}.to_h
end

#implement?(interface_name) ⇒ Boolean

Returns:

  • (Boolean)


272
273
274
# File 'lib/graphql_schema.rb', line 272

def implement?(interface_name)
  interfaces.map(&:name).include?(interface_name)
end

#input_fieldsObject



256
257
258
# File 'lib/graphql_schema.rb', line 256

def input_fields
  @input_fields ||= @hash.fetch('inputFields').map{ |field_hash| InputValue.new(field_hash) }
end

#interfacesObject



268
269
270
# File 'lib/graphql_schema.rb', line 268

def interfaces
  @interfaces ||= @hash.fetch('interfaces').map{ |type_hash| TypeDeclaration.new(type_hash) }.sort_by(&:name)
end

#optional_input_fieldsObject



264
265
266
# File 'lib/graphql_schema.rb', line 264

def optional_input_fields
  @optional_fields ||= input_fields.reject{ |field| field.type.non_null? }
end

#possible_typesObject



276
277
278
# File 'lib/graphql_schema.rb', line 276

def possible_types
  @possible_types ||= @hash.fetch('possibleTypes').map{ |type_hash| TypeDeclaration.new(type_hash) }.sort_by(&:name)
end

#required_input_fieldsObject



260
261
262
# File 'lib/graphql_schema.rb', line 260

def required_input_fields
  @required_fields ||= input_fields.select{ |field| field.type.non_null? }
end