c# - GraphQL.Types.EnumerationGraphType 出错
问题描述
我正在尝试使用枚举创建类,但出现错误。
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);
}
}
推荐阅读
- apache-spark - Spark SQL 中使用的嵌套 java bean
- deployment - 在 JBOSS EAP 7.1 中,如何将 EJB 和 undertow 的统计启用设置为 True?
- c# - 如何在 web.config 中使用 url 重写重定向?
- haskell - 不是逆变/逆变/可分/可判定的好例子?
- visual-studio - 修复退出代码 -2147024891 JetBrains ResharperTestRunner 无法启动
- ruby-on-rails - 将对象导出到当前内联显示数据的 csv 文件
- xslt-2.0 - 无法在 XSLT 中使用 group by 对元素值进行分组
- c# - 如何更新用户的管理器?
- html - 时刻未设置为时间类型
- python - Python:将变量发送到另一个脚本而不运行