integrate subscriptions with elixir
See original GitHub issueFirst of all, I would like to thank the maintainers of this amazing library! I really like my experience with it.
I would like to integrate python with elixir (on a graphQL server). Basically, I want python to handle mutations and queries, but I want elixir to handle subscriptions (because it is better at the job). I am planning to make both python and elixir microservices communicate with each other with rabbitMQ.
I would like python handling the core /graphql
endpoint, and would like subscriptions to look like this.
import asyncio
import strawberry
@strawberry.type
class Query:
@strawberry.field
def hello() -> str:
return "world"
@strawberry.type
class Subscription:
@strawberry.subscription
async def user_created(self):
# communicate with elixir via rabbitMQ
# and make sure that the user is subscribed to a particular topic here.
pass
@strawberry.type
class Mutation:
@strawberry.mutation
def create_user(self, input: UserInput):
# communicate with elixir via rabbitMQ
# and publish an event to a particular topic here.
pass
schema = strawberry.Schema(query=Query, subscription=Subscription, mutation=Mutation)
I was wondering if this is even possible. I want to make sure that all of the state (which clients are subscribed to which topics) to be handled by elixir, and not by python.
And the business logic and ORM should be handled by python. This way, the application can scale better.
I would like to hear some suggestions on how to go about implementing this. Thanks a lot!
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
The schema looks ok, let me summarise the options you have here:
1 - Apollo Federation
Apollo federation is pretty cool and easy to implement, but doesn’t support subscriptions (without additional tools) at the moment
There’s some ways of using federation and subscriptions: https://www.apollographql.com/blog/backend/federation/using-subscriptions-with-your-federated-data-graph/
The solution in the blog post isn’t much different than the following solutions
2 - GraphQL Mesh
GraphQL Mesh by @Urigo seems to support subscriptions (plus a lot more). I’ve never tried it but it could be an option. https://www.graphql-mesh.com/
Not sure if subscriptions are handled by node in that case (I guess so). If so this approach might not be ideal for you
3 - Schema Stiching
https://www.graphql-tools.com/docs/schema-stitching/stitch-combining-schemas
With schema stitching you could combine your schemas and then use a proxy to decided what service to use based on the protocol.
@codebyaryan awesome! yes, please let me know how you get on with it! Happy to chat on discord too!