Unable to ignore the method returning Expression with type extension
Is there an existing issue for this?
- [X] I have searched the existing issues
Product
Hot Chocolate
Describe the bug
Suppose a class has a method whose return type is Expression. Also, there's the type extension which adds the ignore directive for that method.
CUR: The ignore directive isn't actually applied.
Steps to reproduce
Run the reproducible example and in Banana Cake Pop make the retrospective query:
using System;
using System.Linq.Expressions;
using HotChocolate.Types;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace Ademchenko.GraphQLWorkshop.TypeExtensions
{
public class Query
{
public Book Book { get; } = new() { AutorId = 11 };
}
public class Book
{
public int AutorId { get; set; }
public Expression<Func<int>> GetExpression() => throw new NotImplementedException();
}
public class BookTypeExtensions : ObjectTypeExtension<Book>
{
protected override void Configure(IObjectTypeDescriptor<Book> descriptor) => descriptor.Ignore(b => b.GetExpression());
}
/*
public class BookType : ObjectType<Book>
{
protected override void Configure(IObjectTypeDescriptor<Book> descriptor) => descriptor.Ignore(b => b.GetExpression());
}*/
public class Startup
{
public IConfiguration Configuration { get; }
public Startup(IConfiguration configuration) => Configuration = configuration;
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddGraphQLServer()
.AddQueryType<Query>()
//.AddType<BookType>()
.AddTypeExtension<BookTypeExtensions>()
;
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseExceptionHandler(options =>
{
options.Run(async context =>
{
var contextFeature = context.Features.Get<IExceptionHandlerFeature>();
if (contextFeature != null)
{
Console.WriteLine(contextFeature.Error);
}
});
});
app.UseRouting().UseEndpoints(endpoints => endpoints.MapGraphQL());
}
}
}
Relevant log output
1. Unable to infer or resolve a schema type from the type reference `Expression (Input)`.
at HotChocolate.Configuration.TypeInitializer.DiscoverTypes()
at HotChocolate.Configuration.TypeInitializer.Initialize()
at HotChocolate.SchemaBuilder.Setup.InitializeTypes(SchemaBuilder builder, IDescriptorContext context, IReadOnlyList`1 types)
at HotChocolate.SchemaBuilder.Setup.Create(SchemaBuilder builder, LazySchema lazySchema, IDescriptorContext context)
at HotChocolate.Execution.RequestExecutorResolver.CreateSchemaAsync(ConfigurationContext context, RequestExecutorSetup setup, RequestExecutorOptions executorOptions, IServiceProvider schemaServices, TypeModuleChangeMonitor typeModuleChangeMonitor, CancellationToken cancellationToken)
at HotChocolate.Execution.RequestExecutorResolver.CreateSchemaServicesAsync(ConfigurationContext context, RequestExecutorSetup setup, CancellationToken cancellationToken)
at HotChocolate.Execution.RequestExecutorResolver.GetRequestExecutorNoLockAsync(String schemaName, CancellationToken cancellationToken)
at HotChocolate.Execution.RequestExecutorResolver.GetRequestExecutorAsync(String schemaName, CancellationToken cancellationToken)
at HotChocolate.Execution.RequestExecutorProxy.GetRequestExecutorAsync(CancellationToken cancellationToken)
at HotChocolate.AspNetCore.HttpPostMiddlewareBase.HandleRequestAsync(HttpContext context)
at HotChocolate.AspNetCore.HttpPostMiddlewareBase.InvokeAsync(HttpContext context)
at Microsoft.AspNetCore.Builder.EndpointRouteBuilderExtensions.<>c__DisplayClass19_0.<<UseCancellation>b__1>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
Additional Context?
The ignore functionality works for Type though. To verify that uncomment the code related to BookType.
Version
13.8.1
The extension should only be used if there is already a type ... why do you want to use the extension in this case?
@michaelstaib, according to the documentation there is nothing wrong with using the extension in that way. Even further there is an example which does it. And once there's an example of that it's not a surprise that users of HotChocolate follow that way and come across that error. So, to be honest, I don't fully follow the idea why you marked that case as an enhancement but not a bug.
@michaelstaib , any news on that bug so far? Thanks in advance!