Class: GraphQL::Execution::SelectionResult
- Inherits:
-
Object
- Object
- GraphQL::Execution::SelectionResult
- Defined in:
- lib/graphql/execution/selection_result.rb
Overview
A set of key-value pairs suitable for a GraphQL response.
Instance Method Summary collapse
-
#each ⇒ Object
Visit each key-result pair in this result.
-
#fetch(key) ⇒ FieldResult
The result for this field.
-
#initialize ⇒ SelectionResult
constructor
A new instance of SelectionResult.
-
#invalid_null? ⇒ Boolean
True if this selection has been nullified by a null child.
- #owner=(field_result) ⇒ Object
-
#propagate_null ⇒ Object
A field has been unexpectedly nullified.
- #set(key, field_result) ⇒ Object
-
#to_h ⇒ Hash
A plain Hash representation of this result.
Constructor Details
#initialize ⇒ SelectionResult
Returns a new instance of SelectionResult.
6 7 8 9 10 |
# File 'lib/graphql/execution/selection_result.rb', line 6 def initialize @storage = {} @owner = nil @invalid_null = false end |
Instance Method Details
#each ⇒ Object
Visit each key-result pair in this result
25 26 27 28 29 |
# File 'lib/graphql/execution/selection_result.rb', line 25 def each @storage.each do |key, field_res| yield(key, field_res) end end |
#fetch(key) ⇒ FieldResult
Returns The result for this field.
20 21 22 |
# File 'lib/graphql/execution/selection_result.rb', line 20 def fetch(key) @storage.fetch(key) end |
#invalid_null? ⇒ Boolean
Returns True if this selection has been nullified by a null child.
51 52 53 |
# File 'lib/graphql/execution/selection_result.rb', line 51 def invalid_null? @invalid_null end |
#owner=(field_result) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/graphql/execution/selection_result.rb', line 56 def owner=(field_result) if @owner raise("Can't change owners of SelectionResult") else @owner = field_result end end |
#propagate_null ⇒ Object
A field has been unexpectedly nullified. Tell the owner FieldResult if it is present. Record #invalid_null in case an owner is added later.
43 44 45 46 47 48 |
# File 'lib/graphql/execution/selection_result.rb', line 43 def propagate_null if @owner @owner.value = GraphQL::Execution::Execute::PROPAGATE_NULL end @invalid_null = true end |
#set(key, field_result) ⇒ Object
14 15 16 |
# File 'lib/graphql/execution/selection_result.rb', line 14 def set(key, field_result) @storage[key] = field_result end |
#to_h ⇒ Hash
Returns A plain Hash representation of this result.
32 33 34 35 36 37 38 |
# File 'lib/graphql/execution/selection_result.rb', line 32 def to_h if @invalid_null nil else flatten(self) end end |