我试图在ASP中设置一个graphhapi与热巧克力。网络核心。
现在我想将我的应用程序拆分为多个项目/组件。有一个Users组件,它有一个UsersMutation,包含1个字段:
public sealed class UsersMutation
{
public Task CreateUser([Service] ICreateUserMutationHandler handler, CreateUserParameters parameters)
=> handler.Handle(parameters);
}
我尝试像这样将它添加到GraphQl模式中:
public sealed class Mutation
{
public UsersMutation Users => new UsersMutation();
}
配置:
public static class GraphApiConfiguration
{
public static IServiceCollection AddGraphApi<TQuery, TMutation>(this IServiceCollection services)
where TQuery : class
where TMutation : class
{
services.AddGraphQLServer()
.AddQueryType<TQuery>()
.AddMutationType<TMutation>();
services.AddScoped<TQuery>();
services.AddScoped<TMutation>();
return services;
}
}
最后在startup.cs:
services.AddGraphApi<Query, Mutation>();
但我得到以下错误试图看到在操场的模式:
HotChocolate.SchemaException: For more details look at the `Errors` property.
1. The object type `UsersMutation` has to at least define one field in order to be valid. (HotChocolate.Types.ObjectType<ChocoGraph.Components.Users.GraphApi.UsersMutation>)
at HotChocolate.Configuration.TypeInitializer.Initialize(Func`1 schemaResolver, IReadOnlySchemaOptions options)
at HotChocolate.SchemaBuilder.Setup.InitializeTypes(SchemaBuilder builder, IDescriptorContext context, IReadOnlyList`1 types, LazySchema lazySchema)
at HotChocolate.SchemaBuilder.Setup.Create(SchemaBuilder builder, LazySchema lazySchema, IDescriptorContext context)
at HotChocolate.SchemaBuilder.Create(IDescriptorContext context)
at HotChocolate.SchemaBuilder.HotChocolate.ISchemaBuilder.Create(IDescriptorContext context)
at HotChocolate.Execution.RequestExecutorResolver.CreateSchemaAsync(NameString schemaName, RequestExecutorSetup options, RequestExecutorOptions executorOptions, IServiceProvider serviceProvider, TypeModuleChangeMonitor typeModuleChangeMonitor, CancellationToken cancellationToken)
at HotChocolate.Execution.RequestExecutorResolver.CreateSchemaServicesAsync(NameString schemaName, RequestExecutorSetup options, CancellationToken cancellationToken)
at HotChocolate.Execution.RequestExecutorResolver.GetRequestExecutorNoLockAsync(NameString schemaName, CancellationToken cancellationToken)
at HotChocolate.Execution.RequestExecutorResolver.GetRequestExecutorAsync(NameString schemaName, CancellationToken cancellationToken)
at HotChocolate.Execution.RequestExecutorProxy.GetRequestExecutorAsync(CancellationToken cancellationToken)
at HotChocolate.AspNetCore.HttpPostMiddleware.HandleRequestAsync(HttpContext context, AllowedContentType contentType)
at HotChocolate.AspNetCore.HttpPostMiddleware.InvokeAsync(HttpContext context)
at HotChocolate.AspNetCore.WebSocketSubscriptionMiddleware.InvokeAsync(HttpContext context)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
'iisexpress.exe' (CoreCLR: clrhost): Loaded 'C:Program FilesdotnetsharedMicrosoft.NETCore.App5.0.10System.Buffers.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The program '[44280] iisexpress.exe: Program Trace' has exited with code 0 (0x0).
The program '[44280] iisexpress.exe' has exited with code -1 (0xffffffff).
我错过了什么来实现这一点?如果我在Mutation.cs文件中有CreateUser字段,这似乎可以正常工作,但是添加这个额外的步骤似乎会破坏它。
我发现了问题:
为了成为一个有效的字段,Mutation必须返回一些东西。