GraphQL.Types.EnumerationGraphType 错误

Error with GraphQL.Types.EnumerationGraphType

我正在尝试使用枚举创建 class,但出现错误。

public class MarsWheather {
    public Season MarsSeason { get; set; }
}

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

我的 graphql class 看起来像:

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 方法)中注册了它:

services.AddSingleton<SolDataQuery>();
        services.AddSingleton<SolDataMutation>();
        services.AddSingleton<SeasonEnum>();
        services.AddSingleton<MarsWheatherType>();
        services.AddSingleton<ISchema, SolSchema>();
        

我正在使用 GraphQLPlayground。我的要求是:

wheather {     
 marsSeason}

所有这些之后我有一个错误:

GraphQL.Execution.UnhandledError: Error executing document.\r\n ---> >System.InvalidOperationException: Required service for type >GraphQL.Types.EnumerationGraphType`1[Mars.Season] not found\r\n at >GraphQL.Utilities.ServiceProviderExtensions.GetRequiredService(IServiceProvider provider, Type >serviceType) in /_/src/GraphQL/Utilities/ServiceProviderExtensions.cs:line 42

此错误的代码为“INVALID_OPERATION”

有人可以帮帮我吗?我做错了什么? P.S。如果有帮助,我将这个未完成的项目推送到 github

好的。 MarsWheatherType 的正确代码是:

public class MarsWheatherType : ObjectGraphType<MarsWheather>
{
    public MarsWheatherType()
    {
        Field<SeasonEnum>("season", resolve: w => w.Source.MarsSeason);
    }
}