Class: GraphQL::InternalRepresentation::Node
- Inherits:
-
Object
- Object
- GraphQL::InternalRepresentation::Node
- Defined in:
- lib/graphql/internal_representation/node.rb
Instance Attribute Summary collapse
-
#ast_node ⇒ GraphQL::Language::Nodes::AbstractNode
readonly
The AST node (or one of the nodes) where this was derived from.
- #children ⇒ Array<GraphQL::Query::Node> readonly
-
#definition ⇒ GraphQL::Field, GraphQL::Directive
readonly
The definition to use to execute this node.
-
#directives ⇒ Set<GraphQL::Language::Nodes::Directive>
readonly
These are the compiled directives from fragment spreads, inline fragments, and the field itself.
-
#name ⇒ String
readonly
The name to use for the result in the response hash.
-
#on_types ⇒ Set<GraphQL::ObjectType, GraphQL::InterfaceType>
readonly
This may come from the previous field’s return value or an explicitly-typed fragment { person(id: 1) { firstName # => on_type is person } } { node(id: $nodeId) { … on Nameable { firstName # => on_type is Nameable } } }.
- #return_type ⇒ GraphQL::BaseType readonly
-
#spreads ⇒ Array<GraphQL::Language::Nodes::FragmentSpreads>
readonly
Note: by the time this gets out of the Rewrite phase, this will be empty – it’s emptied out when fragments are merged back in.
Instance Method Summary collapse
- #dup ⇒ Object
-
#initialize(ast_node:, return_type: nil, on_types: Set.new, name: nil, definition: nil, children: {}, spreads: [], directives: Set.new) ⇒ Node
constructor
A new instance of Node.
- #inspect(indent = 0) ⇒ Object
Constructor Details
#initialize(ast_node:, return_type: nil, on_types: Set.new, name: nil, definition: nil, children: {}, spreads: [], directives: Set.new) ⇒ Node
Returns a new instance of Node.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/graphql/internal_representation/node.rb', line 6 def initialize(ast_node:, return_type: nil, on_types: Set.new, name: nil, definition: nil, children: {}, spreads: [], directives: Set.new) @ast_node = ast_node @return_type = return_type @on_types = on_types @name = name @definition = definition @children = children @spreads = spreads @directives = directives end |
Instance Attribute Details
#ast_node ⇒ GraphQL::Language::Nodes::AbstractNode (readonly)
Returns The AST node (or one of the nodes) where this was derived from.
32 33 34 |
# File 'lib/graphql/internal_representation/node.rb', line 32 def ast_node @ast_node end |
#children ⇒ Array<GraphQL::Query::Node> (readonly)
56 57 58 |
# File 'lib/graphql/internal_representation/node.rb', line 56 def children @children end |
#definition ⇒ GraphQL::Field, GraphQL::Directive (readonly)
Returns The definition to use to execute this node.
26 27 28 |
# File 'lib/graphql/internal_representation/node.rb', line 26 def definition @definition end |
#directives ⇒ Set<GraphQL::Language::Nodes::Directive> (readonly)
These are the compiled directives from fragment spreads, inline fragments, and the field itself
23 24 25 |
# File 'lib/graphql/internal_representation/node.rb', line 23 def directives @directives end |
#name ⇒ String (readonly)
Returns the name to use for the result in the response hash.
29 30 31 |
# File 'lib/graphql/internal_representation/node.rb', line 29 def name @name end |
#on_types ⇒ Set<GraphQL::ObjectType, GraphQL::InterfaceType> (readonly)
This may come from the previous field’s return value or an explicitly-typed fragment {
person(id: 1) {
firstName # => on_type is person
}
} {
node(id: $nodeId) {
... on Nameable {
firstName # => on_type is Nameable
}
}
}
50 51 52 |
# File 'lib/graphql/internal_representation/node.rb', line 50 def on_types @on_types end |
#return_type ⇒ GraphQL::BaseType (readonly)
53 54 55 |
# File 'lib/graphql/internal_representation/node.rb', line 53 def return_type @return_type end |
#spreads ⇒ Array<GraphQL::Language::Nodes::FragmentSpreads> (readonly)
Note: by the time this gets out of the Rewrite phase, this will be empty – it’s emptied out when fragments are merged back in
19 20 21 |
# File 'lib/graphql/internal_representation/node.rb', line 19 def spreads @spreads end |
Instance Method Details
#dup ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/graphql/internal_representation/node.rb', line 67 def dup self.class.new({ ast_node: ast_node, return_type: return_type, on_types: on_types, name: name, definition: definition, children: children, spreads: spreads, directives: directives, }) end |
#inspect(indent = 0) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/graphql/internal_representation/node.rb', line 58 def inspect(indent = 0) own_indent = " " * indent self_inspect = "#{own_indent}<Node #{name} (#{definition ? definition.name + ": " : ""}{#{on_types.to_a.join("|")}} -> #{return_type})>" if children.any? self_inspect << " {\n#{children.values.map { |n| n.inspect(indent + 2 )}.join("\n")}\n#{own_indent}}" end self_inspect end |