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, #name, #upcase_name

Constructor Details

This class inherits a constructor from GraphQLSchema::Type

Instance Method Details

#enum_values(include_deprecated: false) ⇒ Object



227
228
229
230
# File 'lib/graphql_schema.rb', line 227

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



198
199
200
201
# File 'lib/graphql_schema.rb', line 198

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

#implement?(interface_name) ⇒ Boolean

Returns:

  • (Boolean)


219
220
221
# File 'lib/graphql_schema.rb', line 219

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

#input_fieldsObject



203
204
205
# File 'lib/graphql_schema.rb', line 203

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

#interfacesObject



215
216
217
# File 'lib/graphql_schema.rb', line 215

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

#optional_input_fieldsObject



211
212
213
# File 'lib/graphql_schema.rb', line 211

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

#possible_typesObject



223
224
225
# File 'lib/graphql_schema.rb', line 223

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

#required_input_fieldsObject



207
208
209
# File 'lib/graphql_schema.rb', line 207

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