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


43
44
45
46
47
48
49
50
# File 'lib/graphql/query/context.rb', line 43

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

Instance Attribute Details

#errorsArray<GraphQL::ExecutionError> (readonly)


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

def errors
  @errors
end

#execution_strategyObject Also known as: strategy

Returns the value of attribute execution_strategy


6
7
8
# File 'lib/graphql/query/context.rb', line 6

def execution_strategy
  @execution_strategy
end

#irep_nodeGraphQL::InternalRepresentation::Node


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

def irep_node
  @irep_node
end

#pathArray<String, Integer> (readonly)


38
39
40
# File 'lib/graphql/query/context.rb', line 38

def path
  @path
end

#queryGraphQL::Query (readonly)


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

def query
  @query
end

#schemaGraphQL::Schema (readonly)


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

def schema
  @schema
end

#wardenGraphQL::Schema::Mask::Warden (readonly)


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

def warden
  @warden
end

Instance Method Details

#[](key) ⇒ Object

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


53
54
55
# File 'lib/graphql/query/context.rb', line 53

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

#[]=(key, value) ⇒ Object

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


58
59
60
# File 'lib/graphql/query/context.rb', line 58

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

#ast_nodeGraphQL::Language::Nodes::Field


21
22
23
# File 'lib/graphql/query/context.rb', line 21

def ast_node
  @irep_node.ast_node
end

#spawn(path:, irep_node:) ⇒ Object


62
63
64
# File 'lib/graphql/query/context.rb', line 62

def spawn(path:, irep_node:)
  FieldResolutionContext.new(context: self, path: path, irep_node: irep_node)
end