@@ -197,7 +197,10 @@ export interface StreamUsage {
197
197
fieldDetailsList : FieldDetailsList ;
198
198
}
199
199
200
- type GraphQLWrappedResult < T > = [ T , Array < IncrementalDataRecord > | undefined ] ;
200
+ interface GraphQLWrappedResult < T > {
201
+ rawResult : T ;
202
+ incrementalDataRecords : Array < IncrementalDataRecord > | undefined ;
203
+ }
201
204
202
205
const UNEXPECTED_EXPERIMENTAL_DIRECTIVES =
203
206
'The provided schema unexpectedly contains experimental directives (@defer or @stream). These directives may only be utilized if experimental execution features are explicitly enabled.' ;
@@ -360,18 +363,14 @@ export function experimentalExecuteQueryOrMutationOrSubscriptionEvent(
360
363
361
364
if ( isPromise ( graphqlWrappedResult ) ) {
362
365
return graphqlWrappedResult . then (
363
- ( resolved ) => buildDataResponse ( exeContext , resolved [ 0 ] , resolved [ 1 ] ) ,
366
+ ( resolved ) => buildDataResponse ( exeContext , resolved ) ,
364
367
( error : unknown ) => ( {
365
368
data : null ,
366
369
errors : withError ( exeContext . errors , error as GraphQLError ) ,
367
370
} ) ,
368
371
) ;
369
372
}
370
- return buildDataResponse (
371
- exeContext ,
372
- graphqlWrappedResult [ 0 ] ,
373
- graphqlWrappedResult [ 1 ] ,
374
- ) ;
373
+ return buildDataResponse ( exeContext , graphqlWrappedResult ) ;
375
374
} catch ( error ) {
376
375
return { data : null , errors : withError ( exeContext . errors , error ) } ;
377
376
}
@@ -442,10 +441,10 @@ function addIncrementalDataRecords(
442
441
if ( incrementalDataRecords === undefined ) {
443
442
return ;
444
443
}
445
- if ( graphqlWrappedResult [ 1 ] === undefined ) {
446
- graphqlWrappedResult [ 1 ] = [ ...incrementalDataRecords ] ;
444
+ if ( graphqlWrappedResult . incrementalDataRecords === undefined ) {
445
+ graphqlWrappedResult . incrementalDataRecords = [ ...incrementalDataRecords ] ;
447
446
} else {
448
- graphqlWrappedResult [ 1 ] . push ( ...incrementalDataRecords ) ;
447
+ graphqlWrappedResult . incrementalDataRecords . push ( ...incrementalDataRecords ) ;
449
448
}
450
449
}
451
450
@@ -458,9 +457,9 @@ function withError(
458
457
459
458
function buildDataResponse (
460
459
exeContext : ExecutionContext ,
461
- data : ObjMap < unknown > ,
462
- incrementalDataRecords : ReadonlyArray < IncrementalDataRecord > | undefined ,
460
+ graphqlWrappedResult : GraphQLWrappedResult < ObjMap < unknown > > ,
463
461
) : ExecutionResult | ExperimentalIncrementalExecutionResults {
462
+ const { rawResult : data , incrementalDataRecords } = graphqlWrappedResult ;
464
463
const errors = exeContext . errors ;
465
464
if ( incrementalDataRecords === undefined ) {
466
465
return errors !== undefined ? { errors, data } : { data } ;
@@ -675,7 +674,7 @@ function executeFieldsSerially(
675
674
fieldPath ,
676
675
incrementalContext ,
677
676
) ;
678
- graphqlWrappedResult [ 0 ] [ responseName ] = null ;
677
+ graphqlWrappedResult . rawResult [ responseName ] = null ;
679
678
return graphqlWrappedResult ;
680
679
}
681
680
@@ -693,16 +692,25 @@ function executeFieldsSerially(
693
692
}
694
693
if ( isPromise ( result ) ) {
695
694
return result . then ( ( resolved ) => {
696
- graphqlWrappedResult [ 0 ] [ responseName ] = resolved [ 0 ] ;
697
- addIncrementalDataRecords ( graphqlWrappedResult , resolved [ 1 ] ) ;
695
+ graphqlWrappedResult . rawResult [ responseName ] = resolved . rawResult ;
696
+ addIncrementalDataRecords (
697
+ graphqlWrappedResult ,
698
+ resolved . incrementalDataRecords ,
699
+ ) ;
698
700
return graphqlWrappedResult ;
699
701
} ) ;
700
702
}
701
- graphqlWrappedResult [ 0 ] [ responseName ] = result [ 0 ] ;
702
- addIncrementalDataRecords ( graphqlWrappedResult , result [ 1 ] ) ;
703
+ graphqlWrappedResult . rawResult [ responseName ] = result . rawResult ;
704
+ addIncrementalDataRecords (
705
+ graphqlWrappedResult ,
706
+ result . incrementalDataRecords ,
707
+ ) ;
703
708
return graphqlWrappedResult ;
704
709
} ,
705
- [ Object . create ( null ) , undefined ] as GraphQLWrappedResult < ObjMap < unknown > > ,
710
+ {
711
+ rawResult : Object . create ( null ) ,
712
+ incrementalDataRecords : undefined ,
713
+ } ,
706
714
) ;
707
715
}
708
716
@@ -720,10 +728,10 @@ function executeFields(
720
728
deferMap : ReadonlyMap < DeferUsage , DeferredFragmentRecord > | undefined ,
721
729
) : PromiseOrValue < GraphQLWrappedResult < ObjMap < unknown > > > {
722
730
const results = Object . create ( null ) ;
723
- const graphqlWrappedResult : GraphQLWrappedResult < ObjMap < unknown > > = [
724
- results ,
725
- undefined ,
726
- ] ;
731
+ const graphqlWrappedResult : GraphQLWrappedResult < ObjMap < unknown > > = {
732
+ rawResult : results ,
733
+ incrementalDataRecords : undefined ,
734
+ } ;
727
735
let containsPromise = false ;
728
736
729
737
try {
@@ -742,13 +750,19 @@ function executeFields(
742
750
if ( result !== undefined ) {
743
751
if ( isPromise ( result ) ) {
744
752
results [ responseName ] = result . then ( ( resolved ) => {
745
- addIncrementalDataRecords ( graphqlWrappedResult , resolved [ 1 ] ) ;
746
- return resolved [ 0 ] ;
753
+ addIncrementalDataRecords (
754
+ graphqlWrappedResult ,
755
+ resolved . incrementalDataRecords ,
756
+ ) ;
757
+ return resolved . rawResult ;
747
758
} ) ;
748
759
containsPromise = true ;
749
760
} else {
750
- results [ responseName ] = result [ 0 ] ;
751
- addIncrementalDataRecords ( graphqlWrappedResult , result [ 1 ] ) ;
761
+ results [ responseName ] = result . rawResult ;
762
+ addIncrementalDataRecords (
763
+ graphqlWrappedResult ,
764
+ result . incrementalDataRecords ,
765
+ ) ;
752
766
}
753
767
}
754
768
}
@@ -772,10 +786,10 @@ function executeFields(
772
786
// Otherwise, results is a map from field name to the result of resolving that
773
787
// field, which is possibly a promise. Return a promise that will return this
774
788
// same map, but with any promises replaced with the values they resolved to.
775
- return promiseForObject ( results , ( resolved ) => [
776
- resolved ,
777
- graphqlWrappedResult [ 1 ] ,
778
- ] ) ;
789
+ return promiseForObject ( results , ( resolved ) => ( {
790
+ rawResult : resolved ,
791
+ incrementalDataRecords : graphqlWrappedResult . incrementalDataRecords ,
792
+ } ) ) ;
779
793
}
780
794
781
795
function toNodes ( fieldDetailsList : FieldDetailsList ) : ReadonlyArray < FieldNode > {
@@ -871,7 +885,7 @@ function executeField(
871
885
path ,
872
886
incrementalContext ,
873
887
) ;
874
- return [ null , undefined ] ;
888
+ return { rawResult : null , incrementalDataRecords : undefined } ;
875
889
} ) ;
876
890
}
877
891
return completed ;
@@ -884,7 +898,7 @@ function executeField(
884
898
path ,
885
899
incrementalContext ,
886
900
) ;
887
- return [ null , undefined ] ;
901
+ return { rawResult : null , incrementalDataRecords : undefined } ;
888
902
}
889
903
}
890
904
@@ -997,7 +1011,7 @@ function completeValue(
997
1011
incrementalContext ,
998
1012
deferMap ,
999
1013
) ;
1000
- if ( ( completed as GraphQLWrappedResult < unknown > ) [ 0 ] === null ) {
1014
+ if ( ( completed as GraphQLWrappedResult < unknown > ) . rawResult === null ) {
1001
1015
throw new Error (
1002
1016
`Cannot return null for non-nullable field ${ info . parentType } .${ info . fieldName } .` ,
1003
1017
) ;
@@ -1007,7 +1021,7 @@ function completeValue(
1007
1021
1008
1022
// If result value is null or undefined then return null.
1009
1023
if ( result == null ) {
1010
- return [ null , undefined ] ;
1024
+ return { rawResult : null , incrementalDataRecords : undefined } ;
1011
1025
}
1012
1026
1013
1027
// If field type is List, complete each item in the list with the inner type
@@ -1027,7 +1041,10 @@ function completeValue(
1027
1041
// If field type is a leaf type, Scalar or Enum, coerce to a valid value,
1028
1042
// returning null if coercion is not possible.
1029
1043
if ( isLeafType ( returnType ) ) {
1030
- return [ completeLeafValue ( returnType , result ) , undefined ] ;
1044
+ return {
1045
+ rawResult : completeLeafValue ( returnType , result ) ,
1046
+ incrementalDataRecords : undefined ,
1047
+ } ;
1031
1048
}
1032
1049
1033
1050
// If field type is an abstract type, Interface or Union, determine the
@@ -1103,7 +1120,7 @@ async function completePromisedValue(
1103
1120
path ,
1104
1121
incrementalContext ,
1105
1122
) ;
1106
- return [ null , undefined ] ;
1123
+ return { rawResult : null , incrementalDataRecords : undefined } ;
1107
1124
}
1108
1125
}
1109
1126
@@ -1201,10 +1218,10 @@ async function completeAsyncIteratorValue(
1201
1218
) : Promise < GraphQLWrappedResult < ReadonlyArray < unknown > > > {
1202
1219
let containsPromise = false ;
1203
1220
const completedResults : Array < unknown > = [ ] ;
1204
- const graphqlWrappedResult : GraphQLWrappedResult < Array < unknown > > = [
1205
- completedResults ,
1206
- undefined ,
1207
- ] ;
1221
+ const graphqlWrappedResult : GraphQLWrappedResult < Array < unknown > > = {
1222
+ rawResult : completedResults ,
1223
+ incrementalDataRecords : undefined ,
1224
+ } ;
1208
1225
let index = 0 ;
1209
1226
const streamUsage = getStreamUsage (
1210
1227
exeContext . validatedExecutionArgs ,
@@ -1323,10 +1340,10 @@ async function completeAsyncIteratorValue(
1323
1340
}
1324
1341
1325
1342
return containsPromise
1326
- ? /* c8 ignore start */ Promise . all ( completedResults ) . then ( ( resolved ) => [
1327
- resolved ,
1328
- graphqlWrappedResult [ 1 ] ,
1329
- ] )
1343
+ ? /* c8 ignore start */ Promise . all ( completedResults ) . then ( ( resolved ) => ( {
1344
+ rawResult : resolved ,
1345
+ incrementalDataRecords : graphqlWrappedResult . incrementalDataRecords ,
1346
+ } ) )
1330
1347
: /* c8 ignore stop */ graphqlWrappedResult ;
1331
1348
}
1332
1349
@@ -1393,10 +1410,10 @@ function completeIterableValue(
1393
1410
// where the list contains no Promises by avoiding creating another Promise.
1394
1411
let containsPromise = false ;
1395
1412
const completedResults : Array < unknown > = [ ] ;
1396
- const graphqlWrappedResult : GraphQLWrappedResult < Array < unknown > > = [
1397
- completedResults ,
1398
- undefined ,
1399
- ] ;
1413
+ const graphqlWrappedResult : GraphQLWrappedResult < Array < unknown > > = {
1414
+ rawResult : completedResults ,
1415
+ incrementalDataRecords : undefined ,
1416
+ } ;
1400
1417
let index = 0 ;
1401
1418
const streamUsage = getStreamUsage (
1402
1419
exeContext . validatedExecutionArgs ,
@@ -1469,10 +1486,10 @@ function completeIterableValue(
1469
1486
}
1470
1487
1471
1488
return containsPromise
1472
- ? Promise . all ( completedResults ) . then ( ( resolved ) => [
1473
- resolved ,
1474
- graphqlWrappedResult [ 1 ] ,
1475
- ] )
1489
+ ? Promise . all ( completedResults ) . then ( ( resolved ) => ( {
1490
+ rawResult : resolved ,
1491
+ incrementalDataRecords : graphqlWrappedResult . incrementalDataRecords ,
1492
+ } ) )
1476
1493
: graphqlWrappedResult ;
1477
1494
}
1478
1495
@@ -1511,8 +1528,8 @@ function completeListItemValue(
1511
1528
completedResults . push (
1512
1529
completedItem . then (
1513
1530
( resolved ) => {
1514
- addIncrementalDataRecords ( parent , resolved [ 1 ] ) ;
1515
- return resolved [ 0 ] ;
1531
+ addIncrementalDataRecords ( parent , resolved . incrementalDataRecords ) ;
1532
+ return resolved . rawResult ;
1516
1533
} ,
1517
1534
( rawError : unknown ) => {
1518
1535
handleFieldError (
@@ -1530,8 +1547,8 @@ function completeListItemValue(
1530
1547
return true ;
1531
1548
}
1532
1549
1533
- completedResults . push ( completedItem [ 0 ] ) ;
1534
- addIncrementalDataRecords ( parent , completedItem [ 1 ] ) ;
1550
+ completedResults . push ( completedItem . rawResult ) ;
1551
+ addIncrementalDataRecords ( parent , completedItem . incrementalDataRecords ) ;
1535
1552
} catch ( rawError ) {
1536
1553
handleFieldError (
1537
1554
rawError ,
@@ -1572,8 +1589,8 @@ async function completePromisedListItemValue(
1572
1589
if ( isPromise ( completed ) ) {
1573
1590
completed = await completed ;
1574
1591
}
1575
- addIncrementalDataRecords ( parent , completed [ 1 ] ) ;
1576
- return completed [ 0 ] ;
1592
+ addIncrementalDataRecords ( parent , completed . incrementalDataRecords ) ;
1593
+ return completed . rawResult ;
1577
1594
} catch ( rawError ) {
1578
1595
handleFieldError (
1579
1596
rawError ,
@@ -2343,12 +2360,12 @@ function buildCompletedExecutionGroup(
2343
2360
path : Path | undefined ,
2344
2361
result : GraphQLWrappedResult < ObjMap < unknown > > ,
2345
2362
) : CompletedExecutionGroup {
2363
+ const { rawResult : data , incrementalDataRecords } = result ;
2346
2364
return {
2347
2365
pendingExecutionGroup,
2348
2366
path : pathToArray ( path ) ,
2349
- result :
2350
- errors === undefined ? { data : result [ 0 ] } : { data : result [ 0 ] , errors } ,
2351
- incrementalDataRecords : result [ 1 ] ,
2367
+ result : errors === undefined ? { data } : { data, errors } ,
2368
+ incrementalDataRecords,
2352
2369
} ;
2353
2370
}
2354
2371
@@ -2583,7 +2600,7 @@ function completeStreamItem(
2583
2600
itemPath ,
2584
2601
incrementalContext ,
2585
2602
) ;
2586
- result = [ null , undefined ] ;
2603
+ result = { rawResult : null , incrementalDataRecords : undefined } ;
2587
2604
}
2588
2605
} catch ( error ) {
2589
2606
return {
@@ -2602,7 +2619,7 @@ function completeStreamItem(
2602
2619
itemPath ,
2603
2620
incrementalContext ,
2604
2621
) ;
2605
- return [ null , undefined ] as GraphQLWrappedResult < unknown > ;
2622
+ return { rawResult : null , incrementalDataRecords : undefined } ;
2606
2623
} )
2607
2624
. then (
2608
2625
( resolvedItem ) =>
@@ -2620,9 +2637,10 @@ function buildStreamItemResult(
2620
2637
errors : ReadonlyArray < GraphQLError > | undefined ,
2621
2638
result : GraphQLWrappedResult < unknown > ,
2622
2639
) : StreamItemResult {
2640
+ const { rawResult : item , incrementalDataRecords } = result ;
2623
2641
return {
2624
- item : result [ 0 ] ,
2642
+ item,
2625
2643
errors,
2626
- incrementalDataRecords : result [ 1 ] ,
2644
+ incrementalDataRecords,
2627
2645
} ;
2628
2646
}
0 commit comments