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

errors do not conform to the GraphQL specification #221

Open
oliverpool opened this issue Oct 3, 2024 · 1 comment
Open

errors do not conform to the GraphQL specification #221

oliverpool opened this issue Oct 3, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@oliverpool
Copy link

Describe the bug

According to the end of 7.1.2 Errors, non-standard fields should be put under extensions in case of error.

Currently when returning an error, this extension behaves like the counter example and sets code, fields, short_message and vars directly:

{
  "data": null,
  "errors": [
    {
      "code": "forbidden",
      "fields": [],
      "locations": [{ "column": 3, "line": 2 }],
      "message": "forbidden",
      "path": ["some_path"],
      "short_message": "forbidden",
      "vars": {}
    }
  ]
}

To Reproduce
Setup a GraphQL server and perform a request which triggers an authentication failure.

Expected behavior
The non-standard fields should be put under an extensions key:

{
  "data": null,
  "errors": [
    {
      "locations": [{ "column": 3, "line": 2 }],
      "message": "forbidden",
      "path": ["some_path"],
      "extensions": {
        "code": "forbidden",
        "fields": [],
        "short_message": "forbidden",
        "vars": {}
      }
    }
  ]
}

To not break backward compatibility while providing support for spec-compliant clients, the fields could be duplicated in the meantime:

{
  "data": null,
  "errors": [
    {
      "locations": [{ "column": 3, "line": 2 }],
      "message": "forbidden",
      "path": ["some_path"],

      "code": "forbidden",
      "fields": [],
      "short_message": "forbidden",
      "vars": {}
      "extensions": {
        "code": "forbidden",
        "fields": [],
        "short_message": "forbidden",
        "vars": {}
      }
    }
  ]
}

Additional context
I am querying the GraphQL server with a Go client which discards non-standard keys not put under extensions: https://pkg.go.dev/github.com/vektah/gqlparser/[email protected]/gqlerror#Error

@oliverpool oliverpool added the bug Something isn't working label Oct 3, 2024
@oliverpool oliverpool changed the title errors do not confirm to the GraphQL specification errors do not conform to the GraphQL specification Oct 3, 2024
@zachdaniel
Copy link
Contributor

Thanks for the report! There is no harm in adding it to both places. I won't have time to do this in the near future, but PRs welcome 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Someday
Development

No branches or pull requests

2 participants