我试图用枚举创建类,但我有一个错误。
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}
在这一切之后,我有一个错误:
执行文档时出错\r\n
此错误的代码为"INVALID_OPERATION“。
有人能帮帮我吗?我做错什么了?如果有帮助的话,我把这个还没完成的项目推到github上
发布于 2021-03-29 10:58:37
好的。MarsWheatherType的正确代码是:
public class MarsWheatherType : ObjectGraphType<MarsWheather>
{
public MarsWheatherType()
{
Field<SeasonEnum>("season", resolve: w => w.Source.MarsSeason);
}
}https://stackoverflow.com/questions/66815481
复制相似问题