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

refactored execFieldSelection to return multiple errors on the same path if err instance of interface { Unwrap() []error } #625

Closed
wants to merge 1 commit into from

Conversation

savaki
Copy link
Contributor

@savaki savaki commented Oct 16, 2023

I opened this discussion, but thou, but thought it might be useful to provide the code change being proposed. This allows joined errors to be returned as:

{
  "errors": [
    {
      "message": "You cannot do this because of X.",
      "path": [
        "field"
      ],
      "extensions": {
        "code": "failed_x"
      }
    },
    {
      "message": "You cannot do this because of Y.",
      "path": [
        "field"
      ],
      "extensions": {
        "code": "failed_y"
      }
    },
    {
      "message": "You cannot do this because of Z.",
      "path": [
        "field"
      ],
      "extensions": {
        "code": "failed_z"
      }
    }
  ],
  "data": {
    "field": null
  }
}

rather than being using extensions and a more nested:

{
  "errors": [
    {
      "message": "failed_x: You cannot do this because of X., failed_y: You cannot do this because of Y., failed_z: You cannot do this because of Z.",
      "path": [
        "field"
      ],
      "extensions": {
        "details": [
          {
            "code": "failed_x",
            "message": "You cannot do this because of X."
          },
          {
            "code": "failed_y",
            "message": "You cannot do this because of Y."
          },
          {
            "code": "failed_z",
            "message": "You cannot do this because of Z."
          }
        ]
      }
    }
  ],
  "data": {
    "field": null
  }
}

…ath if err instance of `interface { Unwrap() []error }`
@pavelnikolov
Copy link
Member

pavelnikolov commented Oct 17, 2023

This is against the GraphQL spec, which clearly states:

If the field returns null because of a field error which has already been added to the "errors" list in the response, the "errors" list must not be further affected. That is, only one error should be added to the errors list per field.

https://spec.graphql.org/October2021/#sel-EANRNDLAACNAn7V

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