GraphQL文档资源管理器未显示在浏览器.net core 3.1中

GraphQL文档资源管理器未显示在浏览器.net core 3.1中,graphql,.net-core-3.1,Graphql,.net Core 3.1,我是GraphQL新手,我已经使用GraphQL构建了一个示例项目,该项目运行良好,但是'Documentation Explore'(我的自定义模式)没有加载到浏览器中。net core 3.1还附带了StartUp.cs。 注意:它是在.NETCore2.0中工作的 这里是startup.cs using GraphiQl; using GraphQL; using GraphQL.Server; using GraphQL.Types; { public class Startup

我是GraphQL新手,我已经使用GraphQL构建了一个示例项目,该项目运行良好,但是'Documentation Explore'(我的自定义模式)没有加载到浏览器中。net core 3.1还附带了StartUp.cs。 注意:它是在.NETCore2.0中工作的

这里是startup.cs

using GraphiQl;
using GraphQL;
using GraphQL.Server;
using GraphQL.Types;
{
    public class Startup
    {

        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<IISServerOptions>(options =>
            {
                options.AllowSynchronousIO = true;
            });

            services.AddSingleton<IDependencyResolver>(c => new FuncDependencyResolver(type => c.GetRequiredService(type)));

            services.AddDbContext<RealEstateContext>(options => options.UseSqlServer(Configuration["ConnectionStrings:RealEstateDb"]));
            services.AddScoped<IDocumentExecuter, DocumentExecuter>();
            services.AddScoped<PropertyQuery>();
            services.AddScoped<PropertyMutation>();
            services.AddScoped<PropertyType>();
            services.AddScoped<ConstituencyType>();
            services.AddScoped<PropertyInputType>();
            services.AddScoped<PaymentType>();
                    services.AddGraphQL(options =>
            {
                options.EnableMetrics = true;
                options.ExposeExceptions = true;
            }).AddWebSockets();
        }

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env,RealEstateContext db)
        {
            app.UseWebSockets();
            app.UseGraphQLWebSockets<RealEstateSchema>("/graphql");
            app.UseGraphQL<RealEstateSchema>("/graphql");
            db.EnsureSeedData();
        }

    }
}
使用GraphiQl;
使用GraphQL;
使用GraphQL.Server;
使用GraphQL.Types;
{
公营创业
{
public void配置服务(IServiceCollection服务)
{
配置(选项=>
{
options.AllowSynchronousIO=true;
});
services.AddSingleton(c=>newFuncDependencyResolver(type=>c.GetRequiredService(type));
services.AddDbContext(options=>options.UseSqlServer(配置[“connectionString:RealEstateDb]”);
services.addScope();
services.addScope();
services.addScope();
services.addScope();
services.addScope();
services.addScope();
services.addScope();
services.AddGraphQL(选项=>
{
options.EnableMetrics=true;
options.exposeeexceptions=true;
}).AddWebSockets();
}
public void配置(IApplicationBuilder应用程序、IWebHostEnvironment环境、RealEstateContext数据库)
{
app.UseWebSockets();
app.UseGraphQLWebSockets(“/graphql”);
app.UseGraphQL(“/graphql”);
db.ensureseddata();
}
}
}

您的查询结果是否以“数据”开头?如果不是,这可能就是问题所在。Documentation Explorer(它是一个React应用程序)希望其元数据查询的结果以“数据”开头

我在
GraphQLController
中添加了以下代码,然后出现了文档

[Route(“/graphql”)]
[HttpPost]
公共异步任务Post([FromBody]GraphQLQueryTo查询)
{
var result=wait\u execute.ExecuteAsync(\u=>
{
_.Schema=_Schema;
_.Query=Query.Query;
_.Inputs=query.Variables?.ToInputs();
});
如果(结果错误?.Count>0){
返回BadRequest(结果.错误[0].ToString());
}
//json的响应不是以“数据”开头的——也许是为了看起来更漂亮
//这个问题是当GraphiQL请求模式时,GraphiQL
//正在等待一个启动“data”的响应。因此,我将“data”添加到
//如果这是架构请求,则返回响应的前面。
if(typeof(Dictionary.IsInstanceOfType(result.Data)){
var dictData=(Dictionary)result.Data;
if(dictData.ContainsKey(“\u模式”)){
var result2=新字典();
结果2.添加(“数据”,dictData);
返回Ok(结果2);
}否则{
返回Ok(结果数据);
}
}
返回Ok(结果);
}