graphql-platform icon indicating copy to clipboard operation
graphql-platform copied to clipboard

NodeResolver can't handle parameter names other than `id`

Open tobias-tengler opened this issue 3 years ago • 0 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Describe the bug

When creating a node resolver you might want to use something like userId as the parameter name of the node resolver, i.e.

[Node]
[ExtendObjectType(typeof(User))]
public class UserNode
{
    [NodeResolver]
    public User GetUserAsync(int userId)
    {
        // ...
    }
}

Currently this will fail with the following error, if you issue a query with node(id: "..."):

There was no argument with the name userId found on the field node.

I think we should either:

  1. Just inject the Id value in the first field, if it has the correct type
  2. We leave it like is, document that it has to be called id and improve the error message to point to the issue

Steps to reproduce

  1. Create a simple model + type extension
public class Model
{
    public long Id { get; set; } = 123;
}

[Node]
[ExtendObjectType(typeof(Model))]
public class ModelNode
{
    [NodeResolver]
    public Model GetModelAsync(long serial)
    {
        // ...
    }
}
  1. Issue a query like the following
{
  node(id: "TW9kZWwKbDEyMw==") {
    id
  }
}
  1. You receive the following error:

There was no argument with the name serial found on the field node.

Relevant log output

No response

Additional Context?

No response

Product

Hot Chocolate

Version

12.4.0-preview.14

tobias-tengler avatar Dec 04 '21 11:12 tobias-tengler