-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
create separate pubsub.asyncIterable method and deprecate pubsub.asyncIterator #147
create separate pubsub.asyncIterable method and deprecate pubsub.asyncIterator #147
Conversation
…cate pubsub.asyncIterator
I have refactored the |
@jonbudd actually I don't think this is a work in progress anymore... |
Although I think |
so IMO async iterators still give you quite a nice way to manipulate these things i think the best way to go is to just have some explicit closeability concept; see what we did in https://github.com/4Catalyzer/graphql-subscription-server/pull/20/files |
@taion But who calls that? Don't we depend on https://github.com/apollographql/subscriptions-transport-ws to call |
the approach we use is:
so we just don't use |
Okay, so that would require modifying the transport... |
Thanks @jedwards1211 and sorry we didn't get to this sooner. A lot has changed with the codebase since this was opened, and some of these changes are already coming in 3.0. I'll close this off but please open any new PR's (ideally based off of the
😂 |
As @jquense wisely helped me realize in #143,
pubsub.asyncIterator
is unsafe and could leave dangling event listeners when consumed by 3rd-party code.In general the documentation mistakenly states that GraphQL
subscribe
resolvers must return anAsyncIterator
; rather, they should return anAsyncIterable
, and event listener registration/anything else necessitating cleanup should only be performed when thatAsyncIterable
'sSymbol.asyncIterator
method is actually called, sincefor await
and probably most 3rd-party code is only guaranteed toreturn
the iterator if it ends up starting iteration (i.e. callingSymbol.asyncIterator
).As a solution, I've created a new
pubsub.asyncIterable
method that we should advise people to use. I also madeeventEmitterToAsyncIterator
print a deprecation warning when it's used like anAsyncIterable
(which will happen with the current recommended usage ofpubsub.asyncIterator
).The
withFilter
method still needs to be redesigned to operate onAsyncIterable
s instead ofAsyncIterators
.