在我的 Strapi 项目中,我正在尝试编写一个 Graphql 查询,该查询通过一组标签过滤帖子。 帖子必须属于给定数组的所有标签。 例如。如果给定的数组为 [1,2,3],则下面的帖子将不满足条件,但如果数组为 [3,5],则将通过条件。
任何帮助将不胜感激
示例帖子:
{
"id": "1",
"title": "Lorem Iopsum",
"created_at": "2021-02-19T22:53:19.204Z",
"tags": [
{
"id": "3",
"tag": "Porte De Gentily"
},
{
"id": "5",
"tag": "Bridges"
},
{
"id": "6",
"tag": "Towers"
}
]
}
我正在尝试类似的东西:
query {
posts( where: {tags: {id_contains: [3,1]}}) {
title
tags{id},
created_at
}
}
答案 0 :(得分:0)
你可以这样做
query($ids:[ID]) {
posts( where: {tags: {id:$ids}}) {
title
tags{id},
created_at
}
}
并将您的 ID 作为查询变量传递:
{
"ids": [1,5]
}