Class: GraphQL::Schema::InputObject Private

Inherits:
Member
  • Object
show all
Extended by:
Forwardable, Member::AcceptsDefinition, Member::HasArguments
Defined in:
lib/graphql/schema/input_object.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary

Constants included from Member::GraphQLTypeNames

Member::GraphQLTypeNames::Boolean, Member::GraphQLTypeNames::ID, Member::GraphQLTypeNames::Int

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Member::HasArguments

argument, argument_class, own_arguments

Methods included from Member::TypeSystemHelpers

#kind, #list?, #non_null?, #to_list_type, #to_non_null_type

Methods included from Member::BaseDSLMethods

#description, #graphql_name, #introspection, #mutation, #name, #overridden_graphql_name, #to_graphql, #unwrap

Methods included from Relay::TypeExtensions

#connection_type, #define_connection, #define_edge, #edge_type

Methods included from Member::CachedGraphQLDefinition

#graphql_definition, #initialize_copy

Constructor Details

#initialize(values, context:, defaults_used:) ⇒ InputObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of InputObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/graphql/schema/input_object.rb', line 9

def initialize(values, context:, defaults_used:)
  @context = context
  @arguments = self.class.arguments_class.new(values, context: context, defaults_used: defaults_used)
  # Symbolized, underscored hash:
  @ruby_style_hash = @arguments.to_kwargs
  # Apply prepares, not great to have it duplicated here.
  self.class.arguments.each do |name, arg_defn|
    ruby_kwargs_key = arg_defn.keyword
    if @ruby_style_hash.key?(ruby_kwargs_key) && arg_defn.prepare
      @ruby_style_hash[ruby_kwargs_key] = arg_defn.prepare_value(self, @ruby_style_hash[ruby_kwargs_key])
    end
  end
end

Class Attribute Details

.arguments_classClass<GraphQL::Arguments>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Class<GraphQL::Arguments>)


54
55
56
# File 'lib/graphql/schema/input_object.rb', line 54

def arguments_class
  @arguments_class
end

Instance Attribute Details

#argumentsGraphQL::Query::Arguments (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The underlying arguments instance

Returns:



27
28
29
# File 'lib/graphql/schema/input_object.rb', line 27

def arguments
  @arguments
end

#contextGraphQL::Query::Context (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The context for this query

Returns:



24
25
26
# File 'lib/graphql/schema/input_object.rb', line 24

def context
  @context
end

Class Method Details

.argument(*args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



56
57
58
59
60
61
62
63
# File 'lib/graphql/schema/input_object.rb', line 56

def argument(*args)
  argument_defn = super
  # Add a method access
  arg_name = argument_defn.graphql_definition.name
  define_method(Member::BuildType.underscore(arg_name)) do
    @arguments.public_send(arg_name)
  end
end

.kindObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



81
82
83
# File 'lib/graphql/schema/input_object.rb', line 81

def kind
  GraphQL::TypeKinds::INPUT_OBJECT
end

.to_graphqlObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/graphql/schema/input_object.rb', line 65

def to_graphql
  type_defn = GraphQL::InputObjectType.new
  type_defn.name = graphql_name
  type_defn.description = description
  type_defn.[:type_class] = self
  type_defn.mutation = mutation
  arguments.each do |name, arg|
    type_defn.arguments[arg.graphql_definition.name] = arg.graphql_definition
  end
  # Make a reference to a classic-style Arguments class
  self.arguments_class = GraphQL::Query::Arguments.construct_arguments_class(type_defn)
  # But use this InputObject class at runtime
  type_defn.arguments_class = self
  type_defn
end

Instance Method Details

#[](key) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Lookup a key on this object, it accepts new-style underscored symbols Or old-style camelized identifiers.

Parameters:

  • key (Symbol, String)


35
36
37
38
39
40
41
# File 'lib/graphql/schema/input_object.rb', line 35

def [](key)
  if @ruby_style_hash.key?(key)
    @ruby_style_hash[key]
  else
    @arguments[key]
  end
end

#key?(key) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



43
44
45
# File 'lib/graphql/schema/input_object.rb', line 43

def key?(key)
  @ruby_style_hash.key?(key) || @arguments.key?(key)
end

#to_kwargsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

A copy of the Ruby-style hash



48
49
50
# File 'lib/graphql/schema/input_object.rb', line 48

def to_kwargs
  @ruby_style_hash.dup
end