Skip to content

Commit 88a12ef

Browse files
committed
feat(server): Log a warning for unsupported subprotocols
Closes: #92
1 parent 2a61268 commit 88a12ef

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/use/ws.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type * as http from 'http';
22
import type * as ws from 'ws';
33
import { makeServer, ServerOptions } from '../server';
44
import { Disposable } from '../types';
5+
import { GRAPHQL_TRANSPORT_WS_PROTOCOL } from '../protocol';
56

67
// for nicer documentation
78
type WebSocket = typeof ws.prototype;
@@ -108,6 +109,14 @@ export function useServer(
108109
socket.once('close', (code, reason) => {
109110
if (pongWait) clearTimeout(pongWait);
110111
if (pingInterval) clearInterval(pingInterval);
112+
if (!isProd && code === 1002) {
113+
console.warn(
114+
`WebSocket protocol error occured. It was most likely caused due to an ` +
115+
`unsupported subprotocol "${socket.protocol}" requested by the client. ` +
116+
`graphql-ws implements exclusively the "${GRAPHQL_TRANSPORT_WS_PROTOCOL}" subprotocol, ` +
117+
'please make sure that the client implements it too.',
118+
);
119+
}
111120
closed(code, reason);
112121
});
113122
});

0 commit comments

Comments
 (0)