nestjs / graphql

GraphQL (TypeScript) module for Nest framework (node.js) 🍷
https://docs.nestjs.com/graphql/quick-start
MIT License
1.45k stars 391 forks source link

feat(apollo): subscription with initial data #3234

Open TrisNol opened 2 months ago

TrisNol commented 2 months ago

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

What is the current behavior?

Subscriptions created by utilizing the @nestjs/graphql related libs only serve updates triggered by the PubSub.asyncIterator while in some circumstances a subscription may serve initial data to avoid a Query + Subscription scenario resulting in complicated merges within the clients' business logic.

Issue Number: N/A

What is the new behavior?

A utils function has been added which can be used to combine an AsyncIterator with an array of existing data returning an AsyncIterableIterator which does satisfy the AsyncIterator interface - meaning that existing code / frameworks will not be broken if employed - while serving the list of initial entries first, followed by all real-time updates triggered via the PubSub iterator.

Does this PR introduce a breaking change?

Other information

The apollo package may not be the right place to store such utils, feedback would be highly appreciated! Furthermore, an update to linting related dependencies had to be made in order to run the husky pre-commit locally.