class GraphQL::Schema::Context
Expose some query-specific info to field resolve functions. It delegates `[]` to the hash that's passed to `GraphQL::Query#initialize`.
Attributes
@return [Array<GraphQL::ExecutionError>] errors returned during execution
@return [Array<String, Integer>] The current position in the result
@return [GraphQL::Query] The query whose context this is
@return [GraphQL::Schema]
@api private
Public Class Methods
Make a new context which delegates key lookup to `values` @param query [GraphQL::Query] the query who owns this context @param values [Hash] A hash of arbitrary values which will be accessible at query-time
# File lib/graphql/query/context.rb, line 146 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
Public Instance Methods
@return [GraphQL::Language::Nodes::Field] The AST node for the currently-executing field
# File lib/graphql/query/context.rb, line 127 def ast_node @irep_node.ast_node end
# File lib/graphql/query/context.rb, line 114 def execution_strategy=(new_strategy) # GraphQL::Batch re-assigns this value but it was previously not used # (ExecutionContext#strategy was used instead) # now it _is_ used, but it breaks GraphQL::Batch tests @execution_strategy ||= new_strategy end
# File lib/graphql/query/context.rb, line 185 def inspect "#<Query::Context ...>" end
@return [GraphQL::InternalRepresentation::Node] The internal representation for this query node
# File lib/graphql/query/context.rb, line 122 def irep_node @irep_node ||= query.irep_selection end
Get an isolated hash for `ns`. Doesn't affect user-provided storage. @param ns [Object] a usage-specific namespace identifier @return [Hash] namespaced storage
# File lib/graphql/query/context.rb, line 181 def namespace(ns) @storage[ns] end
@api private
# File lib/graphql/query/context.rb, line 190 def received_null_child @invalid_null = true @value = nil end
@return [GraphQL::Schema::Warden]
# File lib/graphql/query/context.rb, line 174 def warden @warden ||= @query.warden end