I'm using Hot Chocolate as a GraphQL server. All my models inherit one base class that contains a property that does not have a public setter:
public class BaseModel
{
...
public DateTime LastModified { get; private set; }
}
These models are used as output and as input objects. For my input objects I get the following exception:
No compatible constructor found for input type type
SomeModel. Either you have to provide a public constructor with settable properties or a public constructor that allows to pass in values for read-only properties. There was no way to set the following properties: LastModified.
I could add [GraphQLIgnore], but this will also ignore the property for my output object types.
I tried registering a type for my base class to ignore the property only for all of my input object types:
public class BaseModelInputType : InputObjectType<BaseModel>
{
protected override void Configure(IInputObjectTypeDescriptor<BaseModel> descriptor)
{
descriptor.Ignore(x => x.LastModified);
}
}
And in the startup:
services.AddGraphQLServer()
.AddType<BaseModelInputType>()
.AddQueryType<Query>()
.AddMutationType<Mutation>()
But this only seem to work on the concrete classes.