query GetArticleData(){
articles {
id
description
}
}
在哪里?
文章查询
如下所示:
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.");
}
}