Class: GraphQL::Query::Arguments
- Inherits:
-
Object
- Object
- GraphQL::Query::Arguments
- Extended by:
- Delegate
- Defined in:
- lib/graphql/query/arguments.rb
Overview
Defined Under Namespace
Classes: ArgumentValue
Constant Summary collapse
- NO_ARGS =
self.new({}, argument_definitions: [])
Class Attribute Summary collapse
-
.argument_definitions ⇒ Object
Returns the value of attribute argument_definitions.
Class Method Summary collapse
Instance Method Summary collapse
-
#[](key) ⇒ Object
The argument at that key.
-
#each_value {|argument_value| ... } ⇒ Object
Access each key, value and type for the arguments in this set.
-
#initialize(values, argument_definitions:) ⇒ Arguments
constructor
A new instance of Arguments.
-
#key?(key) ⇒ Boolean
True if the argument was present in this field.
-
#to_h ⇒ Hash
Get the hash of all values, with stringified keys.
Methods included from Delegate
Constructor Details
#initialize(values, argument_definitions:) ⇒ Arguments
Returns a new instance of Arguments.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/graphql/query/arguments.rb', line 39 def initialize(values, argument_definitions:) @argument_values = values.inject({}) do |memo, (inner_key, inner_value)| arg_defn = argument_definitions[inner_key.to_s] arg_value = wrap_value(inner_value, arg_defn.type) string_key = arg_defn.expose_as memo[string_key] = ArgumentValue.new(string_key, arg_value, arg_defn) memo end end |
Class Attribute Details
.argument_definitions ⇒ Object
Returns the value of attribute argument_definitions.
91 92 93 |
# File 'lib/graphql/query/arguments.rb', line 91 def argument_definitions @argument_definitions end |
Class Method Details
.construct_arguments_class(argument_owner) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/graphql/query/arguments.rb', line 10 def self.construct_arguments_class(argument_owner) argument_definitions = argument_owner.arguments argument_owner.arguments_class = Class.new(self) do self.argument_definitions = argument_definitions def initialize(values) super(values, argument_definitions: self.class.argument_definitions) end argument_definitions.each do |_arg_name, arg_definition| expose_as = arg_definition.expose_as.to_s # Don't define a helper method if it would override something. if instance_methods.include?(expose_as) warn( "Unable to define a helper for argument with name '#{expose_as}' "\ "as this is a reserved name. If you're using an argument such as "\ "`argument #{expose_as}`, consider renaming this argument.`" ) next end define_method(expose_as) do self[expose_as] end end end end |
Instance Method Details
#[](key) ⇒ Object
Returns the argument at that key.
52 53 54 55 |
# File 'lib/graphql/query/arguments.rb', line 52 def [](key) key_s = key.is_a?(String) ? key : key.to_s @argument_values.fetch(key_s, NULL_ARGUMENT_VALUE).value end |
#each_value {|argument_value| ... } ⇒ Object
Access each key, value and type for the arguments in this set.
82 83 84 85 86 |
# File 'lib/graphql/query/arguments.rb', line 82 def each_value @argument_values.each_value do |argument_value| yield(argument_value) end end |
#key?(key) ⇒ Boolean
Returns true if the argument was present in this field.
59 60 61 62 |
# File 'lib/graphql/query/arguments.rb', line 59 def key?(key) key_s = key.is_a?(String) ? key : key.to_s @argument_values.key?(key_s) end |
#to_h ⇒ Hash
Get the hash of all values, with stringified keys
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/graphql/query/arguments.rb', line 66 def to_h @to_h ||= begin h = {} each_value do |arg_value| arg_key = arg_value.definition.expose_as h[arg_key] = unwrap_value(arg_value.value) end h end end |