From 32423cd6ed6d1612f9669b88a41ae78cde749cf8 Mon Sep 17 00:00:00 2001 From: Hugh Willson Date: Fri, 21 Jun 2019 21:03:40 -0400 Subject: [PATCH] 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 --- Changelog.md | 9 ++++++++- src/Query.tsx | 21 ++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Changelog.md b/Changelog.md index 70471afd44..8332aba3e2 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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.
+ [@hwillson](https://github.com/hwillson) in [#3151](https://github.com/apollographql/react-apollo/pull/3151) ## 2.5.7 (2019-06-21) diff --git a/src/Query.tsx b/src/Query.tsx index 7574b1a784..c1a41c3418 100644 --- a/src/Query.tsx +++ b/src/Query.tsx @@ -488,8 +488,27 @@ export default class Query 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;