fetchMore sets networkStatus to 1
See original GitHub issueIntended outcome:
When calling the fetchMore function of a query the networkStatus should be set to 3 and remain 3 for the entire duration of the request as in Apollo Client 2.
Actual outcome:
After I call fetchMore on a query that has { notifyOnNetworkStatusChange: true, fetchPolicy: 'cache-and-network' }
as its parameters the networkStatus is set to 3 for a moment of time, but then it becomes 1:
[Wed Aug 26 2020 14:10:09.560] 7
[Wed Aug 26 2020 14:10:10.640] 3
[Wed Aug 26 2020 14:10:10.879] 1
[Wed Aug 26 2020 14:10:10.886] 1
[Wed Aug 26 2020 14:10:11.259] 7
How to reproduce the issue:
I couldn’t reproduce the issue in the sandbox, but this is my setup: https://codesandbox.io/s/happy-bhabha-rjyt0.
I’m using react-native with the following code:
const { data, refetch, fetchMore, networkStatus } = useQuery(
query,
{
variables,
notifyOnNetworkStatusChange: true,
fetchPolicy: 'cache-and-network'
}
)
// .....
const onEndReached = useCallback(() => fetchMore({
variables: {
after: lastId
count: 30
}
}), [fetchMore])
Versions
System: OS: Linux 4.19 Debian GNU/Linux 10 (buster) 10 (buster) Binaries: Node: 14.8.0 - /usr/bin/node npm: 6.14.8 - /usr/bin/npm Browsers: Firefox: 68.11.0esr npmPackages: @apollo/client: ^3.1.3 => 3.1.3 apollo-cache-persist: ^0.1.1 => 0.1.1
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:5
They made a change on the behavior of the fetch policies
cache-and-network
andnetwork-only
. I think when the cache of the query changes (using fetchMore for example) it automatically refetches unless you specifynextFetchPolicy
option.Have you tried using
nextFetchPolicy: 'cache-first'
?The doc is not up to date yet but there are some comments on issues like https://github.com/apollographql/apollo-client/issues/6760#issuecomment-668188727, https://github.com/apollographql/apollo-client/issues/6819#issuecomment-673000015…
I think we might soon configure it globally if that’s the kind of behavior you prefer : https://github.com/apollographql/apollo-client/issues/6833#issuecomment-679446789
@gergof In my case,
useQuery
is actually making a second request whennetworkStatus
changes to1
with the default variables from the initial request. Do you observe similar behavior?@apollo/client: 3.1.3