Skip to content

Interoperability suggestions #83

Closed
@morris

Description

@morris

Hi!

First of all thanks a lot for taking over this and moving GraphQL over web sockets forward, I believe it's quite important to get some consistency here 🎉 !

I was playing around with this a bit and built an alternate server implementation of the protocol, with the goal of supporting @apollo/client out of the box, with no changes on the client side. I found that there's only a few changes that would allow the latest @apollo/client:

  • Allow both graphql-transport-ws and graphql-ws sub-protocols (the latter is used with @apollo/client)
  • Allow type: "start" in addition to type: "subscribe" for Subscribe messages
  • Allow type: "stop" in addition to type: "complete" for client-to-server Complete messages
  • Use type: "data" instead of type: "next" for Next messages if socket.protocol === "graphql-ws"
  • Allow the client to send Subscribe messages before receiving ConnectionAck. This was the "hardest" one, as the server needs to defer handling the received Subscribe messages until it actually acknowledges the connection. I resolved this through introducing a promise for the acknowledgment, which the Subscribe handlers await before proceeding.

I believe some degree of legacy protocol handling could drive adoption a lot. If we had a server-side GraphQL-over-WS implementation that caters to all popular clients right now, that would be really cool (and graphql-ws could be just that!).

This does not necessarily have to be reflected in the spec and may just go to the implementation. Still, I could imagine adding something like:

  • Servers MAY accept Subscribe messages before a client received the ConnectionAck message in order to support legacy clients.
  • Servers MUST NOT handle Subscribe messages before sending the ConnectionAck message.
  • etc.

I did write an alternate implementation from scratch (and this was quite easy thanks to your work on the protocol) but I could easily provide a PR for the above if you're interested. Let know what you think :)

All the best
Morris

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information about the library is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions