Class: GraphQL::Language::Nodes::AbstractNode
- Inherits:
-
Object
- Object
- GraphQL::Language::Nodes::AbstractNode
- Defined in:
- lib/graphql/language/nodes.rb
Overview
AbstractNode is the base class for all nodes in a GraphQL AST.
It provides some APIs for working with ASTs:
- children
returns all AST nodes attached to this one. Used for tree traversal.
- scalars
returns all scalar (Ruby) values attached to this one. Used for comparing nodes.
- to_query_string
turns an AST node into a GraphQL string
Direct Known Subclasses
Argument, Directive, DirectiveDefinition, Document, EnumTypeDefinition, EnumTypeExtension, EnumValueDefinition, Field, FieldDefinition, FragmentDefinition, FragmentSpread, InlineFragment, InputObject, InputObjectTypeDefinition, InputObjectTypeExtension, InputValueDefinition, InterfaceTypeDefinition, InterfaceTypeExtension, NameOnlyNode, ObjectTypeDefinition, ObjectTypeExtension, OperationDefinition, ScalarTypeDefinition, ScalarTypeExtension, SchemaDefinition, SchemaExtension, UnionTypeDefinition, UnionTypeExtension, VariableDefinition, WrapperType
Defined Under Namespace
Modules: Scalars
Instance Attribute Summary collapse
-
#col ⇒ Object
Returns the value of attribute col.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#line ⇒ Object
Returns the value of attribute line.
Instance Method Summary collapse
-
#children ⇒ Array<GraphQL::Language::Nodes::AbstractNode>
All nodes in the tree below this one.
-
#eql?(other) ⇒ Boolean
Value equality.
-
#initialize(options = {}) ⇒ AbstractNode
constructor
Initialize a node by extracting its position, then calling the class’s
initialize_node
method. -
#initialize_node(options = {}) ⇒ Object
This is called with node-specific options.
-
#position ⇒ Object
-
#scalars ⇒ Array<Integer, Float, String, Boolean, Array>
Scalar values attached to this node.
-
#to_query_string(printer: GraphQL::Language::Printer.new) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ AbstractNode
Initialize a node by extracting its position,
then calling the class’s initialize_node
method.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/graphql/language/nodes.rb', line 26 def initialize(={}) if .key?(:position_source) position_source = .delete(:position_source) @line, @col = position_source.line_and_column end @filename = .delete(:filename) initialize_node() end |
Instance Attribute Details
#col ⇒ Object
Returns the value of attribute col
21 22 23 |
# File 'lib/graphql/language/nodes.rb', line 21 def col @col end |
#filename ⇒ Object
Returns the value of attribute filename
21 22 23 |
# File 'lib/graphql/language/nodes.rb', line 21 def filename @filename end |
#line ⇒ Object
Returns the value of attribute line
21 22 23 |
# File 'lib/graphql/language/nodes.rb', line 21 def line @line end |
Instance Method Details
#children ⇒ Array<GraphQL::Language::Nodes::AbstractNode>
Returns all nodes in the tree below this one
52 53 54 |
# File 'lib/graphql/language/nodes.rb', line 52 def children [] end |
#eql?(other) ⇒ Boolean
Value equality
44 45 46 47 48 49 |
# File 'lib/graphql/language/nodes.rb', line 44 def eql?(other) return true if equal?(other) other.is_a?(self.class) && other.scalars.eql?(self.scalars) && other.children.eql?(self.children) end |
#initialize_node(options = {}) ⇒ Object
This is called with node-specific options
38 39 40 |
# File 'lib/graphql/language/nodes.rb', line 38 def initialize_node(={}) raise NotImplementedError end |
#position ⇒ Object
61 62 63 |
# File 'lib/graphql/language/nodes.rb', line 61 def position [line, col] end |
#scalars ⇒ Array<Integer, Float, String, Boolean, Array>
Returns Scalar values attached to this node
57 58 59 |
# File 'lib/graphql/language/nodes.rb', line 57 def scalars [] end |