-
I am currently connecting to my GraphQL server using apollo client and graphql-ws: const wsLink = new GraphQLWsLink(
createClient({
url: process.env.NEXT_PUBLIC_WEBSOCKET_DATAGATE_ADDRESS,
reconnect: true,
lazy: false,
connectionParams: () => {
return {
headers: {
Authorization: token,
},
};
},
})
);
this.apolloClient = new ApolloClient({
link: wsLink,
cache: new InMemoryCache(),
}); Is there a way to detect when the connection of GraphQLWsLink gets broken and force reconnect? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The client automatically performs silent reconnects when the connection is abruptly closed. By default, it retries 5 times using randomised exponential backoff. You can disable the retries by setting the Furthermore, you can listen for the closed event for when the WebSocket connection closes. P.S. there is no const wsLink = new GraphQLWsLink(
createClient({
url: process.env.NEXT_PUBLIC_WEBSOCKET_DATAGATE_ADDRESS,
- reconnect: true,
lazy: false,
connectionParams: () => {
return {
headers: {
Authorization: token,
},
};
},
})
); |
Beta Was this translation helpful? Give feedback.
The client automatically performs silent reconnects when the connection is abruptly closed. By default, it retries 5 times using randomised exponential backoff. You can disable the retries by setting the
retryAttempts
client option to zero (0).Furthermore, you can listen for the closed event for when the WebSocket connection closes.
P.S. there is no
reconnect
option in the client.const wsLink = new GraphQLWsLink( createClient({ url: process.env.NEXT_PUBLIC_WEBSOCKET_DATAGATE_ADDRESS, - reconnect: true, lazy: false, connectionParams: () => { return { headers: { Authorization: token, }, }; …