@@ -236,6 +236,10 @@ class LandscapeFeature < BaseEnum
236
236
end
237
237
238
238
class Query < BaseObject
239
+ def self . authorized? ( obj , ctx )
240
+ !ctx [ :query_unauthorized ]
241
+ end
242
+
239
243
field :hidden , Integer , null : false
240
244
field :unauthorized , Integer , null : true , method : :itself
241
245
field :int2 , Integer , null : true do
@@ -386,7 +390,7 @@ def self.unauthorized_object(err)
386
390
elsif err . object == :replace
387
391
33
388
392
else
389
- raise GraphQL ::ExecutionError , "Unauthorized #{ err . type . graphql_name } : #{ err . object } "
393
+ raise GraphQL ::ExecutionError , "Unauthorized #{ err . type . graphql_name } : #{ err . object . inspect } "
390
394
end
391
395
end
392
396
@@ -679,7 +683,7 @@ def auth_execute(*args)
679
683
it "adds the error to the errors key" do
680
684
query = "{ unauthorized }"
681
685
response = AuthTest ::Schema . execute ( query , root_value : :hide )
682
- assert_equal [ "Unauthorized Query: hide" ] , response [ "errors" ] . map { |e | e [ "message" ] }
686
+ assert_equal [ "Unauthorized Query: : hide" ] , response [ "errors" ] . map { |e | e [ "message" ] }
683
687
end
684
688
end
685
689
end
@@ -820,7 +824,7 @@ def auth_execute(*args)
820
824
assert_nil unauthorized_res [ "data" ] . fetch ( "a" )
821
825
assert_equal "b" , unauthorized_res [ "data" ] [ "b" ] [ "value" ]
822
826
# Also, the custom handler was called:
823
- assert_equal [ "Unauthorized UnauthorizedCheckBox: a " ] , unauthorized_res [ "errors" ] . map { |e | e [ "message" ] }
827
+ assert_equal [ "Unauthorized UnauthorizedCheckBox: \" a \" " ] , unauthorized_res [ "errors" ] . map { |e | e [ "message" ] }
824
828
end
825
829
826
830
it "Works for lazy connections" do
@@ -885,7 +889,7 @@ def auth_execute(*args)
885
889
886
890
res = auth_execute ( query )
887
891
# An error from two, values from the others
888
- assert_equal [ "Unauthorized UnauthorizedCheckBox: a" , "Unauthorized UnauthorizedCheckBox: a " ] , res [ "errors" ] . map { |e | e [ "message" ] }
892
+ assert_equal [ "Unauthorized UnauthorizedCheckBox: \" a \" " , "Unauthorized UnauthorizedCheckBox: \" a \" " ] , res [ "errors" ] . map { |e | e [ "message" ] }
889
893
assert_equal [ { "value" => "z" } , { "value" => "z2" } , nil , nil ] , res [ "data" ] [ "unauthorizedLazyListInterface" ]
890
894
end
891
895
@@ -897,5 +901,15 @@ def auth_execute(*args)
897
901
res = auth_execute ( query , context : { replace_me : false } )
898
902
assert_equal false , res [ "data" ] [ "replacedObject" ] [ "replaced" ]
899
903
end
904
+
905
+ it "works when the query hook returns false and there's no root object" do
906
+ query = "{ __typename }"
907
+ res = auth_execute ( query )
908
+ assert_equal "Query" , res [ "data" ] [ "__typename" ]
909
+
910
+ unauth_res = auth_execute ( query , context : { query_unauthorized : true } )
911
+ assert_nil unauth_res [ "data" ]
912
+ assert_equal [ { "message" => "Unauthorized Query: nil" } ] , unauth_res [ "errors" ]
913
+ end
900
914
end
901
915
end
0 commit comments