Module: GraphQL::Query::Context::SharedMethods

Included in:
GraphQL::Query::Context, FieldResolutionContext
Defined in:
lib/graphql/query/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#objectObject

Returns The target for field resultion

Returns:

  • (Object)

    The target for field resultion



11
12
13
# File 'lib/graphql/query/context.rb', line 11

def object
  @object
end

#skippedBoolean Also known as: skipped?

Returns were any fields of this selection skipped?

Returns:

  • (Boolean)

    were any fields of this selection skipped?



17
18
19
# File 'lib/graphql/query/context.rb', line 17

def skipped
  @skipped
end

#valueHash, ... (readonly)

Returns The resolved value for this field

Returns:

  • (Hash, Array, String, Integer, Float, Boolean, nil)

    The resolved value for this field



14
15
16
# File 'lib/graphql/query/context.rb', line 14

def value
  @value
end

Instance Method Details

#add_error(error) ⇒ void

This method returns an undefined value.

Add error at query-level.

Parameters:



58
59
60
61
62
63
64
# 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

#backtraceGraphQL::Backtrace

Returns The backtrace for this point in query execution

Examples:

Print the GraphQL backtrace during field resolution

puts ctx.backtrace

Returns:



70
71
72
# File 'lib/graphql/query/context.rb', line 70

def backtrace
  GraphQL::Backtrace.new(self)
end

#delete(child_ctx) ⇒ 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.

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



37
38
39
# File 'lib/graphql/query/context.rb', line 37

def delete(child_ctx)
  @value.delete(child_ctx.key)
end

#execution_errorsObject



74
75
76
# File 'lib/graphql/query/context.rb', line 74

def execution_errors
  @execution_errors ||= ExecutionErrors.new(self)
end

#invalid_null?Boolean

Returns True if this selection has been nullified by a null child

Returns:

  • (Boolean)

    True if this selection has been nullified by a null child



30
31
32
# File 'lib/graphql/query/context.rb', line 30

def invalid_null?
  @invalid_null
end

#lookaheadObject



78
79
80
81
82
# File 'lib/graphql/query/context.rb', line 78

def lookahead
  ast_nodes = irep_node.ast_nodes
  field = irep_node.definition.[:type_class] || raise("Lookahead is only compatible with class-based schemas")
  Execution::Lookahead.new(query: query, ast_nodes: ast_nodes, field: field)
end

#skipObject

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



25
26
27
# File 'lib/graphql/query/context.rb', line 25

def skip
  GraphQL::Execution::Execute::SKIP
end

#spawn_child(key:, irep_node:, object:) ⇒ 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.

Create a child context to use for key

Parameters:



45
46
47
48
49
50
51
52
53
# 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