Class: GraphQL::Query::Context::FieldResolutionContext

Inherits:
Object
  • Object
show all
Extended by:
Delegate
Includes:
SharedMethods, Tracing::Traceable
Defined in:
lib/graphql/query/context.rb

Instance Attribute Summary collapse

Attributes included from SharedMethods

#object, #skipped, #value

Instance Method Summary collapse

Methods included from Delegate

def_delegators

Methods included from Tracing::Traceable

#trace

Methods included from SharedMethods

#backtrace, #delete, #invalid_null?, #skip, #spawn_child

Constructor Details

#initialize(context:, key:, irep_node:, parent:, object:) ⇒ FieldResolutionContext

Returns a new instance of FieldResolutionContext.



170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/graphql/query/context.rb', line 170

def initialize(context:, key:, irep_node:, parent:, object:)
  @context = context
  @key = key
  @parent = parent
  @object = object
  @irep_node = irep_node
  @field = irep_node.definition
  @parent_type = irep_node.owner_type
  @type = field.type
  # This is needed constantly, so set it ahead of time:
  @query = context.query
  @schema = context.schema
  @tracers = @query.tracers
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



167
168
169
# File 'lib/graphql/query/context.rb', line 167

def field
  @field
end

#irep_nodeObject (readonly) Also known as: selection

Returns the value of attribute irep_node.



167
168
169
# File 'lib/graphql/query/context.rb', line 167

def irep_node
  @irep_node
end

#keyObject (readonly)

Returns the value of attribute key.



167
168
169
# File 'lib/graphql/query/context.rb', line 167

def key
  @key
end

#parentObject (readonly)

Returns the value of attribute parent.



167
168
169
# File 'lib/graphql/query/context.rb', line 167

def parent
  @parent
end

#parent_typeObject (readonly)

Returns the value of attribute parent_type.



167
168
169
# File 'lib/graphql/query/context.rb', line 167

def parent_type
  @parent_type
end

#queryObject (readonly)

Returns the value of attribute query.



167
168
169
# File 'lib/graphql/query/context.rb', line 167

def query
  @query
end

#schemaObject (readonly)

Returns the value of attribute schema.



167
168
169
# File 'lib/graphql/query/context.rb', line 167

def schema
  @schema
end

#typeObject (readonly)

Returns the value of attribute type.



167
168
169
# File 'lib/graphql/query/context.rb', line 167

def type
  @type
end

Instance Method Details

#add_error(error) ⇒ void

This method returns an undefined value.

Add error to current field resolution.

Parameters:



202
203
204
205
206
207
# File 'lib/graphql/query/context.rb', line 202

def add_error(error)
  super
  error.ast_node ||= irep_node.ast_node
  error.path ||= path
  nil
end

#ast_nodeGraphQL::Language::Nodes::Field

Returns The AST node for the currently-executing field.

Returns:



195
196
197
# File 'lib/graphql/query/context.rb', line 195

def ast_node
  @irep_node.ast_node
end

#inspectObject



209
210
211
# File 'lib/graphql/query/context.rb', line 209

def inspect
  "#<GraphQL Context @ #{irep_node.owner_type.name}.#{field.name}>"
end

#pathObject



185
186
187
# File 'lib/graphql/query/context.rb', line 185

def path
  @path ||= @parent.path.dup << @key
end

#value=(new_value) ⇒ 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.

Set a new value for this field in the response. It may be updated after resolving a Lazy. If it is Execute::PROPAGATE_NULL, tell the owner to propagate null. If it's Execute::Execution::SKIP, remove this field result from its parent

Parameters:

  • new_value (Any)

    The GraphQL-ready value



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/graphql/query/context.rb', line 219

def value=(new_value)
  case new_value
  when GraphQL::Execution::Execute::PROPAGATE_NULL, nil
    @invalid_null = true
    @value = nil
    if @type.kind.non_null?
      @parent.received_null_child
    end
  when GraphQL::Execution::Execute::SKIP
    @parent.skipped = true
    @parent.delete(self)
  else
    @value = new_value
  end
end