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.

Refetch returns cached data

See original GitHub issue

Intended outcome:

The promise returned from query.refetch() should resolve with the data fetched from the refetch.

Actual outcome:

The promise returned from query.refetch() resolves with the cached data from the initial query.

How to reproduce the issue:

I crated a minimal reproduction example: https://codesandbox.io/s/cache-and-network-with-cache-present-wlptu

The server just returns the current time, check in the log to see that the refetch result is the same as in the initial render.

Versions

3.1.3

This is the same as issue #3243 that got closed even though the issue still exists as can be seen in the linked example.

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
Pajncommented, Jun 24, 2020

This has nothing to do with having or not having an id property. As stated in the issue, the problem is that the promise returned from query.refetch() resolves with the cached data from the initial query instead of the refetched data.

1reaction
ivan-kleshnincommented, Jun 23, 2020

In my case the fetched data has ids (was getting warnings about merge without them) but still the cache is not updated. @MahmudHamid is there any other reason for this you can think of?

I succeeded to update the pagination cache with refetch only by sending a unique random variable to the query, like random: Math.random(). Very hacky.

Without this, refetch just returns CACHED data – instead of the data fetched from the server 🤷

Read more comments on GitHub >

github_iconTop Results From Across the Web

Refetching queries in Apollo Client - Apollo GraphQL Docs
Local cache updates and refetching work especially well in combination: your application can display the results of local cache modifications immediately, while ...
Read more >
Avoiding refetch to update Apollo Client cached data (React)
In order for Apollo Client to update the cache automatically, we have to remember to always return the new data in operation responses....
Read more >
Should RTK query only be used to fetch data that doesn't need ...
RTK Query is only for caching fetched data. It's always been common to fetch data from the server and put it into the...
Read more >
How to Query GraphQL - LogiCloud
If all data is available locally, useQuery returns that data and doesn't query your GraphQL server. This cache-first policy is Apollo Client's default...
Read more >
GraphQL Cache Updates Made Easy - Christian Lüdemann
Refetch query; Built-in normalization · Configure/design the client-side data using cache policies. Query data using client. · By splitting the results into ...
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