asp.net-core - 没有可用的架构 graphiql aspnet 核心
问题描述
我在https://github.com/nmarun/customergraph有我的仓库。当我运行应用程序时,我在文档资源管理器中看不到任何架构。当我查看“网络”选项卡时,我看到了 404。
我想我需要将 GraphiQl 配置为调用 /graphql 端点来检索架构详细信息,并且由于某种原因,我的 HTTP POST 操作方法没有在 /graph 端点处受到打击。
当我到达端点时,所有通过邮递员的调用都可以正常工作: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();
推荐阅读
- c# - 如何将条件等于两个字符串
- python - 随机 url 生成器,但确保结果是唯一的
- python - 熊猫将(不等长度)列表的列拆分为多列
- python - Youtube V3 API 不对视频进行排序
- azure-devops - 将管道变量从 Designer 传递到 YAML 作业模板
- node.js - 有没有办法使用多个优先路径来保存 pug 文件?
- db2-400 - 在 QSYS2 中使用函数 TIMESTAMP_FORMAT 无效。成员数据映射错误
- java - kotlin-jpa 插件不生成默认构造函数
- jquery - 未捕获的 SyntaxError:意外的标识符和意外的令牌
- php - PHP 根缓冲区中的内容以及如果它大于 10K 会发生什么