如何从Prisma/GraphQL查询中只获取过滤后的数据



我有两组数据(用户事件(,具有多对多关系。我正在使用以下查询来检索和筛选数据。

{
events(
where: {
AND: [
{ location: { name: "Test" } }
{
time: {
startDate_lt: "2018-12-03T13:46:13.021Z"
endDate_gt: "2018-12-03T13:46:13.021Z"
}
}
{
participantList_some: {
participant: { firstName: "Lorem", lastName: "Ipsum" }
}
}
]
}
) {
participantList {
participant {
firstName
lastName
}
}
location {
name
}
}
}

到目前为止还不错,我得到了以下结果:

{
"data": {
"events": [
{
"participantList": [
{
"participant": {
"firstName": "Chuck",
"lastName": "Norris"
}
},
{
"participant": {
"firstName": "Lorem",
"lastName": "Ipsum"
}
}
],
"location": {
"name": "Test"
}
}
]
}
}

我想要的是只得到我过滤过的参与者,即"Lorem Ipsum"。通过这种方式,我得到了该活动的所有(2(名参与者。所以我想要的结果是:

{
"data": {
"events": [
{
"participantList": [
{
"participant": {
"firstName": "Lorem",
"lastName": "Ipsum"
}
}
],
"location": {
"name": "Test"
}
}
]
}
}

目前我正在从代码中过滤掉不需要的数据。我已经搜索了如何或是否可以使用查询或其他参数来完成这项工作,但没有找到有用的东西。感谢任何帮助或指导。

您可以向请求的任何字段添加筛选器。这意味着你可以过滤你发现的事件中的参与者:

{
events(
where: {
AND: [
{ location: { name: "Test" } }
{
time: {
startDate_lt: "2018-12-03T13:46:13.021Z"
endDate_gt: "2018-12-03T13:46:13.021Z"
}
}
{
participantList_some: {
participant: { firstName: "Lorem", lastName: "Ipsum" }
}
}
]
}
) {
participantList (where: { participant: { firstName: "Lorem", lastName: "Ipsum" } }) {
participant {
firstName
lastName
}
}
location {
name
}
}
}

最新更新