Skip to content

Commit

Permalink
feat(server): Log a warning for unsupported subprotocols
Browse files Browse the repository at this point in the history
Closes: enisdenjo#92
  • Loading branch information
enisdenjo committed Jan 13, 2021
1 parent 2a61268 commit 88a12ef
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/use/ws.ts
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
});
});
Expand Down

0 comments on commit 88a12ef

Please sign in to comment.