Skip to content

Commit 447a381

Browse files
committed
Ensure data entry exists for execution errors
According to the spec, the `data` entry should always exist once execution starts. Only if an error is raised _before_ execution starts should the `data` key be omitted. The only test that needed updating was when an `ExecutionError` was raised during the `execute_query` trace hook. Despite this running before `super`, this still happens "during execution" and should have the `data` key present. Ref: https://spec.graphql.org/draft/#sec-Data
1 parent db11d0c commit 447a381

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

lib/graphql/execution/interpreter.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ def run_all(schema, query_options, context: {}, max_complexity: schema.max_compl
8080
end
8181
rescue GraphQL::ExecutionError => err
8282
query.context.errors << err
83-
NO_OPERATION
8483
end
8584
end
8685
results[idx] = result

spec/graphql/authorization_spec.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -909,8 +909,11 @@ def auth_execute(*args, **kwargs)
909909
assert_equal "Query", res["data"]["__typename"]
910910

911911
unauth_res = auth_execute(query, context: { query_unauthorized: true })
912-
assert_nil unauth_res["data"]
913-
assert_equal [{"message"=>"Unauthorized Query: nil"}], unauth_res["errors"]
912+
913+
assert_equal({
914+
"errors" => [{"message"=>"Unauthorized Query: nil"}],
915+
"data" => nil,
916+
}, unauth_res.to_h)
914917
end
915918

916919
describe "when the object authorization raises an UnauthorizedFieldError" do

spec/graphql/execution/instrumentation_spec.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,13 @@ def int(value:)
128128
it "rescues execution errors from execute_query" do
129129
context = {raise_execution_error: true}
130130
res = schema.execute(" { int(value: 2) } ", context: context)
131-
assert_equal "Raised from trace execute_query", res["errors"].first["message"]
132-
refute res.key?("data"), "The query doesn't run"
131+
132+
assert_equal({
133+
"data" => nil,
134+
"errors" => [
135+
{ "message" => "Raised from trace execute_query" },
136+
]
137+
}, res.to_h)
133138
end
134139

135140
it "can assign a query string there" do

0 commit comments

Comments
 (0)