-
Notifications
You must be signed in to change notification settings - Fork 22
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
[Request] Serving invalidated data while refetching (if online) #43
Comments
Hey @mogelbrod! Got back from vacation this week and been busy but getting around to this issue. Thanks for your patience! So I thought more about it and I think it's fundamentally rather tricky. The way the Apollo Client works is that the refetching is triggered by the data eviction. When a I'm happy to chat more about the technical limitations and brainstorm ideas though! |
Welcome back 👋 Absolutely no worries, hope you had a good time! I was worried about that being the case. I have a few questions about how the apollo client/cache interactions work that I would love if you'd be able to clarify. It would help narrowing down possible approaches of implementing this feature.
Happy holidays btw! |
Hey @mogelbrod ! Sorry for the delay, getting back to you on this:
You've probably moved on from this work since last we spoke so again apologize for the delay. Let me know if you have any thoughts if you're still interested. |
No worries @danReynolds! Great, so based off that it seems like it should definitely be possible to implement this behavior as an Apollo cache layer, like this package does - right? I'm definitely still interested in this and can spend some time trying to implement a POC to begin with. I'm hoping to start this or next week - will get back to you here once I start running into major challenges 😅 Edit: Looks like #47 will have to be addressed before I can dig into this. |
#47 should be addressed now, let me know if there's anything you want to go over. Thanks for taking a look! |
Just writing to let you know that with #47 resolved I'll try implementing this as a POC starting today 👍 |
@danReynolds I think I may have found bug/limitation that I'm guessing would be hard to fix without the change in behaviour that this issue proposes. I've created an expanded version of the original CSB in #47 which adds a dropdown to each individual film page to navigate between them. It's currently not hosted on CSB since I'll be using it when working on #43, but can be cloned from https://github.com/mogelbrod/apollo-cache-policies. Repro:
Actual outcome of (10) is: My hypothesis is that switching from invalidation to fetchPolicy manipulation would avoid this issue. I'm guessing the harder challenge when doing so would be to still allow for garbage collection of no longer referenced fields. |
Yea I agree, invalidation is relatively simple because Apollo will handle all of the fetch logic in response to the eviction. Manipulating the fetch policy to fetch data that we determine is expired but has not yet been evicted is where it becomes more difficult. |
Dove into the API now, and unfortunately it seems like the cache doesn't have direct access to the request/context and thus can't manipulate the I guess this library would have to include a custom Apollo link that interacts with the cache for it to be possible? |
Feature request extracted from #39 (comment).
As I was looking into adopting this plugin I assumed that data which had been invalidated (but not yet garbage collected/evicted from the cache) would still be accessible to apollo client (but marked as stale), behaving similarly as
fetchPolicy: 'cache-and-network'
. This is currently not the case however - invalidated data seems to be completely inaccessible to apollo.If the above was possible it would enable using apollo-cache-policies together with apollo3-cache-persist to display stale data while re-fetching in the background (if/when online).
The text was updated successfully, but these errors were encountered: