Subscriptions via Absinthe and Plug/Cowboy (without Phoenix)

Hi there, longtime lurker, first time caller.

I’ve been searching thoroughly for an Absinthe graphql-ws implementation that does not require Phoenix. I already have a stable setup with plain Plug/Cowboy and Absinthe and can make queries, mutations, etc. via Apollo.

I’ve encountered a scenario where subscriptions would be excellent, however I’m at a bit of a loss for implementing websockets without Phoenix. I’ve been resistant to Phoenix since Plug does everything I need it to, and the router serves a compiled frontend. Though LiveView would have been excellent, the circumstances that led to the implementation resulted in a ReScript-React frontend since it is familiar to JS devs.

Back to the present: investigation has brought me to AbsintheGraphqlWS. I’m having difficulty figuring out how to proceed since it still depends on Phoenix, and it seems like a lot of work to support something like Plug.Socket or a homegrown implementation. I realize this is an uncommon stack and a relatively new protocol for Absinthe, and if need be I can just poll the backend using queries on an interval, but it would be really convenient to have subscriptions.

Lastly, if I absolutely must use Phoenix, I would love to understand a minimal setup that can wrap my existing Plug implementation.

Thanks for reading, I’m just happy to be here :slightly_smiling_face:

EDIT: fixed an incorrect link.

1 Like

What do you think about creating a new open-source library, implementing the protocol defined in graphql-sse with Absinthe and Elixir for the server side?

Any reason why you’d choose WebSockets over Server Sent Events?

1 Like

I’m interested in a new library! Good way for me to dip my toe into contributing back to the ecosystem.

My main reasoning for sticking with websockets is ease of implementation. I’m using rescript-apollo-graphql which supports websockets out of the box, whereas SSE support seems a little shaky. If I can keep the bulk of the work on the Elixir side that would be tremendous.