question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

integrate subscriptions with elixir

See original GitHub issue

First 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:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
patrick91commented, Jul 30, 2021

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.

1reaction
patrick91commented, Jul 30, 2021

@codebyaryan awesome! yes, please let me know how you get on with it! Happy to chat on discord too!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding Subscriptions — absinthe v1.7.0 - HexDocs
GraphQL subscriptions are a way to have events in the server push data out to clients in real time. The client submits a...
Read more >
Can you build membership and subscription websites on Hub ...
Hopefully this blog post gives you a better understanding of membership and subscription websites on Hub CMS. At Elixir Solutions, we offer ...
Read more >
Testing Subscriptions - Craft GraphQL APIs in Elixir ... - O'Reilly
Selection from Craft GraphQL APIs in Elixir with Absinthe [Book] ... SubscriptionCase module for managing the subscription integration tests via channels.
Read more >
AbsintheClient – GraphQL client with Subscriptions - Libraries
AbsintheClient is a Req plugin to perform GraphQL operations, including subscriptions. Performs query and mutation operations via JSON POST ...
Read more >
Stripe payments for subscriptions with Phoenix - tolc.io
Integrating Stripe in a Phoenix application via stripity_stripe ... I would have wanted to read when I first started with Stripe and Elixir....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found