skip in useQuery hook doesn't work as expected
See original GitHub issueIntended outcome:
I was trying to make request conditional, using “skip” in “useQuery” hook, here a brief code of that
here the second query GET_COURSE_BY_ID should be “skipped” if the bought is true, that’s well and good when logged in the console, I get courseDetails as undefined if bought is true, but the thing is it actually makes the network request and sends back the requested data!!
here’s what I get in the console
As expected 👍, courseDetails is undefined if bought is true, But as seen in the network tab it still actually makes a network request and return back the data for courseDetails it so happens that it just makes it undefined later;
The first request - for CHECK_COURSE_BOUGHT
The second request -for GET_COURSE_BY_ID
Actual outcome:
The network request should not be made!!, It should be “skipped” else what is the use of using it. if it is later on just reassigning the data to undefined.
How to reproduce the issue:
Just fallow the code above
Versions
System: OS: Windows 10 10.0.18363 Binaries: Node: 12.13.1 - C:\Program Files\nodejs\node.EXE Yarn: 1.17.3 - F:\softwares\yarn\bin\yarn.CMD npm: 6.12.1 - C:\Program Files\nodejs\npm.CMD Browsers: Edge: 44.18362.449.0 npmPackages: apollo-link-context: ^1.0.20 => 1.0.20 @apollo/client: “^3.0.0-beta.43”,
Issue Analytics
- State:
- Created 3 years ago
- Reactions:16
- Comments:69 (2 by maintainers)
Top GitHub Comments
Just in case, this is not fixed in 3.3.16.
As a work-around, I’m using
fetchPolicy: skip ? 'cache-only' : 'cache-first'
, but this is a nasty bug.