Class: GraphQL::InputObjectType

Inherits:
BaseType
  • Object
show all
Defined in:
lib/graphql/input_object_type.rb

Overview

A complex input type for a field argument.

Examples:

An input type with name and number

PlayerInput = GraphQL::InputObjectType.define do
  name("Player")
  input_field :name, !types.String
  input_field :number, !types.Int
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseType

#==, #coerce_input, #resolve_type, #to_list_type, #to_non_null_type, #to_s, #unwrap, #valid_input?

Methods included from DefinitionHelpers::DefinedByConfig

included

Methods included from DefinitionHelpers::NonNullWithBang

#!

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



11
12
13
# File 'lib/graphql/input_object_type.rb', line 11

def description
  @description
end

#input_fieldsObject

Returns the value of attribute input_fields.



11
12
13
# File 'lib/graphql/input_object_type.rb', line 11

def input_fields
  @input_fields
end

#nameObject

Returns the value of attribute name.



11
12
13
# File 'lib/graphql/input_object_type.rb', line 11

def name
  @name
end

Instance Method Details

#coerce_non_null_input(value) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/graphql/input_object_type.rb', line 28

def coerce_non_null_input(value)
  input_values = {}
  input_fields.each do |input_key, input_field_defn|
    field_value = value[input_key]
    field_value = input_field_defn.type.coerce_input(field_value)
    if field_value.nil?
      field_value = input_field_defn.default_value
    end
    input_values[input_key] = field_value unless field_value.nil?
  end
  GraphQL::Query::Arguments.new(input_values)
end

#kindObject



18
19
20
# File 'lib/graphql/input_object_type.rb', line 18

def kind
  GraphQL::TypeKinds::INPUT_OBJECT
end

#valid_non_null_input?(input) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
# File 'lib/graphql/input_object_type.rb', line 22

def valid_non_null_input?(input)
  return false unless input.is_a?(Hash) || input.is_a?(GraphQL::Query::Arguments)
  return false unless input.all? { |name, value| input_fields[name] }
  input_fields.all? { |name, field| field.type.valid_input?(input[name]) }
end