Skip to content

Commit 5c427d1

Browse files
committed
remove completePromisedValue
1 parent d996635 commit 5c427d1

File tree

2 files changed

+105
-92
lines changed

2 files changed

+105
-92
lines changed

Diff for: 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'],

Diff for: src/execution/execute.ts

+90-77
Original file line numberDiff line numberDiff line change
@@ -748,15 +748,33 @@ function executeField(
748748
const result = resolveFn(source, args, contextValue, info);
749749

750750
if (isPromise(result)) {
751-
return completePromisedValue(
752-
exeContext,
753-
returnType,
754-
fieldGroup,
755-
info,
756-
path,
757-
result,
758-
incrementalContext,
759-
deferMap,
751+
return (
752+
result
753+
.then((resolved) =>
754+
completeValue(
755+
exeContext,
756+
returnType,
757+
fieldGroup,
758+
info,
759+
path,
760+
resolved,
761+
incrementalContext,
762+
deferMap,
763+
),
764+
)
765+
// Note: we don't rely on a `catch` method, but we do expect "thenable"
766+
// to take a second callback for the error case.
767+
.then(undefined, (rawError) => {
768+
handleFieldError(
769+
rawError,
770+
exeContext,
771+
returnType,
772+
fieldGroup,
773+
path,
774+
incrementalContext,
775+
);
776+
return null;
777+
})
760778
);
761779
}
762780

@@ -972,46 +990,6 @@ function completeValue(
972990
);
973991
}
974992

975-
async function completePromisedValue(
976-
exeContext: ExecutionContext,
977-
returnType: GraphQLOutputType,
978-
fieldGroup: FieldGroup,
979-
info: GraphQLResolveInfo,
980-
path: Path,
981-
result: Promise<unknown>,
982-
incrementalContext: IncrementalContext | undefined,
983-
deferMap: ReadonlyMap<DeferUsage, DeferredFragmentRecord> | undefined,
984-
): Promise<unknown> {
985-
try {
986-
const resolved = await result;
987-
let completed = completeValue(
988-
exeContext,
989-
returnType,
990-
fieldGroup,
991-
info,
992-
path,
993-
resolved,
994-
incrementalContext,
995-
deferMap,
996-
);
997-
998-
if (isPromise(completed)) {
999-
completed = await completed;
1000-
}
1001-
return completed;
1002-
} catch (rawError) {
1003-
handleFieldError(
1004-
rawError,
1005-
exeContext,
1006-
returnType,
1007-
fieldGroup,
1008-
path,
1009-
incrementalContext,
1010-
);
1011-
return null;
1012-
}
1013-
}
1014-
1015993
/**
1016994
* Returns an object containing info for streaming if a field should be
1017995
* streamed based on the experimental flag, stream directive present and
@@ -1454,16 +1432,32 @@ function completeListItemValue(
14541432
): boolean {
14551433
if (isPromise(item)) {
14561434
completedResults.push(
1457-
completePromisedValue(
1458-
exeContext,
1459-
itemType,
1460-
fieldGroup,
1461-
info,
1462-
itemPath,
1463-
item,
1464-
incrementalContext,
1465-
deferMap,
1466-
),
1435+
item
1436+
.then((resolved) =>
1437+
completeValue(
1438+
exeContext,
1439+
itemType,
1440+
fieldGroup,
1441+
info,
1442+
itemPath,
1443+
resolved,
1444+
incrementalContext,
1445+
deferMap,
1446+
),
1447+
)
1448+
// Note: we don't rely on a `catch` method, but we do expect "thenable"
1449+
// to take a second callback for the error case.
1450+
.then(undefined, (rawError) => {
1451+
handleFieldError(
1452+
rawError,
1453+
exeContext,
1454+
itemType,
1455+
fieldGroup,
1456+
itemPath,
1457+
incrementalContext,
1458+
);
1459+
return null;
1460+
}),
14671461
);
14681462
return true;
14691463
}
@@ -2490,24 +2484,43 @@ function completeStreamItems(
24902484
itemType: GraphQLOutputType,
24912485
): PromiseOrValue<StreamItemsResult> {
24922486
if (isPromise(item)) {
2493-
return completePromisedValue(
2494-
exeContext,
2495-
itemType,
2496-
fieldGroup,
2497-
info,
2498-
itemPath,
2499-
item,
2500-
incrementalContext,
2501-
new Map(),
2502-
).then(
2503-
(resolvedItem) =>
2504-
buildStreamItemsResult(incrementalContext, streamRecord, resolvedItem),
2505-
(error) => ({
2506-
streamRecord,
2507-
result: null,
2508-
errors: withError(incrementalContext.errors, error),
2509-
}),
2510-
);
2487+
return item
2488+
.then((resolved) =>
2489+
completeValue(
2490+
exeContext,
2491+
itemType,
2492+
fieldGroup,
2493+
info,
2494+
itemPath,
2495+
resolved,
2496+
incrementalContext,
2497+
new Map(),
2498+
),
2499+
)
2500+
.then(undefined, (rawError) => {
2501+
handleFieldError(
2502+
rawError,
2503+
exeContext,
2504+
itemType,
2505+
fieldGroup,
2506+
itemPath,
2507+
incrementalContext,
2508+
);
2509+
return null;
2510+
})
2511+
.then(
2512+
(resolvedItem) =>
2513+
buildStreamItemsResult(
2514+
incrementalContext,
2515+
streamRecord,
2516+
resolvedItem,
2517+
),
2518+
(error) => ({
2519+
streamRecord,
2520+
result: null,
2521+
errors: withError(incrementalContext.errors, error),
2522+
}),
2523+
);
25112524
}
25122525

25132526
let completedItem;

0 commit comments

Comments
 (0)