我已经在本地安装了strapi-starter-blog,我试图了解如何通过 ID(或 slug)查询文章。当我打开 GraphQL Playground 时,我可以使用以下命令获取所有文章:
query Articles {
articles {
id
title
content
image {
url
}
category {
name
}
}
}
回应是:
{
"data": {
"articles": [
{
"id": "1",
"title": "Thanks for giving this Starter a try!",
"content": "\n# Thanks\n\nWe hope that this starter will make you want to discover Strapi in more details.\n\n## Features\n\n- 2 Content types: Article, Category\n- Permissions set to 'true' for article and category\n- 2 Created Articles\n- 3 Created categories\n- Responsive design using UIkit\n\n## Pages\n\n- \"/\" display every articles\n- \"/article/:id\" display one article\n- \"/category/:id\" display articles depending on the category",
"image": {
"url": "/uploads/blog_header_network_7858ad4701.jpg"
},
"category": {
"name": "news"
}
},
{
"id": "2",
"title": "Enjoy!",
"content": "Have fun!",
"image": {
"url": "/uploads/blog_header_balloon_32675098cf.jpg"
},
"category": {
"name": "trends"
}
}
]
}
}
但是当我尝试使用带有变量的 ID 来获取文章时,就像这里GraphQL Playground 中的github 代码一样,带有以下内容
询问:
query Articles($id: ID!) {
articles(id: $id) {
id
title
content
image {
url
}
category {
name
}
}
}
变量:
{
"id": 1
}
我收到一个错误:
...
"message": "Unknown argument \"id\" on field \"articles\" of type \"Query\"."
...
有什么区别,为什么我不能像 Github repo 的例子那样得到数据。
谢谢你的帮助。