graphql - 带有过滤/条件渲染的 Strapi Graphql 查询
问题描述
在我的 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
}
}
解决方案
你可以这样做
query($ids:[ID]) {
posts( where: {tags: {id:$ids}}) {
title
tags{id},
created_at
}
}
并将您的 id 作为查询变量传递:
{
"ids": [1,5]
}
推荐阅读
- ios - 如何将此导航项标题向左移动?
- html - 以编程方式从 HTML 中获取文本
- anylogic - AB模型中如何使用vehicle inState命令
- backbone.js - 2014 年创建的主干代码停止工作,我不知道如何更新它
- python - 我想像这样设置我的变量值
- loops - 在剧本中为同一主机上的多个用户设置多个授权密钥
- unix - UNIX 中 IF 语句中的 Fork()
- python-3.x - 使用无头 Chrome 驱动程序截屏无法正常工作
- java - 显示从 InputStream/InputReader 流式传输的数据,同时保留空格
- javascript - 如何将 json 对象从 PHP 转换为 Javascript 数组