Class: GraphQL::DSL::Operation
- Includes:
- SelectionSet
- Defined in:
- lib/graphql/dsl/nodes/operation.rb
Overview
Operation GraphQL node
Instance Attribute Summary collapse
-
#__directives ⇒ Array<Directive>
readonly
List of directives.
-
#__operation_type ⇒ Symbol
readonly
Operation type (see #initialize).
-
#__variable_definitions ⇒ Hash<Symbol, VariableDefinition>
readonly
Variable definitions.
Attributes inherited from Node
Instance Method Summary collapse
-
#__var(name, type, default: UNDEFINED, directives: []) ⇒ void
Declare operation variable.
-
#initialize(operation_type, name = nil, variable_definitions = {}, directives = [], &block) ⇒ Operation
constructor
Create operation (query, mutation, subscription).
Methods included from SelectionSet
#__field, #__fragment, #__inline_fragment
Methods inherited from Node
Constructor Details
#initialize(operation_type, name = nil, variable_definitions = {}, directives = [], &block) ⇒ Operation
Create operation (query, mutation, subscription)
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/graphql/dsl/nodes/operation.rb', line 33 def initialize(operation_type, name = nil, variable_definitions = {}, directives = [], &block) variable_definitions.each do |variable_name, _| raise Error, 'Variable name must be specified' if variable_name.nil? || variable_name.empty? end @__operation_type = operation_type @__variable_definitions = variable_definitions.transform_values do |variable_definition| VariableDefinition.from(variable_definition) end @__directives = directives.map { |directive| Directive.from(directive) } super(name, &block) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class GraphQL::DSL::SelectionSet
Instance Attribute Details
#__directives ⇒ Array<Directive> (readonly)
Returns list of directives.
20 21 22 |
# File 'lib/graphql/dsl/nodes/operation.rb', line 20 def __directives @__directives end |
#__operation_type ⇒ Symbol (readonly)
Returns operation type (see #initialize).
12 13 14 |
# File 'lib/graphql/dsl/nodes/operation.rb', line 12 def __operation_type @__operation_type end |
#__variable_definitions ⇒ Hash<Symbol, VariableDefinition> (readonly)
Returns variable definitions.
16 17 18 |
# File 'lib/graphql/dsl/nodes/operation.rb', line 16 def __variable_definitions @__variable_definitions end |
Instance Method Details
#__var(name, type, default: UNDEFINED, directives: []) ⇒ void
This method returns an undefined value.
Declare operation variable
56 57 58 |
# File 'lib/graphql/dsl/nodes/operation.rb', line 56 def __var(name, type, default: UNDEFINED, directives: []) @__variable_definitions[name] = VariableDefinition.new(type, default, directives) end |