.NET Core 3.0 中 GraphQL.Net 库的“INVALID_OPERATION”错误

问题描述

我对 GraphQL.Net 库有疑问。我使用过“GraphQL”版本=“3.2.0”、“GraphQL.Server.Ui.Playground”版本=“4.4.0”和TargetFramework = netcoreapp3.0 我想看看它是如何工作的,我创建了一个简单的类:

    public class Temp
{
    public int MyProperty { get; set; }
}

public class TempType : ObjectGraphType<Temp>
{
    public TempType()
    {
        Name = "TEmp";
        Field(t => t.MyProperty).Description("temp");
    }
}
public class SolDataQuery : ObjectGraphType
{
    public SolDataQuery(ISolDataFill sdFill)
    {
        Name = "Query";
        Field<IntGraphType>("soldata",resolve: context => 5);
        Field<TempType>("wheater",resolve: context => new Temp { MyProperty = 2 });
    }
}

在操场开始后,我请求了一个查询:{wheather {myProperty}} 和 我看到:“消息”:“执行文档时出错。”,“代码”:“INVALID_OPERATION”。 如果我更改了代码和注释行“Field("wheater",resolve: context => new Temp { MyProperty = 2 });”我请求了一个查询 {soldata} 并看到了正确的结果“5”。 谁能告诉我,我的错误在哪里?

解决方法

我忘记在 Startup.cs 中将我的 TempType 添加到 ServiceProvider

public void ConfigureServices(IServiceCollection services)
{
        ...
        services.AddSingleton<TempType>();
        ...
}

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...