Skip to content

NodeResolver can't handle parameter names other than id #4522

@tobias-tengler

Description

@tobias-tengler

Is there an existing issue for this?

  • 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

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions