Skip to content

Allow defining a Relay [NodeResolver] in a [ObjectType<T>] #8225

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

Open
PHILLIPS71 opened this issue Apr 3, 2025 · 0 comments
Open

Allow defining a Relay [NodeResolver] in a [ObjectType<T>] #8225

PHILLIPS71 opened this issue Apr 3, 2025 · 0 comments
Assignees
Milestone

Comments

@PHILLIPS71
Copy link
Contributor

PHILLIPS71 commented Apr 3, 2025

Product

Hot Chocolate

Is your feature request related to a problem?

In v15.0.3, I was able to define all relay node resolvers within my object types, which seemed to work fine and kept type configurations centralized.

After upgrading to v15.1.3, this approach now results in a schema exception: There is no object type implementing interface 'Node'. (HotChocolate.Types.Relay.NodeType)

The solution you'd like

It would be great if this were supported, allowing node resolvers to be inferred within object type definitions. For example, here is an object type I was using in v15.0.3 that didn't raise any schema exceptions:

[ObjectType<User>]
public static partial class UserType
{
    static partial void Configure(IObjectTypeDescriptor<User> descriptor)
    {
        descriptor
            .Field(f => f.Id)
            .ID();

        // ...
    }

    [NodeResolver]
    internal static Task<User?> GetUserByIdAsync(
        Guid id,
        QueryContext<User> query,
        IUserByIdDataLoader dataloader,
        CancellationToken cancellation)
    {
        return dataloader.With(query).LoadAsync(id, cancellation);
    }

    [DataLoader]
    internal static Task<Dictionary<Guid, User>> GetUserByIdAsync(
        IReadOnlyList<Guid> keys,
        QueryContext<User> query,
        ApplicationDbContext database,
        CancellationToken cancellation = default)
    {
        return database
            .Users
            .AsNoTracking()
            .Where(x => keys.Contains(x.Id))
            .With(query)
            .ToDictionaryAsync(x => x.Id, cancellation);
    }
}

This was also discussed in this slack discussion, which might provide additional context.

@michaelstaib michaelstaib added this to the HC-15.1.4 milestone Apr 3, 2025
@michaelstaib michaelstaib self-assigned this Apr 3, 2025
@glen-84 glen-84 changed the title allow defining a Relay [NodeResolver] in a [ObjectType<T>] Allow defining a Relay [NodeResolver] in a [ObjectType<T>] Apr 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants