Skip to content

Commit 583da31

Browse files
madflanderztrojanowski
authored andcommitted
fix: when there is an error the query returns with the previous data instead of empty data (#100)
1 parent e07828b commit 583da31

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/useQuery.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,17 @@ export function useQuery<
135135
() => {
136136
const result = observableQuery.currentResult();
137137

138+
// return the old result data when there is an error
139+
let data = result.data as TData;
140+
if (result.error || result.errors) {
141+
data = {
142+
...result.data,
143+
...(observableQuery.getLastResult() || {}).data,
144+
};
145+
}
146+
138147
return {
139-
data: result.data as TData,
148+
data,
140149
error:
141150
result.errors && result.errors.length > 0
142151
? new ApolloError({ graphQLErrors: result.errors })

0 commit comments

Comments
 (0)