Skip to content

Commit 7df1bc6

Browse files
committed
expand the test for access to the abort signal within resolvers
GraphQL-Core already keeps the abort signal in GraphQLResolveInfo and already had this test, so nothing carries over but a comment clarifying how it relates to the upstream version, which subscribes to an "abort" event instead of cancelling the resolver task. Replicates graphql/graphql-js@566023c
1 parent 352679c commit 7df1bc6

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

tests/execution/test_cancellation.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,17 @@ async def provides_access_to_the_abort_signal_within_resolvers():
145145
)
146146

147147
async def cancellable_async_fn(abort_signal):
148-
# never reached: the resolver is cancelled before its body runs
148+
# never reached: the resolver task is cancelled before its body runs
149149
raise await abort_signal.wait() # pragma: no cover
150150

151151
# Contrary to JavaScript, where the abort signal is passed as an additional
152152
# argument to the resolvers, in GraphQL-Core it is available via the resolve
153-
# info, just like the context value.
153+
# info, just like the context value. The GraphQL.js test that this mirrors
154+
# subscribes to the signal's "abort" event and then throws an unrelated error
155+
# to prove the abort error supersedes it; GraphQL-Core has no event listener
156+
# and instead cancels the running resolver task, so the resolver awaits the
157+
# signal directly and raises its reason (which the cancellation pre-empts) --
158+
# this is race-safe because either path yields the same abort error.
154159
def resolve_id(info):
155160
return cancellable_async_fn(info.abort_signal)
156161

0 commit comments

Comments
 (0)