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.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/graphql/internal_representation/node.rb', line 6 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.
65 66 67 |
# File 'lib/graphql/internal_representation/node.rb', line 65 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
77 78 79 |
# File 'lib/graphql/internal_representation/node.rb', line 77 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).
59 60 61 |
# File 'lib/graphql/internal_representation/node.rb', line 59 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).
34 35 36 |
# File 'lib/graphql/internal_representation/node.rb', line 34 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 } } }
56 57 58 |
# File 'lib/graphql/internal_representation/node.rb', line 56 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
31 32 33 |
# File 'lib/graphql/internal_representation/node.rb', line 31 def directives @directives end |
#included ⇒ Boolean Also known as: included?
Returns false if every field for this node included @skip(if: true)
.
80 81 82 |
# File 'lib/graphql/internal_representation/node.rb', line 80 def included @included end |
#index=(value) ⇒ Object (writeonly)
Sets the attribute index
113 114 115 |
# File 'lib/graphql/internal_representation/node.rb', line 113 def index=(value) @index = value end |
#name ⇒ String (readonly)
Returns the name to use for the result in the response hash.
62 63 64 |
# File 'lib/graphql/internal_representation/node.rb', line 62 def name @name end |
#owner_type ⇒ GraphQL::BaseType (readonly)
71 72 73 |
# File 'lib/graphql/internal_representation/node.rb', line 71 def owner_type @owner_type end |
#parent ⇒ GraphQL::InternalRepresentation::Node (readonly)
Returns The node which this node is a child of.
88 89 90 |
# File 'lib/graphql/internal_representation/node.rb', line 88 def parent @parent end |
#return_type ⇒ GraphQL::BaseType (readonly)
68 69 70 |
# File 'lib/graphql/internal_representation/node.rb', line 68 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
27 28 29 |
# File 'lib/graphql/internal_representation/node.rb', line 27 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.
23 24 25 |
# File 'lib/graphql/internal_representation/node.rb', line 23 def typed_children @typed_children end |
Instance Method Details
#inspect(indent = 0) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/graphql/internal_representation/node.rb', line 115 def inspect(indent = 0) own_indent = " " * indent self_inspect = "#{own_indent}<Node #{name} #{skipped? ? "(skipped)" : ""}(#{definition_name} -> #{return_type})>" 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.
91 92 93 94 95 96 97 98 99 |
# File 'lib/graphql/internal_representation/node.rb', line 91 def owner @owner ||= begin if parent.nil? self else parent.owner end end end |
#path ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/graphql/internal_representation/node.rb', line 101 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
83 84 85 |
# File 'lib/graphql/internal_representation/node.rb', line 83 def skipped? !@included end |