Skip to content
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

feat: replace iterall with native Symbol.asyncIterator + fix return types #232

Merged
merged 5 commits into from Nov 25, 2021

Conversation

n1ru4l
Copy link

@n1ru4l n1ru4l commented Sep 21, 2020

BREAKING fixes the type annotation of the abstract class PubSubEngine. According to the TypeScript type-defintion a PubSubAsyncIterator instance is actually an AsyncIterableIterator instead of an AsyncIterator. The typing of PubSubAsyncIterator is way more convenient as it allows iterating over it with the for await (const foo of iterator) { doSth() } syntax, which is super handy for filtering or mapping (See https://gist.github.com/n1ru4l/127178705cc0942cad0e45d425e2eb63 for some example operators).

This should be able to get merged once Node.js 10 runs out of LTS. See https://nodejs.org/en/about/releases/
Technically this project already dropped Node.js 10 support when removing the Node.js 10 CI build.

Closes #192

@n1ru4l n1ru4l changed the title fix(typings): return AsyncIterableIterator instead of AsyncIterator feat: replace iterall with native Symbol.asyncIterator Sep 21, 2020
@n1ru4l n1ru4l changed the title feat: replace iterall with native Symbol.asyncIterator feat: replace iterall with native Symbol.asyncIterator + fix return types Sep 21, 2020
@robhogan
Copy link

robhogan commented Oct 6, 2020

Since this is a clean slate, would you consider changing the input types for asyncIterableIterator to accept string | readonly string[] (instead of a mutable string[]), as in #234? Changing the existing API would be another breaking change, unfortunately.

@n1ru4l
Copy link
Author

n1ru4l commented Oct 6, 2020

@rh389 Yours could be merged afterwards (if any is ever merged 😅). Doing more stuff in one pr might decrease the chance of it getting merged, so I would like to keep it like that for now 😇

@robhogan
Copy link

robhogan commented Oct 6, 2020

Yeah, sorry I don't mean to hijack - just that this PR introduces asyncIterableIterator, so changing it to readonly after this is merged would require a second breaking change. Hopefully the maintainers will see this note and we can leave it up to them to change if they want to.

@n1ru4l
Copy link
Author

n1ru4l commented May 10, 2021

@glasser I noticed you recently pushed to this repository. Is this repository actively maintained, should new maintainers, or should a deprecation notice be added? A lot of pull requests are still undressed, including this one...

@glasser
Copy link
Member

glasser commented May 12, 2021

It is not particularly maintained. It is a dependency of Apollo Server 2, for not particularly good reasons: AS does not actually use any code from it directly, but it just re-exports all of its exports. Because of that, as part of making AS2 support graphql@15 I had to push a version of this package with appropriate peer deps. While I was at it I merged a major memory leak fix that had excellent tests. However, we're removing that dependency from Apollo Server 3 (as well as the rest of the superficial "support" for subscriptions). I'd suggest using graphql-ws rather than subscriptions-transport-ws/graphql-subscriptions for now. We do hope to implement real support for subscriptions in Apollo Server (actually integrated with ApolloServer in a deep way rather than kinda stapled on the side) either via a brand new implementation or via graphql-ws at some point, but for now I'd recommend using the actively maintained subscriptions packages.

I'm tracking figuring out what to do with these projects in apollographql/apollo-server#5141 as part of the AS3 release process.

@n1ru4l
Copy link
Author

n1ru4l commented May 12, 2021

graphql-subscriptions is actually not a package that is very graphql specific but rather more abstraction for wiring up different EventEmitter like services into AsyncIterables, which graphql-js requires for subscriptions.

I don't know whether you saw my comment over here: #240 (comment)

Maybe this package should be deprecated and instead a EventEmitter abstraction for different systems such as redis pubsub or mqtt could be used.

@n1ru4l
Copy link
Author

n1ru4l commented Nov 18, 2021

@glasser You could have considered this for the v2.0.0 release... It is a shame that the typings are still wrong :/

@glasser
Copy link
Member

glasser commented Nov 20, 2021

@n1ru4l This package is not actively maintained. 2.0.0 was the bare minimum to get it to build with graphql@16.

n1ru4l and others added 4 commits November 25, 2021 12:43
BREAKING fixes the type annotation of the abstract class PubSubEngine. According to the TypeScript type-defintion a `PubSubAsyncIterator` instance is actually a `AsyncIterableIterator` instead of an  `AsyncIterator`. The typing of `PubSubAsyncIterator` is way more convenient as it allows iterating over it with the `for await (const foo of iterator) { doSth() }` syntax, which is super handy for filtering or mapping (See https://gist.github.com/n1ru4l/127178705cc0942cad0e45d425e2eb63 for some example operators).
Copy link
Member

@hwillson hwillson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much @n1ru4l - looks great!

@hwillson hwillson merged commit e27eb2e into apollographql:release-3.0 Nov 25, 2021
@n1ru4l n1ru4l deleted the patch-1 branch November 25, 2021 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pubSub.asyncIterator() return type
4 participants