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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Delegate

def_delegators

Constructor Details

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

Returns a new instance of FieldResolutionContext.



106
107
108
109
110
111
112
113
114
115
116
# File 'lib/graphql/query/context.rb', line 106

def initialize(context:, key:, selection:, parent:, field:, parent_type:)
  @context = context
  @key = key
  @parent = parent
  @selection = selection
  @field = field
  @parent_type = parent_type
  # This is needed constantly, so set it ahead of time:
  @query = context.query
  @schema = context.schema
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



104
105
106
# File 'lib/graphql/query/context.rb', line 104

def field
  @field
end

#parent_typeObject (readonly)

Returns the value of attribute parent_type.



104
105
106
# File 'lib/graphql/query/context.rb', line 104

def parent_type
  @parent_type
end

#queryObject (readonly)

Returns the value of attribute query.



104
105
106
# File 'lib/graphql/query/context.rb', line 104

def query
  @query
end

#schemaObject (readonly)

Returns the value of attribute schema.



104
105
106
# File 'lib/graphql/query/context.rb', line 104

def schema
  @schema
end

#selectionObject (readonly)

Returns the value of attribute selection.



104
105
106
# File 'lib/graphql/query/context.rb', line 104

def selection
  @selection
end

Instance Method Details

#add_error(error) ⇒ void

This method returns an undefined value.

Add error to current field resolution.

Parameters:



140
141
142
143
144
145
146
147
148
149
# File 'lib/graphql/query/context.rb', line 140

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:



128
129
130
# File 'lib/graphql/query/context.rb', line 128

def ast_node
  @selection.ast_node
end

#irep_nodeGraphQL::InternalRepresentation::Node



133
134
135
# File 'lib/graphql/query/context.rb', line 133

def irep_node
  @selection
end

#pathObject



118
119
120
# File 'lib/graphql/query/context.rb', line 118

def path
  @path ||= @parent.path.dup << @key
end

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



151
152
153
154
155
156
157
158
159
160
# File 'lib/graphql/query/context.rb', line 151

def spawn(key:, selection:, parent_type:, field:)
  FieldResolutionContext.new(
    context: @context,
    parent: self,
    key: key,
    selection: selection,
    parent_type: parent_type,
    field: field,
  )
end