graphql / graphql/graphql-spec

Discussion: Generic error codes in the spec

Open
#698 33 comments 14 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
14.6k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

**Abstract**
I am researching and planning to build a generic test suite to check the compliance of the various GraphQL libraries The [project idea](https://github.com/graphql/foundation/tree/master/mentorship/2020/gsoc#1-graphql-compatibility-acceptance-tests-medium) is given by the GraphQL Foundation for the `Google Summer of Code 2020`. There are various implementations of GraphQL and all of them are throwing error in various ways.
As all errors are thrown in plain text(string). There is no way to test these implementations for such errors.

Say we have given an incorrect query (with circular fragment) to a GraphQL server and we are expecting an error. If the error comes with a specific **error code** then it would be great to test the libraries and provides and assuring the actual cause of the error, therefore, improving the DX as well.

```
For example imagine a well known error place that can hold a "spec rule number" that is indicative of what validation rule you have caused an error message to fail on

errors : [ { message : "any old message", extensions : [ __graphqlspec : { reason : "March2018-5.1.2.4" }}}}
```
Follow this discussion -> https://github.com/graphql-java/graphql-java/issues/1826#issuecomment-601550014

**Motivation**
I am really impressed by the standardisation of the error codes in the following projects.
- React error codes -> https://github.com/facebook/react/blob/master/scripts/error-codes/codes.json
- Rust lang -> https://doc.rust-lang.org/error-index.html
- TypeScript -> https://github.com/microsoft/TypeScript/blob/master/src/compiler/diagnosticMessages.json

**What can be done**
It would be great if we can come up with such standard error codes in the GraphQL spec.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.