router
router copied to clipboard
Websocket protocol name is misnamed for subscription
We're using protocol name for websocket in subscriptions. But for the old one instead of naming it graphql-transport-ws we should name it subscriptions-transport-ws to avoid any confusions.
I don't think this is just a naming issue, the docs seem to be wrong here:
graphql_ws
Used by the graphql-ws library
This subprotocol is the default value and is recommended for GraphQL server libraries implementing WebSocket-based subscriptions.
graphql_transport_ws
Legacy subprotocol used by the subscriptions-transport-ws library, which is unmaintained but provided for backward compatibility.
The sentence "used by the graphql-ws" library seems to imply that the graphql_ws config option is referring to the library's subprotocol. This is wrong; the graphql-ws library uses the graphql-transport-ws subprotocol, which we can see in its docs. In fact, the graphql-ws library was originally named graphql-transport-ws, which is how I think this happened.
The older subscriptions-transport-ws library seems to use a subprotocol named graphql-ws (which is not referring to the library above, since it was not created yet) based on this file in its codebase referring to a protocol named graphql-ws, and this Elixir implementation of subscriptions-transport-ws, whose docs say to set the subprotocol on the server to graphql-ws.
It looks like these associations are correct in the dropdown in Apollo Studio:
Naming aside, the current state of the router subscription config is this:
-
setting the router config
protocoltographql_wsresults in aSec-Websocket-Protocolrequest header sent from router tographql-transport-ws. This sort of makes sense since this is the subprotocol used by thegraphql-wslibrary, so we can say that the config is referring to the library here and not its subprotocol. -
Setting the router config
protocoltographql_transport_wsresults in aSec-Websocket-Protocolrequest header value ofgraphql-ws. This does not make sense;graphql_transport_wsis a protocol, so setting the value of the request header to the name of its parent library is likely to cause bugs and confusion. Renaming this config value tosubscription_transport_wsseems reasonable-ish as long as it's clear that its subprotocol isgraphql-wsand the expected value of the header will begraphql-ws. This is not currently clear in the docs.