As far as I can tell, client.Query()
behaves like useSuspenseQuery()
, respecting errorPolicy
and throwing if the policy is None
, and returning the error otherwise. I did not see this documented
Ah ya what you’re seeing here is the difference in our “core” API and the “React” API.
client.query() is UI framework agnostic, and because it returns a promise which you need to await yourself, rejecting on errors here make sense. Totally agree with you though that our documentation could be better in this regard. The closest thing we have to spelling this out is the
client.query() API doc, which states:
This resolves a single query according to the options specified and returns a Promise which is either resolved with the resulting data or rejected with an error.
This is hard to find though. At some point in the future, we’d like to revamp our docs to provide more documentation on our core API first, while moving some of the React bits later. Our docs make it seem like Apollo Client is a React library since it provides the basis of most of the client behavior through the React API, but this isn’t quite accurate as the core API provides pretty rich behavior on its own.
We’ll do our best to see if we can find some stop-gap solutions for now until we get our docs revamp, and this is definitely one of them. Sorry for the confusion here!
I am also a bit confused about the errors
fields in ApolloQueryResult`; consider if there’s sufficient docs about them.
To be honest, I’m not entirely sure of the history here and why this design choice was made. I believe
errors is a shortcut to
error.graphqlErrors, but its not entirely obvious to me why we can’t just ask our users to access this via the
This is actually why
useSuspenseQuery only exposes
error (when you have the right
errorPolicy set), to try and avoid this confusion. I’d love to see if we can remove the
errors distinction and make this a little nicer in a future version, but we’ll need to do this in a major version as this would be a breaking change.
It seems to me that error responses are cached (at least for “resolver errors”; not sure about network errors)
Could you describe to me what you mean by “resolver errors” here?
Errors should not be cached at all by the client, so if you’re seeing this, there must be a bug somewhere. What version of Apollo Client are you using?