-
Expected Behaviour Actual Behaviour Debug Information const server = makeServer({
onSubscribe: async () => {
throw new Error('hello');
},
});
// websocket connection established ...
server.opened({
// ...
close: (code, reason) => {
console.log('close', code, reason); // <- Does not get called
ws.close(code, reason);
},
// ...
}); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
This behaviour is intentional. It is up to the implementor to decide what throwing from any of the hooks, including onSubscribe, does. When you throw there, the In all of the built-in adapters, graphql-ws will close the connection after throwing, but it's a choice. For example, here's the Lines 144 to 161 in 85985ee |
Beta Was this translation helpful? Give feedback.
This behaviour is intentional. It is up to the implementor to decide what throwing from any of the hooks, including onSubscribe, does.
When you throw there, the
onMessage(callback)
callback function will throw and you decide whether to close the connection or gracefully handle it (because it might be just one specific subscription failing, not needing to kick off the client complately).In all of the built-in adapters, graphql-ws will close the connection after throwing, but it's a choice. For example, here's the
use/ws
adapter:graphql-ws/src/use/ws.ts
Lines 144 to 161 in 85985ee