Using pagination with fetchMore and fetchPolicy involving network together causes bug where next page data is cleared
See original GitHub issueIntended outcome:
fetchMore
and updateQuery
for pagination via useQuery
should work well without a bug with fetchPolicy
that involves network such as 'network-only'
, 'cache-and-network'
, etc.
Actual outcome:
fetchMore
and updateQuery
works, but updateQuery
immediately triggers apollo’s query observables to refetch query with old variables
(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 and updateQuery
from official example and use fetchPolicy: "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
Issue Analytics
- State:
- Created 3 years ago
- Reactions:16
- Comments:21 (5 by maintainers)
Maybe a good idea to actually add
nextFetchPolicy
into the docs next time instead of everyone spending hours working out why the initial query just fired again…like I just did. Also how many breaking changes can you possible introduce in a new version? Migration is basically just changing the entire application zzzzzzzz.@benjamn Yes, that is the case. And I use as fetchPolicy ‘cache-and-network’. version 3.1.2
I currently circumvent this behaviour of the data of the original query being refetched, by using the current option values: { fetchPolicy: ‘cache-and-network’, nextFetchPolicy: ‘cache-first’, }
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.