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

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/graphql/query/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context:, path:, selection:, field:, parent_type:) ⇒ FieldResolutionContext

Returns a new instance of FieldResolutionContext.



94
95
96
97
98
99
100
# File 'lib/graphql/query/context.rb', line 94

def initialize(context:, path:, selection:, field:, parent_type:)
  @context = context
  @path = path
  @selection = selection
  @field = field
  @parent_type = parent_type
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



92
93
94
# File 'lib/graphql/query/context.rb', line 92

def field
  @field
end

#parent_typeObject (readonly)

Returns the value of attribute parent_type.



92
93
94
# File 'lib/graphql/query/context.rb', line 92

def parent_type
  @parent_type
end

#pathObject (readonly)

Returns the value of attribute path.



92
93
94
# File 'lib/graphql/query/context.rb', line 92

def path
  @path
end

#selectionObject (readonly)

Returns the value of attribute selection.



92
93
94
# File 'lib/graphql/query/context.rb', line 92

def selection
  @selection
end

Instance Method Details

#add_error(error) ⇒ void

This method returns an undefined value.

Add error to current field resolution.

Parameters:



120
121
122
123
124
125
126
127
128
129
# File 'lib/graphql/query/context.rb', line 120

def add_error(error)
  if !error.is_a?(ExecutionError)
    raise TypeError, "expected error to be a ExecutionError, but was #{error.class}"
  end

  error.ast_node ||= irep_node.ast_node
  error.path ||= path
  errors << error
  nil
end

#ast_nodeGraphQL::Language::Nodes::Field

Returns The AST node for the currently-executing field.

Returns:



108
109
110
# File 'lib/graphql/query/context.rb', line 108

def ast_node
  @selection.ast_node
end

#irep_nodeGraphQL::InternalRepresentation::Node



113
114
115
# File 'lib/graphql/query/context.rb', line 113

def irep_node
  @selection
end

#spawn(key:, selection:, parent_type:, field:) ⇒ Object



131
132
133
134
135
136
137
138
139
# File 'lib/graphql/query/context.rb', line 131

def spawn(key:, selection:, parent_type:, field:)
  FieldResolutionContext.new(
    context: @context,
    path: path + [key],
    selection: selection,
    parent_type: parent_type,
    field: field,
  )
end