strawberry-graphql / strawberry

A GraphQL library for Python that leverages type annotations 🍓
https://strawberry.rocks
MIT License
3.84k stars 510 forks source link

Functionality for filtering events in Subscriptions #3513

Closed HenriKorver closed 1 day ago

HenriKorver commented 1 month ago

It would be nice if an equivalent of the withFilter-function as described in Apollo Server (https://www.apollographql.com/docs/apollo-server/data/subscriptions#filtering-events) is added to Strawberry.

Upvote & Fund

Fund with Polar

erikwrede commented 1 month ago

Hey @HenriKorver , thanks for the request. I'm not sure this is in scope for strawberry, neither am I certain about wether or not we would set the wrong incentives with this. Event bus subscriptions can have massive throughput. My personal preference is to keep the stateful part of a GraphQL application as small as possible, thereby reducing the amount of messages arriving in your resolver. This implies moving this functionality into business logic (optimally a filter on the event bus subscription topic), as opposed to the resolver itself.

You can already achieve async iterable filtering with userland libraries: https://asyncstdlib.readthedocs.io/en/latest/source/api/builtins.html#asyncstdlib.builtins.filter

It might make sense to just document the aforementioned library in the guide, this should help anyone achieve your desired functionality. Please LMK your thoughts on this 😊

DoctorJohn commented 1 day ago

I agreeing with Erik on this. The python ecosystem already has great tooling for business logic specific issue. I don't see much value in providing an extra helper for from the strawberry library. But feel free to open a PR updating the docs which a library recommendation and feel free to request us to reopen this issue if needed.