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
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hwillson committed Jun 22, 2019
1 parent 771406a commit d73ec05
Showing 1 changed file with 20 additions and 1 deletion.
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 d73ec05

Please sign in to comment.