graphql-zeus icon indicating copy to clipboard operation
graphql-zeus copied to clipboard

web socket protocol confusion

Open tintin10q opened this issue 1 year ago • 1 comments

Hey there, I have generated a client with --subscriptions graphql-ws . I am also using hasura subscription and I want to migrate from my apolo subscription client to the zeus one.

When I look at the messages that this client generates I get:

{"id":"c1a9e1a2-60b6-4cad-b6a8-b031449f8280","type":"subscribe","payload":"..........."}

But the old apolloclient actually sends a message like this:

{"id":"1","type":"start","payload":"...."}

So instead of a message with type subscribe it sends a message with type start.

I looked in the protocol description: https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md

But the zeus actually seems to be the right one. There is no mention of a start message. So it seems that apollo used a different protocol.

So can someone please tell me what protocol the protocol using the start message is. I tried to look but I couldn't find it.

tintin10q avatar Jan 11 '24 16:01 tintin10q

Be wary of the confusing names of the protocols and libraries...

There are 2 graphql subscriptions protocols over WebSocket:

  • the older and deprecated Apollo's graphql-ws (implemented by the subscriptions-transport-ws library): https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md
  • the more recent and recommended graphql-transport-ws (implemented by the graphql-ws library), that you pointed to

Which one to use depends what your gql server implements and whether you are limited by 3rd party libs that support one or the other, e.g. older versions of apollo client don't support graphql-transport-ws, or Zeus doesn't support graphql-ws. Note that on the server-side, you can support both of them (it might require a fair amount of debugging to get it right depending on your server's solution). If you use Zeus generated client, then you have to support graphql-transport-ws on your server-side (I haven't looked at stucco, I don't how standard/non-standard it is).

The first part of this article does a good job presenting the differences between both protocols.

gthau avatar Feb 16 '24 18:02 gthau