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<Node>
readonly
deprecated
Deprecated.
use #typed_children instead
-
#definition ⇒ GraphQL::Field, GraphQL::Directive
readonly
The static definition for this field (it might be an interface field definition even though an object field definition will be used at runtime).
-
#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
deprecated
Deprecated.
use #typed_children to find matching children, the use the node's #definition
-
#directives ⇒ Set<GraphQL::Language::Nodes::Directive>
readonly
These are the compiled directives from fragment spreads, inline fragments, and the field itself.
-
#included ⇒ Boolean
(also: #included?)
False if every field for this node included
@skip(if: true)
. -
#index ⇒ Object
writeonly
Sets the attribute index.
-
#name ⇒ String
readonly
The name to use for the result in the response hash.
- #owner_type ⇒ GraphQL::BaseType readonly
-
#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.
-
#typed_children ⇒ Hash{GraphQL::BaseType => Hash{String => Node}] Children for each type condition
readonly
Hash=> Hash{String => Node] Children for each type condition.
Instance Method Summary collapse
-
#initialize(parent:, ast_node: nil, return_type: nil, owner_type: nil, name: nil, definition_name: nil, definition: nil, spreads: [], directives: Set.new, included: true, typed_children: Hash.new {|h, k| h[k] = {} }, definitions: {}, children: {}) ⇒ 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. - #path ⇒ Object
- #skipped? ⇒ Boolean
Constructor Details
#initialize(parent:, ast_node: nil, return_type: nil, owner_type: nil, name: nil, definition_name: nil, definition: nil, spreads: [], directives: Set.new, included: true, typed_children: Hash.new {|h, k| h[k] = {} }, definitions: {}, children: {}) ⇒ Node
Returns a new instance of Node.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/graphql/internal_representation/node.rb', line 7 def initialize(parent:, ast_node: nil, return_type: nil, owner_type: nil, name: nil, definition_name: nil, definition: nil, spreads: [], directives: Set.new, included: true, typed_children: Hash.new {|h, k| h[k] = {} }, definitions: {}, children: {}) @ast_node = ast_node @return_type = return_type @owner_type = owner_type @name = name @definition_name = definition_name @definition = definition @parent = parent @spreads = spreads @directives = directives @included = included @typed_children = typed_children @children = children @definitions = definitions 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.
66 67 68 |
# File 'lib/graphql/internal_representation/node.rb', line 66 def ast_node @ast_node end |
#children ⇒ Array<Node> (readonly)
use #typed_children instead
Returns leaf selections on this node. Known to be buggy: deeply nested selections are not handled properly
78 79 80 |
# File 'lib/graphql/internal_representation/node.rb', line 78 def children @children end |
#definition ⇒ GraphQL::Field, GraphQL::Directive (readonly)
Returns the static definition for this field (it might be an interface field definition even though an object field definition will be used at runtime).
60 61 62 |
# File 'lib/graphql/internal_representation/node.rb', line 60 def definition @definition 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).
35 36 37 |
# File 'lib/graphql/internal_representation/node.rb', line 35 def definition_name @definition_name end |
#definitions ⇒ Hash<GraphQL::BaseType => GraphQL::Field> (readonly)
use #typed_children to find matching children, the use the node's #definition
A shallow cache of type-field pairs for executing & analyzing this node.
Known to be buggy: some fields are deeply merged when they shouldn't be.
{ person(id: 1) { firstName # => defined type is person } } { node(id: $nodeId) { ... on Nameable { firstName # => defined type is Nameable } } }
57 58 59 |
# File 'lib/graphql/internal_representation/node.rb', line 57 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
32 33 34 |
# File 'lib/graphql/internal_representation/node.rb', line 32 def directives @directives end |
#included ⇒ Boolean Also known as: included?
Returns false if every field for this node included @skip(if: true)
.
81 82 83 |
# File 'lib/graphql/internal_representation/node.rb', line 81 def included @included end |
#index=(value) ⇒ Object (writeonly)
Sets the attribute index
114 115 116 |
# File 'lib/graphql/internal_representation/node.rb', line 114 def index=(value) @index = value end |
#name ⇒ String (readonly)
Returns the name to use for the result in the response hash.
63 64 65 |
# File 'lib/graphql/internal_representation/node.rb', line 63 def name @name end |
#owner_type ⇒ GraphQL::BaseType (readonly)
72 73 74 |
# File 'lib/graphql/internal_representation/node.rb', line 72 def owner_type @owner_type end |
#parent ⇒ GraphQL::InternalRepresentation::Node (readonly)
Returns The node which this node is a child of.
89 90 91 |
# File 'lib/graphql/internal_representation/node.rb', line 89 def parent @parent end |
#return_type ⇒ GraphQL::BaseType (readonly)
69 70 71 |
# File 'lib/graphql/internal_representation/node.rb', line 69 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
28 29 30 |
# File 'lib/graphql/internal_representation/node.rb', line 28 def spreads @spreads end |
#typed_children ⇒ Hash{GraphQL::BaseType => Hash{String => Node}] Children for each type condition (readonly)
Returns Hash=> Hash{String => Node] Children for each type condition.
24 25 26 |
# File 'lib/graphql/internal_representation/node.rb', line 24 def typed_children @typed_children end |
Instance Method Details
#inspect(indent = 0) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/graphql/internal_representation/node.rb', line 116 def inspect(indent = 0) own_indent = " " * indent self_inspect = "#{own_indent}<Node #{name} #{skipped? ? "(skipped)" : ""}(#{definition_name} -> #{return_type})>".dup if typed_children.any? self_inspect << " {" typed_children.each do |type_defn, children| self_inspect << "\n#{own_indent} #{type_defn} => (#{children.keys.join(",")})" end self_inspect << "\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.
92 93 94 95 96 97 98 99 100 |
# File 'lib/graphql/internal_representation/node.rb', line 92 def owner @owner ||= begin if parent.nil? self else parent.owner end end end |
#path ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/graphql/internal_representation/node.rb', line 102 def path warn("InternalRepresentation::Node#path is deprecated, use Query::Context#path instead") if parent path = parent.path path << name path << @index if @index path else [] end end |
#skipped? ⇒ Boolean
84 85 86 |
# File 'lib/graphql/internal_representation/node.rb', line 84 def skipped? !@included end |