Skip to content

Commit 33370e7

Browse files
committed
feat(Compatibilty) more null handling specifications
1 parent 0bad071 commit 33370e7

File tree

1 file changed

+82
-24
lines changed

1 file changed

+82
-24
lines changed

lib/graphql/compatibility/execution_specification.rb

Lines changed: 82 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ def self.build_schema(execution_strategy)
9999
obj.organization_ids.map { |id| DATA[id] }
100100
}
101101
end
102+
field :first_organization, !organization_type do
103+
resolve ->(obj, args, ctx) {
104+
DATA[obj.organization_ids.first]
105+
}
106+
end
102107
end
103108

104109
organization_type = GraphQL::ObjectType.define do
@@ -107,7 +112,7 @@ def self.build_schema(execution_strategy)
107112
field :name, !types.String
108113
field :leader, !person_type do
109114
resolve ->(obj, args, ctx) {
110-
DATA[obj.leader_id]
115+
DATA[obj.leader_id] || (ctx[:return_error] ? ExecutionError.new("Error on Nullable") : nil)
111116
}
112117
end
113118
field :returnedError, types.String do
@@ -152,6 +157,12 @@ def self.build_schema(execution_strategy)
152157
args[:id].start_with?("2") && obj[args[:id]]
153158
}
154159
end
160+
161+
field :organizations, types[organization_type] do
162+
resolve ->(obj, args, ctx) {
163+
[obj["2001"], obj["2002"]]
164+
}
165+
end
155166
end
156167

157168
GraphQL::Schema.define do
@@ -260,26 +271,53 @@ def test_it_exposes_raised_and_returned_user_execution_errors
260271
returnedError
261272
raisedError
262273
}
274+
organizations {
275+
returnedError
276+
raisedError
277+
}
263278
}
264279
|
265280

266281
res = execute_query(query_string)
267282

268283
assert_equal "SNCC", res["data"]["organization"]["name"], "It runs the rest of the query"
269284

270-
expected_returned_error = {
271-
"message"=>"This error was returned",
272-
"locations"=>[{"line"=>5, "column"=>19}],
273-
"path"=>["organization", "returnedError"]
274-
}
275-
assert_includes res["errors"], expected_returned_error, "It turns returned errors into response errors"
276-
277-
expected_raised_error = {
278-
"message"=>"This error was raised",
279-
"locations"=>[{"line"=>6, "column"=>19}],
280-
"path"=>["organization", "raisedError"]
281-
}
282-
assert_includes res["errors"], expected_raised_error, "It turns raised errors into response errors"
285+
expected_errors = [
286+
{
287+
"message"=>"This error was returned",
288+
"locations"=>[{"line"=>5, "column"=>19}],
289+
"path"=>["organization", "returnedError"]
290+
},
291+
{
292+
"message"=>"This error was raised",
293+
"locations"=>[{"line"=>6, "column"=>19}],
294+
"path"=>["organization", "raisedError"]
295+
},
296+
{
297+
"message"=>"This error was raised",
298+
"locations"=>[{"line"=>10, "column"=>19}],
299+
"path"=>["organizations", 0, "raisedError"]
300+
},
301+
{
302+
"message"=>"This error was raised",
303+
"locations"=>[{"line"=>10, "column"=>19}],
304+
"path"=>["organizations", 1, "raisedError"]
305+
},
306+
{
307+
"message"=>"This error was returned",
308+
"locations"=>[{"line"=>9, "column"=>19}],
309+
"path"=>["organizations", 0, "returnedError"]
310+
},
311+
{
312+
"message"=>"This error was returned",
313+
"locations"=>[{"line"=>9, "column"=>19}],
314+
"path"=>["organizations", 1, "returnedError"]
315+
},
316+
]
317+
318+
expected_errors.each do |expected_err|
319+
assert_includes res["errors"], expected_err
320+
end
283321
end
284322

285323
def test_it_applies_masking
@@ -335,19 +373,39 @@ def test_it_runs_the_introspection_query
335373
end
336374

337375
def test_it_propagates_deeply_nested_nulls
338-
skip
376+
query_string = %|
377+
{
378+
node(id: "1001") {
379+
... on Person {
380+
name
381+
first_organization {
382+
leader {
383+
name
384+
}
385+
}
386+
}
387+
}
388+
}
389+
|
390+
res = execute_query(query_string)
391+
assert_equal nil, res["data"]["node"]
392+
assert_equal 1, res["errors"].length
339393
end
340394

341395
def test_it_doesnt_add_errors_for_invalid_nulls_from_execution_errors
342-
skip
343-
end
344-
345-
def test_it_passes_invalid_nulls_to_schema
346-
skip
347-
end
348-
349-
def test_it_includes_path_and_index_in_error_path
350-
skip
396+
query_string = %|
397+
query getOrg($id: ID = "2001"){
398+
failure: node(id: $id) {
399+
... on Organization {
400+
name
401+
leader { name }
402+
}
403+
}
404+
}
405+
|
406+
res = execute_query(query_string, context: {return_error: true})
407+
error_messages = res["errors"].map { |e| e["message"] }
408+
assert_equal ["Error on Nullable"], error_messages
351409
end
352410
end
353411
end

0 commit comments

Comments
 (0)