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 resolution.

Returns:

  • (Object)

    The target for field resolution



9
10
11
# File 'lib/graphql/query/context.rb', line 9

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?



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

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



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

def value
  @value
end

Instance Method Details

#add_error(error) ⇒ void

This method returns an undefined value.

Add error at query-level.

Parameters:



56
57
58
59
60
61
62
# File 'lib/graphql/query/context.rb', line 56

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:



68
69
70
# File 'lib/graphql/query/context.rb', line 68

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

#delete_child(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)



35
36
37
# File 'lib/graphql/query/context.rb', line 35

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

#execution_errorsObject



72
73
74
# File 'lib/graphql/query/context.rb', line 72

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



28
29
30
# File 'lib/graphql/query/context.rb', line 28

def invalid_null?
  @invalid_null
end

#lookaheadObject



76
77
78
79
80
# File 'lib/graphql/query/context.rb', line 76

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



23
24
25
# File 'lib/graphql/query/context.rb', line 23

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:



43
44
45
46
47
48
49
50
51
# File 'lib/graphql/query/context.rb', line 43

def spawn_child(key:, irep_node:, object:)
  FieldResolutionContext.new(
    @context,
    key,
    irep_node,
    self,
    object
  )
end