Skip to content

Commit

Permalink
Revert "remove promiseWithResolvers"
Browse files Browse the repository at this point in the history
This reverts commit 9342626.

it's faster actually with the helper function
  • Loading branch information
yaacovCR committed Oct 29, 2024
1 parent 9342626 commit 7dea80e
Showing 1 changed file with 50 additions and 47 deletions.
97 changes: 50 additions & 47 deletions src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { addPath, pathToArray } from '../jsutils/Path.js';
import { promiseForObject } from '../jsutils/promiseForObject.js';
import type { PromiseOrValue } from '../jsutils/PromiseOrValue.js';
import { promiseReduce } from '../jsutils/promiseReduce.js';
import { promiseWithResolvers } from '../jsutils/promiseWithResolvers.js';

import { GraphQLError } from '../error/GraphQLError.js';
import { locatedError } from '../error/locatedError.js';
Expand Down Expand Up @@ -867,41 +868,42 @@ function executeField(
const result = resolveFn(source, args, contextValue, info, abortSignal);

if (isPromise(result)) {
return new Promise((resolve, reject) => {
abortSignal?.addEventListener(
'abort',
() => {
try {
resolve({
rawResult: null,
incrementalDataRecords: undefined,
errors: [
buildFieldError(
abortSignal.reason,
returnType,
fieldDetailsList,
path,
),
],
});
} catch (error) {
reject(error as GraphQLError);
}
},
{ once: true },
);
completePromisedValue(
exeContext,
returnType,
fieldDetailsList,
info,
path,
result,
incrementalContext,
deferMap,
// eslint-disable-next-line @typescript-eslint/use-unknown-in-catch-callback-variable
).then(resolve, reject);
});
const { promise, resolve, reject } =
promiseWithResolvers<GraphQLWrappedResult<unknown>>();
abortSignal?.addEventListener(
'abort',
() => {
try {
resolve({
rawResult: null,
incrementalDataRecords: undefined,
errors: [
buildFieldError(
abortSignal.reason,
returnType,
fieldDetailsList,
path,
),
],
});
} catch (error) {
reject(error);
}
},
{ once: true },
);
completePromisedValue(
exeContext,
returnType,
fieldDetailsList,
info,
path,
result,
incrementalContext,
deferMap,
// eslint-disable-next-line @typescript-eslint/use-unknown-in-catch-callback-variable
).then(resolve, reject);
return promise;
}

const completed = completeValue(
Expand Down Expand Up @@ -2204,18 +2206,19 @@ function executeSubscription(
const result = resolveFn(rootValue, args, contextValue, info, abortSignal);

if (isPromise(result)) {
return new Promise((resolve, reject) => {
abortSignal?.addEventListener(
'abort',
() =>
reject(
locatedError(abortSignal.reason, fieldNodes, pathToArray(path)),
),
{ once: true },
);
// eslint-disable-next-line @typescript-eslint/use-unknown-in-catch-callback-variable
result.then(resolve, reject);
})
const { promise, resolve, reject } = promiseWithResolvers<unknown>();
abortSignal?.addEventListener(
'abort',
() =>
reject(
locatedError(abortSignal.reason, fieldNodes, pathToArray(path)),
),
{ once: true },
);
// eslint-disable-next-line @typescript-eslint/use-unknown-in-catch-callback-variable
result.then(resolve, reject);

return promise
.then(assertEventStream)
.then(undefined, (error: unknown) => {
throw locatedError(error, fieldNodes, pathToArray(path));
Expand Down

0 comments on commit 7dea80e

Please sign in to comment.