diff --git a/src/use/ws.ts b/src/use/ws.ts index dfd3282c..bf6576d3 100644 --- a/src/use/ws.ts +++ b/src/use/ws.ts @@ -2,6 +2,7 @@ import type * as http from 'http'; import type * as ws from 'ws'; import { makeServer, ServerOptions } from '../server'; import { Disposable } from '../types'; +import { GRAPHQL_TRANSPORT_WS_PROTOCOL } from '../protocol'; // for nicer documentation type WebSocket = typeof ws.prototype; @@ -108,6 +109,14 @@ export function useServer( socket.once('close', (code, reason) => { if (pongWait) clearTimeout(pongWait); if (pingInterval) clearInterval(pingInterval); + if (!isProd && code === 1002) { + 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.', + ); + } closed(code, reason); }); });