-
Notifications
You must be signed in to change notification settings - Fork 722
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
Manipulating cache #73
Comments
This is still very much work in progress, but we've recently added a The main use case we had in mind with this is to support persistent caches, and we've done some thinking about client cache policies with contributors from Airbnb. So please join the conversation so we can make sure to address your use cases too! |
So, I think I'm starting to get some clarity into how this could be accomplished within Apollo. In my current GraphQL client implementation on iOS, I'm using a custom network layer provided by Moya, and I persist my data via CoreData, all supplemented with ReactiveSwift. We utilize CoreData to ensure that the user can use the app offline. My database layer was initially based off of the objc.io CoreData book, but has been modified to adopt more of a one way data flow. When a user submits some data to be saved, those changes are made immediately to the database, and the user continues on with their session. In the background, I create some If there is anything that should block the user, I just observe that sync signal producer on the main thread. Syncs happen by pushing local changes that have not been synchronized, then iterates through a collection of I'd like to refactor this pattern going forward by routing all mutations and queries through the apollo client. i.e. When a user submits some data via form UI, I would grab the values of the form, and create a mutation. I would issue that mutation to the Apollo client, which would have some concept of a driver or middleware to handle the To query some data, I'd follow the same patterns that are currently demonstrated in sample applications. The driver (in the case of CoreData), given the cache policy, could map queries to All returned objects would be mapped to the immutable structs provided by apollo-codegen, bringing CoreData into the world of immutability. I'm somewhat confused as to how we can handle updates and changes that were made offline and ensure they get up to the server in order |
I think that is pretty much the design I have in mind too. Some of this is still implicit in the current codebase because it is work in progress, but the idea is that UI components can watch queries (or individual fragments), and will receive updates whenever relevant data in the store changes. This is based around simple callbacks, but it would also be a great fit for ReactiveSwift I think (I just want to keep the dependency optional). I'm currently in the process of adding store read/write operations similar to the Apollo JS API (as described in this blog post). The idea is to allow you to use queries or fragments both to read and write to the store, basically giving you a typed denormalized interface to a normalized record store. These read/write operations can also be used to implement optimistic updates, temporarily updating the in memory cache until the real results from the server are in. So The idea is that this allows for a pretty minimal interface to pluggable cache implementations, basically just the Does this make sense to you? How does this compare to what you have in mind? Do you think this would be sufficient to integrate with your existing CoreData store? |
@martijnwalraven |
@justinmakaila: The code on master is very much work in progress, so things may be broken. If you do want to try it out, you'll also need to |
@martijnwalraven I just did that... I'm currently trying to use the
But I'm not sure how I can use |
Yeah, I realize the interface is more geared towards a key-value store right now. A You can configure your own |
@martijnwalraven How would this work for singleton objects? i.e. the current user (we literally only ever have one around), and computed objects that are accessible from the root query? |
The query root is also an object, and the record for that object contains fields (which may include arguments) that usually refer to other objects. This is an example of querying the So in your case, the |
@martijnwalraven All of this is sounding great, and stuff that I'm really happy is happening. This is example is actually going really well, aside from the fact that a few types are lacking public interfaces, such as |
@justinmakaila: Really good to hear! I feel bad I haven't been able to document things better yet, but the code in master is a fairy substantial redesign, and I'm working on some more changes before the design is more stable. The reason a lot of types are lacking public interfaces is because I didn't want to commit to an interface yet and wanted to be able to move fast without breaking other people's code. But I'm happy opening things up if that helps you test drive it, because that is the only way to get more people involved and figure out if this is actually working :) |
I'm going to close this issue because it isn't really actionable. Feel free to open issues for specific bugs or features. Also note we just released Apollo iOS 0.6.0-beta.1, which includes the starting point of cache manipulation. Make sure to use |
Is there a way to manipulate the cache?
Our back-end GraphQL implementation has an
expiry
property added to every object.This is a date object and basically tells you if the object is still valid or not.
So I'm now looking for a way to use this property to either throw stuff from the cache.
Or prevent the cache from returning objects that are no longer valid.
The text was updated successfully, but these errors were encountered: