@@ -115,15 +115,20 @@ module InputObjectPrepareTest
115115 class InputObj < GraphQL ::Schema ::InputObject
116116 argument :a , Integer
117117 argument :b , Integer , as : :b2
118- argument :c , Integer , prepare : :prep
118+ argument :c , Integer , prepare : :prep , validates : { exclusion : { in : [ 5 , 10 ] } }
119119 argument :d , Integer , prepare : :prep , as : :d2
120120 argument :e , Integer , prepare : -> ( val , ctx ) { val * ctx [ :multiply_by ] * 2 } , as : :e2
121121 argument :instrument_id , ID , loads : Jazz ::InstrumentType
122122 argument :danger , Integer , required : false , prepare : -> ( val , ctx ) { raise GraphQL ::ExecutionError . new ( 'boom!' ) }
123+ argument :nested , self , required : false , validates : { allow_null : true } , prepare : :echo
123124
124125 def prep ( val )
125126 val * context [ :multiply_by ]
126127 end
128+
129+ def echo ( val )
130+ val
131+ end
127132 end
128133
129134 class Thing < GraphQL ::Schema ::Object
@@ -258,6 +263,13 @@ def self.resolve_type(type, obj, ctx)
258263 res = InputObjectPrepareTest ::Schema . execute ( query_str , context : { multiply_by : 3 } )
259264 expected_obj = [ { a : 1 , b2 : 2 , c : 9 , d2 : 12 , e2 : 30 , instrument : Jazz ::Models ::Instrument . new ( "Drum Kit" , "PERCUSSION" ) } . inspect , "Drum Kit" ]
260265 assert_equal expected_obj , res [ "data" ] [ "inputs" ]
266+
267+ query_str2 = <<-GRAPHQL
268+ { inputs(input: { a: 1, b: 2, c: 3, d: 4, e: 5, instrumentId: "Instrument/Drum Kit", nested: { a: 2, b: 4, c: 6, d: 8, e: 10, instrumentId: "Instrument/Drum Kit" } }) }
269+ GRAPHQL
270+ res2 = InputObjectPrepareTest ::Schema . execute ( query_str2 , context : { multiply_by : 3 } )
271+ expected_hash_values = { a : 2 , b2 : 4 , c : 6 , d2 : 8 , e2 : 60 } . inspect . sub ( "{" , "" ) . sub ( "}" , "" )
272+ assert_includes res2 [ "data" ] [ "inputs" ] [ 0 ] , expected_hash_values
261273 end
262274
263275 it "calls load_ methods for arguments when they're present" do
0 commit comments