@@ -115,15 +115,20 @@ module InputObjectPrepareTest
115
115
class InputObj < GraphQL ::Schema ::InputObject
116
116
argument :a , Integer
117
117
argument :b , Integer , as : :b2
118
- argument :c , Integer , prepare : :prep
118
+ argument :c , Integer , prepare : :prep , validates : { exclusion : { in : [ 5 , 10 ] } }
119
119
argument :d , Integer , prepare : :prep , as : :d2
120
120
argument :e , Integer , prepare : -> ( val , ctx ) { val * ctx [ :multiply_by ] * 2 } , as : :e2
121
121
argument :instrument_id , ID , loads : Jazz ::InstrumentType
122
122
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
123
124
124
125
def prep ( val )
125
126
val * context [ :multiply_by ]
126
127
end
128
+
129
+ def echo ( val )
130
+ val
131
+ end
127
132
end
128
133
129
134
class Thing < GraphQL ::Schema ::Object
@@ -258,6 +263,13 @@ def self.resolve_type(type, obj, ctx)
258
263
res = InputObjectPrepareTest ::Schema . execute ( query_str , context : { multiply_by : 3 } )
259
264
expected_obj = [ { a : 1 , b2 : 2 , c : 9 , d2 : 12 , e2 : 30 , instrument : Jazz ::Models ::Instrument . new ( "Drum Kit" , "PERCUSSION" ) } . inspect , "Drum Kit" ]
260
265
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
261
273
end
262
274
263
275
it "calls load_ methods for arguments when they're present" do
0 commit comments