Class: GraphQL::Query::Context
- Inherits:
-
Object
- Object
- GraphQL::Query::Context
- Extended by:
- Forwardable
- Includes:
- SharedMethods
- Defined in:
- lib/graphql/query/context.rb
Overview
Expose some query-specific info to field resolve functions.
It delegates []
to the hash that’s passed to GraphQL::Query#initialize
.
Defined Under Namespace
Modules: SharedMethods Classes: ExecutionErrors, FieldResolutionContext
Instance Attribute Summary collapse
-
#errors ⇒ Array<GraphQL::ExecutionError>
readonly
Errors returned during execution.
-
#execution_strategy ⇒ Object
(also: #strategy)
Returns the value of attribute execution_strategy.
-
#path ⇒ Array<String, Integer>
readonly
The current position in the result.
-
#query ⇒ GraphQL::Query
readonly
The query whose context this is.
-
#schema ⇒ GraphQL::Schema
readonly
-
#value ⇒ Object
writeonly
private
Attributes included from SharedMethods
Instance Method Summary collapse
-
#[](key) ⇒ Object
Lookup
key
from the hash passed to Schema#execute ascontext:
. -
#[]=(key, value) ⇒ Object
Reassign
key
to the hash passed to Schema#execute ascontext:
. -
#ast_node ⇒ GraphQL::Language::Nodes::Field
The AST node for the currently-executing field.
-
#initialize(query:, values:, object:) ⇒ Context
constructor
Make a new context which delegates key lookup to
values
. -
#inspect ⇒ Object
-
#irep_node ⇒ GraphQL::InternalRepresentation::Node
The internal representation for this query node.
-
#namespace(ns) ⇒ Hash
Get an isolated hash for
ns
. -
#received_null_child ⇒ Object
private
-
#warden ⇒ GraphQL::Schema::Warden
Methods included from SharedMethods
#add_error, #backtrace, #delete, #execution_errors, #invalid_null?, #skip, #spawn_child
Constructor Details
#initialize(query:, values:, object:) ⇒ Context
Make a new context which delegates key lookup to values
140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/graphql/query/context.rb', line 140 def initialize(query:, values: , object:) @query = query @schema = query.schema @provided_values = values || {} @object = object # Namespaced storage, where user-provided values are in `nil` namespace: @storage = Hash.new { |h, k| h[k] = {} } @storage[nil] = @provided_values @errors = [] @path = [] @value = nil @context = self # for SharedMethods end |
Instance Attribute Details
#errors ⇒ Array<GraphQL::ExecutionError> (readonly)
Returns errors returned during execution
126 127 128 |
# File 'lib/graphql/query/context.rb', line 126 def errors @errors end |
#execution_strategy ⇒ Object Also known as: strategy
Returns the value of attribute execution_strategy
104 105 106 |
# File 'lib/graphql/query/context.rb', line 104 def execution_strategy @execution_strategy end |
#path ⇒ Array<String, Integer> (readonly)
Returns The current position in the result
135 136 137 |
# File 'lib/graphql/query/context.rb', line 135 def path @path end |
#query ⇒ GraphQL::Query (readonly)
Returns The query whose context this is
129 130 131 |
# File 'lib/graphql/query/context.rb', line 129 def query @query end |
#schema ⇒ GraphQL::Schema (readonly)
132 133 134 |
# File 'lib/graphql/query/context.rb', line 132 def schema @schema end |
#value=(value) ⇒ Object (writeonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
155 156 157 |
# File 'lib/graphql/query/context.rb', line 155 def value=(value) @value = value end |
Instance Method Details
#[](key) ⇒ Object
Lookup key
from the hash passed to Schema#execute as context:
|
# File 'lib/graphql/query/context.rb', line 160
|
#[]=(key, value) ⇒ Object
Reassign key
to the hash passed to Schema#execute as context:
|
# File 'lib/graphql/query/context.rb', line 163
|
#ast_node ⇒ GraphQL::Language::Nodes::Field
Returns The AST node for the currently-executing field
121 122 123 |
# File 'lib/graphql/query/context.rb', line 121 def ast_node @irep_node.ast_node end |
#inspect ⇒ Object
179 180 181 |
# File 'lib/graphql/query/context.rb', line 179 def inspect "#<Query::Context ...>" end |
#irep_node ⇒ GraphQL::InternalRepresentation::Node
Returns The internal representation for this query node
116 117 118 |
# File 'lib/graphql/query/context.rb', line 116 def irep_node @irep_node ||= query.irep_selection end |
#namespace(ns) ⇒ Hash
Get an isolated hash for ns
. Doesn’t affect user-provided storage.
175 176 177 |
# File 'lib/graphql/query/context.rb', line 175 def namespace(ns) @storage[ns] end |
#received_null_child ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
184 185 186 187 |
# File 'lib/graphql/query/context.rb', line 184 def received_null_child @invalid_null = true @value = nil end |
#warden ⇒ GraphQL::Schema::Warden
168 169 170 |
# File 'lib/graphql/query/context.rb', line 168 def warden @warden ||= @query.warden end |