-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 stops updating after first network error #6759
Comments
Just in case, setting |
I worked around this by implementing a custom hook: const useLatest = (uid: string) => {
const [data, setData] = useState(null);
const [loading, setLoading] = useState(true);
const [stopPolling, setStopPolling] = useState(() => {
return () => {};
});
const [error, setError] = useState(null);
const apolloClient = useApolloClient();
useEffect(() => {
const watchQuery = apolloClient.watchQuery({
errorPolicy: 'all',
fetchPolicy: 'no-cache',
notifyOnNetworkStatusChange: true,
pollInterval: 1000,
query: LATEST_QUERY,
variables: {
uid,
},
});
const subscriber = {
error: (apolloError) => {
setError(apolloError);
setTimeout(() => {
watchQuery.resetLastResults();
watchQuery.subscribe(subscriber);
}, 1000);
},
next: (state) => {
if (!deepEqual(state.data, data)) {
setData(state.data);
}
setLoading(state.loading);
setError(null);
},
};
watchQuery.subscribe(subscriber);
setStopPolling(() => {
return () => {
watchQuery.stopPolling();
};
});
}, [apolloClient, data, uid]);
return {
data,
error,
loading,
stopPolling,
};
}; |
If you were to just use Somewhat related issues: |
If someone can provide a small runnable reproduction that demonstrates this happening with |
Intended outcome:
I want to get updates about every time that a query fails.
Actual outcome:
Only the first error propagates to query results.
How to reproduce the issue:
If you look at the screenshot, it is clear that only the first time that an error occurs that it propagates to the results.
The expected result is that we should see:
after the last error in the console log.
Versions
The text was updated successfully, but these errors were encountered: