In a prisma binding how can I pass a filter to a r...
# orm-help
j
In a prisma binding how can I pass a filter to a relation? This query works in the playground:
Copy code
query {
  groups {
      id
      name
      users(where:{
        location: {
          id: "cjh5xorfq000c0824kmvjjd63"
        }
      }) {
        id
      }
    }
}
But I dont know how to pass the location filter to the users relation in my resolver:
Copy code
groups(parent, args, ctx, info) {
  const {location} = args;
  return ctx.db.query.groups({}, info);
},
t
I've also encountered this. I guess we have to use the
request
method with the full query.
c
You can use almost the exact same syntax:
Copy code
return ctx.db.query.groups({ where: { location: { id: "id-string" } } }, info)
t
@Corjen That does not answer the question. He's querying groups.users.location.
c
How is this not answering the question? If you would query the groups you would do
ctx.db.query.groups({where: { id: "group-id" }})
j
@Corjen I need to return all the groups (no filtering), and for each group return the users who also have a relationship to a specific location. I think you’ve misunderstood my requirements?
c
Ah, yes I misunderstood 😅 Still early in the morning here 😄
This should probably work:
Copy code
return ctx.db.query.groups({ where: {} }, `{
      id
      name
      users(where:{
        location: {
          id: ${location}
        }
      }) {
        id
      }
    }`)
j
You have to put strings around the location var but it does work, thanks!
Copy code
return ctx.db.query.groups(
      {},
      `
        {
          id
          name
          users(
              where: {
                location: {
                  id: "${location}"
                }
              }
            ) {
            id
          }
        }
      `,
    );
c
Cool! 😄