apollographql / federation

🌐  Build and scale a single data graph across multiple services with Apollo's federation gateway.
https://apollographql.com/docs/federation/
Other
666 stars 251 forks source link

Subscriptions support #353

Open ChrisSG opened 4 years ago

ChrisSG commented 4 years ago

Hello all,

I created this request as the community is desperately awaiting subscriptions in Apollo federation. I did this for gathering information, as it is obvious that subscriptions can't be implemented quickly because there seem to be non trivial problems on the way. The intent is to gather high level information around:

Please everybody to contribute as it seems demanded and I guess a lot of people are willing and able to help!

Thank you all!

Regards,

Christian

ChrisSG commented 4 years ago

@martijnwalraven @abernix Could you please shed some light on this?

DoctorVoid commented 4 years ago

Same here, Didn't see anything planned in the 3.x roadmap

gromov-io commented 4 years ago

@martijnwalraven @abernix

ChrisSG commented 4 years ago

Where should we start? What are the basic inner workings of it and what is the main problem?

lwintch commented 3 years ago

Where should we start? What are the basic inner workings of it and what is the main problem?

From my perspective (React - browser), one of the non-trivial problems is the need to triage a client subscription to an individual backend service and maintain multiple subscriptions. Key details that are think are problematic:

This obstacle appears to be similar to not being able to use multiple GraphQL endpoints nicely in the Apollo Client (without overriding the apolloClient prop in the component).

As far as solving this problem, I would appreciate any information that can refute or support my perspective. I'm happy to jump in after Q2, but could use someone else's perspective before contributing. I just need a direction. Any details would be much appreciated.

sgentile commented 3 years ago

what are options for federation and subscriptions ?

psteinroe commented 3 years ago

@lwintch you can checkout mercuriusjs as a reference implementation. The client creates a single connection to the gateway, and the gateway creates another connection to the respective service.

haddadr commented 3 years ago

Hello any update on this feature. We are waiting for it. Is there any beta version to be released?

onichandame commented 3 years ago

didn't intend to flood this thread. But I believe a briefing from maintainers could help relieve the despair of the community

arneschreuder commented 3 years ago

I am happy to help out with the implementation of this, but I think some guidance from maintainers would be nice. I agree with the topics as pointed out by @lwintch .

abernix commented 3 years ago

The original support for GraphQL Subscriptions was Apollo's first attempt at answering the need for Subscriptions and pre-dated the existence of Federation. We've learned a lot from that original approach, and with the release of Federation we started to get more feedback that is invaluable in building the future of subscriptions.

Apollo's current stance on how to implement subscriptions in a Federated graph is outlined in our recent blog post. It comes with working examples in a repository that can be cloned.

While we can imagine a future with a different story, we're not there yet and we believe that this is an approach that has worked quite well for the large-scale implementors we've worked closely with so far. We're certainly interested in more feedback on how this approach works, but we've had good reception to this!

arneschreuder commented 3 years ago

@abernix Thank you for the feedback.

sammysaglam commented 2 years ago

having waited for this a while now ⏳ , i was instead able to put together a small library implementing federation with subscriptions (the way we'd hoped for, without a separate service just for subscriptions). was able to get it working using schema-stitching & graphql-tools, it's basically just transforming federation SDL into schema-stitching SDL and using websockets across the gateway & subgraphs: https://github.com/sammysaglam/federation-with-subscriptions

hope that helps

arneschreuder commented 2 years ago

@sammysaglam well done! Thank you!

haydenmcp commented 2 years ago

I've implemented the solution recommended in Mandi's post. However, I'm currently looking into incorporating CSRF protection. I notice that ApolloServer now has a beautiful csrfPrevention flag in its options. Any recommendations or advice on how to approach CSRF protection using Mandi's recommended approach?

haydenmcp commented 2 years ago

Nevermind. I got my answer from OWASP:

"...Forcing the victim to retrieve data doesn’t benefit an attacker because the attacker doesn’t receive the response, the victim does. As such, CSRF attacks target state-changing requests."