Class: GraphQL::Execution::Interpreter::Arguments
- Inherits:
-
Object
- Object
- GraphQL::Execution::Interpreter::Arguments
- Extended by:
- Forwardable
- Includes:
- Dig
- Defined in:
- lib/graphql/execution/interpreter/arguments.rb
Overview
A wrapper for argument hashes in GraphQL queries.
This object is immutable so that the runtime code can be sure that modifications don't leak from one use to another
See GraphQL::Query#arguments_for to get access to these objects.
Constant Summary collapse
- NO_ARGS =
GraphQL::EmptyObjects::EMPTY_HASH
- EMPTY =
self.new(argument_values: nil, keyword_arguments: NO_ARGS).freeze
Instance Attribute Summary collapse
-
#argument_values ⇒ Object
readonly
Returns.
-
#keyword_arguments ⇒ Object
readonly
The Ruby-style arguments hash, ready for a resolver.
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(keyword_arguments: nil, argument_values:) ⇒ Arguments
constructor
Parameters.
- #inspect ⇒ Object
-
#merge_extras(extra_args) ⇒ Object
Create a new arguments instance which includes these extras.
Methods included from Dig
Constructor Details
#initialize(keyword_arguments: nil, argument_values:) ⇒ Arguments
Parameters
argument_values(nil, Hash{Symbol => ArgumentValue})keyword_arguments(nil, Hash{Symbol => Object})
:call-seq:
initialize(nil | Hash[Symbol, Object] keyword_arguments:, nil | Hash[Symbol, ArgumentValue] argument_values:)
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/graphql/execution/interpreter/arguments.rb', line 33 def initialize(keyword_arguments: nil, argument_values:) @empty = argument_values.nil? || argument_values.empty? # This is only present when `extras` have been merged in: if keyword_arguments # This is a little crazy. We expect the `:argument_details` extra to _include extras_, # but the object isn't created until _after_ extras are put together. # So, we have to use a special flag here to say, "at the last minute, add yourself to the keyword args." # # Otherwise: # - We can't access the final Arguments instance _while_ we're preparing extras # - After we _can_ access it, it's frozen, so we can't add anything. # # So, this flag gives us a chance to sneak it in before freezing, _and_ while we have access # to the new Arguments instance itself. if keyword_arguments[:argument_details] == :__arguments_add_self keyword_arguments[:argument_details] = self end @keyword_arguments = keyword_arguments.freeze elsif !@empty @keyword_arguments = {} argument_values.each do |name, arg_val| @keyword_arguments[name] = arg_val.value end @keyword_arguments.freeze else @keyword_arguments = NO_ARGS end @argument_values = argument_values ? argument_values.freeze : NO_ARGS freeze end |
Instance Attribute Details
#argument_values ⇒ Object (readonly)
Returns
Hash{Symbol => ArgumentValue}
67 68 69 |
# File 'lib/graphql/execution/interpreter/arguments.rb', line 67 def argument_values @argument_values end |
#keyword_arguments ⇒ Object (readonly)
The Ruby-style arguments hash, ready for a resolver. This hash is the one used at runtime.
Returns
Hash<Symbol, Object>
24 25 26 |
# File 'lib/graphql/execution/interpreter/arguments.rb', line 24 def keyword_arguments @keyword_arguments end |
Instance Method Details
#empty? ⇒ Boolean
69 70 71 |
# File 'lib/graphql/execution/interpreter/arguments.rb', line 69 def empty? @empty end |
#inspect ⇒ Object
76 77 78 |
# File 'lib/graphql/execution/interpreter/arguments.rb', line 76 def inspect "#<#{self.class} @keyword_arguments=#{keyword_arguments.inspect}>" end |
#merge_extras(extra_args) ⇒ Object
Create a new arguments instance which includes these extras.
This is called by the runtime to implement field extras: [...]
Parameters
extra_args(Hash<Symbol => Object>)
Returns
Interpreter::Arguments
92 93 94 95 96 97 |
# File 'lib/graphql/execution/interpreter/arguments.rb', line 92 def merge_extras(extra_args) # :nodoc: self.class.new( argument_values: argument_values, keyword_arguments: keyword_arguments.merge(extra_args) ) end |