Intended outcome:
Refetch errors should not lead to Unhandled Promise Rejection. See #1449 where it was fixed for startQuery.
Actual outcome:
Refetch without network connection leads to Unhandled Promise Rejection
How to reproduce the issue:
Turn off network connection. Trigger refetch with any query.
Versions
apollo-cache-inmemory: 1.2.4 => 1.2.4
apollo-client: 2.3.4 => 2.3.4
apollo-link: 1.2.2 => 1.2.2
apollo-link-context: 1.0.8 => 1.0.8
apollo-link-error: 1.1.0 => 1.1.0
apollo-link-http: 1.5.4 => 1.5.4
apollo-link-state: 0.4.1 => 0.4.1
react-apollo: 2.1.5 => 2.1.5
I'm hitting this as well.
Same issue! The following can throw an unhandled exception if the refetchQueries request fails:
try {
await this.props.someMutation({
variables: {
data: "some data",
},
refetchQueries: ["otherApi"],
});
} catch (error) {
// handle error
}
Whereas this code can handle exceptions from either:
try {
await this.props.someMutation({
variables: {
data: "some data",
},
});
await this.props.otherApi.refetch();
} catch (error) {
// handle error
}
Presumably, this is because the refetchQueries will just fire these queries asynchronously to not block your original calling code (imagine a single mutation which refetches three other queries, waiting for all the queries to refetch will take longer than just running the mutation).
This makes sense and is reasonable (if this is what is in fact happening), however, the result is the inability to handle exceptions if the refetchQueries block fails.
What happened to this issue? There was a fix but I'm still hitting it and this issue left open...
I am still experiencing similar errors, with useQuery() and refetch()
tsx
const { data, refetch, error } = useQuery(QUERY);
return (
<FlatList
data={data?.items|| []}
onRefresh={() => refetch()}
// ...
/>
);
Refreshing, thrown an unhandled exception.
A workaround for now is to catch it:
tsx
return (
<FlatList
data={data?.items|| []}
onRefresh={() => { refetch().catch(() => undefined); }}
// ...
/>
);
For Mutations with refetchQueries and awaitRefetchQueries enabled, we can have promise error handling passed on to the onError function if they add a simple .catch(err => reject(err)) after Promise.all call.
Yeah its a pretty big use case for us to have refetchQueries and have awaitRefetchQueries enabled in our project, but we cannot do this at the moment because of this unhandled promise rejection bug.
Would be great to get a fix in for this as it means we can then use that feature.
I'm facing the same issue trying to use refetchQueriesand awaitRefetchQueries: true
Most helpful comment
I'm facing the same issue trying to use
refetchQueriesandawaitRefetchQueries: true