我有一个简单的模式,我试图查询如下:
{
subQuery {
subObjectGraph {
Name
}
}
}
但是“graphiql”会引发以下错误,甚至似乎都没有运行我的查询。
{
"errors": [
{
"message": "Expected non-null value, resolve delegate return null for \"$Api.Schema.Queries.MySubObjectGraphType\"",
"extensions": {
"code": "INVALID_OPERATION"
}
}
]
}
我的架构有什么问题(如下)?我正在新建一个子对象,所以我不明白为什么错误消息暗示该值为空。
public class Schema: GraphQL.Types.Schema
{
public Schema(IDependencyResolver resolver): base(resolver)
{
Query = resolver.Resolve<RootQuery>();
Mutation = null;
}
}
public class RootQuery: ObjectGraphType
{
public RootQuery(IDependencyResolver resolver)
{
Name = "Query";
Field<MySubQuery>(
name: "subQuery",
resolve: ctx => resolver.Resolve<MySubQuery>());
}
}
public class MySubQuery: ObjectGraphType
{
public MySubQuery()
{
Name = "TempSubQuery";
Field<StringGraphType>("SubQueryName", resolve: ctx => "Some string value");
Field<MySubObjectGraphType>(
name: "subObjectGraph",
resolve: ctx => FetchFromRepo());
}
//Repo access would go here, but just new-ing the object for now.
private SubObject FetchFromRepo()
{
return new SubObject() { Name = "some sub object" };
}
}
public class SubObject
{
public string Name { get; set; }
}
public class MySubObjectGraphType: ObjectGraphType<SubObject>
{
public MySubObjectGraphType()
{
Name = "MySubObject";
Description = "An object with leaf nodes";
Field(l => l.Name);
}
}
如果我用 StringGraphType 替换 MySubObjectGraphType 代码可以正常工作,所以问题一定出在 MySubObjectGraphType 的配置上。
请帮忙?我正在使用 v2.4。