-
Notifications
You must be signed in to change notification settings - Fork 11
feat: add "network-only" cacheability option #568
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
Conversation
Codecov Report
@@ Coverage Diff @@
## main #568 +/- ##
=======================================
Coverage 85.39% 85.39%
=======================================
Files 765 765
Lines 15712 15712
Branches 1996 1996
=======================================
Hits 13418 13418
Misses 2261 2261
Partials 33 33
Continue to review full report at Codecov.
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
NotCacheable = 'no-cache', // Values used by apollo | ||
Cacheable = 'cache-first' | ||
Cacheable = 'cache-first', | ||
NetworkOnly = 'network-only' |
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.
What does it do?
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.
NotCacheable means it doesn't read or write to the cache, this would be it always reads but will write back. I'd suggest changing the name though to something like RefreshCache
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.
Done.
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.
So it would return previous cached value immediately and later update that value once gql calls complete?
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.
other way around. Instead of reading from the cache, it makes a regular network call. Unlike no-cache
, the result of that call is written back to the cache when returned. To the caller, the two look the same - to the next caller, the cache has the latest value.
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.
It's basically the "force refresh" case. Sometimes, we might mutate something and want to force a refetch and ignore the cache, but later queries can read again from the cache. We should never use this at the handler level (because if we use it every time, it's the same as no-cache).
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.
got it. But the mutation query already does it ootb right? I think Apollo supports this. The requirement is that the mutation should return a valid object with id and all of the mutated properties in it. Apollo would find the relevant object in cache and add mutated properties there. This may require some caching rules to be configured but I think i tried this with a poc.
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.
unfortunately a lot of our mutations are not returning the item they're mutating, or are weird things like single primitive flags etc.
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.
yeah. this is the reason I have that weird change in my other pr. May be on the graphql service side, we can define a standard expectations from these mutations
?
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.
Really depends on the API though - some of the mutation apis are really just setting a single field of another object (or of multiple other objects) so I think it's going to be hard to do anything too standard here.
…i into add-network-only
Description
Add "network-only" cacheability option
Testing
NA
Checklist: