Altair: Subscriptions and graphql-ruby

Created on 20 Mar 2019  ·  18Comments  ·  Source: imolorhe/altair

Graphql subscriptions not working as expected.

We are running a GraphQL API server on rails with graphql-ruby gem and we find difficulties to test them with altair.

Our server keeps receiving:

(...)
Started GET "/cable/" [WebSocket] for 127.0.0.1 at 2019-03-20 13:03:25 +0200
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
Finished "/cable/" [WebSocket] for 127.0.0.1 at 2019-03-20 13:03:25 +0200

Started GET "/cable" for 127.0.0.1 at 2019-03-20 13:03:26 +0200
Started GET "/cable/" [WebSocket] for 127.0.0.1 at 2019-03-20 13:03:26 +0200
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
Finished "/cable/" [WebSocket] for 127.0.0.1 at 2019-03-20 13:03:26 +0200

Started GET "/cable" for 91.156.113.159 at 2019-03-20 13:03:33 +0200
Started GET "/cable/" [WebSocket] for 91.156.113.159 at 2019-03-20 13:03:33 +0200
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
Finished "/cable/" [WebSocket] for 91.156.113.159 at 2019-03-20 13:03:33 +0200

While the app stays stuck on: wss://development-cable.ngrok.io/cable and nothing happens there.

Are we doing something wrong here?

All 18 comments

👋🏾Thanks for opening your first issue here! Be sure to follow the issue template! ✌🏾

Hey,

It doesn't look like anything is broken. 🤔 Altair uses the subscriptions-transport-ws package to handle the subscriptions via websockets. I'm assuming graphql-ruby follows the same implementation. If so I think everything should work well.

It seems Altair keeps calling the server once it’s upgraded.

On 20 Mar 2019, at 14.28, Samuel notifications@github.com wrote:

Hey,

It doesn't look like anything is broken. 🤔 Altair uses the subscriptions-transport-ws package to handle the subscriptions via websockets. I'm assuming graphql-ruby follows the same implementation. If so I think everything should work well.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.

In the developer tools console are there any errors?
I'm there network tab, does it keep retrying the subscription URL?

I wasn't aware of a developer console.

Now that I checked: yes there are some errors:

Screenshot 2019-03-21 at 12 56 45 PM

FYI: this exact subscription works in our React app. I'm not sure what is not working here. We use:

  • the subscription code
  • the same graphql URL
  • the same WebSocket url
  • the exact same server instance running

@sayduck-daniel How do you use the GraphQL subscriptions in your React app? Do you use Apollo for that? Or a different library? I'm trying to understand the subscription implementation.

I'll try to create a simple project with that to see how it works. Although looking at the link you provided, it seems it makes use of pusherjs which I'm not familiar with and don't know if it follows the same Graphql subscription specification.

Look closely on the link I got you, it is compatible with pusher, ably, ActionCable and others, but the one we use is the standard ActionCable that comes with rails.

On 24 Mar 2019, at 20.53, Samuel notifications@github.com wrote:

I'll try to create a simple project with that to see how it works. Although looking at the link you provided, it seems it makes use of pusherjs which I'm not familiar with and don't know if it follows the same Graphql subscription specification.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

You should start looking from this point :

@imolorhe any news on this issue?

Unfortunately I haven't been able to set up a demo project with graphql-ruby (I don't work with ruby so it's not a very easy task). Perhaps you could help setting up the demo project and I can look at that?

Hi @imolorhe

I created a sample project with:

  • Rails
  • graphql-ruby
  • 1 basic query

    • hello just to test if graphql is working

  • 2 mutations

    • createStatus gives you a random id to subscribe to

    • updateStatus triggers an event on this id

  • 1 subscription

    • statusChanged send the first message on subscription and then sends an event when you call updateStatus

Find it here https://github.com/Sayduck/graphql-ruby-sample

GitHub
graphql-ruby with subscriptions sample. Contribute to Sayduck/graphql-ruby-sample development by creating an account on GitHub.

Awesome! I will take a look.

@sayduck-daniel The subscription URL ws://localhost:3000/cable returned 404. In the README you have it as http://127.0.0.1:3003/cable but subscriptions need to be websocket URLs (with the ws:// protocol).

Going through the graphql-ruby docs, I can see that the GraphQL subscription implementations used by Altair and graphql-ruby are different, and are not compatible.

graphql-ruby provides a special javascript client for using subscriptions on Ruby, which doesn't use the same protocol implementation for Apollo's GraphQL subscription proposal (which Altair uses). Apollo's GraphQL subscription proposal is the most popular and widely accepted protocol, which is why Altair chose to support that above others.

Unfortunately Altair wouldn't be including the subscription implementation used by graphql-ruby, as that is just one of several implementations used in the wild, and we can't afford to support all of them.

Hopefully there would be a unified protocol for GraphQL subscriptions soon, which would prevent this.

Implementing the Apollo GraphQL subscription interface on the graphql-ruby subscription server implementation could be an alternative way to go. I'm not sure what would be required but I can imagine that it should be possible to create such an intermediary adapter which would just make all other client implementations work (including Altair).

Ok, thanks for trying. I opened an issue on graphql-ruby's Github

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rshea0 picture rshea0  ·  11Comments

trafficfox picture trafficfox  ·  8Comments

imolorhe picture imolorhe  ·  3Comments

simPod picture simPod  ·  5Comments

benhutton picture benhutton  ·  10Comments