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.

@client @export $variable not refetching Query when state changes

See original GitHub issue

Intended outcome:

When using local @client state as a query variable via @export I would expect that changing that state would cause the query to re-run (as the variable has changed and it shouldn’t be in cache).

Actual outcome:

The query does not re-run. Using @client(always: true) doesn’t help, nor does changing fetchPolicy.

How to reproduce the issue:

Using Query component (haven’t tried as a HOC) write a query using @client @export, and inside that component have some event change client state with writeData. The query will not re-run.

However doing something else to cause the component to re-render will cause the query to re-run, it’s just not automatically tracked by Apollo. In the example I increment the Query component’s key to force it to re-render, and then Apollo re-fetches the query with the new state.

https://codesandbox.io/s/o57v4x1x25

Versions

  System:
    OS: macOS 10.14.3
  Binaries:
    Node: 11.9.0 - /usr/local/bin/node
    Yarn: 1.13.0 - /usr/local/bin/yarn
    npm: 6.5.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 72.0.3626.119
    Safari: 12.0.3
  npmPackages:
    apollo-cache-inmemory: ^1.5.1 => 1.5.1 
    apollo-client: ^2.5.1 => 2.5.1 
    apollo-link-http: ^1.5.9 => 1.5.11 
    react-apollo: ^2.4.1 => 2.5.1 

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:13
  • Comments:27 (10 by maintainers)

github_iconTop GitHub Comments

6reactions
jidecommented, Mar 12, 2019

…any update on this ?

3reactions
hwillsoncommented, Mar 6, 2019

Sorry to hear of your frustration @jide! I’ll post back with an update on this shortly (I’m tackling this and a few other 2.5 issues today). Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Query refetch on local state change - Help - Apollo GraphQL
Hello, I'm using Apollo Client to paginate a feed of data. My local state contains two tabs that are supposed to fetch either...
Read more >
How to prevent useQuery for running when state changes?
Have a look at the skip option which can be used to entirely skip the query. You can do something like this: const...
Read more >
Custom useQuery and refetch - TinyHouse: A Fullstack React ...
The fetchApi() function in our useQuery Hook is the function we'll want to run again if we needed to refetch query information and...
Read more >
React + Apollo: How to Redirect after Refetching a Query
We can pass in a variable called refetchQueries , which will refetch any queries we ask for. this.props.mutate({ variables:{ title: this.state.title,
Read more >
Redux Essentials, Part 8: RTK Query Advanced Patterns
Some of the changes in this section aren't strictly necessary ... RTK Query saw that it did not have the data in cache...
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