Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

react-apollo 2.0: data.error prop is undefined after server returns an error #1320

Closed
nbudin opened this issue Nov 3, 2017 · 5 comments
Closed

Comments

@nbudin
Copy link

nbudin commented Nov 3, 2017

Intended outcome:
I've got a React component that uses logic like this when rendering:

    const { data } = this.props;

    if (data.loading) {
      return <LoadingIndicator />;
    }
    if (data.error) {
      return <div className="alert alert-danger">{data.error.message}</div>;
    }

    // render some stuff

I recently wrote an invalid GraphQL query against my schema (the server is a Rails app running graphql-ruby). It returned this error response with a HTTP 200 status:

{"errors":[{"message":"Field 'team_members' doesn't exist on type 'Event'","locations":[{"line":3,"column":5}],"fields":["query","event","team_members"]}]}

I expected to see the alert div containing this message.

Actual outcome:
I didn't see the alert div. Instead, the component attempted to render (and failed, naturally, since the data it expected wasn't present).

Looking at this with a JavaScript debugger, I saw a couple of interesting things:

How to reproduce the issue:

https://nbudin.github.io/react-apollo-error-template/master/
https://github.com/nbudin/react-apollo-error-template

Version

@peggyrayzis
Copy link
Contributor

Hi @nbudin, thanks for writing up this detailed bug report! I'm looking into the issue now. Seems to also be related to #1206.

@jbaxleyiii
Copy link
Contributor

@nbudin this will be fixed via apollographql/apollo-client#2491! Thanks for the report!

@jbaxleyiii
Copy link
Contributor

Fixed with apollo-client2.0.2!

@nbudin
Copy link
Author

nbudin commented Nov 6, 2017

Thanks for the super-quick turnaround! 🎉

@adamdonahue
Copy link

Any chance this addresses #1314 as well?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants