-
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
Read from cache again in ObservableQuery#getCurrentResult. #5791
Conversation
dff41e1
to
868aaf4
Compare
This partially reverts two commits from PR #5565, preserving related improvements that have happened in the meantime: * Revert "Remove partial field from ApolloCurrentQueryResult type." This reverts commit ca2cef6. * Revert "Stop reading from cache in ObservableQuery#getCurrentResult." This reverts commit 01376a3. One of the motivations behind the original changes was to lay the foundations for eventually supporting asynchronous (Promise-based) cache reads, but that form of asynchrony is no longer a goal of Apollo Client 3.0 or any planned future version, so there's not as much benefit to weakening getCurrentResult in this way. On the other hand, allowing getCurrentResult to read synchronously from the cache ensures that custom field read functions can return new results immediately, which helps with issues like #5782. Immediate cache reads have also been the behavior of Apollo Client for much longer than #5565, which makes this change appealing from an ease-of-upgrading perspective.
868aaf4
to
ecfb48f
Compare
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.
Looks great @benjamn - thanks!
@benjamn I re-ran the tests to get them to pass; we have a timing issue buried in one of our polling tests, which I've made a note of and will address separately. |
I was just about to file a bug report. This PR fixes the issue, but wanted to document it here in case you had been unaware of this specific problem. Using values in the cache as default arguments to queries (via the https://github.com/jkonowitch/react-apollo-error-template/tree/export-error I set up a repro with the error template. I slighly extended the "server" schema so that the I then added The following query did not return a result, whereas it should return the people entities, sorted correctly. const ALL_PEOPLE = gql`
query AllPeople($orderBy: SortOrder!) {
activeSortOrder @client @export(as: "orderBy")
people(orderBy: $orderBy) {
id
name
}
}
`; This works as expected with |
This partially reverts two commits from PR #5565, preserving related improvements that have happened in the meantime:
ApolloCurrentQueryResult
type."This reverts commit ca2cef6.
ObservableQuery#getCurrentResult
."This reverts commit 01376a3.
One of the motivations behind the original changes was to lay the foundations for eventually supporting asynchronous (specifically,
Promise
-based) cache reads, but that form of asynchrony is no longer a goal of Apollo Client 3.0 or any planned future version (there will be other ways to deliver results asynchronously, without requiring every cache read to return aPromise
), so there's not as much benefit to weakeninggetCurrentResult
in this way.On the other hand, allowing
getCurrentResult
to read synchronously from the cache ensures that custom fieldread
functions can return new results immediately, which helps with issues like #5782.Immediate cache reads have also been the behavior of Apollo Client for much longer than #5565, which makes this change appealing from an ease-of-upgrading perspective.