This repository has been archived by the owner on Apr 13, 2023. It is now read-only.
If initial Query errors, data is undefined instead of empty object #1977
Labels
good first issue
Issues that are suitable for first-time contributors.
Intended outcome:
The data prop passed to the Query component is never undefined. That's my understanding anyways, from reading https://github.com/apollographql/react-apollo/blob/master/src/Query.tsx#L89
Actual outcome:
If your first request for a Query errors, data ends up being null. It ends up hitting this line, https://github.com/apollographql/react-apollo/blob/master/src/Query.tsx#L378, which overwrites the default-created empty object and replaces it with
(this.queryObservable!.getLastResult() || {}).data,
, which will be undefined if the query doesn't have a result yetHow to reproduce the issue:
On any react-apollo application with a Query, force an error to occur and log the data passed to children. I personally encountered this when I had accidentally not had my graphql server running. As a result, the first Query request failed due to a network error, and I got an exception because I was assuming data would be an empty object and not undefined.
Version
The text was updated successfully, but these errors were encountered: