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.

3.6.0 Some queries never executing with a conditional skip and overridden fetchPolicy

See original GitHub issue

Intended outcome:

In my example app, clicking a person’s name uses setState to store their ID, and then runs a second query to find their country and display it. This second query only executes if a personId is passed in (using skip: !personId).

Actual outcome:

In apollo-client 3.4 and 3.5, this works as expected and displays a country. In 3.6, clicking a person’s name does nothing.

How to reproduce the issue:

See https://github.com/dmarkow/apollo-default-options-issue. Open the console and try clicking names. One render completes due to the setState call, however placesLoading from the second query remains false and the query never executes.

This seems to only happen if I have both defaultOptions.watchQuery.fetchPolicy set to anything, and a conditional skip option. If I completely remove the fetchPolicy setting it works, but then I can’t control caching on my queries. It also works if I remove the skip: !personId option and change the resolver to return an empty list when no personId is passed in.

Versions

  System:
    OS: macOS 12.3.1
  Binaries:
    Node: 16.14.2 - ~/.volta/tools/image/node/16.14.2/bin/node
    Yarn: 1.22.18 - ~/.volta/tools/image/yarn/1.22.18/bin/yarn
    npm: 8.5.0 - ~/.volta/tools/image/node/16.14.2/bin/npm
  Browsers:
    Chrome: 100.0.4896.127
    Safari: 15.4
  npmPackages:
    @apollo/client: 3.6.0 => 3.6.0

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:3
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

10reactions
mydeswebcommented, Apr 30, 2022

v3.6.1 is not working with React Native, queries are not executed. Have to downgrade to v3.5.10

2reactions
Vednuscommented, May 5, 2022

@benjamn @saladestomateoignon 3.7.0-alpha.2 fixed the issues for me on react native. I have a custom fetchPolicy and a number of typePolicies and things seem to be working as expected after the update.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Queries - Apollo GraphQL Docs
To run a query within a React component, call useQuery and pass it a GraphQL query string. When your component renders, useQuery returns...
Read more >
@apollo/client | Yarn - Package Manager
Using onQueryUpdated , you can override the default FetchPolicy of the query, by (for example) calling ObservableQuery methods like refetch to force a...
Read more >
apollo-client - Awesome JS
Make queries with a pollInterval respect the no-cache fetch policy, ... fix bug where skip: true queries failed to execute upon switching to...
Read more >
Customizing Queries - Redux Toolkit
Implementing a custom baseQuery ​. RTK Query expects a baseQuery function to be called with three arguments: args , api , and extraOptions...
Read more >
Better way to handle conditional query in apollo graphql react
Right now this is sitting in my component, and it takes up around 100 lines alone. I have a few set of the...
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