-
-
Notifications
You must be signed in to change notification settings - Fork 172
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-wsandgraphql-wssub-protocols (the latter is used with @apollo/client) - Allow
type: "start"in addition totype: "subscribe"forSubscribemessages - Allow
type: "stop"in addition totype: "complete"for client-to-serverCompletemessages - Use
type: "data"instead oftype: "next"forNextmessages ifsocket.protocol === "graphql-ws" - Allow the client to send
Subscribemessages before receivingConnectionAck. This was the "hardest" one, as the server needs to defer handling the receivedSubscribemessages until it actually acknowledges the connection. I resolved this through introducing a promise for the acknowledgment, which theSubscribehandlers 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
Subscribemessages before a client received theConnectionAckmessage in order to support legacy clients. - Servers MUST NOT handle
Subscribemessages before sending theConnectionAckmessage. - 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