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.

Automatic Cache Update Not Working

See original GitHub issue

Hello! I am trying to take advantage of the Apollo automatic cache updates as described here, but when I try to update my single entity, the cache remains the same:

Here I make the mutation: Screen Shot 2020-01-10 at 1 31 25 PM

and here I check the cache afterwards to see if it has changed: Screen Shot 2020-01-10 at 1 32 37 PM

Despite the isHidden flag being set by the mutation, it is not updated. Is there something I’m missing for automatic cache updates besides single entity, and request the ID and modified fields back in the mutation?

Here are my system facts: Screen Shot 2020-01-17 at 9 59 54 AM

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
danReynoldscommented, Jan 17, 2020

After looking into it some more, it looks like we hit this issue because our apollo client config specified:

const apolloClient = new ApolloClient({
  defaultOptions: {
    watchQuery: {
      fetchPolicy: APOLLO_FETCH_POLICY.CACHE_AND_NETWORK,
    },
    mutate: {
      fetchPolicy: APOLLO_FETCH_POLICY.NO_CACHE,
    },
  },
});

Which for mutate we had thought meant always hit the network similarly to what it means for a query but it also means do not cache the result, which causes the update option to not be triggered and does not write anything to the cache. Seeing as this is expected behavior I’m closing this issue.

1reaction
dylanwulfcommented, Jan 17, 2020

From what I can see it looks like the cache should be updating. Could you provide a runnable reproduction, preferably using codesandbox? It’s difficult to see what’s going on without being able to run the code. Issues in this repo are much more likely to be looked at if they have a runnable reproduction

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reading and writing data to the cache - Apollo GraphQL Docs
To update cached data safely, see Combining reads and writes. If the cache is missing data for any of the query's fields, readQuery...
Read more >
Automatic cache updates do not work in react apollo
When I update one of the reviews from the list to the server, react apollo does not automatically update the cached review:
Read more >
GraphQL Cache Updates Made Easy - Christian Lüdemann
We looked at how the Apollo Client handles automatic cache updates using normalization, refetch queries, and manual updates of the cahce. We finished...
Read more >
Advanced Topics on Caching – Angular
refetchQueries is the simplest way of updating the cache. ... a problem arises when later retrieving or updating paginated queries in the ...
Read more >
GraphQL Mutations and Caching using Apollo Client
This would indicate that the mutation was complete. If the mutation cache was not updated, we would need to refresh the page to...
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