Show beautiful GraphQL error messages
See original GitHub issueGraphQL returns great error messages:
GraphQLError: [{"message":"Resource not accessible by integration","type":"FORBIDDEN","path":["resource","author","hovercard"],"locations":[{"line":11,"column":15}]}]
We should take advantage of that and make them B-E-A-utiful!
There was an error in your GraphQL Query:
on line 11, column 15:
... on User {
hovercard {
^-- FORBIDDEN: Resource not accessible by integration
We need to get a full spec on what all the GraphQL errors will include, but here’s some thoughts:
- If
locations
is included, then show the original query with a pointer to exactly where the error occurred - Colorize the output so the error message is in red, and the context is in gray/white
- If there are multiple errors, do this for all of them
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Full Stack Error Handling with GraphQL and Apollo
Having well-defined error codes in your error responses lays the groundwork to make GraphQL errors more actionable and universal. The benefits ...
Read more >Handling GraphQL errors like a champ with unions and ...
Error handling can be frustrating in GraphQL. This post shows you how to use unions and interfaces to handle errors in a more...
Read more >A Guide to GraphQL Errors
We love GraphQL for it's type system. The errors key of a GraphQL response, commonly called "Top-Level" errors, don't have such schema. They...
Read more >The Definitive Guide to Handling GraphQL Errors | by Matt Krick
There are a plethora of errors that a client can encounter when querying a GraphQL Server. Whether it's a query, mutation, or subscription,...
Read more >200 OK! Error Handling in GraphQL - Sasha Solomon - Medium
You get an error. And you'll find it in the errors array . Canonically, this is where errors can be found in a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As discussed in Slack
And also looking back at the spec that was linked above:
So per the spec, errors can still be present even when partial data is returned. On the client side (Apollo, Relay), they recommend looking at error types and only presenting ones in the UI that make sense to display to the user. I think it would make sense here to just use
log.error
for any error messages instead of throwing.Testing this locally, I get
GitHub request: POST /graphql - 200 OK
for all responses, including queries that return no data and all errors, and ones that return partial data and some errors. This means we can never intentionally throw, since some data can still be returned even though other resources are blocked.Example:
Pushing the errors up into the client could be accomplished by only returning
res.data
(instead ofres.data.data
), then doing something like this:It doesn’t feel that awesome, but since the errors have types that need to be handled based on the needs of the app, I think we have to push the errors up into the client.
the graphql error messages are much more useful now that we use
@octokit/graphql
. I made a follow up issue for the format Brandon suggested above: https://github.com/octokit/graphql.js/issues/239