Skip to content

Commit d1c0a6f

Browse files
glen-84michaelstaib
authored andcommitted
Added missing condition to TypeRegistry#Register (#8058)
1 parent 0475635 commit d1c0a6f

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/HotChocolate/Core/src/Types/Configuration/TypeRegistry.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ public void Register(RegisteredType registeredType)
162162
_nameRefs.Add(typeDef.Name, registeredType.References[0]);
163163
}
164164
else if (registeredType.Kind == TypeKind.Scalar &&
165-
registeredType.Type is ScalarType scalar)
165+
registeredType.Type is ScalarType scalar &&
166+
!_nameRefs.ContainsKey(scalar.Name))
166167
{
167168
_nameRefs.Add(scalar.Name, registeredType.References[0]);
168169
}

src/HotChocolate/Core/test/Types.Tests/Configuration/TypeDiscoveryTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ public void InferInputTypeWithComputedProperty()
5454
.MatchSnapshot();
5555
}
5656

57+
[Fact]
58+
public void Custom_LocalDate_Should_Throw_SchemaException_When_Not_Bound()
59+
{
60+
static void Act() =>
61+
SchemaBuilder.New()
62+
.AddQueryType<QueryTypeWithCustomLocalDate>()
63+
.Create();
64+
65+
Assert.Equal(
66+
"The name `LocalDate` was already registered by another type.",
67+
Assert.Throws<SchemaException>(Act).Errors[0].Message);
68+
}
69+
5770
public class QueryWithDateTime
5871
{
5972
public DateTimeOffset DateTimeOffset(DateTimeOffset time) => time;
@@ -153,4 +166,14 @@ public class QueryTypeWithComputedProperty
153166
{
154167
public int Foo(InputTypeWithReadOnlyProperties arg) => arg.Property1;
155168
}
169+
170+
public class QueryTypeWithCustomLocalDate
171+
{
172+
public LocalDate Foo() => new();
173+
}
174+
175+
public class LocalDate
176+
{
177+
public DateOnly Date { get; set; } = new();
178+
}
156179
}

0 commit comments

Comments
 (0)