apollographql / apollo-link-state

✨ Manage your application's state with Apollo!
MIT License
1.4k stars 100 forks source link

Right way to handle ApolloErrors #96

Closed jbaxleyiii closed 7 years ago

jbaxleyiii commented 7 years ago

Hi, I have one pretty simple, but important question about error handling in react-apollo.

My problem is: I execute my query in GraphiQL and get an error in response, but also I have some data, that can be queried without error.

untitled

So I want to show to user this successfully queried data and show an error in section with error data, but in Apollo-connected component I can get only errors block, without successfully queried data

You can reproduced it like this:

{
  empireHero: hero(episode: 'works fine with this argument') {
    name
  }
  jediHero: hero(episode: 'failed with this argument') {
    name
  }
}

All you query will be 'invalid', instead of getting error and data sections, you will get only error section. Probably I trying to make something wrong? Can you try help me with this problem?

Version

jbaxleyiii commented 7 years ago

➤ Peggy Rayzis commented:

Hi @EugeneDraitsev! react-apollo's default policy is to treat any GraphQL errors as runtime errors and to discard the data. To customize this policy, learn more here.

jbaxleyiii commented 7 years ago

➤ Eugene Draitsev commented:

Hi @peggyrayzis, thanks for quick response. I tried to set my options like

{ variables: { appLang, tenant, manufacturers }, errorPolicy: 'all', // Also tried all other values }But I still can't see any data, when query has errors (and doublechecked that I get data in GraphiQL)

When I get error in my callQueue and still can't see successfully fetched contentInfo data: untitled

When I don't have any errors: https://user-images.githubusercontent.com/21238050/32392259-f31ab4d0-c0e5-11e7-82b1-dba7b9eca418.png

Probably I still missed something, or I should override errorPolicy by another way?