Skip to content

Instantly share code, notes, and snippets.

@shobhitchittora
Last active April 11, 2020 23:24
Show Gist options
  • Select an option

  • Save shobhitchittora/15e934ea4e1331c837ba106215ecf2b5 to your computer and use it in GitHub Desktop.

Select an option

Save shobhitchittora/15e934ea4e1331c837ba106215ecf2b5 to your computer and use it in GitHub Desktop.
[RFC] Standard Error Codes

This RFC is an attempt to identify and standardize error codes for GraphQL errors. This has bee previously discussed, and some great work and ideas came out of it. Follow the previous discussion here - #698

Why standard error codes ?

Errors ( error codes ) are the silent guardians in the programming world. Though no one wants them in their code, they actually teach us a lot and mold our thinking process. This is especially true for statically typed compiled languages like c, rust etc, where the compiler

Proposal

This proposal puts forward the intent to add code key to the standard errors spec in GraphQL. A sample implementation for the same is attached along with a sample output -

"errors": [ { "message": "Query root type must be provided.", "code": "GQ0001" } ]

Sample code to achieve this - https://github.com/shobhitchittora/graphql-js/commit/4fdfa74cbfbbcc01c2316a49ec1b6f1c94987e7c

The idea here is to have a listing of error messages and codes for the below phases of the runtime - Parse, Validate and Execute.

Current status quo in other runtimes / frameworks

Some reference in the open where errors have status codes associated for better understanding and traceability.

@shobhitchittora
Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment