61
61
end
62
62
end
63
63
64
- <<<<<<< HEAD
65
64
describe "prepare: / loads: / as:" do
66
65
module InputObjectPrepareTest
67
- =======
68
- describe "prepare: / as: (argument)" do
69
- module InputObjectPrepareArgumentTest
70
- >>>>>>> Prepare input objects
71
66
class InputObj < GraphQL ::Schema ::InputObject
72
67
argument :a , Integer , required : true
73
68
argument :b , Integer , required : true , as : :b2
@@ -140,13 +135,8 @@ def self.resolve_type(type, obj, ctx)
140
135
{ inputs(input: { a: 1, b: 2, c: 3, d: 4, e: 5, instrumentId: "Instrument/Drum Kit" }) }
141
136
GRAPHQL
142
137
143
- <<<<<<< HEAD
144
138
res = InputObjectPrepareTest ::Schema . execute ( query_str , context : { multiply_by : 3 } )
145
139
expected_obj = [ { a : 1 , b2 : 2 , c : 9 , d2 : 12 , e2 : 30 , instrument : Jazz ::Models ::Instrument . new ( "Drum Kit" , "PERCUSSION" ) } . inspect , "Drum Kit" ]
146
- =======
147
- res = InputObjectPrepareArgumentTest ::Schema . execute ( query_str , context : { multiply_by : 3 } )
148
- expected_obj = { a : 1 , b2 : 2 , c : 9 , d2 : 12 , e2 : 30 } . inspect
149
- >>>>>>> Prepare input objects
150
140
assert_equal expected_obj , res [ "data" ] [ "inputs" ]
151
141
end
152
142
@@ -181,33 +171,31 @@ def self.resolve_type(type, obj, ctx)
181
171
end
182
172
end
183
173
184
- describe "loading application object(s)" do
185
- module InputObjectLoadsTest
186
- class BaseArgument < GraphQL ::Schema ::Argument
187
- def authorized? ( obj , val , ctx )
188
- if contains_spinal_tap? ( val )
189
- false
190
- else
191
- true
192
- end
174
+ describe "prepare (entire input object)" do
175
+ module InputObjectPrepareObjectTest
176
+ class InputObj < GraphQL ::Schema ::InputObject
177
+ argument :min , Integer , required : true
178
+ argument :max , Integer , required : false
179
+
180
+ def prepare
181
+ min ..max
193
182
end
183
+ end
194
184
195
- def contains_spinal_tap? ( val )
196
- if val . is_a? ( Array )
197
- val . any? { |v | contains_spinal_tap? ( v ) }
198
- else
199
- val . is_a? ( Jazz ::Models ::Ensemble ) && val . name == "Spinal Tap"
200
- end
185
+ class Query < GraphQL ::Schema ::Object
186
+ field :inputs , String , null : false do
187
+ argument :input , InputObj , required : true
188
+ end
189
+
190
+ def inputs ( input :)
191
+ input . inspect
201
192
end
202
193
end
203
194
204
- <<<<<<< HEAD
205
- =======
206
195
class Schema < GraphQL ::Schema
207
196
query ( Query )
208
197
209
198
if TESTING_INTERPRETER
210
- use GraphQL ::Analysis ::AST
211
199
use GraphQL ::Execution ::Interpreter
212
200
end
213
201
end
@@ -234,9 +222,27 @@ class Schema < GraphQL::Schema
234
222
end
235
223
end
236
224
225
+
237
226
describe "loading application object(s)" do
238
227
module InputObjectLoadsTest
239
- >>>>>>> initial debug
228
+ class BaseArgument < GraphQL ::Schema ::Argument
229
+ def authorized? ( obj , val , ctx )
230
+ if contains_spinal_tap? ( val )
231
+ false
232
+ else
233
+ true
234
+ end
235
+ end
236
+
237
+ def contains_spinal_tap? ( val )
238
+ if val . is_a? ( Array )
239
+ val . any? { |v | contains_spinal_tap? ( v ) }
240
+ else
241
+ val . is_a? ( Jazz ::Models ::Ensemble ) && val . name == "Spinal Tap"
242
+ end
243
+ end
244
+ end
245
+
240
246
class SingleLoadInputObj < GraphQL ::Schema ::InputObject
241
247
argument_class BaseArgument
242
248
argument :instrument_id , ID , required : true , loads : Jazz ::InstrumentType
@@ -266,10 +272,6 @@ def multi_load_input(input:)
266
272
267
273
class Schema < GraphQL ::Schema
268
274
query ( Query )
269
- if TESTING_INTERPRETER
270
- use GraphQL ::Execution ::Interpreter
271
- use GraphQL ::Analysis ::AST
272
- end
273
275
274
276
def self . object_from_id ( id , ctx )
275
277
Jazz ::GloballyIdentifiableType . find ( id )
@@ -278,6 +280,11 @@ def self.object_from_id(id, ctx)
278
280
def self . resolve_type ( type , obj , ctx )
279
281
type
280
282
end
283
+
284
+ if TESTING_INTERPRETER
285
+ use GraphQL ::Analysis ::AST
286
+ use GraphQL ::Execution ::Interpreter
287
+ end
281
288
end
282
289
end
283
290
0 commit comments