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
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 ⇒ Hash{Symbol => ArgumentValue} readonly
-
#keyword_arguments ⇒ Hash<Symbol, 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
A new instance of Arguments.
- #inspect ⇒ Object
-
#merge_extras(extra_args) ⇒ Interpreter::Arguments
private
Create a new arguments instance which includes these extras.
Methods included from Dig
Constructor Details
#initialize(keyword_arguments: nil, argument_values:) ⇒ Arguments
Returns a new instance of Arguments.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/graphql/execution/interpreter/arguments.rb', line 24 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 ⇒ Hash{Symbol => ArgumentValue} (readonly)
56 57 58 |
# File 'lib/graphql/execution/interpreter/arguments.rb', line 56 def argument_values @argument_values end |
#keyword_arguments ⇒ Hash<Symbol, Object> (readonly)
The Ruby-style arguments hash, ready for a resolver. This hash is the one used at runtime.
20 21 22 |
# File 'lib/graphql/execution/interpreter/arguments.rb', line 20 def keyword_arguments @keyword_arguments end |
Instance Method Details
#empty? ⇒ Boolean
58 59 60 |
# File 'lib/graphql/execution/interpreter/arguments.rb', line 58 def empty? @empty end |
#inspect ⇒ Object
65 66 67 |
# File 'lib/graphql/execution/interpreter/arguments.rb', line 65 def inspect "#<#{self.class} @keyword_arguments=#{keyword_arguments.inspect}>" end |
#merge_extras(extra_args) ⇒ Interpreter::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.
Create a new arguments instance which includes these extras.
This is called by the runtime to implement field extras: [...]
76 77 78 79 80 81 |
# File 'lib/graphql/execution/interpreter/arguments.rb', line 76 def merge_extras(extra_args) self.class.new( argument_values: argument_values, keyword_arguments: keyword_arguments.merge(extra_args) ) end |