kowainik / github-graphql

🕸️ GraphQL bindings to GitHub API
https://kowainik.github.io/projects/github-graphql
Mozilla Public License 2.0
7 stars 0 forks source link

Improve error-reporting mechanism #38

Closed chshersh closed 3 years ago

chshersh commented 3 years ago

Currently, when something is wrong, it's hard to understand why. I propose to add a custom data type and return it as an error.

The data type will contain:

When you provide an invalid query like this:

query {
  repository(owner: "kowainik", "github-graphql") {
    issue(number: 5) {
      bodies
    }
  }
}

GitHub API returns the following message:

{
  "errors": [
    {
      "message": "Parse error on \"github-graphql\" (STRING) at [2, 33]",
      "locations": [
        {
          "line": 2,
          "column": 33
        }
      ]
    }
  ]
}

Ideally, this shouldn't happen in users' code (because we provide type-safe API), but this still can happen due to errors in our library, so it's good to provide more info here.