-
Notifications
You must be signed in to change notification settings - Fork 737
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
removeObject(for:) is not updating Query Watchers #3493
Comments
Sorry this question fell through the cracks @majda107. It was posted during the holidays and we must have just missed it. What you're asking for is definitely an intended use of query watchers. Looking at our code now, I'm seeing that the But that doesn't explain why using |
Looking into implementing the fix for the The watcher is currently keeping track of the keys of each field that is watched, but not the actual entity itself. So the cache needs to return a list of the actual cache keys for each of the fields that are being removed for us to update watchers. This probably isn't ideal, but would require a more involved rewrite of the entire query watcher and caching system to solve right now. This will be a major breaking change, and due to that, it is probably better left for the 2.0 version. |
Thank you for the feedback. I indeed planned to heavily rely on the query watchers specifically for this use case, so I’m quite happy to hear that this issue will be further investigated. I’m not entirely sure about the update functionality—I’ll look into it in more detail and provide some examples in the next few days. However, I wanted to ask if there’s any possibility for me to "hotfix" the |
Question
Hello Apollo-iOS team,
Is there a built-in mechanism in Apollo-iOS to automatically propagate data to a query watcher subscription when the underlying cached data is modified? Alternatively, is there a way to make the query watcher automatically re-fetch data from the server when part of the cached response is evicted or updated?
Here’s an example of what I’m trying to achieve:
I’m building a simple post ↔ comments mechanism. I have a GraphQL object
Comment
with a uniqueid
identifier, and I’ve defined a custom cache key for it like so:I also have a
CommentsQuery(postId)
that fetches all comments for a given post. When the UI modifies or deletes a comment, I want to evict this comment from the cache:Alternatively, I might modify the comment using
transaction.updateObject()
. However, neither of these methods seem to trigger the query watcher to re-run, even when the cached data associated with the query has changed.I’ve tried experimenting with different fetch policies, but none of them seem to produce the desired behavior.
For example:
I know that the Apollo Web client offers a nextFetchPolicy mechanism, which allows the client to first fetch data from the server and then listen for live updates from the cache. Is there a similar feature or recommended approach in Apollo-iOS to achieve this behavior?
PS: I understand that I can manually trigger updates by using the
watcher.refetch()
call to fetch new data. However, I would prefer to leverage the built-in mechanisms in Apollo-iOS to handle this more elegantly, especially for more complex use cases. For example, the evicted comment might appear in multiple parts of the UI - such as a notifications section or a "recent comments" list - and I want to propagate updates to all affected parts of the app automatically, without manually managing each instance. This level of automation would help maintain consistency and reduce boilerplate code across the application.Thank you for your guidance!
The text was updated successfully, but these errors were encountered: