question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fetchMore sets networkStatus to 1

See original GitHub issue

Intended 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:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:5

github_iconTop GitHub Comments

8reactions
Alex153commented, Aug 28, 2020

They made a change on the behavior of the fetch policies cache-and-network and network-only. I think when the cache of the query changes (using fetchMore for example) it automatically refetches unless you specify nextFetchPolicy 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

4reactions
DanielMarkielcommented, Aug 26, 2020

@gergof In my case, useQuery is actually making a second request when networkStatus changes to 1 with the default variables from the initial request. Do you observe similar behavior?

@apollo/client: 3.1.3

Read more comments on GitHub >

github_iconTop Results From Across the Web

Queries - Apollo GraphQL Docs
This article shows how to fetch GraphQL data in React with the useQuery hook and attach the result to your UI. You'll also...
Read more >
https://www.unpkg.com/@apollo-elements/gluon@2.0.2...
import type { NetworkStatus } from 'apollo-client'; import ... 1. `loading`: The query has never been run before and the request is now...
Read more >
Interfaces: ApolloQuery - Apollo Elements
networkStatus is an enum with different number values between 1 and 8. These number values each represent a different network state.
Read more >
FetchMore not updating data with queryroot : r/graphql - Reddit
Hi! I'm trying to get some products in a specific collection and show them on the screen. However, I don't want to load...
Read more >
React Apollo Client - query results mixing up in cache
Asked 1 year ago ... const { loading, data: newBooks, fetchMore, networkStatus } = useQuery(NEW_BOOKS, { variables: { first: PAGE_SIZE, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found