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

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
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 Tracing::Traceable

#trace

Methods included from SharedMethods

#backtrace, #delete_child, #execution_errors, #invalid_null?, #lookahead, #skip, #spawn_child

Constructor Details

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

Returns a new instance of FieldResolutionContext.



263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/graphql/query/context.rb', line 263

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
  # This hack flag is required by ConnectionResolve
  @wrapped_connection = false
  @wrapped_object = false
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



260
261
262
# File 'lib/graphql/query/context.rb', line 260

def field
  @field
end

#irep_nodeObject (readonly) Also known as: selection

Returns the value of attribute irep_node.



260
261
262
# File 'lib/graphql/query/context.rb', line 260

def irep_node
  @irep_node
end

#keyObject (readonly)

Returns the value of attribute key.



260
261
262
# File 'lib/graphql/query/context.rb', line 260

def key
  @key
end

#parentObject (readonly)

Returns the value of attribute parent.



260
261
262
# File 'lib/graphql/query/context.rb', line 260

def parent
  @parent
end

#parent_typeObject (readonly)

Returns the value of attribute parent_type.



260
261
262
# File 'lib/graphql/query/context.rb', line 260

def parent_type
  @parent_type
end

#queryObject (readonly)

Returns the value of attribute query.



260
261
262
# File 'lib/graphql/query/context.rb', line 260

def query
  @query
end

#schemaObject (readonly)

Returns the value of attribute schema.



260
261
262
# File 'lib/graphql/query/context.rb', line 260

def schema
  @schema
end

#typeObject (readonly)

Returns the value of attribute type.



260
261
262
# File 'lib/graphql/query/context.rb', line 260

def type
  @type
end

#wrapped_connectionObject

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.



282
283
284
# File 'lib/graphql/query/context.rb', line 282

def wrapped_connection
  @wrapped_connection
end

#wrapped_objectObject

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.



282
283
284
# File 'lib/graphql/query/context.rb', line 282

def wrapped_object
  @wrapped_object
end

Instance Method Details

#add_error(error) ⇒ void

This method returns an undefined value.

Add error to current field resolution.

Parameters:



301
302
303
304
305
306
# File 'lib/graphql/query/context.rb', line 301

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:



294
295
296
# File 'lib/graphql/query/context.rb', line 294

def ast_node
  @irep_node.ast_node
end

#inspectObject



308
309
310
# File 'lib/graphql/query/context.rb', line 308

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

#pathObject



284
285
286
# File 'lib/graphql/query/context.rb', line 284

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



318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# File 'lib/graphql/query/context.rb', line 318

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_child(self)
  else
    @value = new_value
  end
end