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.

Calling refetch fires off a network request when skip is true

See original GitHub issue

Calling refetch ignores the skip: true option for the query hook. The full config of the query hook is:

fetchPolicy: "cache-and-network",
nextFetchPolicy: "cache-first",
notifyOnNetworkStatusChange: true,
variables: { ... },
skip: true

Intended outcome:

Calling refetch when skip is true should not produce a network request.

Actual outcome:

Calling refetch when skip is true produces a network request. While the request is in flight the loading state is false, when the data is fetched it’s not rendered (not passed to the data prop). The reason why skip is true in this case is lack of certain variables, that would filter a large data set. There’s a button on the page that can “refresh” the data, which calls the refetch function. Previously (on v3.1.3) refetch was throwing an error, instead of firing off a network request (which was also a bad behavior and was something that we handled in a weird way). It would be nice if it can just respect the skip property and not do anything if it’s true.

Versions

npmPackages: @apollo/client: ^3.3.19 => 3.3.19

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
knedev42commented, Jun 22, 2021

This is exactly what I’m doing at the moment. That said, the current behavior is clearly broken even if we ignore the fact that it fires off a network request when skip is true (the data is never received by the hook even though a request was in flight and has completed). Plus the behavior was different in the previous minor version (it threw an error instead of firing off a request)…

What’s the point of versioning if things aren’t getting fixed because someone might rely on a non-sensical/buggy behavior?

1reaction
Minishlinkcommented, Nov 23, 2021

@brainkim @hwillson Is there not a difference between skip and the standby fetchPolicy? I tend to think that if skip is true, requests are all skipped, but if it is in standby, the user can still manually update the cache or refetch Either this or the documentation needs updating 😃

Uses the same logic as cache-first, except this query does not automatically update when underlying field values change. You can still manually update this query with refetch and updateQueries.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Refetch no longer works in 3.5 when skip is true #9101 - GitHub
Hello. I've been using refetch from useQuery for over a year. In my code, I use it in combination with skip: true to...
Read more >
HOC - Apollo GraphQL Docs
If config.skip is true , then all of the React Apollo code is skipped entirely. Your component behaves as if the graphql() function...
Read more >
Is it possible to prevent `useLazyQuery` queries from being re ...
When using useLazyQuery , you can set nextFetchPolicy to "standby" . This will prevent the query from firing again after the first fetch....
Read more >
intercept - Cypress Documentation
The routeHandler function is called whenever a request is matched, with the first argument being the request object. From inside the callback, you...
Read more >
Reliably Send an HTTP Request as a User Leaves a Page
The root of the issue is that, by default, XHR requests (via fetch or XMLHttpRequest ) are asynchronous and non-blocking. As soon as...
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