ChilliCream / ChilliCream/graphql-platform

Only one error should be returned per field

Open
#7,074 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

🌶️ hot chocolate Area: Type System
Dominant language
C#
Stars
5.8k
Forks
810
Avg merge
15h 39m
Merged PRs (30d)
98

Description

Product

Hot Chocolate

Version

14.0.0-p.93

Link to minimal reproduction

See below

Steps to reproduce

Repro solution: HotChocolateBugRepro.zip

Code for reference:

var builder = WebApplication.CreateBuilder(args);

builder
    .Services
    .AddGraphQLServer()
    .AddQueryType<Query>();

var app = builder.Build();

app.MapGraphQL();
app.Run();

public class Query
{
    public string Test() =>
        throw new AggregateException(
            new GraphQLException("Test1"),
            new GraphQLException("Test2")
        );
}
What is expected?
{
  "errors": [
    {
      "message": "Test1",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "test"
      ]
    },
  ],
  "data": null
}
What is actually happening?
{
  "errors": [
    {
      "message": "Test1",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "test"
      ]
    },
    {
      "message": "Test2",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "test"
      ]
    }
  ],
  "data": null
}
Relevant log output

No response

Additional context

If you now go "what?!", then I agree.

The GraphQL spec's section "Handling Field Errors" seems absolutely clear:

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.

(Emphasis mine.)

I am surprised by this. I think it is useful to be able to return multiple errors per field, for example if a field has multiple arguments and more than one of them are determined (during execution) to be invalid. I am unsure why the spec says this is not allowed. But I can't find any ambiguity here.

I'm OK with this being closed as "wontfix". That, however, puts the responsibility of following the spec on users, which I don't like.

Assuming this will not be fixed, I would very much like the opinions of more experienced GraphQL devs on whether breaking this part of the spec is OK or even the right thing to do.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the attached HotChocolateBugRepro.zip and the C# resolver shown in the issue, then trace Hot Chocolate's field-error handling for AggregateException and multiple GraphQLException instances. Compare the response with the cited GraphQL specification; done means the behavior is resolved or explicitly documented with a regression test covering one field producing multiple errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.