【问题标题】:no schema available graphiql aspnet core没有可用的架构 graphiql aspnet 核心
【发布时间】:2019-12-23 19:25:18
【问题描述】:

我有我的回购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();
        }
    }
}

谢谢, 阿伦

【问题讨论】:

标签: asp.net-core graphql graphiql


【解决方案1】:

这是由 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();

【讨论】:

  • 完美。像魅力一样工作。非常感谢@MaartenDev
猜你喜欢
  • 2021-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-06
  • 2016-10-10
  • 2019-05-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多