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