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

Source Generator cannot deal with [BindField] #7786

Open
PascalSenn opened this issue Nov 30, 2024 · 0 comments
Open

Source Generator cannot deal with [BindField] #7786

PascalSenn opened this issue Nov 30, 2024 · 0 comments
Assignees
Milestone

Comments

@PascalSenn
Copy link
Member

PascalSenn commented Nov 30, 2024

Product

Hot Chocolate

Version

14.1.0

Link to minimal reproduction

.

Steps to reproduce

[ObjectType<LineItem>]
public static partial class LineItemType
{
    [BindField("product")]
    public static Product GetProduct([Parent] LineItem lineItem)
        => new(lineItem.ProductId);
}

generates:

public static partial class LineItemType
{
    internal static void Initialize(global::HotChocolate.Types.IObjectTypeDescriptor<global::quick_start.Ordering.Types.LineItem> descriptor)
    {
        const global::System.Reflection.BindingFlags bindingFlags =
            global::System.Reflection.BindingFlags.Public
                | global::System.Reflection.BindingFlags.NonPublic
                | global::System.Reflection.BindingFlags.Static;

        var thisType = typeof(global::quick_start.Ordering.Types.LineItemType);
        var bindingResolver = descriptor.Extend().Context.ParameterBindingResolver;
        global::quick_start.Ordering.Types.LineItemTypeResolvers.InitializeBindings(bindingResolver);

        descriptor
            .Field(thisType.GetMember("GetProduct", bindingFlags)[0])
            .ExtendWith(c =>
            {
                c.Definition.SetSourceGeneratorFlags();
                c.Definition.Resolvers = global::quick_start.Ordering.Types.LineItemTypeResolvers.LineItemType_GetProduct();
            });

        descriptor // <---- HERE IS THE ISSUE

        Configure(descriptor);
    }

    static partial void Configure(global::HotChocolate.Types.IObjectTypeDescriptor<global::quick_start.Ordering.Types.LineItem> descriptor);
}
}

Workaround:

public static partial class LineItemType
{
    static partial void Configure(IObjectTypeDescriptor<LineItem> descriptor)
    {
        descriptor.Ignore(x => x.ProductId);
    }

    public static Product GetProduct([Parent] LineItem lineItem)
        => new(lineItem.ProductId);
}

What is expected?

The code is generated correctly

What is actually happening?

There is a compilation errros

Relevant log output

Additional context

No response

@michaelstaib michaelstaib changed the title Source Generator cannot deal with [BindMember] Source Generator cannot deal with [BindFIeld] Dec 2, 2024
@michaelstaib michaelstaib added this to the HC-14.3.0 milestone Dec 3, 2024
@michaelstaib michaelstaib self-assigned this Dec 3, 2024
@michaelstaib michaelstaib modified the milestones: HC-14.3.0, HC-14.4.0 Dec 16, 2024
@glen-84 glen-84 changed the title Source Generator cannot deal with [BindFIeld] Source Generator cannot deal with [BindField] Dec 17, 2024
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