diff --git a/src/HotChocolate/Core/src/Types/Types/Descriptors/Conventions/DescriptorContext.cs b/src/HotChocolate/Core/src/Types/Types/Descriptors/Conventions/DescriptorContext.cs index a4eaa83a427..8cb7f493d17 100644 --- a/src/HotChocolate/Core/src/Types/Types/Descriptors/Conventions/DescriptorContext.cs +++ b/src/HotChocolate/Core/src/Types/Types/Descriptors/Conventions/DescriptorContext.cs @@ -154,7 +154,6 @@ public T GetConventionOrDefault( CreateConventions(scope, out convention, out var extensions); convention ??= convention as T; - convention ??= _serviceHelper.GetService(); convention ??= factory(); if (convention is Convention init) diff --git a/src/HotChocolate/Core/test/Execution.Tests/RequestExecutorManagerTests.cs b/src/HotChocolate/Core/test/Execution.Tests/RequestExecutorManagerTests.cs index 77b4dd85ad7..0dd42d37da5 100644 --- a/src/HotChocolate/Core/test/Execution.Tests/RequestExecutorManagerTests.cs +++ b/src/HotChocolate/Core/test/Execution.Tests/RequestExecutorManagerTests.cs @@ -1,5 +1,7 @@ +using System.Reflection; using HotChocolate.Execution.Configuration; using HotChocolate.Language; +using HotChocolate.Types.Descriptors; using HotChocolate.Types; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -244,6 +246,48 @@ public async Task WarmupTask_Should_Be_Able_To_Access_Schema_And_Regular_Service cts.Dispose(); } + [Fact] + public async Task EvictExecutor_With_Custom_TypeInspector_Should_Rebuild_Without_Init_Exception() + { + // arrange + using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(50)); + var executorEvictedResetEvent = new SemaphoreSlim(0, 1); + + var manager = new ServiceCollection() + .AddGraphQL() + .AddQueryType() + .TryAddConvention() + .Services + .BuildServiceProvider() + .GetRequiredService(); + + manager.Subscribe(new RequestExecutorEventObserver(@event => + { + if (@event.Type == RequestExecutorEventType.Evicted) + { + executorEvictedResetEvent.Release(); + } + })); + + // act + var initialExecutor = await manager.GetExecutorAsync(cancellationToken: cts.Token); + var initialResult = await initialExecutor.ExecuteAsync("{ ping }"); + + manager.EvictExecutor(); + + await executorEvictedResetEvent.WaitAsync(cts.Token); + + var rebuiltExecutor = await manager.GetExecutorAsync(cancellationToken: cts.Token); + var rebuiltResult = await rebuiltExecutor.ExecuteAsync("{ ping }"); + + // assert + Assert.Empty(initialResult.ExpectOperationResult().Errors); + Assert.Empty(rebuiltResult.ExpectOperationResult().Errors); + Assert.NotNull(initialResult.ExpectOperationResult().Data); + Assert.NotNull(rebuiltResult.ExpectOperationResult().Data); + Assert.NotSame(initialExecutor, rebuiltExecutor); + } + #pragma warning disable CS9113 // Parameter is unread. private sealed class CustomWarmupTask(IDocumentCache documentCache, SomeService service) : IRequestExecutorWarmupTask #pragma warning restore CS9113 // Parameter is unread. @@ -259,4 +303,18 @@ private sealed class TriggerableTypeModule : TypeModule { public void TriggerChange() => OnTypesChanged(); } + + public sealed class Issue6695Query + { + public string Ping() => "pong"; + } + + private sealed class TuneDataTypeInspector : DefaultTypeInspector + { + public override bool IsMemberIgnored(MemberInfo member) + => base.IsMemberIgnored(member) || member.IsDefined(typeof(ApiIgnoreAttribute)); + } + + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Method)] + private sealed class ApiIgnoreAttribute : Attribute; } diff --git a/src/HotChocolate/Core/test/Types.Tests/SchemaBuilderTests.cs b/src/HotChocolate/Core/test/Types.Tests/SchemaBuilderTests.cs index fc43611ff02..eb0198ee072 100644 --- a/src/HotChocolate/Core/test/Types.Tests/SchemaBuilderTests.cs +++ b/src/HotChocolate/Core/test/Types.Tests/SchemaBuilderTests.cs @@ -1326,81 +1326,6 @@ public void AddConvention_ServiceDependency() Assert.Equal(dependencyOfConvention, ((TestConventionServiceDependency)convention).Dependency); } - [Fact] - public void AddConvention_Through_ServiceCollection() - { - // arrange - var services = new ServiceCollection(); - services.AddTransient(); - var provider = services.BuildServiceProvider(); - - // act - var schema = SchemaBuilder.New() - .AddServices(provider) - .AddType() - .AddQueryType(d => d - .Name("Query") - .Field("foo") - .Resolve("bar")) - .Create(); - - // assert - var testType = schema.Types.GetType("ConventionTestType"); - var convention = testType.Context.GetConventionOrDefault(new TestConvention2()); - Assert.IsType(convention); - } - - [Fact] - public void AddConvention_Through_ServiceCollection_ProvideImplementation() - { - // arrange - var services = new ServiceCollection(); - var conventionImpl = new TestConvention(); - services.AddSingleton(conventionImpl); - var provider = services.BuildServiceProvider(); - - // act - var schema = SchemaBuilder.New() - .AddServices(provider) - .AddType() - .AddQueryType(d => d - .Name("Query") - .Field("foo") - .Resolve("bar")) - .Create(); - - // assert - var testType = schema.Types.GetType("ConventionTestType"); - var convention = testType.Context.GetConventionOrDefault(new TestConvention2()); - Assert.IsType(convention); - Assert.Equal(convention, conventionImpl); - } - - [Fact] - public void AddConvention_Through_ServiceCollection_And_SchemaBuilderOverrides() - { - // arrange - var services = new ServiceCollection(); - services.AddSingleton(); - var provider = services.BuildServiceProvider(); - - // act - var schema = SchemaBuilder.New() - .AddServices(provider) - .AddConvention(typeof(IConvention), typeof(TestConvention2)) - .AddType() - .AddQueryType(d => d - .Name("Query") - .Field("foo") - .Resolve("bar")) - .Create(); - - // assert - var testType = schema.Types.GetType("ConventionTestType"); - var convention = testType.Context.GetConventionOrDefault(new TestConvention2()); - Assert.IsType(convention); - } - [Fact] public void AddConvention_NamingConvention() { diff --git a/src/HotChocolate/Core/test/Types.Tests/Types/Attributes/RequiredAttributeTests.cs b/src/HotChocolate/Core/test/Types.Tests/Types/Attributes/RequiredAttributeTests.cs index 7ef07abe5cd..1714dc1bc88 100644 --- a/src/HotChocolate/Core/test/Types.Tests/Types/Attributes/RequiredAttributeTests.cs +++ b/src/HotChocolate/Core/test/Types.Tests/Types/Attributes/RequiredAttributeTests.cs @@ -1,6 +1,5 @@ using System.ComponentModel.DataAnnotations; using HotChocolate.Types.Descriptors; -using Microsoft.Extensions.DependencyInjection; namespace HotChocolate.Types; @@ -21,14 +20,11 @@ public void Ignore_RequiredAttribute() { // arrange var inspector = new DefaultTypeInspector(ignoreRequiredAttribute: true); - var services = new ServiceCollection() - .AddSingleton(typeof(ITypeInspector), inspector) - .BuildServiceProvider(); // act & assert SchemaBuilder.New() .AddQueryType() - .AddServices(services) + .AddConvention(inspector) .Create() .ToString() .MatchSnapshot(); diff --git a/src/HotChocolate/Core/test/Types.Tests/Types/Descriptors/DescriptorContextTests.cs b/src/HotChocolate/Core/test/Types.Tests/Types/Descriptors/DescriptorContextTests.cs index f6493c78031..28d9259cb48 100644 --- a/src/HotChocolate/Core/test/Types.Tests/Types/Descriptors/DescriptorContextTests.cs +++ b/src/HotChocolate/Core/test/Types.Tests/Types/Descriptors/DescriptorContextTests.cs @@ -7,33 +7,6 @@ namespace HotChocolate.Types.Descriptors; public class DescriptorContextTests { - [Fact] - public void Create_With_Custom_NamingConventions() - { - // arrange - var options = new SchemaOptions(); - var namingConventions = new DefaultNamingConventions( - new XmlDocumentationProvider( - new XmlDocumentationFileResolver(), - new NoOpStringBuilderPool())); - var services = new ServiceCollection() - .AddSingleton(typeof(INamingConventions), namingConventions) - .BuildServiceProvider(); - - // act - var context = DescriptorContext.Create( - options, - services, - new FeatureCollection(), - new SchemaBuilder.LazySchema(), - new AggregateTypeInterceptor()); - - // assert - Assert.Equal(namingConventions, context.Naming); - Assert.NotNull(context.TypeInspector); - Assert.Equal(options, context.Options); - } - [Fact] public void Create_With_Custom_NamingConventions_AsIConvention() { @@ -65,30 +38,6 @@ public void Create_With_Custom_NamingConventions_AsIConvention() Assert.Equal(options, context.Options); } - [Fact] - public void Create_With_Custom_TypeInspector() - { - // arrange - var options = new SchemaOptions(); - var inspector = new DefaultTypeInspector(); - var services = new ServiceCollection() - .AddSingleton(typeof(ITypeInspector), inspector) - .BuildServiceProvider(); - - // act - var context = DescriptorContext.Create( - options, - services, - new FeatureCollection(), - new SchemaBuilder.LazySchema(), - new AggregateTypeInterceptor()); - - // assert - Assert.Equal(inspector, context.TypeInspector); - Assert.NotNull(context.Naming); - Assert.Equal(options, context.Options); - } - [Fact] public void Create_Without_Services() { diff --git a/src/HotChocolate/Data/test/Data.Filters.Tests/FilterInputTypeTest.cs b/src/HotChocolate/Data/test/Data.Filters.Tests/FilterInputTypeTest.cs index 7320f3e1139..64bd382cee7 100644 --- a/src/HotChocolate/Data/test/Data.Filters.Tests/FilterInputTypeTest.cs +++ b/src/HotChocolate/Data/test/Data.Filters.Tests/FilterInputTypeTest.cs @@ -263,7 +263,10 @@ public void FilterInputType_Should_ThrowException_WhenNoConventionIsRegistered() // act // assert var exception = Assert.Throws(builder.Create); - exception.Message.MatchSnapshot(); + Assert.Contains( + "No filter convention found for scope `Foo`. Register a convention with " + + "`AddConvention(\"Foo\")` on the schema builder.", + exception.Message); } [Fact] @@ -281,7 +284,9 @@ public void FilterInputType_Should_ThrowException_WhenNoConventionIsRegisteredDe // act // assert var exception = Assert.Throws(builder.Create); - exception.Message.MatchSnapshot(); + Assert.Contains( + "No default filter convention found. Call `AddFiltering()` on the schema builder.", + exception.Message); } [Fact] diff --git a/src/HotChocolate/Data/test/Data.Filters.Tests/__snapshots__/FilterInputTypeTest.FilterInputType_Should_ThrowException_WhenNoConventionIsRegistered.snap b/src/HotChocolate/Data/test/Data.Filters.Tests/__snapshots__/FilterInputTypeTest.FilterInputType_Should_ThrowException_WhenNoConventionIsRegistered.snap deleted file mode 100644 index a0f55d519d0..00000000000 --- a/src/HotChocolate/Data/test/Data.Filters.Tests/__snapshots__/FilterInputTypeTest.FilterInputType_Should_ThrowException_WhenNoConventionIsRegistered.snap +++ /dev/null @@ -1,20 +0,0 @@ -For more details look at the `Errors` property. - -1. For more details look at the `Errors` property. - -1. No filter convention found for scope `Foo`. Register a convention with `AddConvention("Foo")` on the schema builder. - (HotChocolate.Types.ObjectType) - - at HotChocolate.Data.FilterDescriptorContextExtensions.<>c__DisplayClass1_0.b__0() in FilterDescriptorContextExtensions.cs:line 19 - at HotChocolate.Types.Descriptors.DescriptorContext.GetConventionOrDefault[T](Func`1 factory, String scope) in DescriptorContext.cs:line 158 - at HotChocolate.Data.FilterDescriptorContextExtensions.GetFilterConvention(IDescriptorContext context, String scope) in FilterDescriptorContextExtensions.cs:line 18 - at HotChocolate.Types.FilterObjectFieldDescriptorExtensions.<>c__DisplayClass9_0.b__1(IDescriptorContext c, ObjectFieldConfiguration definition) in FilterObjectFieldDescriptorExtensions.cs:line 209 - at HotChocolate.Types.Descriptors.DescriptorBase`1.<>c__DisplayClass21_0.b__0(IDescriptorContext c, ITypeSystemConfiguration d) in DescriptorBase~1.cs:line 97 - at HotChocolate.Types.Descriptors.Configurations.OnCreateTypeSystemConfigurationTask.Configure(IDescriptorContext context) in OnCreateTypeSystemConfigurationTask.cs:line 26 - at HotChocolate.Types.Descriptors.DescriptorBase`1.CreateConfiguration() in DescriptorBase~1.cs:line 57 - at HotChocolate.Types.Descriptors.ObjectTypeDescriptor.OnCreateConfiguration(ObjectTypeConfiguration definition) in ObjectTypeDescriptor.cs:line 100 - at HotChocolate.Types.Descriptors.DescriptorBase`1.CreateConfiguration() in DescriptorBase~1.cs:line 45 - at HotChocolate.Types.ObjectType.CreateConfiguration(ITypeDiscoveryContext context) in ObjectType.Initialization.cs:line 37 - at HotChocolate.Types.TypeSystemObject`1.Initialize(ITypeDiscoveryContext context) in TypeSystemObjectBase~1.cs:line 29 - at HotChocolate.Configuration.TypeRegistrar.InitializeType(TypeSystemObject typeSystemObject, String scope, Boolean isInferred) in TypeRegistrar.cs:line 171 - diff --git a/src/HotChocolate/Data/test/Data.Filters.Tests/__snapshots__/FilterInputTypeTest.FilterInputType_Should_ThrowException_WhenNoConventionIsRegisteredDefault.snap b/src/HotChocolate/Data/test/Data.Filters.Tests/__snapshots__/FilterInputTypeTest.FilterInputType_Should_ThrowException_WhenNoConventionIsRegisteredDefault.snap deleted file mode 100644 index 822d32d3f6d..00000000000 --- a/src/HotChocolate/Data/test/Data.Filters.Tests/__snapshots__/FilterInputTypeTest.FilterInputType_Should_ThrowException_WhenNoConventionIsRegisteredDefault.snap +++ /dev/null @@ -1,20 +0,0 @@ -For more details look at the `Errors` property. - -1. For more details look at the `Errors` property. - -1. No default filter convention found. Call `AddFiltering()` on the schema builder. - (HotChocolate.Types.ObjectType) - - at HotChocolate.Data.FilterDescriptorContextExtensions.<>c__DisplayClass1_0.b__0() in FilterDescriptorContextExtensions.cs:line 19 - at HotChocolate.Types.Descriptors.DescriptorContext.GetConventionOrDefault[T](Func`1 factory, String scope) in DescriptorContext.cs:line 158 - at HotChocolate.Data.FilterDescriptorContextExtensions.GetFilterConvention(IDescriptorContext context, String scope) in FilterDescriptorContextExtensions.cs:line 18 - at HotChocolate.Types.FilterObjectFieldDescriptorExtensions.<>c__DisplayClass9_0.b__1(IDescriptorContext c, ObjectFieldConfiguration definition) in FilterObjectFieldDescriptorExtensions.cs:line 209 - at HotChocolate.Types.Descriptors.DescriptorBase`1.<>c__DisplayClass21_0.b__0(IDescriptorContext c, ITypeSystemConfiguration d) in DescriptorBase~1.cs:line 97 - at HotChocolate.Types.Descriptors.Configurations.OnCreateTypeSystemConfigurationTask.Configure(IDescriptorContext context) in OnCreateTypeSystemConfigurationTask.cs:line 26 - at HotChocolate.Types.Descriptors.DescriptorBase`1.CreateConfiguration() in DescriptorBase~1.cs:line 57 - at HotChocolate.Types.Descriptors.ObjectTypeDescriptor.OnCreateConfiguration(ObjectTypeConfiguration definition) in ObjectTypeDescriptor.cs:line 100 - at HotChocolate.Types.Descriptors.DescriptorBase`1.CreateConfiguration() in DescriptorBase~1.cs:line 45 - at HotChocolate.Types.ObjectType.CreateConfiguration(ITypeDiscoveryContext context) in ObjectType.Initialization.cs:line 37 - at HotChocolate.Types.TypeSystemObject`1.Initialize(ITypeDiscoveryContext context) in TypeSystemObjectBase~1.cs:line 29 - at HotChocolate.Configuration.TypeRegistrar.InitializeType(TypeSystemObject typeSystemObject, String scope, Boolean isInferred) in TypeRegistrar.cs:line 171 - diff --git a/src/HotChocolate/Data/test/Data.Sorting.Tests/SortInputTypeTests.cs b/src/HotChocolate/Data/test/Data.Sorting.Tests/SortInputTypeTests.cs index 68335c49fba..ddafbe0368c 100644 --- a/src/HotChocolate/Data/test/Data.Sorting.Tests/SortInputTypeTests.cs +++ b/src/HotChocolate/Data/test/Data.Sorting.Tests/SortInputTypeTests.cs @@ -184,7 +184,10 @@ public void SortInputType_Should_ThrowException_WhenNoConventionIsRegistered() // act // assert var exception = Assert.Throws(builder.Create); - exception.Message.MatchSnapshot(); + Assert.Contains( + "No sorting convention found for scope `Foo`. Register a convention with " + + "`AddConvention(\"Foo\")` on the schema builder.", + exception.Message); } [Fact] @@ -202,7 +205,9 @@ public void SortInputType_Should_ThrowException_WhenNoConventionIsRegisteredDefa // act // assert var exception = Assert.Throws(builder.Create); - exception.Message.MatchSnapshot(); + Assert.Contains( + "No default sorting convention found. Call `AddSorting()` on the schema builder.", + exception.Message); } [Fact] diff --git a/src/HotChocolate/Data/test/Data.Sorting.Tests/__snapshots__/SortInputTypeTests.SortInputType_Should_ThrowException_WhenNoConventionIsRegistered.snap b/src/HotChocolate/Data/test/Data.Sorting.Tests/__snapshots__/SortInputTypeTests.SortInputType_Should_ThrowException_WhenNoConventionIsRegistered.snap deleted file mode 100644 index efacf9fe012..00000000000 --- a/src/HotChocolate/Data/test/Data.Sorting.Tests/__snapshots__/SortInputTypeTests.SortInputType_Should_ThrowException_WhenNoConventionIsRegistered.snap +++ /dev/null @@ -1,20 +0,0 @@ -For more details look at the `Errors` property. - -1. For more details look at the `Errors` property. - -1. No sorting convention found for scope `Foo`. Register a convention with `AddConvention("Foo")` on the schema builder. - (HotChocolate.Types.ObjectType) - - at HotChocolate.Data.SortDescriptorContextExtensions.<>c__DisplayClass1_0.b__0() in SortDescriptorContextExtensions.cs:line 20 - at HotChocolate.Types.Descriptors.DescriptorContext.GetConventionOrDefault[T](Func`1 factory, String scope) in DescriptorContext.cs:line 158 - at HotChocolate.Data.SortDescriptorContextExtensions.GetSortConvention(IDescriptorContext context, String scope) in SortDescriptorContextExtensions.cs:line 19 - at HotChocolate.Types.SortingObjectFieldDescriptorExtensions.<>c__DisplayClass9_0.b__1(IDescriptorContext c, ObjectFieldConfiguration definition) in SortingObjectFieldDescriptorExtensions.cs:line 210 - at HotChocolate.Types.Descriptors.DescriptorBase`1.<>c__DisplayClass21_0.b__0(IDescriptorContext c, ITypeSystemConfiguration d) in DescriptorBase~1.cs:line 97 - at HotChocolate.Types.Descriptors.Configurations.OnCreateTypeSystemConfigurationTask.Configure(IDescriptorContext context) in OnCreateTypeSystemConfigurationTask.cs:line 26 - at HotChocolate.Types.Descriptors.DescriptorBase`1.CreateConfiguration() in DescriptorBase~1.cs:line 57 - at HotChocolate.Types.Descriptors.ObjectTypeDescriptor.OnCreateConfiguration(ObjectTypeConfiguration definition) in ObjectTypeDescriptor.cs:line 100 - at HotChocolate.Types.Descriptors.DescriptorBase`1.CreateConfiguration() in DescriptorBase~1.cs:line 45 - at HotChocolate.Types.ObjectType.CreateConfiguration(ITypeDiscoveryContext context) in ObjectType.Initialization.cs:line 37 - at HotChocolate.Types.TypeSystemObject`1.Initialize(ITypeDiscoveryContext context) in TypeSystemObjectBase~1.cs:line 29 - at HotChocolate.Configuration.TypeRegistrar.InitializeType(TypeSystemObject typeSystemObject, String scope, Boolean isInferred) in TypeRegistrar.cs:line 171 - diff --git a/src/HotChocolate/Data/test/Data.Sorting.Tests/__snapshots__/SortInputTypeTests.SortInputType_Should_ThrowException_WhenNoConventionIsRegisteredDefault.snap b/src/HotChocolate/Data/test/Data.Sorting.Tests/__snapshots__/SortInputTypeTests.SortInputType_Should_ThrowException_WhenNoConventionIsRegisteredDefault.snap deleted file mode 100644 index c96ecc90cb2..00000000000 --- a/src/HotChocolate/Data/test/Data.Sorting.Tests/__snapshots__/SortInputTypeTests.SortInputType_Should_ThrowException_WhenNoConventionIsRegisteredDefault.snap +++ /dev/null @@ -1,20 +0,0 @@ -For more details look at the `Errors` property. - -1. For more details look at the `Errors` property. - -1. No default sorting convention found. Call `AddSorting()` on the schema builder. - (HotChocolate.Types.ObjectType) - - at HotChocolate.Data.SortDescriptorContextExtensions.<>c__DisplayClass1_0.b__0() in SortDescriptorContextExtensions.cs:line 20 - at HotChocolate.Types.Descriptors.DescriptorContext.GetConventionOrDefault[T](Func`1 factory, String scope) in DescriptorContext.cs:line 158 - at HotChocolate.Data.SortDescriptorContextExtensions.GetSortConvention(IDescriptorContext context, String scope) in SortDescriptorContextExtensions.cs:line 19 - at HotChocolate.Types.SortingObjectFieldDescriptorExtensions.<>c__DisplayClass9_0.b__1(IDescriptorContext c, ObjectFieldConfiguration definition) in SortingObjectFieldDescriptorExtensions.cs:line 210 - at HotChocolate.Types.Descriptors.DescriptorBase`1.<>c__DisplayClass21_0.b__0(IDescriptorContext c, ITypeSystemConfiguration d) in DescriptorBase~1.cs:line 97 - at HotChocolate.Types.Descriptors.Configurations.OnCreateTypeSystemConfigurationTask.Configure(IDescriptorContext context) in OnCreateTypeSystemConfigurationTask.cs:line 26 - at HotChocolate.Types.Descriptors.DescriptorBase`1.CreateConfiguration() in DescriptorBase~1.cs:line 57 - at HotChocolate.Types.Descriptors.ObjectTypeDescriptor.OnCreateConfiguration(ObjectTypeConfiguration definition) in ObjectTypeDescriptor.cs:line 100 - at HotChocolate.Types.Descriptors.DescriptorBase`1.CreateConfiguration() in DescriptorBase~1.cs:line 45 - at HotChocolate.Types.ObjectType.CreateConfiguration(ITypeDiscoveryContext context) in ObjectType.Initialization.cs:line 37 - at HotChocolate.Types.TypeSystemObject`1.Initialize(ITypeDiscoveryContext context) in TypeSystemObjectBase~1.cs:line 29 - at HotChocolate.Configuration.TypeRegistrar.InitializeType(TypeSystemObject typeSystemObject, String scope, Boolean isInferred) in TypeRegistrar.cs:line 171 -