class GraphQL::Query::Context::FieldResolutionContext
Attributes
field[R]
irep_node[R]
key[R]
parent[R]
parent_type[R]
query[R]
schema[R]
selection[R]
type[R]
wrapped_connection[RW]
@api private
wrapped_object[RW]
@api private
Public Class Methods
new(context:, key:, irep_node:, parent:, object:)
click to toggle source
# File lib/graphql/query/context.rb, line 196 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
Public Instance Methods
add_error(error)
click to toggle source
Add error to current field resolution. @param error [GraphQL::ExecutionError] an execution error @return [void]
Calls superclass method
GraphQL::Query::Context::SharedMethods#add_error
# File lib/graphql/query/context.rb, line 234 def add_error(error) super error.ast_node ||= irep_node.ast_node error.path ||= path nil end
ast_node()
click to toggle source
@return [GraphQL::Language::Nodes::Field] The AST node for the currently-executing field
# File lib/graphql/query/context.rb, line 227 def ast_node @irep_node.ast_node end
inspect()
click to toggle source
# File lib/graphql/query/context.rb, line 241 def inspect "#<GraphQL Context @ #{irep_node.owner_type.name}.#{field.name}>" end
path()
click to toggle source
# File lib/graphql/query/context.rb, line 217 def path @path ||= @parent.path.dup << @key end
value=(new_value)
click to toggle source
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 @param new_value [Any] The GraphQL-ready value @api private
# File lib/graphql/query/context.rb, line 251 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
Protected Instance Methods
received_null_child()
click to toggle source
# File lib/graphql/query/context.rb, line 269 def received_null_child case @value when Hash self.value = GraphQL::Execution::Execute::PROPAGATE_NULL when Array if list_of_non_null_items?(@type) self.value = GraphQL::Execution::Execute::PROPAGATE_NULL end when nil # TODO This is a hack # It was already nulled out but it's getting reassigned else raise "Unexpected value for received_null_child (#{self.value.class}): #{value}" end end
Private Instance Methods
list_of_non_null_items?(type)
click to toggle source
# File lib/graphql/query/context.rb, line 287 def list_of_non_null_items?(type) case type when GraphQL::NonNullType # Unwrap [T]! list_of_non_null_items?(type.of_type) when GraphQL::ListType type.of_type.is_a?(GraphQL::NonNullType) else raise "Unexpected list_of_non_null_items check: #{type}" end end