diff --git a/src/Core/Types.Tests/CodeFirstTests.cs b/src/Core/Types.Tests/CodeFirstTests.cs index e79afee400d..47ba6c6ecd5 100644 --- a/src/Core/Types.Tests/CodeFirstTests.cs +++ b/src/Core/Types.Tests/CodeFirstTests.cs @@ -34,6 +34,34 @@ public void Type_Is_Correctly_Upgraded() .MatchSnapshot(); } + [Fact] + public void Change_DefaultBinding_For_DateTime() + { + SchemaBuilder.New() + .AddQueryType() + .BindClrType() + .Create() + .ToString() + .MatchSnapshot(); + } + + [Fact] + public void Remove_ClrType_Bindings_That_Are_Not_Used() + { + // arrange + // act + ISchema schema = SchemaBuilder.New() + .AddQueryType() + .BindClrType() + .BindClrType() + .ModifyOptions(o => o.RemoveUnreachableTypes = true) + .Create(); + + // assert + bool exists = schema.TryGetType("Url", out INamedType _); + Assert.False(exists); + } + public class Query { public string SayHello(string name) => @@ -72,5 +100,33 @@ public class Dog : IPet public string? Name => throw new NotImplementedException(); } + + public class QueryWithDateTimeType : ObjectType + { + protected override void Configure(IObjectTypeDescriptor descriptor) + { + descriptor.Field(t => t.GetModel()).Type(); + } + } + + public class QueryWithDateTime + { + public ModelWithDateTime GetModel() => new ModelWithDateTime(); + } + + public class ModelWithDateTimeType : ObjectType + { + protected override void Configure(IObjectTypeDescriptor descriptor) + { + descriptor.Field(t => t.Foo).Type(); + } + } + + public class ModelWithDateTime + { + public DateTime Foo { get; set; } + + public DateTime Bar { get; set; } + } } } diff --git a/src/Core/Types.Tests/__snapshots__/CodeFirstTests.Change_DefaultBinding_For_DateTime.snap b/src/Core/Types.Tests/__snapshots__/CodeFirstTests.Change_DefaultBinding_For_DateTime.snap new file mode 100644 index 00000000000..c94ce6132d1 --- /dev/null +++ b/src/Core/Types.Tests/__snapshots__/CodeFirstTests.Change_DefaultBinding_For_DateTime.snap @@ -0,0 +1,18 @@ +schema { + query: QueryWithDateTime +} + +type ModelWithDateTime { + bar: DateTime! + foo: Date +} + +type QueryWithDateTime { + model: ModelWithDateTime +} + +"The `Date` scalar represents an ISO-8601 compliant date type." +scalar Date + +"The `DateTime` scalar represents an ISO-8601 compliant date time type." +scalar DateTime diff --git a/src/Core/Types/Configuration/ClrTypeReferenceHandler.cs b/src/Core/Types/Configuration/ClrTypeReferenceHandler.cs index 6ac18d097a9..b594f1970a7 100644 --- a/src/Core/Types/Configuration/ClrTypeReferenceHandler.cs +++ b/src/Core/Types/Configuration/ClrTypeReferenceHandler.cs @@ -1,6 +1,6 @@ -using System.Linq; using System; using System.Collections.Generic; +using System.Linq; using HotChocolate.Types; using HotChocolate.Types.Descriptors; using HotChocolate.Utilities; diff --git a/src/Core/Types/Configuration/TypeDiscoverer.cs b/src/Core/Types/Configuration/TypeDiscoverer.cs index 4cc2c062c8f..29b22e87bf4 100644 --- a/src/Core/Types/Configuration/TypeDiscoverer.cs +++ b/src/Core/Types/Configuration/TypeDiscoverer.cs @@ -29,6 +29,7 @@ public TypeDiscoverer( { _unregistered.AddRange(IntrospectionTypes.All); _unregistered.AddRange(Directives.All); + _unregistered.AddRange(clrTypeReferences.Values); _unregistered.AddRange(initialTypes); _clrTypeReferences = clrTypeReferences;