useQuery - data and error not updating with refetch

I have a query like this,

const { data, error, refetch } = useQuery<{ me }>(QUERY, { fetchPolicy: "network-only", nextFetchPolicy: "network-only" })

When I call refetch and the API returns an error, both data and error don’t update. error is null, and data holds the values from the last successful fetch. But the promise returned from refetch rejects with the error. Is that the intended behavior? If so, how do I get data to clear when the api returns an error?

The refetch will return a promise, just await it and parse the resolved promise like:

const {data} = refetch();

More here:Refetching queries in Apollo Client - Apollo GraphQL Docs

1 Like