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.

[Question] Clarify inmemorycache and cache redirecting behavior

See original GitHub issue

I’m looking at the documentation for cache redirecting for cache resolvers here: https://www.apollographql.com/docs/react/features/cache-updates.html#cacheRedirect. This is the code I’m referring to:

cacheResolvers: { Query: { book: (_, args) => toIdValue(cache.config.dataIdFromObject({ __typename: 'Book', id: args.id })), }, },

I’m a bit confused by the documentation and had a few questions, answers to any of them are helpful!

  1. Is the cacheResolvers feature still supported? It looks to be missing in the documentation here: https://github.com/apollographql/apollo-client/tree/master/packages/apollo-cache-inmemory

  2. What is the first argument (_) signify in the function call. When inspecting it, it looks to be a list of id-values to their responses, so I’m assuming it’s the list of id values that have been mapped in cache from previous queries for that particular query. So for the book query above, _ would be the list of all the previous query request’s id-values, is that correct?

  3. I’m a bit confused about when this resolver is called. Is it called on every query to book in the example above, or does it only fire when the default behavior of hitting the cache for the book query misses (it doesn’t find it from object id defined in dataIdFromObject or the query path)?

  4. Given a book has three different fields ‘name’, ‘date’, ‘authors’, and I was to query for ‘name’ and ‘authors’ at some point and then later on queried for ‘name’, ‘date’, and ‘authors’ on the same unique book, will it retrieve ‘name’ and ‘authors’ from cache and ‘date’ from the server? Then afterwards, is the ‘date’ field added to the same cache object?

  5. What happens if the id defined by dataIdFromObject isn’t unique? What does the cache look like in this case? In cases like this should the user take more granular control via direct cache accessing?

/label question

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:9
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

47reactions
acomitocommented, Mar 10, 2018

It does feel like you need a Phd in apollo-client to do simple CRUD sometimes.

6reactions
hwillsoncommented, Jul 27, 2018

To help provide a more clear separation between feature requests / discussions and bugs, and to help clean up the feature request / discussion backlog, Apollo Client feature requests / discussions are now being managed under the https://github.com/apollographql/apollo-feature-requests repository.

This feature request / discussion will be closed here, but anyone interested in migrating this issue to the new repository (to make sure it stays active), can click here to start the migration process. This manual migration process is intended to help identify which of the older feature requests are still considered to be of value to the community. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring the Apollo Client cache - Apollo GraphQL Docs
To customize cache behavior, you provide a configuration object to the InMemoryCache constructor. This object supports the following fields: ...
Read more >
Does the Apollo client cache nested objects in React?
No, it doesn't (as of Nov 2019, at least). To put the bar object in the cache when running the Foo query, you...
Read more >
Caching a table in Memory - Ask TOM
If you alter table t CACHE, you simply change that behaviour. The blocks read from that long full table scan are not subject...
Read more >
Reinforcing, Reminding, and Redirecting
Name concrete and specific behaviors. ... 'I hear your point, but I have a different idea' or ask a clarifying question the way...
Read more >
What is Caching and How it Works - Amazon AWS
A cache is a high-speed data storage layer which stores a subset of data, ... fail to achieve the low latency performance provided...
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