Skip to content

Commit

Permalink
Added missing condition to TypeRegistry#Register (#8058)
Browse files Browse the repository at this point in the history
  • Loading branch information
glen-84 authored Feb 21, 2025
1 parent c212945 commit 88e76b4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<QueryTypeWithCustomLocalDate>()
.Create();

Assert.Equal(
"The name `LocalDate` was already registered by another type.",
Assert.Throws<SchemaException>(Act).Errors[0].Message);
}

public class QueryWithDateTime
{
public DateTimeOffset DateTimeOffset(DateTimeOffset time) => time;
Expand Down Expand Up @@ -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();
}
}

0 comments on commit 88e76b4

Please sign in to comment.