diff --git a/src/HotChocolate/Core/src/Types/Configuration/TypeRegistry.cs b/src/HotChocolate/Core/src/Types/Configuration/TypeRegistry.cs index da331219c81..18a49690f39 100644 --- a/src/HotChocolate/Core/src/Types/Configuration/TypeRegistry.cs +++ b/src/HotChocolate/Core/src/Types/Configuration/TypeRegistry.cs @@ -162,7 +162,8 @@ public void Register(RegisteredType registeredType) _nameRefs.Add(typeDef.Name, registeredType.References[0]); } else if (registeredType.Kind == TypeKind.Scalar && - registeredType.Type is ScalarType scalar) + registeredType.Type is ScalarType scalar && + !_nameRefs.ContainsKey(scalar.Name)) { _nameRefs.Add(scalar.Name, registeredType.References[0]); } diff --git a/src/HotChocolate/Core/test/Types.Tests/Configuration/TypeDiscoveryTests.cs b/src/HotChocolate/Core/test/Types.Tests/Configuration/TypeDiscoveryTests.cs index c919d211bc2..f68975bb8ab 100644 --- a/src/HotChocolate/Core/test/Types.Tests/Configuration/TypeDiscoveryTests.cs +++ b/src/HotChocolate/Core/test/Types.Tests/Configuration/TypeDiscoveryTests.cs @@ -54,6 +54,19 @@ public void InferInputTypeWithComputedProperty() .MatchSnapshot(); } + [Fact] + public void Custom_LocalDate_Should_Throw_SchemaException_When_Not_Bound() + { + static void Act() => + SchemaBuilder.New() + .AddQueryType() + .Create(); + + Assert.Equal( + "The name `LocalDate` was already registered by another type.", + Assert.Throws(Act).Errors[0].Message); + } + public class QueryWithDateTime { public DateTimeOffset DateTimeOffset(DateTimeOffset time) => time; @@ -153,4 +166,14 @@ public class QueryTypeWithComputedProperty { public int Foo(InputTypeWithReadOnlyProperties arg) => arg.Property1; } + + public class QueryTypeWithCustomLocalDate + { + public LocalDate Foo() => new(); + } + + public class LocalDate + { + public DateOnly Date { get; set; } = new(); + } }