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

How to get only the filtered data from Prisma / GraphQL query

我有 2 组数据(usersevents ) 多对多关系。 我正在使用以下查询来检索和过滤数据。

{
  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
    }
  }
}