Class: GraphQL::Query::Arguments
- Inherits:
-
Object
- Object
- GraphQL::Query::Arguments
- Extended by:
- Forwardable
- Defined in:
- lib/graphql/query/arguments.rb
Overview
Defined Under Namespace
Classes: ArgumentValue
Constant Summary collapse
- NO_ARGS =
self.new({}, argument_definitions: [])
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 original Ruby hash.
Constructor Details
#initialize(values, argument_definitions:) ⇒ Arguments
Returns a new instance of Arguments.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/graphql/query/arguments.rb', line 10 def initialize(values, argument_definitions:) @original_values = values @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 |
Instance Method Details
#[](key) ⇒ Object
Returns the argument at that key.
24 25 26 |
# File 'lib/graphql/query/arguments.rb', line 24 def [](key) @argument_values.fetch(key.to_s, NULL_ARGUMENT_VALUE).value end |
#each_value {|argument_value| ... } ⇒ Object
Access each key, value and type for the arguments in this set.
45 46 47 48 49 |
# File 'lib/graphql/query/arguments.rb', line 45 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.
30 31 32 |
# File 'lib/graphql/query/arguments.rb', line 30 def key?(key) @argument_values.key?(key.to_s) end |
#to_h ⇒ Hash
Get the original Ruby hash
36 37 38 |
# File 'lib/graphql/query/arguments.rb', line 36 def to_h @unwrapped_values ||= unwrap_value(@original_values) end |