Class: GraphQL::Query::Context

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(query:, values:) ⇒ Context

Make a new context which delegates key lookup to values

Parameters:

  • query (GraphQL::Query)

    the query who owns this context

  • values (Hash)

    A hash of arbitrary values which will be accessible at query-time



41
42
43
44
45
46
47
# File 'lib/graphql/query/context.rb', line 41

def initialize(query:, values:)
  @query = query
  @schema = query.schema
  @values = values || {}
  @errors = []
  @path = []
end

Instance Attribute Details

#errorsArray<GraphQL::ExecutionError> (readonly)

Returns errors returned during execution.

Returns:



27
28
29
# File 'lib/graphql/query/context.rb', line 27

def errors
  @errors
end

#execution_strategyObject 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_nodeGraphQL::InternalRepresentation::Node

Returns The internal representation for this query node.

Returns:



19
20
21
# File 'lib/graphql/query/context.rb', line 19

def irep_node
  @irep_node
end

#pathArray<String, Integer> (readonly)

Returns The current position in the result.

Returns:

  • (Array<String, Integer>)

    The current position in the result



36
37
38
# File 'lib/graphql/query/context.rb', line 36

def path
  @path
end

#queryGraphQL::Query (readonly)

Returns The query whose context this is.

Returns:



30
31
32
# File 'lib/graphql/query/context.rb', line 30

def query
  @query
end

#schemaGraphQL::Schema (readonly)

Returns:



33
34
35
# File 'lib/graphql/query/context.rb', line 33

def schema
  @schema
end

Instance Method Details

#[](key) ⇒ Object

Lookup key from the hash passed to Schema#execute as context:



50
51
52
# File 'lib/graphql/query/context.rb', line 50

def [](key)
  @values[key]
end

#[]=(key, value) ⇒ Object

Reassign key to the hash passed to Schema#execute as context:



60
61
62
# File 'lib/graphql/query/context.rb', line 60

def []=(key, value)
  @values[key] = value
end

#ast_nodeGraphQL::Language::Nodes::Field

Returns The AST node for the currently-executing field.

Returns:



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



64
65
66
67
68
69
70
71
72
# File 'lib/graphql/query/context.rb', line 64

def spawn(key:, selection:, parent_type:, field:)
  FieldResolutionContext.new(
    context: self,
    path: path + [key],
    selection: selection,
    parent_type: parent_type,
    field: field,
  )
end

#wardenGraphQL::Schema::Warden



55
56
57
# File 'lib/graphql/query/context.rb', line 55

def warden
  @warden ||= @query.warden
end