only increment lastRequestId when using links to get results #7956
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fetchQueryByPolicy
currently always incrementsqueryInfo.lastRequestId
, even when a new request is not necessary and results are instead read directly from cache.An example way to trigger this bug:
Then, try deleting an item. You’ll notice in the network tab the mutation fires successfully and so does the refetch query with the correct results of one less bid item. However, the Apollo cache doesn’t update so 4 items will remain. Subsequent deletes / adds work just fine.
The cache is not updating because we are updating
fetchPolicy
manually from our useQuery invocation, which triggersfetchQueryByPolicy
, but the result ends up just reading from cache. However, since it also updates thelastRequestid
, the conditions to write the result to cache are no longer satisfied:lastRequestId
is not greater thanqueryInfo.lastRequestId
, so the cache does not get updated after refetch: https://github.com/apollographql/apollo-client/blob/main/src/core/QueryManager.ts#L869