我正在尝试在 ASP.NET Core 中使用 Hot Chocolate 设置 GraphApi。
现在我想将我的应用程序拆分为多个项目/组件。有一个 Users 组件,其中的 UsersMutation 包含 1 个字段:
public sealed class UsersMutation
{
public Task CreateUser([Service] ICreateUserMutationHandler handler, CreateUserParameters parameters)
=> handler.Handle(parameters);
}
Run Code Online (Sandbox Code Playgroud)
我尝试将其添加到 GraphQl 架构中,如下所示:
public sealed class Mutation
{
public UsersMutation Users => new UsersMutation();
}
Run Code Online (Sandbox Code Playgroud)
配置:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
最后在startup.cs中:
services.AddGraphApi<Query, Mutation>();
Run Code Online (Sandbox Code Playgroud)
但我在尝试查看游乐场中的架构时遇到以下错误:
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 Files\dotnet\shared\Microsoft.NETCore.App\5.0.10\System.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).
Run Code Online (Sandbox Code Playgroud)
为了实现这个目标我缺少什么?如果我在 Mutation.cs 文件中有 CreateUser 字段,这似乎工作得很好,但添加这个额外的步骤似乎会破坏它。
归档时间: |
|
查看次数: |
2462 次 |
最近记录: |