@@ -15,7 +15,7 @@ import { SubscriptionContext } from './types/graphql'
15
15
import { PreprocessingData } from './types/preprocessing_data'
16
16
import { RequestOptions , FileUploadOptions } from './types/options'
17
17
import crossFetch from 'cross-fetch'
18
- import { FileUpload } from 'graphql-upload'
18
+ import { FileUpload } from 'graphql-upload/Upload '
19
19
20
20
// Imports:
21
21
import stream from 'stream'
@@ -349,10 +349,16 @@ function inferLinkArguments<TSource, TContext, TArgs>({
349
349
resolveData,
350
350
source,
351
351
args
352
- } : inferLinkArgumentsParam < TSource , TContext , TArgs > ) {
352
+ } : inferLinkArgumentsParam < TSource , TContext , TArgs > ) {
353
353
if ( typeof value === 'object' ) {
354
354
return Object . entries ( value ) . reduce ( ( acc , [ key , value ] ) => {
355
- acc [ key ] = inferLinkArguments ( { paramName, value, resolveData, source, args} )
355
+ acc [ key ] = inferLinkArguments ( {
356
+ paramName,
357
+ value,
358
+ resolveData,
359
+ source,
360
+ args
361
+ } )
356
362
return acc
357
363
} , { } )
358
364
}
@@ -361,13 +367,22 @@ function inferLinkArguments<TSource, TContext, TArgs>({
361
367
return value
362
368
} else if ( value . search ( / { | } / ) === - 1 ) {
363
369
return isRuntimeExpression ( value )
364
- ? resolveRuntimeExpression ( paramName , value , resolveData , source , args )
365
- : value
370
+ ? resolveRuntimeExpression ( paramName , value , resolveData , source , args )
371
+ : value
366
372
} else {
367
373
// Replace link parameters with appropriate values
368
374
const linkParams = value . match ( / { ( [ ^ } ] * ) } / g)
369
375
linkParams . forEach ( ( linkParam ) => {
370
- value = value . replace ( linkParam , resolveRuntimeExpression ( paramName , linkParam . substring ( 1 , linkParam . length - 1 ) , resolveData , source , args ) )
376
+ value = value . replace (
377
+ linkParam ,
378
+ resolveRuntimeExpression (
379
+ paramName ,
380
+ linkParam . substring ( 1 , linkParam . length - 1 ) ,
381
+ resolveData ,
382
+ source ,
383
+ args
384
+ )
385
+ )
371
386
} )
372
387
return value
373
388
}
@@ -493,7 +508,13 @@ export function getResolver<TSource, TContext, TArgs extends object>({
493
508
494
509
let value = argsFromLink [ paramName ]
495
510
496
- args [ saneParamName ] = inferLinkArguments ( { paramName, value, resolveData, source, args} )
511
+ args [ saneParamName ] = inferLinkArguments ( {
512
+ paramName,
513
+ value,
514
+ resolveData,
515
+ source,
516
+ args
517
+ } )
497
518
}
498
519
499
520
// Stored used parameters to future requests:
@@ -595,51 +616,64 @@ export function getResolver<TSource, TContext, TArgs extends object>({
595
616
} else if ( operation . payloadContentType === 'multipart/form-data' ) {
596
617
form = new FormData ( fileUploadOptions )
597
618
598
- const formFieldsPayloadEntries = Object . entries ( args [ sanePayloadName ] ) ;
599
-
600
- ( await Promise . all ( formFieldsPayloadEntries . map ( ( [ _ , v ] ) => v ) ) )
601
- . forEach ( ( fieldValue , idx ) => {
602
- const fieldName = formFieldsPayloadEntries [ idx ] [ 0 ]
603
-
604
- if ( typeof fieldValue === 'object' && Boolean ( ( fieldValue as Partial < FileUpload > ) . createReadStream ) ) {
605
- const uploadingFile = fieldValue as FileUpload
606
- const originalFileStream = uploadingFile . createReadStream ( )
607
- const filePassThrough = new stream . PassThrough ( )
619
+ const formFieldsPayloadEntries = Object . entries ( args [ sanePayloadName ] )
608
620
609
- originalFileStream . on ( 'readable' , function ( ) {
610
- let data
621
+ ; (
622
+ await Promise . all ( formFieldsPayloadEntries . map ( ( [ _ , v ] ) => v ) )
623
+ ) . forEach ( ( fieldValue , idx ) => {
624
+ const fieldName = formFieldsPayloadEntries [ idx ] [ 0 ]
611
625
612
- while ( data = this . read ( ) ) {
613
- const canReadNext = filePassThrough . write ( data )
614
- if ( ! canReadNext ) {
615
- this . pause ( )
616
- filePassThrough . once ( 'drain' , ( ) => this . resume ( ) )
617
- }
618
- }
619
- } )
626
+ if (
627
+ typeof fieldValue === 'object' &&
628
+ Boolean ( ( fieldValue as Partial < FileUpload > ) . createReadStream )
629
+ ) {
630
+ const uploadingFile = fieldValue as FileUpload
631
+ const originalFileStream = uploadingFile . createReadStream ( )
632
+ const filePassThrough = new stream . PassThrough ( )
633
+
634
+ originalFileStream . on ( 'readable' , function ( ) {
635
+ let data
636
+
637
+ while ( ( data = this . read ( ) ) ) {
638
+ const canReadNext = filePassThrough . write ( data )
639
+ if ( ! canReadNext ) {
640
+ this . pause ( )
641
+ filePassThrough . once ( 'drain' , ( ) => this . resume ( ) )
642
+ }
643
+ }
644
+ } )
620
645
621
- originalFileStream . on ( 'error' , ( ) => {
622
- uploadLog ( 'Encountered an error while uploading the file %s' , uploadingFile . filename )
623
- } )
646
+ originalFileStream . on ( 'error' , ( ) => {
647
+ uploadLog (
648
+ 'Encountered an error while uploading the file %s' ,
649
+ uploadingFile . filename
650
+ )
651
+ } )
624
652
625
- originalFileStream . on ( 'end' , ( ) => {
626
- uploadLog ( 'Upload for received file %s completed' , uploadingFile . filename )
627
- filePassThrough . end ( )
628
- } )
653
+ originalFileStream . on ( 'end' , ( ) => {
654
+ uploadLog (
655
+ 'Upload for received file %s completed' ,
656
+ uploadingFile . filename
657
+ )
658
+ filePassThrough . end ( )
659
+ } )
629
660
630
- uploadLog ( 'Queuing upload for received file %s' , uploadingFile . filename )
661
+ uploadLog (
662
+ 'Queuing upload for received file %s' ,
663
+ uploadingFile . filename
664
+ )
631
665
632
- form . append ( fieldName , filePassThrough , {
633
- filename : uploadingFile . filename ,
634
- contentType : uploadingFile . mimetype
635
- } )
636
- } else if ( typeof fieldValue !== 'string' ) {
637
- // Handle all other primitives that aren't strings as strings the way the web server would expect it
638
- form . append ( fieldName , JSON . stringify ( fieldValue ) )
639
- } else {
640
- form . append ( fieldName , fieldValue )
641
- }
666
+ form . append ( fieldName , filePassThrough , {
667
+ filename : uploadingFile . filename ,
668
+ contentType : uploadingFile . mimetype
642
669
} )
670
+ } else if ( typeof fieldValue !== 'string' ) {
671
+ // Handle all other primitives that aren't strings as strings the way the web server would expect it
672
+ form . append ( fieldName , JSON . stringify ( fieldValue ) )
673
+ } else {
674
+ form . append ( fieldName , fieldValue )
675
+ }
676
+ } )
643
677
644
678
rawPayload = form
645
679
} else {
@@ -772,7 +806,10 @@ export function getResolver<TSource, TContext, TArgs extends object>({
772
806
} else {
773
807
httpLog ( `${ response . status } - ${ Oas3Tools . trim ( body , 100 ) } ` )
774
808
775
- if ( response . headers . get ( 'content-type' ) && operation . responseContentType ) {
809
+ if (
810
+ response . headers . get ( 'content-type' ) &&
811
+ operation . responseContentType
812
+ ) {
776
813
/**
777
814
* Throw warning if the non-application/json content does not
778
815
* match the OAS.
@@ -903,7 +940,7 @@ export function getResolver<TSource, TContext, TArgs extends object>({
903
940
) {
904
941
let arraySaneData = saneData
905
942
906
- if ( 'limit' in args && typeof ( args [ 'limit' ] ) === 'number' ) {
943
+ if ( 'limit' in args && typeof args [ 'limit' ] === 'number' ) {
907
944
const limit = args [ 'limit' ] as number
908
945
909
946
if ( limit >= 0 ) {
@@ -1211,7 +1248,9 @@ function resolveRuntimeExpression(
1211
1248
1212
1249
// CASE: parameter in previous header parameter
1213
1250
} else if ( runtimeExpression . startsWith ( '$request.header' ) ) {
1214
- return resolveData . usedRequestOptions . headers [ runtimeExpression . split ( 'header.' ) [ 1 ] ]
1251
+ return resolveData . usedRequestOptions . headers [
1252
+ runtimeExpression . split ( 'header.' ) [ 1 ]
1253
+ ]
1215
1254
}
1216
1255
} else if ( runtimeExpression . startsWith ( '$response.' ) ) {
1217
1256
/**
@@ -1339,7 +1378,11 @@ function graphQLErrorWithExtensions(
1339
1378
* Replaces the path parameter in the given path with values in the given args.
1340
1379
* Furthermore adds the query parameters for a request.
1341
1380
*/
1342
- export function extractRequestDataFromArgs < TSource , TContext , TArgs extends object > (
1381
+ export function extractRequestDataFromArgs <
1382
+ TSource ,
1383
+ TContext ,
1384
+ TArgs extends object
1385
+ > (
1343
1386
path : string ,
1344
1387
parameters : ParameterObject [ ] ,
1345
1388
args : TArgs , // NOTE: argument keys are sanitized!
@@ -1371,18 +1414,28 @@ export function extractRequestDataFromArgs<TSource, TContext, TArgs extends obje
1371
1414
// Query parameters
1372
1415
case 'query' :
1373
1416
// setting param style as form assumes explode is true by default
1374
- if ( param . style === 'form' && typeof args [ saneParamName ] === 'object' ) {
1417
+ if (
1418
+ param . style === 'form' &&
1419
+ typeof args [ saneParamName ] === 'object'
1420
+ ) {
1375
1421
if ( param . explode === false ) {
1376
- qs [ param . name ] = Object . entries ( args [ saneParamName ] ) . reduce ( ( acc , val ) => {
1377
- acc += val . join ( ',' )
1378
- return acc
1379
- } , '' )
1422
+ qs [ param . name ] = Object . entries ( args [ saneParamName ] ) . reduce (
1423
+ ( acc , val ) => {
1424
+ acc += val . join ( ',' )
1425
+ return acc
1426
+ } ,
1427
+ ''
1428
+ )
1380
1429
} else {
1381
1430
Object . entries ( args [ saneParamName ] ) . forEach ( ( [ key , value ] ) => {
1382
1431
qs [ key ] = value
1383
1432
} )
1384
1433
}
1385
- } else if ( Array . isArray ( args [ saneParamName ] ) && param . style === 'form' && param . explode !== false ) {
1434
+ } else if (
1435
+ Array . isArray ( args [ saneParamName ] ) &&
1436
+ param . style === 'form' &&
1437
+ param . explode !== false
1438
+ ) {
1386
1439
qs [ param . name ] = args [ saneParamName ] . join ( ',' )
1387
1440
} else {
1388
1441
qs [ param . name ] = args [ saneParamName ]
0 commit comments