Skip to content
This repository was archived by the owner on Apr 13, 2023. It is now read-only.
This repository was 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

@TLadd

Description

@TLadd

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 yet

How 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueIssues that are suitable for first-time contributors.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions