Skip to content

Commit 3924bcc

Browse files
committed
fix(defer) make tests pass
1 parent 4e49d70 commit 3924bcc

File tree

4 files changed

+106
-101
lines changed

4 files changed

+106
-101
lines changed

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ RuboCop::RakeTask.new(:rubocop) do |t|
2222
.exclude("lib/graphql/language/lexer.rb")
2323
end
2424

25-
task(default: [:test, :rubocop])
25+
task(default: [:test_both_strategies, :rubocop])
2626

2727
desc "Use Racc & Ragel to regenerate parser.rb & lexer.rb from configuration files"
2828
task :build_parser do

lib/graphql/execution/deferred_execution.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def execute(ast_operation, root_type, query_object)
159159
defers = next_defers
160160
end
161161
else
162-
query_object.context.errors.push(*initial_thread.errors)
162+
query_object.context.errors.concat(initial_thread.errors)
163163
end
164164

165165
initial_result
@@ -333,8 +333,9 @@ def resolve_value(scope, thread, frame, value, type_defn)
333333
when GraphQL::TypeKinds::INTERFACE, GraphQL::TypeKinds::UNION
334334
resolved_type = scope.schema.resolve_type(value, scope.query.context)
335335

336-
if !resolved_type.is_a?(GraphQL::ObjectType) || !scope.schema.possible_types(type_defn).include?(resolved_type)
337-
raise GraphQL::UnresolvedTypeError.new(frame.node.definition_name, scope.schema, type_defn, frame.node.parent.return_type, resolved_type)
336+
possible_types = scope.schema.possible_types(type_defn)
337+
if !resolved_type.is_a?(GraphQL::ObjectType) || !possible_types.include?(resolved_type)
338+
raise GraphQL::UnresolvedTypeError.new(frame.node.definition_name, type_defn, frame.node.parent.return_type, resolved_type, possible_types)
338339
else
339340
resolve_value(scope, thread, frame, value, resolved_type)
340341
end

spec/graphql/execution_error_spec.rb

Lines changed: 100 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -52,104 +52,108 @@
5252
}
5353
|}
5454
it "the error is inserted into the errors key and the rest of the query is fulfilled" do
55-
expected_result = {
56-
"data"=>{
57-
"cheese"=>{
58-
"id" => 1,
59-
"error1"=> nil,
60-
"error2"=> nil,
61-
"nonError"=> {
62-
"id" => 3,
63-
"flavor" => "Manchego",
64-
},
65-
"flavor" => "Brie",
66-
},
67-
"allDairy" => [
68-
{ "flavor" => "Brie" },
69-
{ "flavor" => "Gouda" },
70-
{ "flavor" => "Manchego" },
71-
{ "source" => "COW", "executionError" => nil },
72-
{ "source" => "COW", "executionError" => nil },
73-
],
74-
"dairyErrors" => [
75-
{ "__typename" => "Cheese" },
76-
nil,
77-
{ "__typename" => "Cheese" },
78-
{ "__typename" => "Milk" },
79-
{ "__typename" => "Milk" },
80-
],
81-
"dairy" => {
82-
"milks" => [
83-
{
84-
"source" => "COW",
85-
"executionError" => nil,
86-
"allDairy" => [
87-
{ "__typename" => "Cheese" },
88-
{ "__typename" => "Cheese" },
89-
{ "__typename" => "Cheese" },
90-
{ "__typename" => "Milk", "origin" => "Antiquity", "executionError" => nil },
91-
{ "__typename" => "Milk", "origin" => "Modernity", "executionError" => nil },
92-
]
93-
}
94-
]
95-
},
96-
"executionError" => nil,
97-
"valueWithExecutionError" => 0
55+
expected_data = {
56+
"cheese"=>{
57+
"id" => 1,
58+
"error1"=> nil,
59+
"error2"=> nil,
60+
"nonError"=> {
61+
"id" => 3,
62+
"flavor" => "Manchego",
9863
},
99-
"errors"=>[
100-
{
101-
"message"=>"No cheeses are made from Yak milk!",
102-
"locations"=>[{"line"=>5, "column"=>9}],
103-
"path"=>["cheese", "error1"]
104-
},
105-
{
106-
"message"=>"No cheeses are made from Yak milk!",
107-
"locations"=>[{"line"=>8, "column"=>9}],
108-
"path"=>["cheese", "error2"]
109-
},
110-
{
111-
"message"=>"There was an execution error",
112-
"locations"=>[{"line"=>22, "column"=>11}],
113-
"path"=>["allDairy", 3, "executionError"]
114-
},
115-
{
116-
"message"=>"There was an execution error",
117-
"locations"=>[{"line"=>22, "column"=>11}],
118-
"path"=>["allDairy", 4, "executionError"]
119-
},
120-
{
121-
"message"=>"missing dairy",
122-
"locations"=>[{"line"=>25, "column"=>7}],
123-
"path"=>["dairyErrors", 1]
124-
},
125-
{
126-
"message"=>"There was an execution error",
127-
"locations"=>[{"line"=>31, "column"=>11}],
128-
"path"=>["dairy", "milks", 0, "executionError"]
129-
},
130-
{
131-
"message"=>"There was an execution error",
132-
"locations"=>[{"line"=>36, "column"=>15}],
133-
"path"=>["dairy", "milks", 0, "allDairy", 3, "executionError"]
134-
},
135-
{
136-
"message"=>"There was an execution error",
137-
"locations"=>[{"line"=>36, "column"=>15}],
138-
"path"=>["dairy", "milks", 0, "allDairy", 4, "executionError"]
139-
},
140-
{
141-
"message"=>"There was an execution error",
142-
"locations"=>[{"line"=>41, "column"=>7}],
143-
"path"=>["executionError"]
144-
},
145-
{
146-
"message"=>"Could not fetch latest value",
147-
"locations"=>[{"line"=>42, "column"=>7}],
148-
"path"=>["valueWithExecutionError"]
149-
},
150-
]
64+
"flavor" => "Brie",
65+
},
66+
"allDairy" => [
67+
{ "flavor" => "Brie" },
68+
{ "flavor" => "Gouda" },
69+
{ "flavor" => "Manchego" },
70+
{ "source" => "COW", "executionError" => nil },
71+
{ "source" => "COW", "executionError" => nil },
72+
],
73+
"dairyErrors" => [
74+
{ "__typename" => "Cheese" },
75+
nil,
76+
{ "__typename" => "Cheese" },
77+
{ "__typename" => "Milk" },
78+
{ "__typename" => "Milk" },
79+
],
80+
"dairy" => {
81+
"milks" => [
82+
{
83+
"source" => "COW",
84+
"executionError" => nil,
85+
"allDairy" => [
86+
{ "__typename" => "Cheese" },
87+
{ "__typename" => "Cheese" },
88+
{ "__typename" => "Cheese" },
89+
{ "__typename" => "Milk", "origin" => "Antiquity", "executionError" => nil },
90+
{ "__typename" => "Milk", "origin" => "Modernity", "executionError" => nil },
91+
]
92+
}
93+
]
94+
},
95+
"executionError" => nil,
96+
"valueWithExecutionError" => 0
15197
}
152-
assert_equal(expected_result, result)
98+
99+
expected_errors = [
100+
{
101+
"message"=>"Could not fetch latest value",
102+
"locations"=>[{"line"=>42, "column"=>7}],
103+
"path"=>["valueWithExecutionError"]
104+
},
105+
{
106+
"message"=>"No cheeses are made from Yak milk!",
107+
"locations"=>[{"line"=>5, "column"=>9}],
108+
"path"=>["cheese", "error1"]
109+
},
110+
{
111+
"message"=>"No cheeses are made from Yak milk!",
112+
"locations"=>[{"line"=>8, "column"=>9}],
113+
"path"=>["cheese", "error2"]
114+
},
115+
{
116+
"message"=>"There was an execution error",
117+
"locations"=>[{"line"=>22, "column"=>11}],
118+
"path"=>["allDairy", 3, "executionError"]
119+
},
120+
{
121+
"message"=>"There was an execution error",
122+
"locations"=>[{"line"=>22, "column"=>11}],
123+
"path"=>["allDairy", 4, "executionError"]
124+
},
125+
{
126+
"message"=>"missing dairy",
127+
"locations"=>[{"line"=>25, "column"=>7}],
128+
"path"=>["dairyErrors", 1]
129+
},
130+
{
131+
"message"=>"There was an execution error",
132+
"locations"=>[{"line"=>31, "column"=>11}],
133+
"path"=>["dairy", "milks", 0, "executionError"]
134+
},
135+
{
136+
"message"=>"There was an execution error",
137+
"locations"=>[{"line"=>36, "column"=>15}],
138+
"path"=>["dairy", "milks", 0, "allDairy", 3, "executionError"]
139+
},
140+
{
141+
"message"=>"There was an execution error",
142+
"locations"=>[{"line"=>36, "column"=>15}],
143+
"path"=>["dairy", "milks", 0, "allDairy", 4, "executionError"]
144+
},
145+
{
146+
"message"=>"There was an execution error",
147+
"locations"=>[{"line"=>41, "column"=>7}],
148+
"path"=>["executionError"]
149+
},
150+
]
151+
assert_equal(expected_data, result["data"])
152+
# Different exec strategies may order errors differently:
153+
assert_equal(
154+
expected_errors.sort_by { |e| e["locations"].first.values },
155+
result["errors"].sort_by { |e| e["locations"].first.values}
156+
)
153157
end
154158
end
155159

spec/graphql/internal_representation/rewrite_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@
216216

217217
# Make sure all the data is there:
218218
assert_equal 3, cheeses.length
219-
assert_equal 1, milks.length
219+
assert_equal 2, milks.length
220220

221221
cheeses.each do |cheese|
222222
assert_equal ["cheeseInlineOrigin", "cheeseFragmentOrigin", "edibleInlineOrigin", "untypedInlineOrigin"], cheese["selfAsEdible"].keys

0 commit comments

Comments
 (0)