Is it possible in Prisma to give the client the ch...
# orm-help
a
Is it possible in Prisma to give the client the choice on what data Prisma should query? I’m using Prisma with Apollo and I want to give my user the option to filter the content however he likes. The problem is I cannot write thousands of query resolvers for every possible combination the user selects in his filters. For example I want to give the user the option to query all users with age > 20, profile picture = yes, location = Germany etc. And another user queries for the same but additionally where isActive = true. In this case as far as I understood it correctly I have to write two queries: example 1:
query1: (parent, args) => {
return prisma.users.findMany({
where: {
age: {
gte: 20
},
profilepicture: true,
location: 'Germany'
}
})
}
and because the second user wants the same query but also wants to know if the person is active I have to create a complete new query for this case? example2:
query2: (parent, args) => {
return prisma.users.findMany({
where: {
age: {
gte: 20
},
profilepicture: true,
location: 'Germany',
isActive: true
}
})
},
P.s I’m pretty new to Prisma, I’m sorry if there is an obvious solution to it. Just couldn’t find anything in the docs on first glance
h
Hey, @Aaron Waller you can build a “filter payload” and according to the user desires, make a Prisma query.
Copy code
singleQuery: (parent, args) => {
    return prisma.users.findMany({
        where: args.filters
    })
}
a
@Hector Grecco Thank you, is there any resources on that on the internet? I don’t know how to build such a filter payload