lib/graphql/execution/execute.rb in graphql-1.8.4 vs lib/graphql/execution/execute.rb in graphql-1.8.5
- old
+ new
@@ -100,13 +100,17 @@
irep_node = field_ctx.irep_node
parent_type = irep_node.owner_type
field = field_ctx.field
raw_value = begin
- arguments = query.arguments_for(irep_node, field)
- field_ctx.trace("execute_field", { context: field_ctx }) do
- field_ctx.schema.middleware.invoke([parent_type, object, field, arguments, field_ctx])
+ begin
+ arguments = query.arguments_for(irep_node, field)
+ field_ctx.trace("execute_field", { context: field_ctx }) do
+ field_ctx.schema.middleware.invoke([parent_type, object, field, arguments, field_ctx])
+ end
+ rescue GraphQL::UnauthorizedError => err
+ field_ctx.schema.unauthorized_object(err)
end
rescue GraphQL::ExecutionError => err
err
end
@@ -121,25 +125,25 @@
end
rescue GraphQL::ExecutionError => err
err
end
}
- continue_or_wait(inner_value, arguments, field_ctx)
+ continue_or_wait(inner_value, field_ctx.type, field_ctx)
}
else
- continue_or_wait(raw_value, arguments, field_ctx)
+ continue_or_wait(raw_value, field_ctx.type, field_ctx)
end
end
# If the returned object is lazy (unfinished),
# assign the lazy object to `.value=` so we can resolve it later.
# When we resolve it later, reassign it to `.value=` so that
# the finished value replaces the unfinished one.
#
# If the returned object is finished, continue to coerce
# and resolve child fields
- def continue_or_wait(raw_value, arguments, field_ctx)
+ def continue_or_wait(raw_value, field_type, field_ctx)
if (lazy_method = field_ctx.schema.lazy_method_name(raw_value))
field_ctx.value = Execution::Lazy.new {
inner_value = begin
begin
raw_value.public_send(lazy_method)
@@ -148,18 +152,18 @@
end
rescue GraphQL::ExecutionError => err
err
end
- field_ctx.value = continue_or_wait(inner_value, arguments, field_ctx)
+ field_ctx.value = continue_or_wait(inner_value, field_type, field_ctx)
}
else
- field_ctx.value = continue_resolve_field(raw_value, field_ctx)
+ field_ctx.value = continue_resolve_field(raw_value, field_type, field_ctx)
end
end
- def continue_resolve_field(raw_value, field_ctx)
+ def continue_resolve_field(raw_value, field_type, field_ctx)
if field_ctx.parent.invalid_null?
return nil
end
query = field_ctx.query
@@ -167,23 +171,26 @@
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)
+ if !field_type.list?
+ # List type errors are handled above, this is for the case of fields returning an array of errors
+ 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
end
resolve_value(
raw_value,
- field_ctx.type,
+ field_type,
field_ctx,
)
end
def resolve_value(value, field_type, field_ctx)
@@ -227,18 +234,17 @@
key: i,
object: inner_value,
irep_node: field_ctx.irep_node,
)
- inner_result = resolve_value(
+ inner_result = continue_or_wait(
inner_value,
inner_type,
inner_ctx,
)
return PROPAGATE_NULL if inner_result == PROPAGATE_NULL
- inner_ctx.value = inner_result
result << inner_ctx
i += 1
end
result