如何仅从Prisma/GraphQL查询中获取过滤后的数据
我有两组多对多关系的数据(用户和事件)。 我使用以下查询来检索和过滤数据如何仅从Prisma/GraphQL查询中获取过滤后的数据,graphql,prisma,Graphql,Prisma,我有两组多对多关系的数据(用户和事件)。 我使用以下查询来检索和过滤数据 { events( where: { AND: [ { location: { name: "Test" } } { time: { startDate_lt: "2018-12-03T13:46:13.021Z" endDate_gt: "2018-12-03T13:46:13.021Z"
{
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
}
}
}
谢谢@Errorname的回答,但是我在添加where语句时遇到了一个错误。它说,
“不能为不可为null的类型返回null(第4行第7列):\n参与者(其中:{firstName:\'Lorem\',lastName:\'Ipsum\')
.Oh.这似乎与您的模式冲突。您能提供模式的相关部分吗?它实际上是通过在participantList
级别添加where条件来工作的,如下所示:participantList(where:{participant:{firstName:{Lorem,lastName:'Ipsum})