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.

skip in useQuery hook doesn't work as expected

See original GitHub issue

Intended outcome:

I was trying to make request conditional, using “skip” in “useQuery” hook, here a brief code of that

gqlerror

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

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;

req

The first request - for CHECK_COURSE_BOUGHT req1

The second request -for GET_COURSE_BY_ID req2

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:closed
  • Created 3 years ago
  • Reactions:16
  • Comments:69 (2 by maintainers)

github_iconTop GitHub Comments

19reactions
gajuscommented, May 15, 2021

Just in case, this is not fixed in 3.3.16.

16reactions
buzinascommented, Jun 26, 2020

As a work-around, I’m using fetchPolicy: skip ? 'cache-only' : 'cache-first', but this is a nasty bug.

Read more comments on GitHub >

github_iconTop Results From Across the Web

reactjs - Skip argument is being ignored in useQuery hook ...
Apollo Client has issues. The bug in skip is an annoying one. You can abandon GraphQL, or work around them. I recommend abandoning...
Read more >
Hooks - Apollo GraphQL Docs
A GraphQL query string parsed into an AST with the gql template literal. Optional for the useQuery hook, because the query can be...
Read more >
Usage With TypeScript - Redux Toolkit
Define a service using a base URL and expected endpoints ... useQuery/useMutation to access the same hooks. TypeScript; JavaScript.
Read more >
graphql-hooks - npm
import { useQuery } from 'graphql-hooks' const HOMEPAGE_QUERY ... skip : Boolean - defaults to false ; do not execute the query if...
Read more >
Testing | TanStack Query Docs
React Query works by means of hooks - either the ones we offer or custom ones ... and that tests don't run in...
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