samdenty / gqless

a GraphQL client without queries
https://gqless.com
3.66k stars 54 forks source link

How to handle the error coming from the graphql server? #231

Closed nemonemi closed 3 years ago

nemonemi commented 3 years ago

I am accessing a resource by ID which doesn't exist. A reasonable use case. However, I am not sure how to handle this. In the onError callback of the useQuery I'm getting this message: Error: GraphQL Errors, please check .graphQLErrors property

I'd like to get feedback that the access to data with this ID is invalid so that I could toggle my form between creation and updating, for example.

nemonemi commented 3 years ago

@samdenty, I have also experienced this behavior when performing a mutation. I have tested the graphql endpoint, and it resolves the update request without any errors.

What could be the cause for the gqless to complain?

It is kind of hard with this type of message and no documentation that covers it.

PabloSzx commented 3 years ago

As the error mentions, when there is more than a single error in a query there is no perfect solution to show them all, that is why when that happens you have to access the ".graphQLErrors" to get the list of errors

onError(error) {
  console.error(error.graphQLErrors);
 for (cont err of error.graphQLErrors) {
   // err is every error 
 }
}