@@ -185,9 +185,10 @@ export function processTypeArgs<V, T>({
185
185
return ( resolve , parent , args , ctx , info ) => {
186
186
const argDefs = findArgumentsOfType ( type , info )
187
187
if ( argDefs . length ) {
188
- // apply argument transform function to arguments of the selected type
189
- // the caller's transform function is applied to values that may be embedded in lists and promises
190
- // finally the resolver is called with transformed argument values
188
+ // Apply argument transform function to arguments of the selected type
189
+ // The caller's transform function is applied to values that may be embedded
190
+ // in lists and promises, but not to null or undefined values
191
+ // Finally the resolver is called with transformed argument values
191
192
return (
192
193
Promise . all (
193
194
filterMap (
@@ -209,3 +210,55 @@ export function processTypeArgs<V, T>({
209
210
return resolve ( parent , args , ctx , info )
210
211
}
211
212
}
213
+
214
+ export function processArgs ( { visitor } ) : IMiddlewareFunction {
215
+ return ( resolve , parent , args , ctx , info ) => {
216
+ const argDefs = getFieldArguments ( info )
217
+ if ( argDefs . length ) {
218
+ // Apply argument transform function to all arguments
219
+ // The caller's visitor function is applied to values that may be embedded
220
+ // in lists and promises, but not to null or undefined values
221
+ // Finally the resolver is called with transformed argument values
222
+ return (
223
+ Promise . all (
224
+ filterMap (
225
+ makeArgumentTransform ( visitor , parent , args , ctx , info ) ,
226
+ argDefs ,
227
+ ) ,
228
+ )
229
+ // substitute the transformed values into the args object
230
+ . then ( result =>
231
+ result . reduce (
232
+ ( args , [ name , newValue ] ) => ( args [ name ] = newValue ) ,
233
+ args ,
234
+ ) ,
235
+ )
236
+ . then ( newArgs => resolve ( parent , newArgs , ctx , info ) )
237
+ )
238
+ }
239
+
240
+ return resolve ( parent , args , ctx , info )
241
+ }
242
+ }
243
+
244
+ // Preceding revision as a special case --------------------------------------
245
+
246
+ // this object shape is defined by Apollo Upload Server v5.0.0
247
+ export interface IUploadFile {
248
+ stream
249
+ filename
250
+ mimetype
251
+ encoding
252
+ }
253
+
254
+ declare type IUploadHandler < T > = ( upload : IUploadFile ) => Promise < T >
255
+
256
+ export interface IUploadConfig < T > {
257
+ uploadHandler : IUploadHandler < T >
258
+ }
259
+
260
+ export function update < T > ( {
261
+ uploadHandler,
262
+ } : IUploadConfig < T > ) : IMiddlewareFunction {
263
+ return processTypeArgs ( { type : 'Upload' , transform : uploadHandler } )
264
+ }
0 commit comments