簡體   English   中英

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 類看起來像:

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: 執行文檔時出錯。\r\n ---> >System.InvalidOperationException: 在 >GraphQL 中找不到類型 >GraphQL.Types.EnumerationGraphType`1[Mars.Season] 所需的服務\r\n。 Utilities.ServiceProviderExtensions.GetRequiredService(IServiceProvider provider, Type >serviceType) in /_/src/GraphQL/Utilities/ServiceProviderExtensions.cs:line 42

此錯誤的代碼為“INVALID_OPERATION”

有人可以幫我嗎? 我做錯了什么? PS 如果有幫助,我將這個未完成的項目推送到 github

好的。 MarsWheatherType 的正確代碼是:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM