Class: GraphQL::InternalRepresentation::Selection
- Inherits:
-
Object
- Object
- GraphQL::InternalRepresentation::Selection
- Defined in:
- lib/graphql/internal_representation/selection.rb
Overview
A selection is a single field on an object. It's "backed" by one or more Nodes.
Instance Attribute Summary collapse
-
#definition_name ⇒ String
readonly
Name of the field in this selection.
-
#irep_node ⇒ Node
readonly
A "representative" node for this selection.
-
#name ⇒ String
readonly
The key of this selection in the result (may be the field's alias).
Instance Method Summary collapse
-
#each_selection(type:) {|name, subselection| ... } ⇒ Object
Call the block with each name & subselection whose conditions match
type
. -
#initialize(query:, nodes:) ⇒ Selection
constructor
A new instance of Selection.
-
#skipped? ⇒ Boolean
True if any of the backing nodes are skipped.
Constructor Details
#initialize(query:, nodes:) ⇒ Selection
Returns a new instance of Selection.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/graphql/internal_representation/selection.rb', line 7 def initialize(query:, nodes:) @irep_node = nodes.first @definition_name = @irep_node.definition_name @name = @irep_node.name @skipped = nodes.any?(&:skipped?) @query = query @typed_child_nodes = build_typed_selections(query, nodes) @typed_subselections = Hash.new { |h, k| h[k] = {} } end |
Instance Attribute Details
#definition_name ⇒ String (readonly)
Returns name of the field in this selection.
19 20 21 |
# File 'lib/graphql/internal_representation/selection.rb', line 19 def definition_name @definition_name end |
#irep_node ⇒ Node (readonly)
Returns A "representative" node for this selection. Legacy. In the case that a selection appears in multiple nodes, is this valuable?.
25 26 27 |
# File 'lib/graphql/internal_representation/selection.rb', line 25 def irep_node @irep_node end |
#name ⇒ String (readonly)
Returns the key of this selection in the result (may be the field's alias).
22 23 24 |
# File 'lib/graphql/internal_representation/selection.rb', line 22 def name @name end |
Instance Method Details
#each_selection(type:) {|name, subselection| ... } ⇒ Object
Call the block with each name & subselection whose conditions match type
36 37 38 39 40 41 42 43 44 |
# File 'lib/graphql/internal_representation/selection.rb', line 36 def each_selection(type:) subselections = @typed_subselections[type] @typed_child_nodes[type].each do |name, child_nodes| subselection = subselections[name] ||= self.class.new(query: @query, nodes: child_nodes) if !subselection.skipped? yield(name, subselection) end end end |
#skipped? ⇒ Boolean
Returns true if any of the backing nodes are skipped.
28 29 30 |
# File 'lib/graphql/internal_representation/selection.rb', line 28 def skipped? @skipped end |