I’m building GraphQL API with C# and HotChocolate. The library adds "Input" suffix to type names which used as input arguments. I want to get rid of this behavior. And no, we’re not going to discuss why do I want this, and why it is a good practice (even if you really want to, please don’t).
Documentation: https://chillicream.com/docs/hotchocolate/v13/defining-a-schema/input-object-types
Note: If a class is used as an argument to a resolver and it does not end in Input, Hot Chocolate (by default) will append Input to the type name in the resulting schema.
And nothing about how to turn this default behavior off (of course).
I’ve tried an attribute GraphQLName:
[GraphQLName("ProductFilter")]
public record ProductFilter
{
...
}
Nope, didn’t help. It utilizes GraphQLName, yes, but also adds "Input" in the end.
Next, I tried to implement my own naming convention. Pretty straightforward: treat input objects as regular objects, and the rest of types – in a default way:
public class NoInputNamingConvention : DefaultNamingConventions
{
public override string GetTypeName(Type type, TypeKind kind)
{
if (kind == TypeKind.InputObject)
{
return base.GetTypeName(type, TypeKind.Object);
}
else
{
return base.GetTypeName(type, kind);
}
}
}
And it almost worked out, but now I have the following error:
The name `MailingAddress` was already registered by another type.
In my API MailingAddress is used as both input object and regular object (a property of some class). So, looks like the library treats them as two different types, and that’s why we see the error above.
Any other ideas to try? Thanks in advance.