-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Conversation
@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', |
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.
WIthout this markQueryResult
appears to write to the cache:
apollo-client/src/core/QueryManager.ts
Lines 505 to 519 in e9be4be
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'); |
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.
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>( |
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.
Required for access from ObservableQuery.updateQuery
Codecov Report
@@ 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.
|
Waiting for this! |
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. |
Would love to hear from the team on this! |
@mogelbrod any news? |
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. |
Thanks for this @mogelbrod and sorry for the delay. This work was superseded by the work in #6221, which set the apollo-client/src/core/ObservableQuery.ts Lines 413 to 418 in 7041fe7
Thanks! |
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: