无法弄清楚是否可以在 Hot Chocolate 中为 ASP.NET Core 使用多个模式

Can't figure out is it possible to use multiple schemas in Hot Chocolate for ASP.NET Core

我正在尝试在 ASP.NET Core 上使用 Hot Chocolate 库开始开发 GraphQL API,但我不知道如何为不同的端点使用不同的模式。我知道模式拼接,但这不是我要找的。 我想实现的是能够从不同的端点查询不同的类型,例如我想从 localhost:5000/graphapi 查询用户数据并从 localhost:5000/ 查询不同的管理数据admin/graphapi 是的,可以为此创建单独的服务器,但我想要单体 API.

这很简单,

首先为您的模式设置 GraphQL 配置:

public void ConfigureServices(IServiceCollection services)
{
    services
        .AddRouting()

    services
        .AddGraphQLServer()
        .AddQueryType<Query>()
        .AddMutationType<Mutation>();

    services
        .AddGraphQLServer("adminSchema")
        .AddQueryType<QueryAdmin>()
        .AddMutationType<MutationAdmin>();
}

接下来我们需要配置模式到具体路由的映射:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    app
        .UseRouting()
        .UseEndpoints(endpoints =>
        {
            endpoints.MapGraphQL();
            endpoints.MapGraphQL("/admin/graphql", schemaName: "adminSchema");
        });
}

完成。