[英]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.