-
Here's my config: // https://github.com/enisdenjo/graphql-ws
let restartRequestedBeforeConnected = false
let gracefullyRestart = () => {
restartRequestedBeforeConnected = true
}
wsClient.current = createWSClient({
url: `${baseUrl}/graphql`,
retryAttempts: 50,
keepAlive: ms('1 hour'),
lazy: typeof window === 'undefined',
webSocketImpl: typeof window === 'undefined' ? require('ws') : WebSocket,
connectionParams: () => {
return {
token: getToken(),
activeSpaceId: getActiveSpaceId(),
appVersion: process.env.appVersion,
}
},
on: {
closed: console.error,
connected: (socket: unknown) => {
console.info('client connected.', socket)
gracefullyRestart = () => {
if (socket instanceof WebSocket) {
if (socket.readyState === WebSocket.OPEN) {
console.info('emitted client restart')
socket.close(4205, 'Client Restart')
}
} else {
console.error('socket not instance of websocket')
}
}
// just in case you were eager to restart
if (restartRequestedBeforeConnected) {
restartRequestedBeforeConnected = false
gracefullyRestart()
}
},
},
}) I use it with URQL: export const client = createClient({
url: '/graphql',
exchanges: [
devtoolsExchange,
dedupExchange,
// ...,
subscriptionExchange({
enableAllOperations: true,
forwardSubscription(operation) {
return {
subscribe: sink => {
const dispose = wsClient.current?.subscribe(operation, sink)
return {
unsubscribe: () => dispose?.(),
}
},
}
},
}),
],
}) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
Hey hey, the close event is triggered by the server. Client is just communicating it. Our server implementation closes with 1001 when the server is going away (or shutting down as the close reason suggests). Lines 126 to 128 in 88a12ef Looking at the close reason from the provided dev-tools screenshot, the server is closing the client with a |
Beta Was this translation helpful? Give feedback.
Hey hey, the close event is triggered by the server. Client is just communicating it. Our server implementation closes with 1001 when the server is going away (or shutting down as the close reason suggests).
graphql-ws/src/use/ws.ts
Lines 126 to 128 in 88a12ef
Looking at the close reason from the provided dev-tools screenshot, the server is closing the client with a
"shutting down"
reason. This tells me that you're not using thegraphql-ws
server implementation, but rather a different one. So, sadly, I cannot be of much help - you have to check your server implementation out.