Skip to content
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

fix: Allow fetchMore() to be used with 'no-cache' fetchPolicy #6023

Closed
wants to merge 2 commits into from

Conversation

mogelbrod
Copy link

Happy to add test(s) if someone could verify that I've provided a valid fix for the issue.

This PR is basically a continuation of #5239 (comment)

Fixes #5239

Checklist:

  • If this PR is a new feature, please reference an issue where a consensus about the design was reached (not necessary for small changes)
  • Make sure all of the significant new logic is covered by tests

@apollo-cla
Copy link

@mogelbrod: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

@@ -310,7 +311,7 @@ export class ObservableQuery<
...fetchMoreOptions.variables,
},
}),
fetchPolicy: 'network-only',
fetchPolicy: fetchPolicy === 'no-cache' ? 'no-cache' : 'network-only',
Copy link
Author

Choose a reason for hiding this comment

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

WIthout this markQueryResult appears to write to the cache:

private markQueryResult(
queryId: string,
result: ExecutionResult,
{
fetchPolicy,
variables,
errorPolicy,
}: WatchQueryOptions,
fetchMoreForQueryId?: string,
) {
if (fetchPolicy === 'no-cache') {
this.setQuery(queryId, () => ({
newData: { result: result.data, complete: true },
}));
} else {

@@ -331,7 +332,7 @@ export class ObservableQuery<
fetchMoreResult: data,
variables: combinedOptions.variables as TVariables,
}) : data;
});
}, fetchPolicy === 'no-cache');
Copy link
Author

Choose a reason for hiding this comment

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

This argument might be better off as an object?

@@ -1339,7 +1339,7 @@ export class QueryManager<TStore> {
);
}

private setQuery<T extends keyof QueryInfo>(
public setQuery<T extends keyof QueryInfo>(
Copy link
Author

Choose a reason for hiding this comment

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

Required for access from ObservableQuery.updateQuery

@codecov
Copy link

codecov bot commented Mar 5, 2020

Codecov Report

Merging #6023 into master will decrease coverage by 0.04%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6023      +/-   ##
==========================================
- Coverage   95.20%   95.16%   -0.05%     
==========================================
  Files          88       88              
  Lines        3674     3679       +5     
  Branches      873      906      +33     
==========================================
+ Hits         3498     3501       +3     
- Misses        154      155       +1     
- Partials       22       23       +1     

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 e9be4be...29acd01. Read the comment docs.

@mogelbrod mogelbrod changed the title Allow fetchMore() to be used with 'no-cache' fetchPolicy fix: Allow fetchMore() to be used with 'no-cache' fetchPolicy Mar 6, 2020
@mikedizon
Copy link

Waiting for this!

@mogelbrod
Copy link
Author

Would love to get this into the v3.0 release, just waiting for someone knowledgeable (@hwillson perhaps?) of the code base to give some feedback on the approach I used before writing the tests for it.

@mirague
Copy link

mirague commented Jun 17, 2020

Would love to hear from the team on this!

@korengrip
Copy link

korengrip commented Mar 14, 2021

@mogelbrod any news?
Really need this feature.

@mogelbrod
Copy link
Author

@mogelbrod any news?
Really need this feature.

We haven't started our migration to Apollo yet, so I haven't been able to check if this merged v3 PR solved this issue. Hopefully it did though.

@korengrip
Copy link

@mogelbrod any news?
Really need this feature.

We haven't started our migration to Apollo yet, so I haven't been able to check if this merged v3 PR solved this issue. Hopefully it did though.

It seems like it didn't solve the issue.

@jpvajda jpvajda added 🏓 awaiting-contributor-response requires input from a contributor 🏓 awaiting-team-response requires input from the apollo team and removed 🏓 awaiting-contributor-response requires input from a contributor labels May 3, 2022
@hwillson
Copy link
Member

Thanks for this @mogelbrod and sorry for the delay. This work was superseded by the work in #6221, which set the fetchMore fetchPolicy default to no-cache (see the description in that PR for the reasoning):

// The fetchMore request goes immediately to the network and does
// not automatically write its result to the cache (hence no-cache
// instead of network-only), because we allow the caller of
// fetchMore to provide an updateQuery callback that determines how
// the data gets written to the cache.
fetchPolicy: "no-cache",

Thanks!

@hwillson hwillson closed this Aug 10, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🏓 awaiting-team-response requires input from the apollo team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Results of updateQuery ignored for fetchPolicy: no-cache
7 participants