Filter Query with multiple parameters

What is the recommend approach when creating a query that needs to filter based on some conditions which may or may not exist (if the user doesn't specify them we should ignore the filter rule) while using prisma? Something like /posts?category=a&tag=b Should filter posts with a category and tag b
5 Replies
r.omaarr
r.omaarrOP3y ago
But /posts?category=foo should show all posts that have foo category and any tag
Lopen
Lopen3y ago
You can use mutation and pass in the query
r.omaarr
r.omaarrOP3y ago
Do i need to create a case for each combination of filter parameters and use the specific trpc route for that particular combination or how do i deal with empty params in the WHERE field where: { tag='' }, would be in the second case, wouldn't that try to find all posts that have an empty string as a tag?
Leonidas
Leonidas3y ago
Provide the dependency (the category) as a dependency to react query☝🏼
Leonidas
Leonidas3y ago
Dependent Queries | TanStack Query Docs
Dependent (or serial) queries depend on previous ones to finish before they can execute. To achieve this, it's as easy as using the enabled option to tell a query when it is ready to run: `tsx
Want results from more Discord servers?
Add your server