Skip to content

Return type of pubsub.asynctIterator should include AsyncIterable #261

@hayes

Description

@hayes

the pubsub.asyncIterator method currently is typed as returning an AsyncIterator. While this is accurate, it misses an important detail:

The subscribe function of a graphql field expects an AsyncIterable, not an AsyncIterator. At runtime this works because the PubSubAsyncIterator also implements the AsyncIterable interface. Unfortunately this is hidden by the explicit return type in pubsub.asyncIterator Which is typed as returning an AsyncIterator, not a PubSubAsyncIterator, and does not include the [Symbol.asyncIterator] property.

This library is very commonly used when implementing graphql subscriptions, and I believe this has resulted in it becoming common to mis-type the expected return type of subscribe functions (for example in nexus)

This should be a relatively easy, and backwards compatible fix

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions