typescriptgraphqlpublish-subscribeapollo-server

Typescript Issue with asyncIterator in Apollo Server Subscriptions and PubSub


I'm implementing Apollo Server subscriptions with TypeScript and facing an issue with a PubSub-based subscription system. I followed the official Apollo documentation, but encountered the following error:

subscribe: (_, __, { pubsub }) => pubsub.asyncIterator([CHANGE_EVENT]),
// Error: Property 'asyncIterator' does not exist on type 'PubSub<{ CHANGE_EVENT: string; }>'

Solution

  • In version 3.0, a breaking change renamed asyncIterator to asyncIterableIterator (see: https://github.com/apollographql/graphql-subscriptions/releases/tag/v3.0.0). For now, the official Apollo documentation seems outdated regarding this change.