ChilliCream / graphql-platform

Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
https://chillicream.com
MIT License
5.28k stars 748 forks source link

NonNullType for attribute generated object types #7805

Closed josepvg closed 13 hours ago

josepvg commented 13 hours ago

Product

Hot Chocolate

Version

14

Link to minimal reproduction

Exaple in steps to reproduce

Steps to reproduce

If i define a class like this: [ObjectType] public static partial class AppointmentNode {

then i can not use it in a NonNullType like this descriptor.Field(f => f.TAppointments) .Name("appointments") .Description("The appointments for this resource") .Type<NonNullType<ListType<NonNullType< AppointmentNode >>>>() // Explicitly define the type .UseFiltering();

I had to use the old public class AppointmentNode : ObjectType {

What is expected?

defining the class using the objecttype attribute should work the same

What is actually happening?

Compile type error since AppointmentNode is not of type IType

Relevant log output

Additional context

No response

michaelstaib commented 13 hours ago
[ObjectType]
public static partial class AppointmentNode

Is not valid in any case. The source generator API you are referring to only exists when you specify the generic [ObjectType<Appointment>] in which case you can refer in the fluent api to it like the following: NonNullType<ListType<NonNullType<ObjectType<AppointmentNode>>>>>

the ObjectTypeAttribute that is non generic is for if you have an instance type like

[ObjectType]
public class Appointment
{
    public int Id { get; set: }
}

in which case you refer to it in the same way as shown above.