Closed
Description
openedon Jun 27, 2023
Is there an existing issue for this?
- I have searched the existing issues
Product
Hot Chocolate
Describe the bug
Applying the GraphQLNameAttribute
does not work on generic types since it is applied directly without considering the generic part of the type, see example.
Steps to reproduce
[GraphQLName("Bar")] // Note
public class Foo<T>
{
public T Test { get; init; }
}
public class Query
{
// Should be BarOfInt32, but is Bar
public Foo<int> MyIntBar => default!;
// Should be BarOfString, but is Bar (ambiguity -> exception)
public Foo<string> MyStringBar => default!;
}
Relevant log output
HotChocolate.SchemaException: For more details look at the `Errors` property.
1. The name `Bar___` was already registered by another type. (HotChocolate.Types.ObjectType<gqltest.Foo<System.String>>)
at HotChocolate.Configuration.TypeRegistry.Register(String typeName, RegisteredType registeredType)
at HotChocolate.Configuration.TypeInitializer.CompleteTypeName(RegisteredType registeredType)
at HotChocolate.Configuration.TypeInitializer.<CompleteNames>b__23_0(RegisteredType type)
at HotChocolate.Configuration.TypeInitializer.ProcessTypes(TypeDependencyFulfilled fulfilled, Func`2 action)
at HotChocolate.Configuration.TypeInitializer.CompleteNames()
at HotChocolate.Configuration.TypeInitializer.Initialize()
at HotChocolate.SchemaBuilder.Setup.InitializeTypes(SchemaBuilder builder, IDescriptorContext context, IReadOnlyList`1 types)
at HotChocolate.SchemaBuilder.Setup.Create(SchemaBuilder builder, LazySchema lazySchema, IDescriptorContext context)
at HotChocolate.SchemaBuilder.Create(IDescriptorContext context)
at HotChocolate.SchemaBuilder.HotChocolate.ISchemaBuilder.Create(IDescriptorContext context)
Additional Context?
If this is going to be fixed I think it is required to adjust the method
public static string GetGraphQLName(this Type type) to consider gerneric types even if a GraphQLNameAttribute
is present.
Version
13.02.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment