-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable customization of cache normalization behavior. #5443
Conversation
it("can define custom merge functions", function () { | ||
const cache = new InMemoryCache({ | ||
typePolicies: { | ||
Person: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In lieu of full documentation, this test case gives a pretty good illustration of how to use typePolicies
and field policies to implement pagination.
This size will come back down once we remove the existing implementations of functionality replaced by PR #5443.
8c38aac
to
a69591f
Compare
This size will come back down once we remove the existing implementations of functionality replaced by PR #5443.
39948f8
to
88c8ed9
Compare
This size will come back down once we remove the existing implementations of functionality replaced by PR #5443.
88c8ed9
to
1d6329e
Compare
This size will come back down once we remove the existing implementations of functionality replaced by PR #5443.
1d6329e
to
f774ef2
Compare
Since we no longer have an independent readStoreResolver function, we no longer need a dedicated context type. Also took this opportunity to get rid of the pointless (and pointlessly cached) StoreReader#executeStoreQuery method.
This read hook replaces the need for cacheRedirects, and may eventually replace our local state implementation.
Instead of capturing the store:NormalizedCache object using a closure, we can pass it in as an additional context argument each time we call storeObjectMerger.merge, like we already do with mergeOverrides.
Although it was tempting to make the read function feel like a GraphQL resolver function (parentObject, args, context, info), that signature would not have been appropriate for the merge function, and having to remember two totally different signatures for reading and merging did not seem ideal. Now, the only difference between the signatures is that the merge function takes incoming data, to be merged with the existing data (if any): read(existing, { args, parentObject, field, variables }) merge(existing, incoming, { args, parentObject, field, variables }) It would have been nice to use named options for everything, including the existing and incoming parameters, but it's important for those parameters to be positional so that the developer can specify their types, without also having to provide a new type for the entire options object.
This size will come back down once we remove the existing implementations of functionality replaced by PR #5443.
Previously, defining a merge function for an ancestor field would prevent the merge functions of any descendant fields from being called.
f774ef2
to
89eaf6f
Compare
While there's still a lot of related work I'd like to tackle—in particular, allowing |
Still a work in progress; expanded description coming soon.
In our What's new in Apollo Client 2.6 blog post, we promised:
apollo-cache-inmemory
cache implementation promises to normalize your data, to enable efficient cache updates and repeated cache reads. However, not all data benefits from normalization, and the logic for deciding whether separate objects should be normalized together varies across use cases. Future versions of the Apollo Client cache will unify several related features—dataIdFromObject
, the@connection
directive, andcacheRedirects
—so Apollo developers can implement specialized normalization logic, or even disable normalization for certain queries.This pull request implements (most of) those promises already, and some other related improvements are on the way. As an example, it should be possible for the Apollo Client 3.0 cache to implement local state as part of this new configuration API, allowing us to remove/unify much of the code that was added in Apollo Client 2.5.
Stay tuned for more details (and commits) next week!