diff --git a/src/react/hooks/useQuery.ts b/src/react/hooks/useQuery.ts index 40e7bcedc19..30cf93c2540 100644 --- a/src/react/hooks/useQuery.ts +++ b/src/react/hooks/useQuery.ts @@ -222,6 +222,7 @@ export function useQuery< Object.assign(obsQuery, { lastError, lastResult }); if (!error.hasOwnProperty('graphQLErrors')) { + // The error is not a graphQL error throw error; } @@ -230,12 +231,13 @@ export function useQuery< (previousResult && previousResult.loading) || !equal(error, previousResult.error) ) { - setResult({ + prevRef.current.result = { data: previousResult.data, error: error as ApolloError, loading: false, networkStatus: NetworkStatus.error, - }); + }; + setResult(prevRef.current.result); } } @@ -331,6 +333,12 @@ export function useQuery< }; } + // TODO: Is this still necessary? + // Any query errors that exist are now available in `result`, so we'll + // remove the original errors from the `ObservableQuery` query store to + // make sure they aren't re-displayed on subsequent (potentially error + // free) requests/responses. + obsQuery.resetQueryStoreErrors() return { ...obsQueryFields, variables: obsQuery.variables,