Skip to content

Commit f39fefb

Browse files
committed
test: actually test use of AbortSignal in resolver
The previous test didn't really make use of the fact that the AbortSignal could be used in the resolver: the only use it made of it was to call `signal.throwIfAborted` *after* the cancellable promise was already cancelled. The "This operation was aborted" message that shows up in the GraphQL response actually came from the cancellable promise, not the throwIfAborted call. You can see that because if you just replace `throwIfAborted` with throwing another error (as this commit does), the test still passed. Instead, actually make use of the AbortSignal API to observe the abort explicitly.
1 parent ef042cf commit f39fefb

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/execution/__tests__/cancellation-test.ts

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

133+
let aborted = false;
133134
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.
134144
await resolveOnNextTick();
135-
abortSignal.throwIfAborted();
145+
throw Error('some random other error that does not show up in response');
136146
};
137147

138148
const resultPromise = execute({
@@ -165,6 +175,8 @@ describe('Execute: Cancellation', () => {
165175
},
166176
],
167177
});
178+
179+
expect(aborted).to.equal(true);
168180
});
169181

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

0 commit comments

Comments
 (0)