首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GraphQL.Types.EnumerationGraphType错误

GraphQL.Types.EnumerationGraphType错误
EN

Stack Overflow用户
提问于 2021-03-26 10:52:11
回答 1查看 505关注 0票数 0

我试图用枚举创建类,但我有一个错误。

代码语言:javascript
复制
public class MarsWheather {
    public Season MarsSeason { get; set; }
}

public enum Season {
    winter,
    spring,
    summer,
    autumn
}

我的graphql类如下所示:

代码语言:javascript
复制
public class SolSchema : Schema
{
    public SolSchema(IServiceProvider sp) : base(sp)
    {
        Query = sp.GetRequiredService<SolDataQuery>();
        Mutation = sp.GetRequiredService<SolDataMutation>();
    }
}
public class SolDataQuery : ObjectGraphType<object>
{
    public SolDataQuery(INasaProvider nasaProvider)
    {
            Field<MarsWheatherType>("wheather", resolve: context => nasaProvider.GetAsync());
    }
}
public class MarsWheatherType : ObjectGraphType<MarsWheather>
{
    public MarsWheatherType()
    {
        Field(w => w.MarsSeason);
    }
}

public class SeasonEnum : EnumerationGraphType<Season>
{ }

我在startup.cs (ConfigureServices方法)中注册了它:

代码语言:javascript
复制
services.AddSingleton<SolDataQuery>();
        services.AddSingleton<SolDataMutation>();
        services.AddSingleton<SeasonEnum>();
        services.AddSingleton<MarsWheatherType>();
        services.AddSingleton<ISchema, SolSchema>();

我在用GraphQLPlayground。我的要求是:

wheather { marsSeason}

在这一切之后,我有一个错误:

执行文档时出错\r\n

此错误的代码为"INVALID_OPERATION“。

有人能帮帮我吗?我做错什么了?如果有帮助的话,我把这个还没完成的项目推到github

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-29 10:58:37

好的。MarsWheatherType的正确代码是:

代码语言:javascript
复制
public class MarsWheatherType : ObjectGraphType<MarsWheather>
{
    public MarsWheatherType()
    {
        Field<SeasonEnum>("season", resolve: w => w.Source.MarsSeason);
    }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66815481

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档