module GraphQL::Query::Context::SharedMethods

Attributes

object[RW]

@return [Object] The target for field resultion

skipped[RW]

@return [Boolean] were any fields of this selection skipped?

skipped?[R]

@return [Boolean] were any fields of this selection skipped?

value[R]

@return [Hash, Array, String, Integer, Float, Boolean, nil] The resolved value for this field

Public Instance Methods

add_error(error) click to toggle source

Add error at query-level. @param error [GraphQL::ExecutionError] an execution error @return [void]

# File lib/graphql/query/context.rb, line 58
def add_error(error)
  if !error.is_a?(ExecutionError)
    raise TypeError, "expected error to be a ExecutionError, but was #{error.class}"
  end
  errors << error
  nil
end
backtrace() click to toggle source

@example Print the GraphQL backtrace during field resolution

puts ctx.backtrace

@return [GraphQL::Backtrace] The backtrace for this point in query execution

# File lib/graphql/query/context.rb, line 70
def backtrace
  GraphQL::Backtrace.new(self)
end
delete(child_ctx) click to toggle source

Remove this child from the result value (used for null propagation and skip) @api private

# File lib/graphql/query/context.rb, line 37
def delete(child_ctx)
  @value.delete(child_ctx.key)
end
execution_errors() click to toggle source
# File lib/graphql/query/context.rb, line 74
def execution_errors
  @execution_errors ||= ExecutionErrors.new(self)
end
invalid_null?() click to toggle source

@return [Boolean] True if this selection has been nullified by a null child

# File lib/graphql/query/context.rb, line 30
def invalid_null?
  @invalid_null
end
lookahead() click to toggle source
# File lib/graphql/query/context.rb, line 78
def lookahead
  ast_nodes = irep_node.ast_nodes
  field = irep_node.definition.metadata[:type_class] || raise("Lookahead is only compatible with class-based schemas")
  Execution::Lookahead.new(query: query, ast_nodes: ast_nodes, field: field)
end
skip() click to toggle source

Return this value to tell the runtime to exclude this field from the response altogether

# File lib/graphql/query/context.rb, line 25
def skip
  GraphQL::Execution::Execute::SKIP
end
spawn_child(key:, irep_node:, object:) click to toggle source

Create a child context to use for `key` @param key [String, Integer] The key in the response (name or index) @param irep_node [InternalRepresentation::Node] The node being evaluated @api private

# File lib/graphql/query/context.rb, line 45
def spawn_child(key:, irep_node:, object:)
  FieldResolutionContext.new(
    context: @context,
    parent: self,
    object: object,
    key: key,
    irep_node: irep_node,
  )
end