File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -402,9 +402,17 @@ class Mutation < BaseObject
402
402
field :do_unauthorized_stuff , mutation : DoUnauthorizedStuff
403
403
end
404
404
405
+ class Nothing < GraphQL ::Schema ::Directive
406
+ locations ( FIELD )
407
+ def self . visible? ( ctx )
408
+ !!ctx [ :show_nothing_directive ]
409
+ end
410
+ end
411
+
405
412
class Schema < GraphQL ::Schema
406
413
query ( Query )
407
414
mutation ( Mutation )
415
+ directive ( Nothing )
408
416
409
417
lazy_resolve ( Box , :value )
410
418
@@ -601,6 +609,14 @@ def auth_execute(*args, **kwargs)
601
609
refute_includes restricted_sdl , 'Hidden'
602
610
refute_includes restricted_sdl , 'hidden'
603
611
end
612
+
613
+ it "works with directives" do
614
+ query_str = "{ __typename @nothing }"
615
+ visible_response = auth_execute ( query_str , context : { show_nothing_directive : true } )
616
+ assert_equal "Query" , visible_response [ "data" ] [ "__typename" ]
617
+ hidden_response = auth_execute ( query_str )
618
+ assert_equal [ "Directive @nothing is not defined" ] , hidden_response [ "errors" ] . map { |e | e [ "message" ] }
619
+ end
604
620
end
605
621
606
622
describe "applying the authorized? method" do
You can’t perform that action at this time.
0 commit comments