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

Commit

Permalink
Conditionally use AC's ObservableQuery.resetQueryStoreErrors (#3151)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
hwillson authored Jun 22, 2019
1 parent 771406a commit 32423cd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
9 changes: 8 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Change log

## vNext
## 2.5.8 (2019-06-21)

### Bug Fixes

- Makes the use of `apollo-client` 2.6.3's `ObservableQuery.resetQueryStoreErrors`
method optional, for people who can't update to `react-apollo`'s new
`apollo-client` peer dep of 2.6.3. <br/>
[@hwillson](https://github.com/hwillson) in [#3151](https://github.com/apollographql/react-apollo/pull/3151)

## 2.5.7 (2019-06-21)

Expand Down
21 changes: 20 additions & 1 deletion src/Query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,27 @@ export default class Query<TData = any, TVariables = OperationVariables> extends
// remove those errors from the `ObservableQuery` query store, so they
// aren't re-displayed on subsequent (potentially error free)
// requests/responses.
//
// NOTE: Resetting query store errors is handled in 2 different ways here,
// since the `resetQueryStoreErrors` wasn't available until
// `apollo-client` 2.6.3. If a previous version of `apollo-client` is
// being used, errors are reset by reaching into `ObservableQuery`'s
// internals. This hack is temporary, as React Apollo 3 will be
// released shortly, and will enforce `apollo-client` 2.6.3 as the
// minimum.
setTimeout(() => {
this.queryObservable!.resetQueryStoreErrors();
if ((this.queryObservable! as any).resetQueryStoreErrors) {
// Apollo Client >= 2.6.3
(this.queryObservable! as any).resetQueryStoreErrors();
} else {
// Apollo Client < 2.6.3
const { queryManager, queryId } = (this.queryObservable! as any);
const queryStore = queryManager.queryStore.get(queryId);
if (queryStore) {
queryStore.networkError = null;
queryStore.graphQLErrors = [];
}
}
});

result.client = this.client;
Expand Down

0 comments on commit 32423cd

Please sign in to comment.