-
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
Using pagination with fetchMore and fetchPolicy involving network together causes bug where next page data is cleared #6327
Comments
I would also like to some resolution to this, but I recognize this is not an easy thing to implement. I have a similar scenario with a paginated list and a cache-and-network policy. When the user first visits the list and starts scrolling down, the list query starts accumulating the full results. When the user goes away and comes back to the list later, they initially see the full list of items. The network response them comes back and removes everything except the first page. This is something that is typically solved with http etag headers (to trigger optimizations on both the client and server) but I’m not sure what the graphql equivalent is. |
I am also having this issue using version 3.0.0-beta.50. Basically if I do my query as follows it works great
However if I add a fetchPolicy of 'cache-and-network' to the useQuery
The console.log will show the correct output, however when the component updates it will only have the original data and none of the new data. I am using a loadingMore scope here because I couldn't bet the loading variable to update when fetchMore was being called regardless of the notifyOnNetworkStatusChange. |
Having the same issue. |
It looks like this issue/bug is introduced in version |
@arminbro Looks like this is fixed in |
@layerssss Thanks for the heads up.
The other issue: example of my useLazyQuery: const [getQuestions, { data: questionsData, loading: loadingQuestionsData, fetchMore }] = useLazyQuery(
GET_QUESTIONS,
{
fetchPolicy: 'network-only',
notifyOnNetworkStatusChange: true,
}
); @benjamn, Let me know if I need to file a new bug, or if you guys can take care of this issue within this ticket. |
I am having this issue with rc.10 with fetch-policy set to 'no-cache' if the fetch-policy makes any difference |
This does seem to be fixed in the latest RCs, as confirmed by @yamalight's reproduction (#6327 (comment)). The loading status problem for |
I have this issue on 3.1.1 |
@benjamn this issue can be reopened in 3.1.1. After a fetchMore, the data is refetched. |
@jp928 @robertsmit Are you setting |
@benjamn I currently circumvent this behaviour of the data of the original query being refetched, by using the current option values: by using nextFetchPolicy 'cache-first' it wil not refetch the original query after calling fetchmore. But I hope that for the next releases this should not be necessary. |
@robertsmit The |
Hi @benjamn, I am also encountering in my app the behavior @robertsmit described. It's an 'infinite scroll' query where I would like to display a different loader when But It seems to appear in the v3.1.0-pre.4. (Small repro here) Just to be sure, is this behavior working as intended ? |
Maybe a good idea to actually add |
I'm having this same issue with Apollo v2.6.8. Is there a fix for this issue that does not include updating to v3? |
It seems like there is no fix, the only work around is to use |
After searching for hours, finally I found this temporary solution. And for the sake of other readers like me, when using nextFetchPolicy: "cache-first" doesn't trigger loading state. Just in case you need to track loading state, you have to set 'notifyOnNetworkStatusChange' to true. |
In my case, nextFetchPolicy is not working for @apollo/client: ^3.3.19, and am still getting old data on fetchmore
|
Intended outcome:
fetchMore
andupdateQuery
for pagination viauseQuery
should work well without a bug withfetchPolicy
that involves network such as'network-only'
,'cache-and-network'
, etc.Actual outcome:
fetchMore
andupdateQuery
works, butupdateQuery
immediately triggers apollo's query observables to refetch query with oldvariables
(with pagination cursor = null).Refetched data (where cursor = null) overwrites result from
updateQuery
causing new page data to be appended and then immediately removed because of the overwrite.This clearly seems like a bug of apollo client.
How to reproduce the issue:
Implement
useQuery
pagination with cursor andupdateQuery
from official example and usefetchPolicy: "cache-and-network" or "network-only"
.Versions
System:
OS: macOS 10.15.3
Binaries:
Node: 13.13.0 - /usr/local/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.14.4 - /usr/local/bin/npm
Browsers:
Chrome: 81.0.4044.138
Firefox: 75.0
Safari: 13.0.5
npmPackages:
@apollo/client: ^3.0.0-beta.49 => 3.0.0-beta.49
@apollo/link-context: ^2.0.0-beta.3 => 2.0.0-beta.3
@apollo/link-error: ^2.0.0-beta.3 => 2.0.0-beta.3
@apollo/link-persisted-queries: ^1.0.0-beta.0 => 1.0.0-beta.0
The text was updated successfully, but these errors were encountered: