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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query:, values:) ⇒ Context

Make a new context which delegates key lookup to values


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

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

Instance Attribute Details

#ast_nodeGraphQL::Language::Nodes::Field


9
10
11
# File 'lib/graphql/query/context.rb', line 9

def ast_node
  @ast_node
end

#errorsArray<GraphQL::ExecutionError> (readonly)


15
16
17
# File 'lib/graphql/query/context.rb', line 15

def errors
  @errors
end

#execution_strategyObject

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


12
13
14
# File 'lib/graphql/query/context.rb', line 12

def irep_node
  @irep_node
end

#queryGraphQL::Query (readonly)


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

def query
  @query
end

#schemaGraphQL::Schema (readonly)


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

def schema
  @schema
end

Instance Method Details

#[](key) ⇒ Object

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


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

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

#[]=(key, value) ⇒ Object

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


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

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