Skip to content

Commit

Permalink
fix: when there is an error the query returns with the previous data …
Browse files Browse the repository at this point in the history
…instead of empty data (#100)
  • Loading branch information
madflanderz authored and trojanowski committed Mar 25, 2019
1 parent e07828b commit 583da31
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,17 @@ export function useQuery<
() => {
const result = observableQuery.currentResult();

// return the old result data when there is an error
let data = result.data as TData;
if (result.error || result.errors) {
data = {
...result.data,
...(observableQuery.getLastResult() || {}).data,
};
}

return {
data: result.data as TData,
data,
error:
result.errors && result.errors.length > 0
? new ApolloError({ graphQLErrors: result.errors })
Expand Down

0 comments on commit 583da31

Please sign in to comment.