gpt4 book ai didi

asp.net-core - 没有可用的架构 graphql asp net core

转载 作者:行者123 更新时间:2023-12-05 06:24:46 27 4
gpt4 key购买 nike

我的存储库位于 https://github.com/nmarun/customergraph .当我运行该应用程序时,我在文档资源管理器中看不到任何架构。当我查看“网络”选项卡时,我看到了 404。

404 in Network tag

我认为我需要配置 GraphiQl 以调用/graphql 端点来检索模式详细信息,并且出于某种原因我的 HTTP POST 操作方法没有在/graph 端点被命中。

当我到达端点时,通过 postman 的所有调用都工作正常:http://localhost:54068/graphql

请协助。

using CustomerGraph.Models.Schema;
using CustomerGraph.Models.Services;
using GraphiQl;
using GraphQL;
using GraphQL.Server;
using GraphQL.Types;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace CustomerGraph
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddScoped<IDocumentExecuter, DocumentExecuter>();
services.AddSingleton<ICustomerService, CustomerService>();
services.AddSingleton<CustomerType>();
services.AddSingleton<AddressType>();
services.AddSingleton<ContactType>();
services.AddSingleton<ContactMethodType>();
services.AddSingleton<CustomersQuery>();
services.AddSingleton<CustomerSchema>();
services.AddSingleton<IDependencyResolver>(
c => new FuncDependencyResolver(type => c.GetRequiredService(type)));

services.AddGraphQL(_ =>
{
_.EnableMetrics = true;
_.ExposeExceptions = true;
});

var sp = services.BuildServiceProvider();
services.AddSingleton<ISchema>(new CustomerSchema(new FuncDependencyResolver(type => sp.GetService(type))));

}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseGraphiQl("/graphiql");
app.UseGraphQL<ISchema>("/graphql");
app.UseGraphQLWebSockets<CustomerSchema>("/graphql");
app.UseWebSockets();
app.UseHttpsRedirection();
app.UseMvc();
}
}
}

谢谢,阿伦

最佳答案

这是由 UseGraphIQL 方法引起的,它假定 graphql 端点与 GraphQL api 在同一位置。

通过替换以下内容来修复它:

   app.UseGraphiQl("/graphiql");
//app.UseGraphQL<CustomerSchema>("/graph");
//app.UseGraphQLWebSockets<CustomerSchema>("/graphql");
//app.UseWebSockets();
app.UseHttpsRedirection();
app.UseMvc();

通过:

   app.UseGraphiQl("/graphiql", "/graphql");
app.UseGraphQL<CustomerSchema>("/graphql");
app.UseGraphQLWebSockets<CustomerSchema>("/graphql");
app.UseWebSockets();
app.UseHttpsRedirection();
app.UseMvc();

关于asp.net-core - 没有可用的架构 graphql asp net core,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57542100/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com