DEV Community

Discussion on: Handling errors in GraphQL

Collapse
 
prestongarno profile image
Preston

Coincidentally I was reading through that exact part of the spec on errors yesterday and found a few neat things:

  • There is only one requirement for the relationship between data and errors return value: if the query is null/empty there must be an error message

  • The spec recommends that implementations provide a char index in the query in the error message where the error occurred. I don't think all servers I've tried follow this, but the major ones do IME

Overall, the GraphQl spec doesn't enforce a whole lot with the response format - it doesn't even need to be JSON!

I do like that the rules needed to have reliable interaction are pretty rigorously defined but it leaves room for extension of the protocol.