Class: GraphQL::Client::DefinitionVariables::VariablesVisitor
- Inherits:
-
Language::Visitor
- Object
- Language::Visitor
- GraphQL::Client::DefinitionVariables::VariablesVisitor
- Includes:
- TypeStack
- Defined in:
- lib/graphql/client/definition_variables.rb
Instance Attribute Summary collapse
-
#variables ⇒ Object
readonly
Returns the value of attribute variables.
Attributes included from TypeStack
#argument_definitions, #directive_definitions, #field_definitions, #object_types, #path, #schema
Instance Method Summary collapse
-
#initialize(*_args, **_kwargs) ⇒ VariablesVisitor
constructor
A new instance of VariablesVisitor.
- #on_variable_identifier(node, parent) ⇒ Object
Methods included from TypeStack
#on_argument, #on_directive, #on_field, #on_fragment_definition, #on_fragment_spread, #on_inline_fragment, #on_operation_definition
Constructor Details
#initialize(*_args, **_kwargs) ⇒ VariablesVisitor
Returns a new instance of VariablesVisitor.
35 36 37 38 |
# File 'lib/graphql/client/definition_variables.rb', line 35 def initialize(*_args, **_kwargs) super @variables = {} end |
Instance Attribute Details
#variables ⇒ Object (readonly)
Returns the value of attribute variables.
40 41 42 |
# File 'lib/graphql/client/definition_variables.rb', line 40 def variables @variables end |
Instance Method Details
#on_variable_identifier(node, parent) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/graphql/client/definition_variables.rb', line 42 def on_variable_identifier(node, parent) if definition = @argument_definitions.last existing_type = @variables[node.name.to_sym] if existing_type && existing_type.unwrap != definition.type.unwrap raise GraphQL::Client::ValidationError, "$#{node.name} was already declared as #{existing_type.unwrap}, but was #{definition.type.unwrap}" elsif !(existing_type && existing_type.kind.non_null?) @variables[node.name.to_sym] = definition.type end end super end |