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

Exceptions thrown in type converters are not surfaced #7404

Open
cmeeren opened this issue Aug 23, 2024 · 0 comments
Open

Exceptions thrown in type converters are not surfaced #7404

cmeeren opened this issue Aug 23, 2024 · 0 comments
Labels
🐛 bug Something isn't working 🌶️ hot chocolate

Comments

@cmeeren
Copy link
Contributor

cmeeren commented Aug 23, 2024

Product

Hot Chocolate

Version

14.0.0-rc.0

Link to minimal reproduction

See zip below

Steps to reproduce

Repro solution: HotChocolateBugRepro.zip

Code for quick reference:

var builder = WebApplication.CreateBuilder(args);
builder.Services
    .AddGraphQLServer()
    .AddQueryType<Query>()
    .AddTypeConverter<string, UserId>(UserId.Parse)
    .AddTypeConverter<UserId, string>(id => id.Value.ToString())
    .BindRuntimeType<UserId, StringType>();
var app = builder.Build();
app.MapGraphQL();
app.Run();

public record UserId(int Value)
{
    public static UserId Parse(string id)
    {
        if (Int32.TryParse(id, out int result))
        {
            return new UserId(result);
        }

        throw new SerializationException("User ID must be an integer", new StringType());
    }
}

public class Query
{
    public string Test(UserId arg) => "";
}

Run this query:

query {
  test(arg: "invalid")
}

What is expected?

An error containing the message User ID must be an integer. Furthermore, the error, being targeted to clients, should not in any way reference the type name UserId (which is an internal Server implementation detail and not part of the schema).

What is actually happening?

The following error, which:

  • does not use my supplied error message
  • references the internal type name in both message and extensions.requestedType
  • is generally clearly oriented to server implementors
{
  "errors": [
    {
      "message": "Unable to convert the value of the argument `arg` to `UserId`. Check if the requested type is correct or register a custom type converter.",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "test"
      ],
      "extensions": {
        "fieldName": "test",
        "argumentName": "arg",
        "requestedType": "UserId"
      }
    }
  ],
  "data": {
    "test": null
  }
}

Relevant log output

No response

Additional context

No response

@cmeeren cmeeren added the 🐛 bug Something isn't working label Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working 🌶️ hot chocolate
Projects
None yet
Development

No branches or pull requests

1 participant