Description
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
andgraphql-ws
sub-protocols (the latter is used with @apollo/client) - Allow
type: "start"
in addition totype: "subscribe"
forSubscribe
messages - Allow
type: "stop"
in addition totype: "complete"
for client-to-serverComplete
messages - Use
type: "data"
instead oftype: "next"
forNext
messages ifsocket.protocol === "graphql-ws"
- Allow the client to send
Subscribe
messages before receivingConnectionAck
. This was the "hardest" one, as the server needs to defer handling the receivedSubscribe
messages until it actually acknowledges the connection. I resolved this through introducing a promise for the acknowledgment, which theSubscribe
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 theConnectionAck
message in order to support legacy clients. - Servers MUST NOT handle
Subscribe
messages before sending theConnectionAck
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