Skip to content
This repository was archived by the owner on Apr 13, 2023. It is now read-only.

Commit 32423cd

Browse files
authored
Conditionally use AC's ObservableQuery.resetQueryStoreErrors (#3151)
* Conditionally use AC's `ObservableQuery.resetQueryStoreErrors` To fix issue #3090, the `ObservableQuery.resetQueryStoreErrors` method was introduced in `apollo-client` 2.6.3. While `apollo-client` 2.6.3 is a peer dep of the latest version of `react-apollo` (2.5.7), people who can't update their version of `apollo-client` to >= 2.6.3 are running into issues when updating to the latest version of `react-apollo`, since `ObservableQuery.resetQueryStoreErrors` isn't available to them. Since we can't enforce the version of `apollo-client` people are using, this commit adjusts the `Query` component to only use `resetQueryStoreErrors` if it's available. If it isn't, it will call into the `ObservableQuery`'s private API to do the same things as `resetQueryStoreErrors`. This is a hack, but it is temporary as `react-apollo` is launching soon, and will enforce a minimum `apollo-client` version of 2.6.3 (so this workaround won't be needed). Fixes #3148. * Changelog update
1 parent 771406a commit 32423cd

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

Changelog.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Change log
22

3-
## vNext
3+
## 2.5.8 (2019-06-21)
4+
5+
### Bug Fixes
6+
7+
- Makes the use of `apollo-client` 2.6.3's `ObservableQuery.resetQueryStoreErrors`
8+
method optional, for people who can't update to `react-apollo`'s new
9+
`apollo-client` peer dep of 2.6.3. <br/>
10+
[@hwillson](https://github.com/hwillson) in [#3151](https://github.com/apollographql/react-apollo/pull/3151)
411

512
## 2.5.7 (2019-06-21)
613

src/Query.tsx

+20-1
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,27 @@ export default class Query<TData = any, TVariables = OperationVariables> extends
488488
// remove those errors from the `ObservableQuery` query store, so they
489489
// aren't re-displayed on subsequent (potentially error free)
490490
// requests/responses.
491+
//
492+
// NOTE: Resetting query store errors is handled in 2 different ways here,
493+
// since the `resetQueryStoreErrors` wasn't available until
494+
// `apollo-client` 2.6.3. If a previous version of `apollo-client` is
495+
// being used, errors are reset by reaching into `ObservableQuery`'s
496+
// internals. This hack is temporary, as React Apollo 3 will be
497+
// released shortly, and will enforce `apollo-client` 2.6.3 as the
498+
// minimum.
491499
setTimeout(() => {
492-
this.queryObservable!.resetQueryStoreErrors();
500+
if ((this.queryObservable! as any).resetQueryStoreErrors) {
501+
// Apollo Client >= 2.6.3
502+
(this.queryObservable! as any).resetQueryStoreErrors();
503+
} else {
504+
// Apollo Client < 2.6.3
505+
const { queryManager, queryId } = (this.queryObservable! as any);
506+
const queryStore = queryManager.queryStore.get(queryId);
507+
if (queryStore) {
508+
queryStore.networkError = null;
509+
queryStore.graphQLErrors = [];
510+
}
511+
}
493512
});
494513

495514
result.client = this.client;

0 commit comments

Comments
 (0)