Class: Rails::GraphQL::Request::Context
- Inherits:
-
Object
- Object
- Rails::GraphQL::Request::Context
- Defined in:
- lib/rails/graphql/request/context.rb
Overview
GraphQL Request Context
This class is used as context for the response while processing fields, objects, or any data that it’s going to be placed on the response
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
Instance Method Summary collapse
-
#ancestors ⇒ Object
Get all ancestors objects.
-
#at(index) ⇒ Object
Get a value at the given
index
. -
#current_value ⇒ Object
Get the current value, which basically means the first item on the current stack.
-
#initialize ⇒ Context
constructor
A new instance of Context.
-
#override_value(value) ⇒ Object
(also: #current_value=)
Change the current value, either form hits or the actual value.
-
#parent ⇒ Object
Find the parent object.
-
#stack ⇒ Object
Return a duplicated version of the stack, for safety.
-
#stacked(value) ⇒ Object
Add, exec, and then remove the value from the stack.
Constructor Details
#initialize ⇒ Context
Returns a new instance of Context.
13 14 15 16 |
# File 'lib/rails/graphql/request/context.rb', line 13 def initialize @stack = [] @current = Helpers::AttributeDelegator.new(self, :current_value, cache: false) end |
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current.
11 12 13 |
# File 'lib/rails/graphql/request/context.rb', line 11 def current @current end |
Instance Method Details
#ancestors ⇒ Object
Get all ancestors objects
37 38 39 |
# File 'lib/rails/graphql/request/context.rb', line 37 def ancestors @stack[1..-1] end |
#at(index) ⇒ Object
Get a value at the given index
32 33 34 |
# File 'lib/rails/graphql/request/context.rb', line 32 def at(index) @stack[index] end |
#current_value ⇒ Object
Get the current value, which basically means the first item on the current stack
48 49 50 |
# File 'lib/rails/graphql/request/context.rb', line 48 def current_value at(0) end |
#override_value(value) ⇒ Object Also known as: current_value=
Change the current value, either form hits or the actual value
53 54 55 |
# File 'lib/rails/graphql/request/context.rb', line 53 def override_value(value) @stack[0] = value end |
#parent ⇒ Object
Find the parent object
42 43 44 |
# File 'lib/rails/graphql/request/context.rb', line 42 def parent at(1) end |
#stack ⇒ Object
Return a duplicated version of the stack, for safety
27 28 29 |
# File 'lib/rails/graphql/request/context.rb', line 27 def stack @stack.dup end |
#stacked(value) ⇒ Object
Add, exec, and then remove the value from the stack
19 20 21 22 23 24 |
# File 'lib/rails/graphql/request/context.rb', line 19 def stacked(value) @stack.unshift(value) unless value.eql?(@stack[0]) yield(@current) ensure @stack.shift end |