-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useQuery with suspend=false does not keep polling after error #19
Comments
I dug into this a little deeper and apparently it's a little complicated with the way how apollo-client implements the ObservableQuery. The way to solve it is to re-subscribe to the ObservableQuery on error, since apollo leaves the subscription in a terminated state. Not sure if you want to include an extra layer of complexity in this package. Let me know what you think see: |
Hi @wilcoschoneveld, thanks for the report.
Sure. I think it's a good idea (of course it would be better if solved directly in apollo-client but we could have fix for that in react-apollo-hooks until then). |
Would this do it? if (error) {
startPolling(INTERVAL);
return (<p>Error</p>);
} Edit: It does not work. |
@gunar I ended up manually polling with |
I've noticed that the networkStatus return from useQuery() will remain 8 (=error) and due to that it will stop fetching. It will not stop polling however looking in the code of QueryManager.ts you will see that poll() will call maybeFetch() and that will only fetch when not checkInFlight() and here it will stop fetching due to networkStatus=8. I don't have a solution and so far I think this is the root cause that polling will not fetch after an error. EDIT: reviewing the checkInFlight() of QueryManager.ts again looks like it should return false and keep fetching so I'm confused and could be wrong here. EDIT2: Indeed I was wrong. The useQuery() will stop polling completely on an error. While the module remains polling. EDIT3: Investigation the Query module (which keeps polling so it works properly) from react-apollo I found out that this one uses also useQuery. However it imports it from @apollo/react-hooks while I was using the react-apollo-hooks package. I've switched to @apollo/react-hooks and now it keeps polling after / during errors. For me this solved my situation. |
Trying to run the following code:
When the query fails (e.g. when server is down) it stops polling.
Unhandled error Network error: Failed to fetch Error: Network error: Failed to fetch at new ApolloError
With react-apollo's Query component I can keep polling.
Let me know if you need more info
The text was updated successfully, but these errors were encountered: