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



236
237
238
239
# File 'lib/graphql_schema.rb', line 236

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



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

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

#implement?(interface_name) ⇒ Boolean

Returns:



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

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

#input_fieldsObject



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

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

#interfacesObject



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

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

#optional_input_fieldsObject



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

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

#possible_typesObject



232
233
234
# File 'lib/graphql_schema.rb', line 232

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

#required_input_fieldsObject



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

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