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.

Revisions

  1. shobhitchittora revised this gist Apr 11, 2020. 1 changed file with 8 additions and 4 deletions.
    12 changes: 8 additions & 4 deletions rfc-gql-error.md
    Original file line number Diff line number Diff line change
    @@ -3,8 +3,10 @@ This RFC is an attempt to identify and standardize error codes for GraphQL error
    ## 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 scolds and guides the programmer to fix the program's syntax. A few strong argument for having a standard set of error codes for GraphQL can be -

    1. A well documented set of errors would help developers get a better understanding of the underlying spec. Potential suggestions to fix these errors would help developer productivity.
    2. As the spec matures, this would force holistic system thinking and help catch outliers and potential issues. A good amount of effort is being put into creating comparability test suite for the GraphQL spec.
    1. A well documented set of errors would help developers get a better understanding of the issues and errors during development.
    2. Potential suggestions to fix these errors would help developer productivity too.
    3. As the spec matures, this would force holistic system thinking and help catch outliers and potential issues. A good amount of effort is being put into creating comparability test suite for the GraphQL spec. This would supplement this effort too.
    4. Further fine grained detailed can be encoded into the error codes, which would help the community and other implementations. Things like error severity, warning, etc, can be encoded in the error codes too.


    ## Proposal
    @@ -16,8 +18,6 @@ This proposal puts forward the intent to add `code` key to the standard errors s

    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`.

    A mapping of all the identified and important errors codes would be kept in a config ( possibly a js module of json file ) like -

    ```js
    @@ -29,6 +29,10 @@ const MESSAGE_DETAILS = {
    }
    ```

    A very simple implementation would list codes in sequence, with numeric incremented codes( like `GQ0009`, `GQ0010`, and so on ). Further fine grained details like, error severity, type of error and mapping to parts of spec can encoded too.

    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.

  2. shobhitchittora revised this gist Apr 11, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion rfc-gql-error.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    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
    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](https://github.com/graphql/graphql-spec/issues/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 scolds and guides the programmer to fix the program's syntax. A few strong argument for having a standard set of error codes for GraphQL can be -
  3. shobhitchittora revised this gist Apr 11, 2020. 1 changed file with 15 additions and 1 deletion.
    16 changes: 15 additions & 1 deletion rfc-gql-error.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,10 @@
    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
    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 scolds and guides the programmer to fix the program's syntax. A few strong argument for having a standard set of error codes for GraphQL can be -

    1. A well documented set of errors would help developers get a better understanding of the underlying spec. Potential suggestions to fix these errors would help developer productivity.
    2. As the spec matures, this would force holistic system thinking and help catch outliers and potential issues. A good amount of effort is being put into creating comparability test suite for the GraphQL spec.


    ## Proposal
    @@ -15,6 +18,17 @@ Sample code to achieve this - https://github.com/shobhitchittora/graphql-js/comm

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

    A mapping of all the identified and important errors codes would be kept in a config ( possibly a js module of json file ) like -

    ```js
    const MESSAGE_DETAILS = {
    'Query root type must be provided.': {
    code: 'GQ0001'
    },
    ...
    }
    ```

    ## Current status quo in other runtimes / frameworks
    Some reference in the open where errors have status codes associated for better understanding and traceability.

  4. shobhitchittora created this gist Apr 11, 2020.
    24 changes: 24 additions & 0 deletions rfc-gql-error.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    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 -

    ```js
    "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.

    - 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