Class: GraphQL::Query::Context
- Inherits:
-
Object
- Object
- GraphQL::Query::Context
- 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
Classes: 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.
-
#irep_node ⇒ GraphQL::InternalRepresentation::Node
The internal representation for this query node.
-
#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
- #warden ⇒ GraphQL::Schema::Mask::Warden readonly
Instance Method Summary collapse
-
#[](key) ⇒ Object
Lookup
keyfrom the hash passed to Schema#execute ascontext:. -
#[]=(key, value) ⇒ Object
Reassign
keyto the hash passed to Schema#execute ascontext:. -
#ast_node ⇒ GraphQL::Language::Nodes::Field
The AST node for the currently-executing field.
-
#initialize(query:, values:) ⇒ Context
constructor
Make a new context which delegates key lookup to
values. - #spawn(key:, selection:, parent_type:, field:) ⇒ Object
Constructor Details
#initialize(query:, values:) ⇒ Context
Make a new context which delegates key lookup to values
44 45 46 47 48 49 50 51 |
# File 'lib/graphql/query/context.rb', line 44 def initialize(query:, values:) @query = query @schema = query.schema @values = values || {} @errors = [] @warden = query.warden @path = [] end |
Instance Attribute Details
#errors ⇒ Array<GraphQL::ExecutionError> (readonly)
Returns errors returned during execution.
27 28 29 |
# File 'lib/graphql/query/context.rb', line 27 def errors @errors end |
#execution_strategy ⇒ Object Also known as: strategy
Returns the value of attribute execution_strategy.
7 8 9 |
# File 'lib/graphql/query/context.rb', line 7 def execution_strategy @execution_strategy end |
#irep_node ⇒ GraphQL::InternalRepresentation::Node
Returns The internal representation for this query node.
19 20 21 |
# File 'lib/graphql/query/context.rb', line 19 def irep_node @irep_node end |
#path ⇒ Array<String, Integer> (readonly)
Returns The current position in the result.
39 40 41 |
# File 'lib/graphql/query/context.rb', line 39 def path @path end |
#query ⇒ GraphQL::Query (readonly)
Returns The query whose context this is.
30 31 32 |
# File 'lib/graphql/query/context.rb', line 30 def query @query end |
#schema ⇒ GraphQL::Schema (readonly)
33 34 35 |
# File 'lib/graphql/query/context.rb', line 33 def schema @schema end |
#warden ⇒ GraphQL::Schema::Mask::Warden (readonly)
36 37 38 |
# File 'lib/graphql/query/context.rb', line 36 def warden @warden end |
Instance Method Details
#[](key) ⇒ Object
Lookup key from the hash passed to Schema#execute as context:
54 55 56 |
# File 'lib/graphql/query/context.rb', line 54 def [](key) @values[key] end |
#[]=(key, value) ⇒ Object
Reassign key to the hash passed to Schema#execute as context:
59 60 61 |
# File 'lib/graphql/query/context.rb', line 59 def []=(key, value) @values[key] = value end |
#ast_node ⇒ GraphQL::Language::Nodes::Field
Returns The AST node for the currently-executing field.
22 23 24 |
# File 'lib/graphql/query/context.rb', line 22 def ast_node @irep_node.ast_node end |
#spawn(key:, selection:, parent_type:, field:) ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/graphql/query/context.rb', line 63 def spawn(key:, selection:, parent_type:, field:) FieldResolutionContext.new( context: self, path: path + [key], selection: selection, parent_type: parent_type, field: field, ) end |