graphql-ws: Apollo polling does not continue after socket closed graceful reconnect

Simplifying some details my code looks aproximately something like this:

  const { data, error, previousData } = useQuery(LATENCY_QUERY, {
    pollInterval: PING_INTERVAL,
  })
  useEffect(() => console.log(data), [data])

After I shut down my server and restart it (causing the socket to close and gracefully re-open) I stop seeing polling data in my console. How do I get apollo client to restart polling on re-connect?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (8 by maintainers)

Most upvoted comments

Cool, glad you got it working and you’re very welcome!

I found the best workaround was to add a callback to my connection code. When a connection succeeds a counter is incremented via setReconnectCounter(i => i + 1) causing a re-rerender where I use the counter value as the key for my apollo provider: <ApolloProvider client={client} key={reconnectCounter}>. After that the entire React component tree gets remounted so any weirdness in stuck queries gets wiped out in the remount.

Yeah, makes sense. Appreciate it!

If the relevant link gets invoked, the WS client subscription method gets called, but none of the callbacks get triggered; then its likely that graphql-ws is swallowing requests, which is bad! I’ll jump onto this ASAP.

However, if the link is never invoked - I’d guess this issue lies on Apollo’s side.