我不确定他们是否在 .net 核心版本 3.0 中进行了任何更改,但您可以在此处查看我的博客
我在用着GraphQL.Server.Ui.Playground
下面是您可以看到的最小配置
public void ConfigureServices(IServiceCollection services)
{
services
.AddMvc()
.AddJsonOptions(
options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
)
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddGraphQL(x =>
{
x.ExposeExceptions = true; //set true only in development mode. make it switchable.
})
.AddGraphTypes(ServiceLifetime.Scoped);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, Seeder seeder)
{
app.UseGraphQL<DataSchema>();
app.UseGraphQLPlayground(new GraphQLPlaygroundOptions());
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action=Index}/{id?}");
});
}
结果与 GraphiQl 相同
编辑:这是因为 Newtonsoft.Json 在 .Net Core 3 中发生了变化。您可以在此处查看我的答案
ASP.NET Core 3.0 [FromBody] 字符串内容返回“无法将 JSON 值转换为 System.String。”