Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/graphql/execution/interpreter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def run_all(schema, query_options, context: {}, max_complexity: schema.max_compl
end
rescue GraphQL::ExecutionError => err
query.context.errors << err
NO_OPERATION
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure on this solution but this rescue wraps execution so any exception rescued here needs to result in the data key being present.

end
end
results[idx] = result
Expand Down
7 changes: 5 additions & 2 deletions spec/graphql/authorization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -909,8 +909,11 @@ def auth_execute(*args, **kwargs)
assert_equal "Query", res["data"]["__typename"]

unauth_res = auth_execute(query, context: { query_unauthorized: true })
assert_nil unauth_res["data"]
assert_equal [{"message"=>"Unauthorized Query: nil"}], unauth_res["errors"]

assert_equal({
"errors" => [{"message"=>"Unauthorized Query: nil"}],
"data" => nil,
}, unauth_res.to_h)
end

describe "when the object authorization raises an UnauthorizedFieldError" do
Expand Down
9 changes: 7 additions & 2 deletions spec/graphql/execution/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,13 @@ def int(value:)
it "rescues execution errors from execute_query" do
context = {raise_execution_error: true}
res = schema.execute(" { int(value: 2) } ", context: context)
assert_equal "Raised from trace execute_query", res["errors"].first["message"]
refute res.key?("data"), "The query doesn't run"

assert_equal({
"data" => nil,
"errors" => [
{ "message" => "Raised from trace execute_query" },
]
}, res.to_h)
end

it "can assign a query string there" do
Expand Down
Loading