diff --git a/src/common.ts b/src/common.ts index a3d08e43..9569ac1d 100644 --- a/src/common.ts +++ b/src/common.ts @@ -20,6 +20,13 @@ import { */ export const GRAPHQL_TRANSPORT_WS_PROTOCOL = 'graphql-transport-ws'; +/** + * The deprecated subprotocol used by [subscriptions-transport-ws](https://github.com/apollographql/subscriptions-transport-ws). + * + * @private + */ +export const DEPRECATED_GRAPHQL_WS_PROTOCOL = 'graphql-ws'; + /** * `graphql-ws` expected and standard close codes of the [GraphQL over WebSocket Protocol](/PROTOCOL.md). * diff --git a/src/use/fastify-websocket.ts b/src/use/fastify-websocket.ts index d4f2172c..5708a8a9 100644 --- a/src/use/fastify-websocket.ts +++ b/src/use/fastify-websocket.ts @@ -2,7 +2,7 @@ import type { FastifyRequest } from 'fastify'; import type * as fastifyWebsocket from 'fastify-websocket'; import { handleProtocols, makeServer, ServerOptions } from '../server'; import { - GRAPHQL_TRANSPORT_WS_PROTOCOL, + DEPRECATED_GRAPHQL_WS_PROTOCOL, ConnectionInitMessage, CloseCode, } from '../common'; @@ -172,12 +172,14 @@ export function makeHandler< socket.once('close', (code, reason) => { if (pongWait) clearTimeout(pongWait); if (pingInterval) clearInterval(pingInterval); - if (!isProd && code === CloseCode.SubprotocolNotAcceptable) + if ( + !isProd && + code === CloseCode.SubprotocolNotAcceptable && + socket.protocol === DEPRECATED_GRAPHQL_WS_PROTOCOL + ) console.warn( - `WebSocket protocol error occured. It was most likely caused due to an ` + - `unsupported subprotocol "${socket.protocol}" requested by the client. ` + - `graphql-ws implements exclusively the "${GRAPHQL_TRANSPORT_WS_PROTOCOL}" subprotocol, ` + - 'please make sure that the client implements it too.', + `Client provided the unsupported and deprecated subprotocol "${socket.protocol}" used by subscriptions-transport-ws.` + + 'Please see https://www.apollographql.com/docs/apollo-server/data/subscriptions/#switching-from-subscriptions-transport-ws.', ); closed(code, String(reason)); }); diff --git a/src/use/ws.ts b/src/use/ws.ts index 1ed7a17a..d1cedaf0 100644 --- a/src/use/ws.ts +++ b/src/use/ws.ts @@ -2,7 +2,7 @@ import type * as http from 'http'; import type * as ws from 'ws'; import { handleProtocols, makeServer, ServerOptions } from '../server'; import { - GRAPHQL_TRANSPORT_WS_PROTOCOL, + DEPRECATED_GRAPHQL_WS_PROTOCOL, ConnectionInitMessage, CloseCode, Disposable, @@ -157,12 +157,14 @@ export function useServer< socket.once('close', (code, reason) => { if (pongWait) clearTimeout(pongWait); if (pingInterval) clearInterval(pingInterval); - if (!isProd && code === CloseCode.SubprotocolNotAcceptable) + if ( + !isProd && + code === CloseCode.SubprotocolNotAcceptable && + socket.protocol === DEPRECATED_GRAPHQL_WS_PROTOCOL + ) console.warn( - `WebSocket protocol error occured. It was most likely caused due to an ` + - `unsupported subprotocol "${socket.protocol}" requested by the client. ` + - `graphql-ws implements exclusively the "${GRAPHQL_TRANSPORT_WS_PROTOCOL}" subprotocol, ` + - 'please make sure that the client implements it too.', + `Client provided the unsupported and deprecated subprotocol "${socket.protocol}" used by subscriptions-transport-ws.` + + 'Please see https://www.apollographql.com/docs/apollo-server/data/subscriptions/#switching-from-subscriptions-transport-ws.', ); closed(code, String(reason)); });