Class: GraphQL::Language::Nodes::OperationDefinition

Inherits:
AbstractNode
  • Object
show all
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

AbstractNode::NO_CHILDREN

Instance Attribute Summary collapse

Attributes inherited from AbstractNode

#filename

Class Method Summary collapse

Instance Method Summary collapse

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

: (?operation_type: untyped, ?name: untyped, ?variables: Array, ?directives: Array, ?selections: Array[Field | FragmentSpread | InlineFragment], ?line: Integer?, ?col: Integer?, ?pos: Integer?, ?filename: String?, ?source: untyped, ?definition_pos: Integer?) -> void



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, or nil if 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