-
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
Add updateQuery
and updateFragment
methods to ApolloCache
#8382
Add updateQuery
and updateFragment
methods to ApolloCache
#8382
Conversation
@wassim-k Thanks for suggesting and implementing and testing this API! We are technically in the final (release candidate) phase of Apollo Client 3.4 testing (no new features before launch), but we should be able to add this API (or something similar) in the next minor version, v3.5. If you see us create a release branch/PR for v3.5 without revisiting this PR, please feel free to ping me here. |
5c93197
to
328268c
Compare
328268c
to
a4d4574
Compare
Ben and I spoke about this off-GitHub and think there’s merit to functionality like this. Some thoughts:
|
8a104b5
to
4f967b2
Compare
4f967b2
to
a43767a
Compare
I took the liberty of renaming to I think the reason for the separate function parameter is just brevity: if you put that function into the options, it suddenly needs a property name: cache.updateQuery({ query }, data => transform(data))
cache.updateQuery({ query, update: data => transform(data) }) We could later decide to support both ways of passing the function, but the shorter version has my vote (for now) if we have to pick one. |
updateQuery
and updateFragment
methods to ApolloCache
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.
I'm happy to merge and keep iterating on the release-3.5
branch (if need be). Thanks again for implementing this idea @wassim-k!
You're very welcome, thanks for merging it in :) |
Changes are now available in |
Checklist:
Hi,
We love apollo client in our company and use it for all of our state management needs in our project.
With the help of graphql-code-generator, we're able to write 100% type-safe state management code, whether it's from server or client only schema and we quite like using the schema as the layer of abstraction for our state's structure.
This PR is about two helper methods we've been using for quite some time, they're just a more concise way to do common operations, like reading from state, modifying it then writing it back, I hope you find it useful for other users too.
From the example in the docs, this PR allows rewriting this logic:
Into:
Please let me know if you have any questions or suggestions.