apollographql / apollo-client

:rocket:  A fully-featured, production ready caching GraphQL client for every UI framework and GraphQL server.
https://apollographql.com/client
MIT License
19.36k stars 2.66k forks source link

useLazyQuery does not populate "error" field if errorPolicy is "all" #12097

Open gbettencourt opened 2 days ago

gbettencourt commented 2 days ago

Issue Description

QueryResult.errors was recently deprecated in https://github.com/apollographql/apollo-client/pull/11954, with message "Please use error.graphQLErrors instead." But this field is not consistently populated. If a graph resolver throws, the errors property is always set, but error appears to be only populated if errorPolicy is "none".

Link to Reproduction

https://codesandbox.io/p/devbox/snowy-sky-ypkmvp?workspaceId=125b734b-01fa-4547-907b-915bf55739e9

Reproduction Steps

Click on "Load All People" in linked sandbox. Observe that console log of the result has an undefined error field, but populated errors. Change errorPolicy to "none". Now both will be populated.

@apollo/client version

3.11.4

jerelmiller commented 2 days ago

Thanks for the report @gbettencourt!

I can't promise we can look at this until after next week as the team will be gone to a conference, but we will try to take a look sometime after. Thanks for bringing this to our attention!