@@ -24,6 +24,16 @@ def authorized?(parent_object, context)
24
24
end
25
25
end
26
26
27
+ class BaseInputObjectArgument < BaseArgument
28
+ def authorized? ( parent_object , context )
29
+ super && parent_object != :hide3
30
+ end
31
+ end
32
+
33
+ class BaseInputObject < GraphQL ::Schema ::InputObject
34
+ argument_class BaseInputObjectArgument
35
+ end
36
+
27
37
class BaseField < GraphQL ::Schema ::Field
28
38
def initialize ( *args , edge_class : nil , **kwargs , &block )
29
39
@edge_class = edge_class
@@ -243,6 +253,11 @@ class LandscapeFeature < BaseEnum
243
253
value "TAR_PIT" , role : :hidden
244
254
end
245
255
256
+ class AddInput < BaseInputObject
257
+ argument :left , Integer , required : true
258
+ argument :right , Integer , required : true
259
+ end
260
+
246
261
class Query < BaseObject
247
262
def self . authorized? ( obj , ctx )
248
263
!ctx [ :query_unauthorized ]
@@ -347,6 +362,14 @@ def lazy_integers
347
362
def replaced_object
348
363
Replaceable . new
349
364
end
365
+
366
+ field :add_inputs , Integer , null : true do
367
+ argument :input , AddInput , required : true
368
+ end
369
+
370
+ def add_inputs ( input :)
371
+ input [ :left ] + input [ :right ]
372
+ end
350
373
end
351
374
352
375
class DoHiddenStuff < GraphQL ::Schema ::RelayClassicMutation
@@ -737,6 +760,21 @@ def auth_execute(*args)
737
760
assert_equal 5 , visible_response [ "data" ] [ "int2" ]
738
761
end
739
762
763
+ it "halts on unauthorized input object arguments, using the parent object" do
764
+ query = "{ addInputs(input: { left: 3, right: 2 }) }"
765
+ hidden_field_argument_response = auth_execute ( query , root_value : :hide2 )
766
+ assert_nil hidden_field_argument_response [ "data" ] . fetch ( "addInputs" )
767
+ assert_equal [ "Unauthorized Query: :hide2" ] , hidden_field_argument_response [ "errors" ] . map { |e | e [ "message" ] }
768
+
769
+ hidden_input_obj_argument_response = auth_execute ( query , root_value : :hide3 )
770
+ assert_nil hidden_input_obj_argument_response [ "data" ] . fetch ( "addInputs" )
771
+ assert_equal [ "Unauthorized Query: :hide3" ] , hidden_input_obj_argument_response [ "errors" ] . map { |e | e [ "message" ] }
772
+
773
+ visible_response = auth_execute ( query )
774
+ assert_equal 5 , visible_response [ "data" ] [ "addInputs" ]
775
+ refute visible_response . key? ( "errors" )
776
+ end
777
+
740
778
it "works with edges and connections" do
741
779
query = <<-GRAPHQL
742
780
{
0 commit comments