Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add codes to GraphQL errors #167

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

patch0
Copy link
Contributor

@patch0 patch0 commented Mar 29, 2023

This uses a GraphQL extension to provide a symbolic code when returning errors. This is documented in both GraphQL Ruby and in Apollo Server.

So for example, if you request a project you're not permitted to view, you'll now get:

{
  "data": {
    "project": null
  },
  "errors": [
    {
      "message": "An object of type Project was hidden due to permissions",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "project"
      ],
      "extensions": {
        "code": "FORBIDDEN"
      }
    }
  ]
}

Passing errors in this way allows deterministic handling of errors in the React app, as well as things like translations to be used in places where we'd maybe have relied on the message text sent back by the API.

What's changed

  • Added EditorApiError class, which generates classes for various common error states, setting extensions => code with the appropriate code.
  • Replaced most GraphQL::ExecutionErrors with these new error classes.
  • For mutations, added an extra check to ready? to turn down requests for users
  • Refactored the tests to be a bit more consistent on handling the no-op situation

@raspberrypiherokubot raspberrypiherokubot temporarily deployed to editor-api-p-use-graphq-d7izt1 March 29, 2023 11:40 Inactive
@raspberrypiherokubot raspberrypiherokubot temporarily deployed to editor-api-p-use-graphq-kjkxcd March 29, 2023 11:45 Inactive
@raspberrypiherokubot raspberrypiherokubot temporarily deployed to editor-api-p-use-graphq-d7izt1 March 29, 2023 11:45 Inactive
@raspberrypiherokubot raspberrypiherokubot temporarily deployed to editor-api-p-use-graphq-siied9 March 29, 2023 11:50 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants