【发布时间】:2020-04-04 08:14:02
【问题描述】:
我有一个包含以下内容的文档:
{
"data": {
"posts": [
{
"id": "5d9f1af799785458ed55fcf3",
"title": "Lorem ipsum dolor sit amet, consectetuer adipiscing eli",
"likedBy": {
"readers": [
"abc",
"xyz",
"mnp"
]
}
},
{
"id": "5d9f2afa9cf1b45a20edaf93",
"title": "Sed ut perspiciatis unde omnis iste natus error sit volupt",
"likedBy": null
},
{
"id": "5d9f2d1cd12ce45b11e90920",
"title": "But I must explain to you how all this mistaken idea of deno",
"likedBy": null
}
]
}
}
在这里,我有一个字段likedBy,它是一个以数组为值的对象。
现在,我可以运行以下查询来检索所有文档:
{
posts{
id
title
likedBy
}
}
但是,有没有办法在查询级别过滤掉数组的特定值?例如,假设我希望我的输出如下所示:
{
"data": {
"posts": [
{
"id": "5d9f1af799785458ed55fcf3",
"title": "Lorem ipsum dolor sit amet, consectetuer adipiscing eli",
"likedBy": {
"readers": [
"abc",
]
}
},
{
"id": "5d9f2afa9cf1b45a20edaf93",
"title": "Sed ut perspiciatis unde omnis iste natus error sit volupt",
"likedBy": null
},
{
"id": "5d9f2d1cd12ce45b11e90920",
"title": "But I must explain to you how all this mistaken idea of deno",
"likedBy": null
}
]
}
}
在这里,我像以前一样返回了所有文档,除了likedBy 数组中只有abc。 GraphQL 可以做到吗?
【问题讨论】:
标签: graphql apollo-client