Skip to content

Commit b2ff68c

Browse files
committed
remove completePromisedValue
1 parent 4865143 commit b2ff68c

File tree

2 files changed

+100
-92
lines changed

2 files changed

+100
-92
lines changed

src/execution/__tests__/nonnull-test.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -259,16 +259,6 @@ describe('Execute: handles non-nullable types', () => {
259259
path: ['syncNest', 'syncNest', 'sync'],
260260
locations: [{ line: 6, column: 22 }],
261261
},
262-
{
263-
message: promiseError.message,
264-
path: ['syncNest', 'promise'],
265-
locations: [{ line: 5, column: 11 }],
266-
},
267-
{
268-
message: promiseError.message,
269-
path: ['syncNest', 'syncNest', 'promise'],
270-
locations: [{ line: 6, column: 27 }],
271-
},
272262
{
273263
message: syncError.message,
274264
path: ['syncNest', 'promiseNest', 'sync'],
@@ -284,6 +274,21 @@ describe('Execute: handles non-nullable types', () => {
284274
path: ['promiseNest', 'syncNest', 'sync'],
285275
locations: [{ line: 12, column: 22 }],
286276
},
277+
{
278+
message: promiseError.message,
279+
path: ['syncNest', 'promise'],
280+
locations: [{ line: 5, column: 11 }],
281+
},
282+
{
283+
message: promiseError.message,
284+
path: ['syncNest', 'syncNest', 'promise'],
285+
locations: [{ line: 6, column: 27 }],
286+
},
287+
{
288+
message: syncError.message,
289+
path: ['promiseNest', 'promiseNest', 'sync'],
290+
locations: [{ line: 13, column: 25 }],
291+
},
287292
{
288293
message: promiseError.message,
289294
path: ['syncNest', 'promiseNest', 'promise'],
@@ -299,11 +304,6 @@ describe('Execute: handles non-nullable types', () => {
299304
path: ['promiseNest', 'syncNest', 'promise'],
300305
locations: [{ line: 12, column: 27 }],
301306
},
302-
{
303-
message: syncError.message,
304-
path: ['promiseNest', 'promiseNest', 'sync'],
305-
locations: [{ line: 13, column: 25 }],
306-
},
307307
{
308308
message: promiseError.message,
309309
path: ['promiseNest', 'promiseNest', 'promise'],

src/execution/execute.ts

+85-77
Original file line numberDiff line numberDiff line change
@@ -757,16 +757,30 @@ function executeField(
757757
const result = resolveFn(source, args, contextValue, info);
758758

759759
if (isPromise(result)) {
760-
return completePromisedValue(
761-
exeContext,
762-
returnType,
763-
fieldGroup,
764-
info,
765-
path,
766-
result,
767-
incrementalContext,
768-
deferMap,
769-
);
760+
return result
761+
.then((resolved) =>
762+
completeValue(
763+
exeContext,
764+
returnType,
765+
fieldGroup,
766+
info,
767+
path,
768+
resolved,
769+
incrementalContext,
770+
deferMap,
771+
),
772+
)
773+
.then(undefined, (rawError) => {
774+
handleFieldError(
775+
rawError,
776+
exeContext,
777+
returnType,
778+
fieldGroup,
779+
path,
780+
incrementalContext,
781+
);
782+
return null;
783+
});
770784
}
771785

772786
const completed = completeValue(
@@ -981,45 +995,6 @@ function completeValue(
981995
);
982996
}
983997

984-
async function completePromisedValue(
985-
exeContext: ExecutionContext,
986-
returnType: GraphQLOutputType,
987-
fieldGroup: FieldGroup,
988-
info: GraphQLResolveInfo,
989-
path: Path,
990-
result: Promise<unknown>,
991-
incrementalContext: IncrementalContext | undefined,
992-
deferMap: ReadonlyMap<DeferUsage, DeferredFragmentRecord> | undefined,
993-
): Promise<unknown> {
994-
try {
995-
const resolved = await result;
996-
let completed = completeValue(
997-
exeContext,
998-
returnType,
999-
fieldGroup,
1000-
info,
1001-
path,
1002-
resolved,
1003-
incrementalContext,
1004-
deferMap,
1005-
);
1006-
if (isPromise(completed)) {
1007-
completed = await completed;
1008-
}
1009-
return completed;
1010-
} catch (rawError) {
1011-
handleFieldError(
1012-
rawError,
1013-
exeContext,
1014-
returnType,
1015-
fieldGroup,
1016-
path,
1017-
incrementalContext,
1018-
);
1019-
return null;
1020-
}
1021-
}
1022-
1023998
/**
1024999
* Returns an object containing info for streaming if a field should be
10251000
* streamed based on the experimental flag, stream directive present and
@@ -1469,16 +1444,30 @@ function completeListItemValue(
14691444
): boolean {
14701445
if (isPromise(item)) {
14711446
completedResults.push(
1472-
completePromisedValue(
1473-
exeContext,
1474-
itemType,
1475-
fieldGroup,
1476-
info,
1477-
itemPath,
1478-
item,
1479-
incrementalContext,
1480-
deferMap,
1481-
),
1447+
item
1448+
.then((resolved) =>
1449+
completeValue(
1450+
exeContext,
1451+
itemType,
1452+
fieldGroup,
1453+
info,
1454+
itemPath,
1455+
resolved,
1456+
incrementalContext,
1457+
deferMap,
1458+
),
1459+
)
1460+
.then(undefined, (rawError) => {
1461+
handleFieldError(
1462+
rawError,
1463+
exeContext,
1464+
itemType,
1465+
fieldGroup,
1466+
itemPath,
1467+
incrementalContext,
1468+
);
1469+
return null;
1470+
}),
14821471
);
14831472

14841473
return true;
@@ -2492,24 +2481,43 @@ function completeStreamItems(
24922481
itemType: GraphQLOutputType,
24932482
): PromiseOrValue<StreamItemsResult> {
24942483
if (isPromise(item)) {
2495-
return completePromisedValue(
2496-
exeContext,
2497-
itemType,
2498-
fieldGroup,
2499-
info,
2500-
itemPath,
2501-
item,
2502-
incrementalContext,
2503-
new Map(),
2504-
).then(
2505-
(resolvedItem) =>
2506-
buildStreamItemsResult(incrementalContext, streamRecord, resolvedItem),
2507-
(error) => ({
2508-
streamRecord,
2509-
result: null,
2510-
errors: withError(incrementalContext.errors, error),
2511-
}),
2512-
);
2484+
return item
2485+
.then((resolved) =>
2486+
completeValue(
2487+
exeContext,
2488+
itemType,
2489+
fieldGroup,
2490+
info,
2491+
itemPath,
2492+
resolved,
2493+
incrementalContext,
2494+
new Map(),
2495+
),
2496+
)
2497+
.then(undefined, (rawError) => {
2498+
handleFieldError(
2499+
rawError,
2500+
exeContext,
2501+
itemType,
2502+
fieldGroup,
2503+
itemPath,
2504+
incrementalContext,
2505+
);
2506+
return null;
2507+
})
2508+
.then(
2509+
(resolvedItem) =>
2510+
buildStreamItemsResult(
2511+
incrementalContext,
2512+
streamRecord,
2513+
resolvedItem,
2514+
),
2515+
(error) => ({
2516+
streamRecord,
2517+
result: null,
2518+
errors: withError(incrementalContext.errors, error),
2519+
}),
2520+
);
25132521
}
25142522

25152523
let completedItem;

0 commit comments

Comments
 (0)