Class: GraphQL::Query::Context
- Inherits:
 - 
      Object
      
        
- Object
 - GraphQL::Query::Context
 
 
- Extended by:
 - Forwardable
 
- Includes:
 - SharedMethods
 
- 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
Modules: SharedMethods Classes: ExecutionErrors, FieldResolutionContext
Instance Attribute Summary collapse
- 
  
    
      #errors  ⇒ Array<GraphQL::ExecutionError> 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Errors returned during execution.
 - 
  
    
      #execution_strategy  ⇒ Object 
    
    
      (also: #strategy)
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute execution_strategy.
 - 
  
    
      #interpreter  ⇒ Object 
    
    
  
  
  
  
    
    
      writeonly
    
  
  
  
  
  private
  
    
 - 
  
    
      #path  ⇒ Array<String, Integer> 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
The current position in the result.
 - 
  
    
      #query  ⇒ GraphQL::Query 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
The query whose context this is.
 - 
  
    
      #schema  ⇒ GraphQL::Schema 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
 - 
  
    
      #scoped_context  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  private
  
    
 - 
  
    
      #value  ⇒ Object 
    
    
  
  
  
  
    
    
      writeonly
    
  
  
  
  
  private
  
    
 
Attributes included from SharedMethods
Instance Method Summary collapse
- 
  
    
      #[](key)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Lookup
keyfrom the hash passed to Schema#execute ascontext:. - 
  
    
      #[]=(key, value)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Reassign
keyto the hash passed to Schema#execute ascontext:. - 
  
    
      #ast_node  ⇒ GraphQL::Language::Nodes::Field 
    
    
  
  
  
  
  
  
  
  
  
    
The AST node for the currently-executing field.
 - 
  
    
      #initialize(query:, schema: query.schema, values:, object:)  ⇒ Context 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
Make a new context which delegates key lookup to
values. - 
  
    
      #inspect  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
 - 
  
    
      #irep_node  ⇒ GraphQL::InternalRepresentation::Node 
    
    
  
  
  
  
  
  
  
  
  
    
The internal representation for this query node.
 - 
  
    
      #key?(key)  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
 - 
  
    
      #namespace(ns)  ⇒ Hash 
    
    
  
  
  
  
  
  
  
  
  
    
Get an isolated hash for
ns. - 
  
    
      #received_null_child  ⇒ Object 
    
    
  
  
  
  
  
  
  
  private
  
    
 - 
  
    
      #scoped_merge!(hash)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
 - 
  
    
      #scoped_set!(key, value)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
 - 
  
    
      #to_h  ⇒ Object 
    
    
      (also: #to_hash)
    
  
  
  
  
  
  
  
  
  
    
 - 
  
    
      #warden  ⇒ GraphQL::Schema::Warden 
    
    
  
  
  
  
  
  
  
  
  
    
 
Methods included from SharedMethods
#add_error, #backtrace, #delete, #execution_errors, #invalid_null?, #lookahead, #skip, #spawn_child
Constructor Details
#initialize(query:, schema: query.schema, values:, object:) ⇒ Context
Make a new context which delegates key lookup to values
      146 147 148 149 150 151 152 153 154 155 156 157 158 159  | 
    
      # File 'lib/graphql/query/context.rb', line 146 def initialize(query:, schema: query.schema, values:, object:) @query = query @schema = 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 @scoped_context = {} end  | 
  
Instance Attribute Details
#errors ⇒ Array<GraphQL::ExecutionError> (readonly)
Returns errors returned during execution.
      132 133 134  | 
    
      # File 'lib/graphql/query/context.rb', line 132 def errors @errors end  | 
  
#execution_strategy ⇒ Object Also known as: strategy
Returns the value of attribute execution_strategy.
      110 111 112  | 
    
      # File 'lib/graphql/query/context.rb', line 110 def execution_strategy @execution_strategy end  | 
  
#interpreter=(value) ⇒ Object (writeonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
      162 163 164  | 
    
      # File 'lib/graphql/query/context.rb', line 162 def interpreter=(value) @interpreter = value end  | 
  
#path ⇒ Array<String, Integer> (readonly)
Returns The current position in the result.
      141 142 143  | 
    
      # File 'lib/graphql/query/context.rb', line 141 def path @path end  | 
  
#query ⇒ GraphQL::Query (readonly)
Returns The query whose context this is.
      135 136 137  | 
    
      # File 'lib/graphql/query/context.rb', line 135 def query @query end  | 
  
#schema ⇒ GraphQL::Schema (readonly)
      138 139 140  | 
    
      # File 'lib/graphql/query/context.rb', line 138 def schema @schema end  | 
  
#scoped_context ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
      168 169 170  | 
    
      # File 'lib/graphql/query/context.rb', line 168 def scoped_context @scoped_context end  | 
  
#value=(value) ⇒ Object (writeonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
      165 166 167  | 
    
      # File 'lib/graphql/query/context.rb', line 165 def value=(value) @value = value end  | 
  
Instance Method Details
#[](key) ⇒ Object
Lookup key from the hash passed to Schema#execute as context:
      178 179 180 181  | 
    
      # File 'lib/graphql/query/context.rb', line 178 def [](key) return @scoped_context[key] if @scoped_context.key?(key) @provided_values[key] end  | 
  
#[]=(key, value) ⇒ Object
Reassign key to the hash passed to Schema#execute as context:
| 
       | 
    
      # File 'lib/graphql/query/context.rb', line 174
     | 
  
#ast_node ⇒ GraphQL::Language::Nodes::Field
Returns The AST node for the currently-executing field.
      127 128 129  | 
    
      # File 'lib/graphql/query/context.rb', line 127 def ast_node @irep_node.ast_node end  | 
  
#inspect ⇒ Object
      204 205 206  | 
    
      # File 'lib/graphql/query/context.rb', line 204 def inspect "#<Query::Context ...>" end  | 
  
#irep_node ⇒ GraphQL::InternalRepresentation::Node
Returns The internal representation for this query node.
      122 123 124  | 
    
      # File 'lib/graphql/query/context.rb', line 122 def irep_node @irep_node ||= query.irep_selection end  | 
  
#key?(key) ⇒ Boolean
      188 189 190  | 
    
      # File 'lib/graphql/query/context.rb', line 188 def key?(key) @scoped_context.key?(key) || @provided_values.key?(key) end  | 
  
#namespace(ns) ⇒ Hash
Get an isolated hash for ns. Doesn’t affect user-provided storage.
      200 201 202  | 
    
      # File 'lib/graphql/query/context.rb', line 200 def namespace(ns) @storage[ns] end  | 
  
#received_null_child ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
      209 210 211 212  | 
    
      # File 'lib/graphql/query/context.rb', line 209 def received_null_child @invalid_null = true @value = nil end  | 
  
#scoped_merge!(hash) ⇒ Object
      214 215 216  | 
    
      # File 'lib/graphql/query/context.rb', line 214 def scoped_merge!(hash) @scoped_context = @scoped_context.merge(hash) end  | 
  
#scoped_set!(key, value) ⇒ Object
      218 219 220 221  | 
    
      # File 'lib/graphql/query/context.rb', line 218 def scoped_set!(key, value) scoped_merge!(key => value) nil end  | 
  
#to_h ⇒ Object Also known as: to_hash
      183 184 185  | 
    
      # File 'lib/graphql/query/context.rb', line 183 def to_h @provided_values.merge(@scoped_context) end  | 
  
#warden ⇒ GraphQL::Schema::Warden
      193 194 195  | 
    
      # File 'lib/graphql/query/context.rb', line 193 def warden @warden ||= @query.warden end  |