@@ -435,13 +435,11 @@ function executeOperation(
435
435
: executeFields ( exeContext , type , rootValue , path , fields ) ;
436
436
const promise = getPromise ( result ) ;
437
437
if ( promise ) {
438
- return promise
439
- . then ( resolved => ( { data : resolved } ) )
440
- . then ( undefined , error =>
441
- mergeErrors ( exeContext , { data : null , errors : [ error ] } ) ,
442
- ) ;
438
+ return promise . then ( undefined , error =>
439
+ mergeErrors ( exeContext , { data : null , errors : [ error ] } ) ,
440
+ ) ;
443
441
}
444
- return mergeErrors ( exeContext , { data : result } ) ;
442
+ return mergeErrors ( exeContext , result ) ;
445
443
} catch (error) {
446
444
return mergeErrors ( exeContext , { data : null , errors : [ error ] } ) ;
447
445
}
@@ -498,40 +496,36 @@ function executeFieldsSerially(
498
496
sourceValue: mixed,
499
497
path: ResponsePath | void,
500
498
fields: ObjMap< Array < FieldNode > > ,
501
- ) : Promise < ObjMap < mixed > > {
502
- return Object . keys ( fields ) . reduce (
503
- ( prevPromise , responseName ) =>
504
- prevPromise . then ( results => {
505
- const fieldNodes = fields [ responseName ] ;
506
- const fieldPath = addPath ( path , responseName ) ;
507
- const result = resolveField (
508
- exeContext ,
509
- parentType ,
510
- sourceValue ,
511
- fieldNodes ,
512
- fieldPath ,
513
- ) ;
514
- if ( result === null ) {
515
- return results ;
516
- }
517
- const promise = getPromise ( result ) ;
518
- if ( promise ) {
519
- return promise . then ( resolvedResult => {
520
- if ( resolvedResult . errors && resolvedResult . errors . length ) {
521
- exeContext . errors . push . apply ( exeContext . errors , resolvedResult . errors ) ;
522
- }
523
- results [ responseName ] = resolvedResult . data ;
499
+ ) : ExecutionPartialResult < mixed > {
500
+ return Object . keys ( fields )
501
+ . reduce (
502
+ ( prevPromise , responseName ) =>
503
+ prevPromise . then ( results => {
504
+ const fieldNodes = fields [ responseName ] ;
505
+ const fieldPath = addPath ( path , responseName ) ;
506
+ const result = resolveField (
507
+ exeContext ,
508
+ parentType ,
509
+ sourceValue ,
510
+ fieldNodes ,
511
+ fieldPath ,
512
+ ) ;
513
+ if ( result === null ) {
524
514
return results ;
525
- } ) ;
526
- }
527
- if ( result . errors && result . errors . length ) {
528
- exeContext . errors . push . apply ( exeContext . errors , result . errors ) ;
529
- }
530
- results [ responseName ] = result . data ;
531
- return results ;
532
- } ) ,
533
- Promise . resolve ( { } ) ,
534
- ) ;
515
+ }
516
+ const promise = getPromise ( result ) ;
517
+ if ( promise ) {
518
+ return promise . then ( resolvedResult => {
519
+ results [ responseName ] = resolvedResult ;
520
+ return results ;
521
+ } ) ;
522
+ }
523
+ results [ responseName ] = result ;
524
+ return results ;
525
+ } ) ,
526
+ Promise . resolve ( { } ) ,
527
+ )
528
+ . then ( finalResults => mergeEPRs ( finalResults ) ) ;
535
529
}
536
530
537
531
/**
@@ -544,7 +538,7 @@ function executeFields(
544
538
sourceValue: mixed,
545
539
path: ResponsePath | void,
546
540
fields: ObjMap< Array < FieldNode > > ,
547
- ) : MaybePromise < ObjMap < mixed > > {
541
+ ) : ExecutionPartialResult < mixed > {
548
542
let containsPromise = false ;
549
543
550
544
const finalResults = Object . keys ( fields ) . reduce ( ( results , responseName ) => {
@@ -569,23 +563,14 @@ function executeFields(
569
563
570
564
// If there are no promises, we can just return the object
571
565
if ( ! containsPromise ) {
572
- const merged = mergeEPRs ( finalResults ) ;
573
- if ( merged . errors && merged . errors . length ) {
574
- exeContext . errors . push . apply ( exeContext . errors , merged . errors ) ;
575
- }
576
- return merged.data;
566
+ return mergeEPRs ( finalResults ) ;
577
567
}
578
568
579
569
// Otherwise, results is a map from field name to the result
580
570
// of resolving that field, which is possibly a promise. Return
581
571
// a promise that will return this same map, but with any
582
572
// promises replaced with the values they resolved to.
583
- return promiseForObject ( finalResults ) . then ( merged => {
584
- if ( merged . errors && merged . errors . length ) {
585
- exeContext . errors . push . apply ( exeContext . errors , merged . errors ) ;
586
- }
587
- return merged.data;
588
- } ) ;
573
+ return promiseForObject(finalResults);
589
574
}
590
575
591
576
function mergeEPRs (
@@ -1278,19 +1263,14 @@ function completeObjectValue(
1278
1263
if ( ! isTypeOfResult ) {
1279
1264
throw invalidReturnTypeError ( returnType , result , fieldNodes ) ;
1280
1265
}
1281
- const data = collectAndExecuteSubfields (
1266
+ return collectAndExecuteSubfields (
1282
1267
exeContext ,
1283
1268
returnType ,
1284
1269
fieldNodes ,
1285
1270
info ,
1286
1271
path ,
1287
1272
result ,
1288
1273
) ;
1289
- const subpromise = getPromise ( data ) ;
1290
- if ( subpromise ) {
1291
- return subpromise . then ( d => ( { data : d } ) ) ;
1292
- }
1293
- return { data } ;
1294
1274
} ) ;
1295
1275
}
1296
1276
@@ -1299,19 +1279,14 @@ function completeObjectValue(
1299
1279
}
1300
1280
}
1301
1281
1302
- const subfields = collectAndExecuteSubfields (
1282
+ return collectAndExecuteSubfields (
1303
1283
exeContext ,
1304
1284
returnType,
1305
1285
fieldNodes,
1306
1286
info,
1307
1287
path,
1308
1288
result,
1309
1289
) ;
1310
- const subfpromise = getPromise ( subfields ) ;
1311
- if ( subfpromise ) {
1312
- return subfpromise . then ( d => ( { data : d } ) ) ;
1313
- }
1314
- return { data : subfields } ;
1315
1290
}
1316
1291
1317
1292
function invalidReturnTypeError (
@@ -1332,7 +1307,7 @@ function collectAndExecuteSubfields(
1332
1307
info : GraphQLResolveInfo ,
1333
1308
path : ResponsePath ,
1334
1309
result : mixed ,
1335
- ) : mixed {
1310
+ ) : ExecutionPartialResult < mixed > {
1336
1311
// Collect sub-fields to execute to complete this value.
1337
1312
let subFieldNodes = Object . create ( null ) ;
1338
1313
const visitedFragmentNames = Object . create ( null ) ;
0 commit comments