Class: GraphQL::Language::Nodes::OperationDefinition
- Inherits:
-
AbstractNode
- Object
- AbstractNode
- GraphQL::Language::Nodes::OperationDefinition
- Defined in:
- lib/graphql/language/nodes.rb
Overview
A query, mutation or subscription.
May be anonymous or named.
May be explicitly typed (eg mutation { ... }) or implicitly a query (eg { ... }).
Constant Summary
Constants inherited from AbstractNode
Instance Attribute Summary collapse
-
#directives ⇒ Object
readonly
: Array.
-
#name ⇒ Object
readonly
Returns.
-
#operation_type ⇒ Object
readonly
Returns.
-
#selections ⇒ Object
readonly
Returns.
-
#variables ⇒ Object
readonly
Returns.
Attributes inherited from AbstractNode
Class Method Summary collapse
-
.from_a(filename, line, col, operation_type, name, variables, directives, selections, comment: nil) ⇒ Object
rubocop:disable Metrics/ParameterLists.
Instance Method Summary collapse
- #children ⇒ Object
- #initialize(operation_type: nil, name: nil, variables: NO_CHILDREN, directives: NO_CHILDREN, selections: NO_CHILDREN, line: nil, col: nil, pos: nil, filename: nil, source: nil, definition_pos: nil) ⇒ OperationDefinition constructor
- #marshal_dump ⇒ Object
- #marshal_load(values) ⇒ Object
- #merge_directive(**node_opts) ⇒ Object
- #merge_selection(**node_opts) ⇒ Object
- #merge_variable(**node_opts) ⇒ Object
- #scalars ⇒ Object
- #visit_method ⇒ Object
Methods inherited from AbstractNode
#==, #children_method_name, children_of_type, #col, #definition_line, #delete_child, inherited, #initialize_copy, #line, #merge, #position, #replace_child, #to_query_string
Constructor Details
#initialize(operation_type: nil, name: nil, variables: NO_CHILDREN, directives: NO_CHILDREN, selections: NO_CHILDREN, line: nil, col: nil, pos: nil, filename: nil, source: nil, definition_pos: nil) ⇒ OperationDefinition
1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 |
# File 'lib/graphql/language/nodes.rb', line 1074 def initialize(operation_type: nil, name: nil, variables: NO_CHILDREN, directives: NO_CHILDREN, selections: NO_CHILDREN, line: nil, col: nil, pos: nil, filename: nil, source: nil, definition_pos: nil) @line = line @col = col @pos = pos @filename = filename @source = source @operation_type = operation_type @name = name @variables = variables.freeze @directives = directives.freeze @selections = selections.freeze @definition_pos = definition_pos end |
Instance Attribute Details
#directives ⇒ Object (readonly)
: Array
1038 1039 1040 |
# File 'lib/graphql/language/nodes.rb', line 1038 def directives @directives end |
#name ⇒ Object (readonly)
Returns
String, nil— The name for this operation, ornilif unnamed : String?
1026 1027 1028 |
# File 'lib/graphql/language/nodes.rb', line 1026 def name @name end |
#operation_type ⇒ Object (readonly)
Returns
String— The root type for this operation:"query"(including implicit queries),"mutation"or"subscription": String
1020 1021 1022 |
# File 'lib/graphql/language/nodes.rb', line 1020 def operation_type @operation_type end |
#selections ⇒ Object (readonly)
Returns
Array<Field, FragmentSpread, InlineFragment>— Root-level fields on this operation
: Array[Field | FragmentSpread | InlineFragment]
1044 1045 1046 |
# File 'lib/graphql/language/nodes.rb', line 1044 def selections @selections end |
#variables ⇒ Object (readonly)
Returns
Array<VariableDefinition>— Variable $definitions for this operation : Array
1036 1037 1038 |
# File 'lib/graphql/language/nodes.rb', line 1036 def variables @variables end |
Class Method Details
.from_a(filename, line, col, operation_type, name, variables, directives, selections, comment: nil) ⇒ Object
rubocop:disable Metrics/ParameterLists
1088 1089 1090 |
# File 'lib/graphql/language/nodes.rb', line 1088 def self.from_a(filename, line, col, operation_type, name, variables, directives, selections, comment: nil) # rubocop:disable Metrics/ParameterLists self.new(filename: filename, line: line, col: col, operation_type: operation_type, name: name, variables: variables, directives: directives, selections: selections) end |
Instance Method Details
#children ⇒ Object
1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 |
# File 'lib/graphql/language/nodes.rb', line 1058 def children @children ||= begin if !@variables.empty? || !@directives.empty? || !@selections.empty? new_children = [] new_children.concat(@variables) new_children.concat(@directives) new_children.concat(@selections) new_children.freeze new_children else NO_CHILDREN end end end |
#marshal_dump ⇒ Object
1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 |
# File 'lib/graphql/language/nodes.rb', line 1092 def marshal_dump [ line, col, # use methods here to force them to be calculated @filename, @operation_type, @name, @variables, @directives, @selections, ] end |
#marshal_load(values) ⇒ Object
1104 1105 1106 |
# File 'lib/graphql/language/nodes.rb', line 1104 def marshal_load(values) @line, @col, @filename, @operation_type, @name, @variables, @directives, @selections = values end |
#merge_directive(**node_opts) ⇒ Object
1050 1051 1052 |
# File 'lib/graphql/language/nodes.rb', line 1050 def merge_directive(**node_opts) merge(directives: directives + [GraphQL::Language::Nodes::Directive.new(**node_opts)]) end |
#merge_selection(**node_opts) ⇒ Object
1054 1055 1056 |
# File 'lib/graphql/language/nodes.rb', line 1054 def merge_selection(**node_opts) merge(selections: selections + [GraphQL::Language::Nodes::Field.new(**node_opts)]) end |
#merge_variable(**node_opts) ⇒ Object
1046 1047 1048 |
# File 'lib/graphql/language/nodes.rb', line 1046 def merge_variable(**node_opts) merge(variables: variables + [GraphQL::Language::Nodes::VariableDefinition.new(**node_opts)]) end |
#scalars ⇒ Object
1028 1029 1030 |
# File 'lib/graphql/language/nodes.rb', line 1028 def scalars @scalars ||= [@operation_type, @name].freeze end |
#visit_method ⇒ Object
1012 1013 1014 |
# File 'lib/graphql/language/nodes.rb', line 1012 def visit_method :on_operation_definition end |