Skip to content

Commit fcc70b7

Browse files
committed
remove completePromisedValue
1 parent 9a3b505 commit fcc70b7

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
@@ -741,16 +741,30 @@ function executeField(
741741
const result = resolveFn(source, args, contextValue, info);
742742

743743
if (isPromise(result)) {
744-
return completePromisedValue(
745-
exeContext,
746-
returnType,
747-
fieldGroup,
748-
info,
749-
path,
750-
result,
751-
incrementalContext,
752-
deferMap,
753-
);
744+
return result
745+
.then((resolved) =>
746+
completeValue(
747+
exeContext,
748+
returnType,
749+
fieldGroup,
750+
info,
751+
path,
752+
resolved,
753+
incrementalContext,
754+
deferMap,
755+
),
756+
)
757+
.then(undefined, (rawError) => {
758+
handleFieldError(
759+
rawError,
760+
exeContext,
761+
returnType,
762+
fieldGroup,
763+
path,
764+
incrementalContext,
765+
);
766+
return null;
767+
});
754768
}
755769

756770
const completed = completeValue(
@@ -965,45 +979,6 @@ function completeValue(
965979
);
966980
}
967981

968-
async function completePromisedValue(
969-
exeContext: ExecutionContext,
970-
returnType: GraphQLOutputType,
971-
fieldGroup: FieldGroup,
972-
info: GraphQLResolveInfo,
973-
path: Path,
974-
result: Promise<unknown>,
975-
incrementalContext: IncrementalContext | undefined,
976-
deferMap: ReadonlyMap<DeferUsage, DeferredFragmentRecord> | undefined,
977-
): Promise<unknown> {
978-
try {
979-
const resolved = await result;
980-
let completed = completeValue(
981-
exeContext,
982-
returnType,
983-
fieldGroup,
984-
info,
985-
path,
986-
resolved,
987-
incrementalContext,
988-
deferMap,
989-
);
990-
if (isPromise(completed)) {
991-
completed = await completed;
992-
}
993-
return completed;
994-
} catch (rawError) {
995-
handleFieldError(
996-
rawError,
997-
exeContext,
998-
returnType,
999-
fieldGroup,
1000-
path,
1001-
incrementalContext,
1002-
);
1003-
return null;
1004-
}
1005-
}
1006-
1007982
/**
1008983
* Returns an object containing info for streaming if a field should be
1009984
* streamed based on the experimental flag, stream directive present and
@@ -1453,16 +1428,30 @@ function completeListItemValue(
14531428
): boolean {
14541429
if (isPromise(item)) {
14551430
completedResults.push(
1456-
completePromisedValue(
1457-
exeContext,
1458-
itemType,
1459-
fieldGroup,
1460-
info,
1461-
itemPath,
1462-
item,
1463-
incrementalContext,
1464-
deferMap,
1465-
),
1431+
item
1432+
.then((resolved) =>
1433+
completeValue(
1434+
exeContext,
1435+
itemType,
1436+
fieldGroup,
1437+
info,
1438+
itemPath,
1439+
resolved,
1440+
incrementalContext,
1441+
deferMap,
1442+
),
1443+
)
1444+
.then(undefined, (rawError) => {
1445+
handleFieldError(
1446+
rawError,
1447+
exeContext,
1448+
itemType,
1449+
fieldGroup,
1450+
itemPath,
1451+
incrementalContext,
1452+
);
1453+
return null;
1454+
}),
14661455
);
14671456

14681457
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)