Skip to content

Conversation

arjunlalb
Copy link
Contributor

Description

Add "network-only" cacheability option

Testing

NA

Checklist:

  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been merged and published in downstream modules

@arjunlalb arjunlalb requested a review from a team as a code owner February 5, 2021 17:03
@codecov
Copy link

codecov bot commented Feb 5, 2021

Codecov Report

Merging #568 (4924a27) into main (59a2446) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           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           
Impacted Files Coverage Δ
projects/graphql-client/src/graphql-config.ts 100.00% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 59a2446...4924a27. Read the comment docs.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

NotCacheable = 'no-cache', // Values used by apollo
Cacheable = 'cache-first'
Cacheable = 'cache-first',
NetworkOnly = 'network-only'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does it do?

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

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).

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor

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.

@github-actions

This comment has been minimized.

@arjunlalb arjunlalb merged commit ef9b95e into main Feb 5, 2021
@arjunlalb arjunlalb deleted the add-network-only branch February 5, 2021 17:38
@github-actions
Copy link

github-actions bot commented Feb 5, 2021

Unit Test Results

    4 files  ±0  234 suites  ±0   13m 33s ⏱️ - 1m 31s
835 tests ±0  835 ✔️ ±0  0 💤 ±0  0 ❌ ±0 
839 runs  ±0  839 ✔️ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit ef9b95e. ± Comparison against base commit 59a2446.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants