graphql-compose / graphql-compose-mongoose

Mongoose model converter to GraphQL types with resolvers for graphql-compose https://github.com/nodkz/graphql-compose
MIT License
709 stars 94 forks source link

Correct error handling in mutations #399

Closed zhulduz closed 2 years ago

zhulduz commented 2 years ago

Hi! Guys, anyone can explain me how I can catch correct errors in mutations?

I noticed that some request can return 200 status, but inside the response has error field with some problem (like Validation Error). I'm a little doubtful how I can catch such errors? no no how I can parse such response, if every mutation has own projection.

mutation SomeAction(...) {
  someAction(...) {
    ...
    error {
      message
      __typename
    }
  }
}

// using
try {
   const response = await someMutation()
   * // Here response could contain error inside `someAction`: response.someAction.error
} catch (err) {
  // catch error with 400 status, for example
}

maybe I miss something...

zhulduz commented 2 years ago

I know that we can use optional field disableErrorField just to return to standard error flow. But is it possible to apply that flag for every mutation in one place?

Thanks in advance)

zhulduz commented 2 years ago

I found issue here https://github.com/nodkz/conf-talks/tree/master/articles/graphql/errors