Skip to content

Commit

Permalink
fix previousResult not updating on error
Browse files Browse the repository at this point in the history
  • Loading branch information
brainkim committed Aug 5, 2021
1 parent 51a2909 commit 1c1226a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/react/hooks/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 1c1226a

Please sign in to comment.