【发布时间】:2019-07-07 16:36:54
【问题描述】:
我目前设置了一个简单的查询 (ArticleQuery),其中包括两个字段。第一个字段接受一个 id 并返回适当的数据——这个字段的功能与我期望的一样,并且有效。第二个字段(名为articles)应该返回表中的所有对象,但是当使用GraphiQL 接口发出以下查询时,我将返回一个空字符串。
查询:
query GetArticleData(){
articles {
id
description
}
}
ArticleQuery 如下所示:
public class ArticleQuery : ObjectGraphType
{
public ArticleQuery(IArticleService articleService)
{
Field<ArticleType>(
name: "article",
arguments: new QueryArguments(new QueryArgument<IntGraphType> { Name = "id" }),
resolve: context =>
{
var id = context.GetArgument<int>("id");
return articleService.Get(id);
}
);
Field<ListGraphType<ArticleType>>(
name: "articles",
resolve: context =>
{
return articleService.GetAll();
}
);
}
}
请注意,在 articleService.GetAll() 方法中设置的断点永远不会被命中。
最后,ArticleType 类:
public class ArticleType : ObjectGraphType<ArticleViewModel>
{
public ArticleType()
{
Field(x => x.Id).Description("Id of an article.");
Field(x => x.Description).Description("Description of an article.");
}
}
为什么我的查询返回一个空字符串而不是我的文章列表,我该如何解决这个问题?
【问题讨论】:
标签: asp.net asp.net-core .net-core graphql