[Question] Clarify inmemorycache and cache redirecting behavior
See original GitHub issueI’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!
-
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
-
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? -
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)?
-
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?
-
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:
- Created 6 years ago
- Reactions:9
- Comments:5 (1 by maintainers)
Top GitHub Comments
It does feel like you need a Phd in apollo-client to do simple CRUD sometimes.
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!