Open tylerzey opened 7 months ago
+1 for this
+1
+1
+1
+1
+2
This is how I do it right now. this code will be added globally where we include apollo provider
useEffect(() => {
const refetchQueries = () => {
if (document.visibilityState === "visible") {
client.refetchQueries({ include: "active" });
}
};
window.addEventListener("visibilitychange", refetchQueries);
return () => {
window.removeEventListener("visibilitychange", refetchQueries);
};
}, []);
Libraries such as SWR and React Query support opting into queries re-fetching upon the window being re-focused.
They allow to you configure this behavior on a per-query or on a global level. It seems quite popular and might be a feature Apollo would like to support.
Example from React Queries docs
A previous issue (feature request) had a lot of comments on it asking for Apollo to support the feature.
To implement this feature in Apollo current, you have to do the following.
On a global level:
On a per-query level:
https://github.com/apollographql/apollo-feature-requests/issues/247#issuecomment-1063411159
Specifically:
The use case seems fairly common and might be something to consider bringing into Apollo as a feature.