I have a CustomerDetails class:
public record CustomerDetails{
public string? Code { get; init; }
public string? Name { get; init; }
public string? Notes { get; init; }
}
On GraphQL side I have the following:
On queries side:
public class CustomerDetailsGraphType : AutoRegisteringObjectGraphType<CustomerDetails> { }
On mutations side:
public class CustomerDetailsInputGraphType : AutoRegisteringInputObjectGraphType<CustomerDetails> {}
When I run this and try to see the schema into Altair it gives me an error of type:
"message": "GraphQL.Execution.UnhandledError: Error executing document.\r\n ---> System.InvalidOperationException: Unable to register GraphType 'MyProject.Customers.Mutations.ContactDetailsInputGraphType' with the name 'ContactDetails';\nthe name 'ContactDetails' is already registered to 'MyProject.Customers.Query.ContactDetailsGraphType'.\r\n..."
I don't understand why is that happening?
I found the solution. In both cases, the name of the graph type object will be automatically CustomerDetails. This is not right for the GrapQL schema and cannot be generated. So either in the query or in the mutation you have to specify explicitly a different name in the constructor like this:
public class CustomerDetailsGraphType : AutoRegisteringObjectGraphType<CustomerDetails>
{
public CustomerDetailsGraphType()
{
Name = "CustomerDetailsGraphType"; // or any other name you consider
}
}