Skip to content

Commit 31dd666

Browse files
committed
Revert "feat: pass abortSignal to resolvers via GraphQLResolveInfo (graphql#4425)"
This reverts commit fba352d.
1 parent fba352d commit 31dd666

File tree

5 files changed

+9
-26
lines changed

5 files changed

+9
-26
lines changed

src/execution/__tests__/cancellation-test.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -130,19 +130,9 @@ describe('Execute: Cancellation', () => {
130130
}
131131
`);
132132

133-
let aborted = false;
134133
const cancellableAsyncFn = async (abortSignal: AbortSignal) => {
135-
if (abortSignal.aborted) {
136-
aborted = true;
137-
} else {
138-
abortSignal.addEventListener('abort', () => {
139-
aborted = true;
140-
});
141-
}
142-
// We are in an async function so it gets cancelled and the field ends up
143-
// resolving with the abort signal's error.
144134
await resolveOnNextTick();
145-
throw Error('some random other error that does not show up in response');
135+
abortSignal.throwIfAborted();
146136
};
147137

148138
const resultPromise = execute({
@@ -151,8 +141,8 @@ describe('Execute: Cancellation', () => {
151141
abortSignal: abortController.signal,
152142
rootValue: {
153143
todo: {
154-
id: (_args: any, _context: any, info: { abortSignal: AbortSignal }) =>
155-
cancellableAsyncFn(info.abortSignal),
144+
id: (_args: any, _context: any, _info: any, signal: AbortSignal) =>
145+
cancellableAsyncFn(signal),
156146
},
157147
},
158148
});
@@ -175,8 +165,6 @@ describe('Execute: Cancellation', () => {
175165
},
176166
],
177167
});
178-
179-
expect(aborted).to.equal(true);
180168
});
181169

182170
it('should stop the execution when aborted during object field completion with a custom error', async () => {

src/execution/__tests__/executor-test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ describe('Execute: Handles basic execution tasks', () => {
223223
'rootValue',
224224
'operation',
225225
'variableValues',
226-
'abortSignal',
227226
);
228227

229228
const operation = document.definitions[0];

src/execution/execute.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,6 @@ function executeField(
875875
toNodes(fieldDetailsList),
876876
parentType,
877877
path,
878-
abortSignal,
879878
);
880879

881880
// Get the resolve function, regardless of if its result is normal or abrupt (error).
@@ -894,7 +893,7 @@ function executeField(
894893
// The resolve function's optional third argument is a context value that
895894
// is provided to every resolve function within an execution. It is commonly
896895
// used to represent an authenticated user, or request-specific caches.
897-
const result = resolveFn(source, args, contextValue, info);
896+
const result = resolveFn(source, args, contextValue, info, abortSignal);
898897

899898
if (isPromise(result)) {
900899
return completePromisedValue(
@@ -961,7 +960,6 @@ export function buildResolveInfo(
961960
fieldNodes: ReadonlyArray<FieldNode>,
962961
parentType: GraphQLObjectType,
963962
path: Path,
964-
abortSignal: AbortSignal | undefined,
965963
): GraphQLResolveInfo {
966964
const { schema, fragmentDefinitions, rootValue, operation, variableValues } =
967965
validatedExecutionArgs;
@@ -978,7 +976,6 @@ export function buildResolveInfo(
978976
rootValue,
979977
operation,
980978
variableValues,
981-
abortSignal,
982979
};
983980
}
984981

@@ -2082,12 +2079,12 @@ export const defaultTypeResolver: GraphQLTypeResolver<unknown, unknown> =
20822079
* of calling that function while passing along args and context value.
20832080
*/
20842081
export const defaultFieldResolver: GraphQLFieldResolver<unknown, unknown> =
2085-
function (source: any, args, contextValue, info) {
2082+
function (source: any, args, contextValue, info, abortSignal) {
20862083
// ensure source is a value for which property access is acceptable.
20872084
if (isObjectLike(source) || typeof source === 'function') {
20882085
const property = source[info.fieldName];
20892086
if (typeof property === 'function') {
2090-
return source[info.fieldName](args, contextValue, info);
2087+
return source[info.fieldName](args, contextValue, info, abortSignal);
20912088
}
20922089
return property;
20932090
}
@@ -2296,7 +2293,6 @@ function executeSubscription(
22962293
fieldNodes,
22972294
rootType,
22982295
path,
2299-
abortSignal,
23002296
);
23012297

23022298
try {
@@ -2321,7 +2317,7 @@ function executeSubscription(
23212317
// The resolve function's optional third argument is a context value that
23222318
// is provided to every resolve function within an execution. It is commonly
23232319
// used to represent an authenticated user, or request-specific caches.
2324-
const result = resolveFn(rootValue, args, contextValue, info);
2320+
const result = resolveFn(rootValue, args, contextValue, info, abortSignal);
23252321

23262322
if (isPromise(result)) {
23272323
const abortSignalListener = abortSignal

src/type/definition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,7 @@ export type GraphQLFieldResolver<
997997
args: TArgs,
998998
context: TContext,
999999
info: GraphQLResolveInfo,
1000+
abortSignal: AbortSignal | undefined,
10001001
) => TResult;
10011002

10021003
export interface GraphQLResolveInfo {
@@ -1010,7 +1011,6 @@ export interface GraphQLResolveInfo {
10101011
readonly rootValue: unknown;
10111012
readonly operation: OperationDefinitionNode;
10121013
readonly variableValues: VariableValues;
1013-
readonly abortSignal: AbortSignal | undefined;
10141014
}
10151015

10161016
/**

website/pages/upgrade-guides/v16-v17.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ Use the `validateInputValue` helper to retrieve the actual errors.
178178

179179
- Added `hideSuggestions` option to `execute`/`validate`/`subscribe`/... to hide schema-suggestions in error messages
180180
- Added `abortSignal` option to `graphql()`, `execute()`, and `subscribe()` allows cancellation of these methods;
181-
`info.abortSignal` can also be used in field resolvers to cancel asynchronous work that they initiate.
181+
the `abortSignal` can also be passed to field resolvers to cancel asynchronous work that they initiate.
182182
- `extensions` support `symbol` keys, in addition to the normal string keys.
183183
- Added ability for resolver functions to return async iterables.
184184
- Added `perEventExecutor` execution option to allows specifying a custom executor for subscription source stream events, which can be useful for preparing a per event execution context argument.

0 commit comments

Comments
 (0)