|
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? |
Answered by
enisdenjo
Jul 17, 2023
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,
},
};
},
})
); |
0 replies
Answer selected by
enisdenjo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to 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
retryAttemptsclient option to zero (0).Furthermore, you can listen for the closed event for when the WebSocket connection closes.
P.S. there is no
reconnectoption 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, }, }; …