Module: GraphQL::Execution::Execute::ExecutionFunctions Private

Included in:
GraphQL::Execution::Execute
Defined in:
lib/graphql/execution/execute.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Class Method Summary collapse

Class Method Details

.continue_resolve_field(owner, selection, parent_type, field, raw_value, field_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.



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/graphql/execution/execute.rb', line 111

def continue_resolve_field(owner, selection, parent_type, field, raw_value, field_ctx)
  if owner.invalid_null?
    return
  end
  query = field_ctx.query

  case raw_value
  when GraphQL::ExecutionError
    raw_value.ast_node ||= field_ctx.ast_node
    raw_value.path = field_ctx.path
    query.context.errors.push(raw_value)
  when Array
    list_errors = raw_value.each_with_index.select { |value, _| value.is_a?(GraphQL::ExecutionError) }
    if list_errors.any?
      list_errors.each do |error, index|
        error.ast_node = field_ctx.ast_node
        error.path = field_ctx.path + [index]
        query.context.errors.push(error)
      end
    end
  end

  resolve_value(
    owner,
    parent_type,
    field,
    field.type,
    raw_value,
    selection,
    field_ctx,
  )
end

.resolve_field(owner, selection, parent_type, field, object, query_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.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/graphql/execution/execute.rb', line 70

def resolve_field(owner, selection, parent_type, field, object, query_ctx)
  query = query_ctx.query
  field_ctx = query_ctx.spawn(
    parent_type: parent_type,
    field: field,
    key: selection.name,
    selection: selection,
  )

  raw_value = begin
    arguments = query.arguments_for(selection, field)
    query_ctx.schema.middleware.invoke([parent_type, object, field, arguments, field_ctx])
  rescue GraphQL::ExecutionError => err
    err
  end

  result = if query.schema.lazy?(raw_value)
    field.prepare_lazy(raw_value, arguments, field_ctx).then { |inner_value|
      continue_resolve_field(owner, selection, parent_type, field, inner_value, field_ctx)
    }
  elsif raw_value.is_a?(GraphQL::Execution::Lazy)
    # It came from a connection resolve, assume it was already instrumented
    raw_value.then { |inner_value|
      continue_resolve_field(owner, selection, parent_type, field, inner_value, field_ctx)
    }
  else
    continue_resolve_field(owner, selection, parent_type, field, raw_value, field_ctx)
  end

  case result
  when PROPAGATE_NULL, GraphQL::Execution::Lazy, SelectionResult
    FieldResult.new(
      owner: owner,
      type: field.type,
      value: result,
    )
  else
    result
  end
end

.resolve_selection(object, current_type, selection, query_ctx, mutation: false) ⇒ 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.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/graphql/execution/execute.rb', line 36

def resolve_selection(object, current_type, selection, query_ctx, mutation: false )
  selection_result = SelectionResult.new

  selection.typed_children[current_type].each do |name, subselection|
    field_result = resolve_field(
      selection_result,
      subselection,
      current_type,
      subselection.definition,
      object,
      query_ctx
    )

    if field_result.is_a?(Skip)
      next
    end

    if mutation
      GraphQL::Execution::Lazy.resolve(field_result)
    end

    selection_result.set(name, field_result)

    # If the last subselection caused a null to propagate to _this_ selection,
    # then we may as well quit executing fields because they
    # won't be in the response
    if selection_result.invalid_null?
      break
    end
  end

  selection_result
end

.resolve_value(owner, parent_type, field_defn, field_type, value, selection, field_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.



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/graphql/execution/execute.rb', line 144

def resolve_value(owner, parent_type, field_defn, field_type, value, selection, field_ctx)
  if value.nil?
    if field_type.kind.non_null?
      type_error = GraphQL::InvalidNullError.new(parent_type, field_defn, value)
      field_ctx.schema.type_error(type_error, field_ctx)
      PROPAGATE_NULL
    else
      nil
    end
  elsif value.is_a?(GraphQL::ExecutionError)
    if field_type.kind.non_null?
      PROPAGATE_NULL
    else
      nil
    end
  elsif value.is_a?(Skip)
    value
  else
    case field_type.kind
    when GraphQL::TypeKinds::SCALAR
      field_type.coerce_result(value, field_ctx)
    when GraphQL::TypeKinds::ENUM
      field_type.coerce_result(value, field_ctx)
    when GraphQL::TypeKinds::LIST
      inner_type = field_type.of_type
      i = 0
      result = []
      value.each do |inner_value|
        inner_ctx = field_ctx.spawn(
          key: i,
          selection: selection,
          parent_type: parent_type,
          field: field_defn,
        )

        inner_result = resolve_value(
          owner,
          parent_type,
          field_defn,
          inner_type,
          inner_value,
          selection,
          inner_ctx,
        )

        result << GraphQL::Execution::FieldResult.new(type: inner_type, owner: owner, value: inner_result)
        i += 1
      end
      result
    when GraphQL::TypeKinds::NON_NULL
      wrapped_type = field_type.of_type
      resolve_value(
        owner,
        parent_type,
        field_defn,
        wrapped_type,
        value,
        selection,
        field_ctx,
      )
    when GraphQL::TypeKinds::OBJECT
      resolve_selection(
        value,
        field_type,
        selection,
        field_ctx
      )
    when GraphQL::TypeKinds::UNION, GraphQL::TypeKinds::INTERFACE
      query = field_ctx.query
      resolved_type = field_type.resolve_type(value, field_ctx)
      possible_types = query.possible_types(field_type)

      if !possible_types.include?(resolved_type)
        type_error = GraphQL::UnresolvedTypeError.new(value, field_defn, parent_type, resolved_type, possible_types)
        field_ctx.schema.type_error(type_error, field_ctx)
        PROPAGATE_NULL
      else
        resolve_value(
          owner,
          parent_type,
          field_defn,
          resolved_type,
          value,
          selection,
          field_ctx,
        )
      end
    else
      raise("Unknown type kind: #{field_type.kind}")
    end
  end
end