Describe the bug
Two ExtensionTypes on a Type: one has filtering applied, the other doesn't. It will the throw ArgumentNullException at FilterObjectFieldDescriptorExtensions.CompileMiddleware, if we register the one extension type with filtering first. It will not throw if we register the other one first.
To Reproduce
Steps to reproduce the behavior:
using HotChocolate;
using HotChocolate.AspNetCore;
using HotChocolate.Types;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
namespace WebApplication_DemoNullArgExOnFilterOnResolverType
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// -------------------
ISchema schema = SchemaBuilder.New()
.AddQueryType(c => c.Name("Query"))
.AddType<QueryExtensionType_A>() // function group # 1.
.AddType<QueryExtensionType_B>() // function group # 2. **Note: if we switch this line with line above, it will not throw.
.Create();
services.AddGraphQL(schema);
// -------------------
}
public class QueryExtensionType_A : ObjectTypeExtension
{
protected override void Configure(IObjectTypeDescriptor descriptor)
{
descriptor.Name("Query")
.Field("words").Type<ListType<ObjectType<Word>>>().Resolver(new Word[] { new Word { Value = "Hello" }, new Word { Value = "World" } })
.UseFiltering();
}
}
public class QueryExtensionType_B : ObjectTypeExtension
{
protected override void Configure(IObjectTypeDescriptor descriptor)
{
descriptor.Name("Query")
.Field("greeting").Type<StringType>().Resolver("Hello world!");
}
}
public class Word
{
public string Value { get; set; }
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// -------------------
app.UseGraphQL(new QueryMiddlewareOptions { Path = "/gql", EnableSubscriptions = false });
app.UsePlayground(queryPath: "/gql");
// -------------------
}
}
}
WebApplication_DemoNullArgExOnFilterOnResolverType.csproj:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="HotChocolate.AspNetCore" Version="10.3.5" />
<PackageReference Include="HotChocolate.AspNetCore.Playground" Version="10.3.5" />
<PackageReference Include="HotChocolate.Types.Filters" Version="10.3.5" />
</ItemGroup>
</Project>
System.ArgumentNullException
HResult=0x80004003
Message=Value cannot be null.
Source=System.Private.CoreLib
StackTrace:
at System.RuntimeType.MakeGenericType(Type[] instantiation)
at HotChocolate.Types.FilterObjectFieldDescriptorExtensions.CompileMiddleware(ICompletionContext context, ObjectFieldDefinition definition, ITypeReference argumentTypeReference, FieldMiddleware placeholder)
at HotChocolate.Types.FilterObjectFieldDescriptorExtensions.<>c__DisplayClass5_1.<UseFiltering>b__3(ICompletionContext context, ObjectFieldDefinition defintion)
at HotChocolate.Types.Descriptors.TypeConfiguration`1.HotChocolate.Types.Descriptors.Definitions.ILazyTypeConfiguration.Configure(ICompletionContext context)
at HotChocolate.Types.TypeSystemObjectBase`1.ExecuteConfigurations(ICompletionContext context, TDefinition definition, ApplyConfigurationOn kind)
at HotChocolate.Types.TypeSystemObjectBase`1.CompleteType(ICompletionContext context)
at HotChocolate.Configuration.TypeInitializer.<CompleteTypes>b__42_0(RegisteredType registeredType)
at HotChocolate.Configuration.TypeInitializer.CompleteTypes(DiscoveredTypes discoveredTypes, TypeDependencyKind kind, Func`2 action)
at HotChocolate.Configuration.TypeInitializer.CompleteTypes(DiscoveredTypes discoveredTypes)
at HotChocolate.Configuration.TypeInitializer.Initialize(Func`1 schemaResolver, IReadOnlySchemaOptions options)
at HotChocolate.SchemaBuilder.Create()
at HotChocolate.SchemaBuilder.HotChocolate.ISchemaBuilder.Create()
at WebApplication_DemoNullArgExOnFilterOnResolverType.Startup.ConfigureServices(IServiceCollection services) in M:\Users\zguo\source\repos\WebApplication_DemoNullArgExOnFilterOnResolverType\Startup.cs:line 14
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.<Invoke>g__Startup|0(IServiceCollection serviceCollection)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.<Build>b__0(IServiceCollection services)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass12_0.<UseStartup>b__0(HostBuilderContext context, IServiceCollection services)
at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
at Microsoft.Extensions.Hosting.HostBuilder.Build()
at WebApplication_DemoNullArgExOnFilterOnResolverType.Program.Main(String[] args) in M:\Users\zguo\source\repos\WebApplication_DemoNullArgExOnFilterOnResolverType\Program.cs:line 10
Expected behavior
It shouldn't throw exception and the order of ExtensionType shouldn't matter.
Desktop (please complete the following information):
Additional context
Another slightly bigger repo the recreates the issue can be found here
@PascalSenn are you handling this or should I take a look?
After talking to pascal I will take over this one.
OK... got the bug ... but still investigating why it happens ... some how the entity type cannot be inferred.
The issue is that we do not honor the OnCompleted on the lazy configuration.
This one is now officially a bug :)
So the issue is that we are not coping the type extension locks over to the type when we merge them into one object.
I have fixed it in version 11 and will port the fix to version 10.4 now
@zxg93 awesome catch. This was a nasty bug. with your simple repo I could find it quickly. Thanks for your help :)
We will release a bug fix with 10.4.0-preview.15 and 11.0.0-preview.105.
I will give you a ping once we start building the packages.
We have triggered a 10.4 release:
https://github.com/ChilliCream/hotchocolate/releases/tag/10.4.0-preview.15
I will close this issue since it is now fixed.
I just verified that it gets fixed and my code works perfectly with the 10.4.0-preview.16. Thanks so much for the prompt response and fix! Your guys are awesome and building wonderful product! :)