Absinthe Subscriptions alternative?

Hi, trying to use elixir/phoenix/absinthe on the backend and nextjs with typescript on the frontend. Everything seems to be well except that Absinthe/graphql subscriptions seem to be abandoned, outdated corejs, etc. If you are doing subscriptions is there another way ?

2 Likes

I’ll have to implement GraphQL subscriptions in my codebase soon.
I assume that you refer to the package absinthe-socket. I didnt look into it yet but can’t we just use the native JS WebSocket object?

The elixir code seems to be up to date, but there are no updates on the JavaScript code needed for the sockets GitHub - absinthe-graphql/absinthe-socket: Core JavaScript support for Absinthe WS-based operations no updates for several years and open pull request to update dependencies . But even with upgrading the depencies to newer versions will require more change in the code than just increasing the version number. Not sure how relevant that is but it has been complicating my project slightly :wink: lack of typescript does not help in my case. Probably all solvable but if there is an easier way I am interested in hearing about it :wink:

I recommend GitHub - geometerio/absinthe_graphql_ws: Add graphql-ws websocket transport for Absinthe for absinthe websockets. It uses the graphql_ws protocol instead of absinthe over Phoenix channels that is used by absinthe_socket. It’s well supported by client libraries in JavaScript and other languages.

5 Likes

I have a repo on GitHub which allows you to use the Apollo GraphQL client to talk to Absinthe on the back end. Unfortunately, though, I’ve never used it in production and it may be incomplete or out-of-date. But it’s there if you care to look at it: GitHub - easco/absinthe_apollo_sockets: Use the Apollo Websocket protocol to drive Absinthe GraphQL functionality

Thank you for sharing this lib!

If I understand right, this library allows Absinthe to follow the graphql-ws protocol. Two questions:

  1. Absinthe by default then doesn’t follow the protocol? Why not, as graphql-ws is becoming the standard from what I read?

  2. This library only seems to handle the server-side implementation of the protocol, right? What should I use client-side? (I do not want to use a specific framework like Apollo).

I think in the future Absinthe might very well use graphql-ws as the default. Especially as more clients will support it by default.

In regards to your second question, a JS client without Apollo et al. is here: GitHub - enisdenjo/graphql-ws: Coherent, zero-dependency, lazy, simple, GraphQL over WebSocket Protocol compliant server and client. This is the base client that e.g. Apollo have wrappers for.

Thank you for your help! I got confused that graphql-ws has also code for the server. It’s a pity that it is not separated into two packages, as if you don’t run the server on NodeJS, you only need the client-specific code.