Skip to content

Dataloader Code generation doesn't handle nullable reference types in tuples #8470

@williamdenton

Description

@williamdenton

Product

Green Donut

Version

15 (and 14)

Link to minimal reproduction

https://github.com/williamdenton/hotchocolate-tuple-bug

Steps to reproduce

public record Id1();
public record Id2();
public record Stuff();

public class Dataloaders
{
    [DataLoader]
    public static async Task<ILookup<(Id1, Id2?), Stuff>> GetStuff(
        IReadOnlyList<(Id1, Id2?)> keys,
        CancellationToken cancellationToken)
    {
        await Task.CompletedTask;
        return null!;
    }
}

generates

    public interface IStuffDataLoader
        : global::GreenDonut.IDataLoader<(global::Blah.Id1, global::Blah.Id2), global::Blah.Stuff[]>
    {
    }

What is expected?

Item2 (Id2) is nullable in the tuple, and so it should be in the IDataLoader signature too. Code generation does not compile in this scenario.

    public interface IStuffDataLoader
-       : global::GreenDonut.IDataLoader<(global::Blah.Id1, global::Blah.Id2), global::Blah.Stuff[]>
+       : global::GreenDonut.IDataLoader<(global::Blah.Id1, global::Blah.Id2?), global::Blah.Stuff[]>
    {
    }

Argument of type 'System.Collections.Generic.IReadOnlyList<(Blah.Id1, Blah.Id2)>' cannot be used for parameter 'keys' of type 'System.Collections.Generic.IReadOnlyList<(Blah.Id1, Blah.Id2?)>' in 'Blah.GetStuff' because of differences in the nullability of reference types

What is actually happening?

The nullable reference type in the tuple is not carried through to the generated code and so it does not compile when it tries to call the data loader from the wrapper FetchAsync

Relevant log output

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions