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_name ⇒ String
readonly
The name for this node’s definition (#name may be a field’s alias, this is always the name).
-
#definitions ⇒ Hash<GraphQL::BaseType => GraphQL::Field>
readonly
A cache of type-field pairs for executing & analyzing 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.
-
#parent ⇒ GraphQL::InternalRepresentation::Node
readonly
The node which this node is a child of.
- #return_type ⇒ GraphQL::BaseType readonly
-
#spreads ⇒ Array<GraphQL::InternalRepresentation::Node>
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
-
#initialize(parent:, ast_node: nil, return_type: nil, name: nil, definition_name: nil, definitions: {}, children: {}, spreads: [], directives: Set.new) ⇒ Node
constructor
A new instance of Node.
- #inspect(indent = 0) ⇒ Object
-
#owner ⇒ GraphQL::InternalRepresentation::Node
The root node which this node is a (perhaps-distant) child of, or ‘self` if this is a root node.
Constructor Details
#initialize(parent:, ast_node: nil, return_type: nil, name: nil, definition_name: nil, definitions: {}, children: {}, spreads: [], directives: Set.new) ⇒ Node
Returns a new instance of Node.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/graphql/internal_representation/node.rb', line 6 def initialize(parent:, ast_node: nil, return_type: nil, name: nil, definition_name: nil, definitions: {}, children: {}, spreads: [], directives: Set.new) # Make sure these are kept in sync with #dup @ast_node = ast_node @return_type = return_type @name = name @definition_name = definition_name @parent = parent @definitions = definitions @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.
53 54 55 |
# File 'lib/graphql/internal_representation/node.rb', line 53 def ast_node @ast_node end |
#children ⇒ Array<GraphQL::Query::Node> (readonly)
59 60 61 |
# File 'lib/graphql/internal_representation/node.rb', line 59 def children @children end |
#definition_name ⇒ String (readonly)
Returns the name for this node’s definition (#name may be a field’s alias, this is always the name).
28 29 30 |
# File 'lib/graphql/internal_representation/node.rb', line 28 def definition_name @definition_name end |
#definitions ⇒ Hash<GraphQL::BaseType => GraphQL::Field> (readonly)
A cache of type-field pairs for executing & analyzing this node
{
person(id: 1) {
firstName # => defined type is person
}
} {
node(id: $nodeId) {
... on Nameable {
firstName # => defined type is Nameable
}
}
}
47 48 49 |
# File 'lib/graphql/internal_representation/node.rb', line 47 def definitions @definitions end |
#directives ⇒ Set<GraphQL::Language::Nodes::Directive> (readonly)
These are the compiled directives from fragment spreads, inline fragments, and the field itself
25 26 27 |
# File 'lib/graphql/internal_representation/node.rb', line 25 def directives @directives end |
#name ⇒ String (readonly)
Returns the name to use for the result in the response hash.
50 51 52 |
# File 'lib/graphql/internal_representation/node.rb', line 50 def name @name end |
#parent ⇒ GraphQL::InternalRepresentation::Node (readonly)
Returns The node which this node is a child of.
62 63 64 |
# File 'lib/graphql/internal_representation/node.rb', line 62 def parent @parent end |
#return_type ⇒ GraphQL::BaseType (readonly)
56 57 58 |
# File 'lib/graphql/internal_representation/node.rb', line 56 def return_type @return_type end |
#spreads ⇒ Array<GraphQL::InternalRepresentation::Node> (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
21 22 23 |
# File 'lib/graphql/internal_representation/node.rb', line 21 def spreads @spreads end |
Instance Method Details
#inspect(indent = 0) ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/graphql/internal_representation/node.rb', line 75 def inspect(indent = 0) own_indent = " " * indent self_inspect = "#{own_indent}<Node #{name} (#{definition_name}: {#{definitions.keys.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 |
#owner ⇒ GraphQL::InternalRepresentation::Node
Returns The root node which this node is a (perhaps-distant) child of, or ‘self` if this is a root node.
65 66 67 68 69 70 71 72 73 |
# File 'lib/graphql/internal_representation/node.rb', line 65 def owner @owner ||= begin if parent.nil? self else parent.owner end end end |