class GraphQL::Language::Nodes::AbstractNode
{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
Attributes
Public Class Methods
Initialize a node by extracting its position, then calling the class's `initialize_node` method. @param options [Hash] Initial attributes for this node
# File lib/graphql/language/nodes.rb, line 25 def initialize(options={}) if options.key?(:position_source) position_source = options.delete(:position_source) @line, @col = position_source.line_and_column end @filename = options.delete(:filename) initialize_node(options) end
Public Instance Methods
@return [Array<GraphQL::Language::Nodes::AbstractNode>] all nodes in the tree below this one
# File lib/graphql/language/nodes.rb, line 51 def children [] end
Value equality @return [Boolean] True if `self` is equivalent to `other`
# File lib/graphql/language/nodes.rb, line 43 def eql?(other) return true if equal?(other) other.is_a?(self.class) && other.scalars.eql?(self.scalars) && other.children.eql?(self.children) end
This is called with node-specific options
# File lib/graphql/language/nodes.rb, line 37 def initialize_node(options={}) raise NotImplementedError end
# File lib/graphql/language/nodes.rb, line 60 def position [line, col] end
@return [Array<Integer, Float, String, Boolean, Array>] Scalar values attached to this node
# File lib/graphql/language/nodes.rb, line 56 def scalars [] end
# File lib/graphql/language/nodes.rb, line 64 def to_query_string(printer: GraphQL::Language::Printer.new) printer.print(self) end