@@ -11,20 +11,85 @@ def setup
1111 } )
1212 end
1313
14- def test_responds_with_error
14+ def test_responds_with_errors_for_each_unauthorized_child_field
1515 query = %|{
1616 orderA(id: "1") {
1717 customer1 {
1818 phone
19+ slack
1920 }
2021 }
2122 }|
2223
23- result = plan_and_execute ( @supergraph , query , claims : [ "orders" ] ) do |plan |
24- pp plan . as_json
25- end
24+ result = plan_and_execute ( @supergraph , query , claims : [ "orders" ] )
25+ expected = {
26+ "data" => {
27+ "orderA" => {
28+ "customer1" => {
29+ "phone" => nil ,
30+ "slack" => nil ,
31+ } ,
32+ } ,
33+ } ,
34+ "errors" => [ {
35+ "message" => "Unauthorized access" ,
36+ "path" => [ "orderA" , "customer1" , "phone" ] ,
37+ "extensions" => { "code" => "unauthorized" } ,
38+ } , {
39+ "message" => "Unauthorized access" ,
40+ "path" => [ "orderA" , "customer1" , "slack" ] ,
41+ "extensions" => { "code" => "unauthorized" } ,
42+ } ] ,
43+ }
2644
27- pp result . to_h
28- assert true
45+ assert_equal expected , result . to_h
46+ end
47+
48+ def test_errors_of_non_null_child_fields_bubble
49+ query = %|{
50+ orderA(id: "1") {
51+ customer1 {
52+ email
53+ }
54+ }
55+ }|
56+
57+ result = plan_and_execute ( @supergraph , query , claims : [ "orders" ] )
58+ expected = {
59+ "data" => {
60+ "orderA" => { "customer1" => nil } ,
61+ } ,
62+ "errors" => [ {
63+ "message" => "Unauthorized access" ,
64+ "path" => [ "orderA" , "customer1" , "email" ] ,
65+ "extensions" => { "code" => "unauthorized" } ,
66+ } ] ,
67+ }
68+
69+ assert_equal expected , result . to_h
70+ end
71+
72+ def test_responds_with_error_for_unauthorized_parent_field
73+ query = %|{
74+ orderA(id: "1") {
75+ customer2 {
76+ phone
77+ }
78+ }
79+ }|
80+
81+ result = plan_and_execute ( @supergraph , query , claims : [ "orders" ] )
82+ expected = {
83+ "data" => {
84+ "orderA" => { "customer2" => nil } ,
85+ } ,
86+ "errors" => [ {
87+ "message" => "Unauthorized access" ,
88+ "path" => [ "orderA" , "customer2" ] ,
89+ "extensions" => { "code" => "unauthorized" } ,
90+ } ] ,
91+ }
92+
93+ assert_equal expected , result . to_h
2994 end
3095end
0 commit comments