nestjs / graphql

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

GraphQL Federation Subscriptions #3022

Open mfulton26 opened 11 months ago

mfulton26 commented 11 months ago

Is there an existing issue that is already proposing this?

Is your feature request related to a problem? Please describe it

I want to leverage the new subscriptions support in Apollo Federation but NestJS's docs cause me to think that it isn't supported yet in @nestjs/graphql.

https://www.apollographql.com/blog/announcement/backend/federated-subscriptions-in-graphos-real-time-data-at-scale/#subscriptions-meet-apollo-federation

From https://docs.nestjs.com/graphql/federation:

WARNING Federation currently does not support subscriptions.

Describe the solution you'd like

Updated docs, support, and example of using subscriptions with Apollo Federation using @nestjs/graphql.

Teachability, documentation, adoption, migration strategy

No response

What is the motivation / use case for changing the behavior?

Build microservices that can be used by a client as one GraphQL API even with subscriptions across those microservices.

kamilmysliwiec commented 11 months ago

Would you like to create PRs for this?

Hyperxq commented 7 months ago

I've been trying to contribute for the community the way to implement Apollo Subscriptions into Nestjs. I will tell you what is my conclusion after all the research and tries.

Conclusion: You cannot implement it in the free version. Link. However, it's viable with the enterprise version.

In nestjs we use Apollo Gateway and Apollo Subgraph. However, Apollo gateway are not design to support realtime requests: Link. The good news are that Apollo create Apollo Router that improve a lot of things including support for Subscriptions.

You have many differences between using Apollo Gateway and Apollo Router. The main one is that Apollo router is not a npm package instead of it, it is a binary package that you need to download and use it.

I could implement apollo router with all the configurations and I could modify the ApolloFederationDriver to support subscriptions. The problem is when you would like to enable the subscriptions in the router. Because it is an enterprise feature.

@kamilmysliwiec Do you think it is a good idea to implement it anyway?

mfulton26 commented 7 months ago

The documentation hasn't been fully updated yet but GraphQL Yoga supports Apollo Federation for free: