@@ -99,6 +99,11 @@ def self.build_schema(execution_strategy)
99
99
obj . organization_ids . map { |id | DATA [ id ] }
100
100
}
101
101
end
102
+ field :first_organization , !organization_type do
103
+ resolve -> ( obj , args , ctx ) {
104
+ DATA [ obj . organization_ids . first ]
105
+ }
106
+ end
102
107
end
103
108
104
109
organization_type = GraphQL ::ObjectType . define do
@@ -107,7 +112,7 @@ def self.build_schema(execution_strategy)
107
112
field :name , !types . String
108
113
field :leader , !person_type do
109
114
resolve -> ( obj , args , ctx ) {
110
- DATA [ obj . leader_id ]
115
+ DATA [ obj . leader_id ] || ( ctx [ :return_error ] ? ExecutionError . new ( "Error on Nullable" ) : nil )
111
116
}
112
117
end
113
118
field :returnedError , types . String do
@@ -152,6 +157,12 @@ def self.build_schema(execution_strategy)
152
157
args [ :id ] . start_with? ( "2" ) && obj [ args [ :id ] ]
153
158
}
154
159
end
160
+
161
+ field :organizations , types [ organization_type ] do
162
+ resolve -> ( obj , args , ctx ) {
163
+ [ obj [ "2001" ] , obj [ "2002" ] ]
164
+ }
165
+ end
155
166
end
156
167
157
168
GraphQL ::Schema . define do
@@ -260,26 +271,53 @@ def test_it_exposes_raised_and_returned_user_execution_errors
260
271
returnedError
261
272
raisedError
262
273
}
274
+ organizations {
275
+ returnedError
276
+ raisedError
277
+ }
263
278
}
264
279
|
265
280
266
281
res = execute_query ( query_string )
267
282
268
283
assert_equal "SNCC" , res [ "data" ] [ "organization" ] [ "name" ] , "It runs the rest of the query"
269
284
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
283
321
end
284
322
285
323
def test_it_applies_masking
@@ -335,19 +373,39 @@ def test_it_runs_the_introspection_query
335
373
end
336
374
337
375
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
339
393
end
340
394
341
395
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
351
409
end
352
410
end
353
411
end
0 commit comments