class GraphQL::Schema::InputObject
Attributes
Returns
-
GraphQL::Execution::Interpereter::Arguments— The underlying arguments instance
Returns
-
GraphQL::Query::Context— The context for this query
Public Class Methods
# File lib/graphql/schema/input_object.rb, line 157 def argument(*args, **kwargs, &block) args = args #: untyped argument_defn = super(*args, **kwargs, &block) if one_of? if argument_defn.type.non_null? raise ArgumentError, "Argument '#{argument_defn.path}' must be nullable because it is part of a OneOf type, add `required: false`." end if argument_defn.default_value? raise ArgumentError, "Argument '#{argument_defn.path}' cannot have a default value because it is part of a OneOf type, remove `default_value: ...`." end end # Add a method access suppress_redefinition_warning do define_accessor_method(argument_defn.keyword) end argument_defn end
Calls superclass method
Source
# File lib/graphql/schema/input_object.rb, line 175 def kind GraphQL::TypeKinds::INPUT_OBJECT end
# File lib/graphql/schema/input_object.rb, line 34 def initialize(arguments, ruby_kwargs:, context:, defaults_used:) @context = context @ruby_style_hash = ruby_kwargs @arguments = arguments # Apply prepares, not great to have it duplicated here. arg_defns = context ? context.types.arguments(self.class) : self.class.arguments(context).each_value arg_defns.each do |arg_defn| ruby_kwargs_key = arg_defn.keyword if @ruby_style_hash.key?(ruby_kwargs_key) # Weirdly, procs are applied during coercion, but not methods. # Probably because these methods require a `self`. if arg_defn.prepare.is_a?(Symbol) || context.nil? prepared_value = arg_defn.prepare_value(self, @ruby_style_hash[ruby_kwargs_key], context: context) overwrite_argument(ruby_kwargs_key, prepared_value) end end end end
Source
# File lib/graphql/schema/input_object.rb, line 144 def one_of if !one_of? if all_argument_definitions.any? { |arg| arg.type.non_null? } raise ArgumentError, "`one_of` may not be used with required arguments -- add `required: false` to argument definitions to use `one_of`" end directive(GraphQL::Schema::Directive::OneOf) end end
Source
# File lib/graphql/schema/input_object.rb, line 153 def one_of? false # Re-defined when `OneOf` is added end
Public Instance Methods
Source
# File lib/graphql/schema/input_object.rb, line 99 def [](key) if @ruby_style_hash.key?(key) @ruby_style_hash[key] elsif @arguments @arguments[key] else nil end end
Lookup a key on this object, it accepts new-style underscored symbols Or old-style camelized identifiers.
Parameters
-
key(Symbol, String)
# File lib/graphql/schema/input_object.rb, line 61 def deconstruct_keys(keys = nil) if keys.nil? @ruby_style_hash else new_h = {} keys.each { |k| @ruby_style_hash.key?(k) && new_h[k] = @ruby_style_hash[k] } new_h end end
Source
# File lib/graphql/schema/input_object.rb, line 109 def key?(key) @ruby_style_hash.key?(key) || (@arguments && @arguments.key?(key)) || false end
Source
# File lib/graphql/schema/input_object.rb, line 53 def to_h unwrap_value(@ruby_style_hash) end
Source
# File lib/graphql/schema/input_object.rb, line 114 def to_kwargs @ruby_style_hash.dup end
A copy of the Ruby-style hash
Source
# File lib/graphql/schema/input_object.rb, line 75 def unwrap_value(value) case value when Array value.map { |item| unwrap_value(item) } when Hash value.reduce({}) do |h, (key, nested_value)| h.merge!(key => unwrap_value(nested_value)) end when InputObject value.to_h else value end end