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

errors[R]

@return [Array<GraphQL::ExecutionError>] errors returned during execution

execution_strategy[R]
path[R]

@return [Array<String, Integer>] The current position in the result

query[R]

@return [GraphQL::Query] The query whose context this is

schema[R]

@return [GraphQL::Schema]

strategy[R]
value[W]

@api private

Public Class Methods

new(query:, values: , object:) click to toggle source

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 139
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

ast_node() click to toggle source

@return [GraphQL::Language::Nodes::Field] The AST node for the currently-executing field

# File lib/graphql/query/context.rb, line 120
def ast_node
  @irep_node.ast_node
end
execution_strategy=(new_strategy) click to toggle source
# File lib/graphql/query/context.rb, line 107
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
inspect() click to toggle source
# File lib/graphql/query/context.rb, line 178
def inspect
  "#<Query::Context ...>"
end
irep_node() click to toggle source

@return [GraphQL::InternalRepresentation::Node] The internal representation for this query node

# File lib/graphql/query/context.rb, line 115
def irep_node
  @irep_node ||= query.irep_selection
end
namespace(ns) click to toggle source

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 174
def namespace(ns)
  @storage[ns]
end
received_null_child() click to toggle source

@api private

# File lib/graphql/query/context.rb, line 183
def received_null_child
  @invalid_null = true
  @value = nil
end
warden() click to toggle source

@return [GraphQL::Schema::Warden]

# File lib/graphql/query/context.rb, line 167
def warden
  @warden ||= @query.warden
end