How would one apply a filter only if a variable is...
# prisma-whats-new
w
How would one apply a filter only if a variable is not null ? For example
Copy code
allItems(filter: {
    OR: [{ price_gte: 50 }, { location: { placeId: $placeId } } ]
})
I want to apply the location filter only if
$placeId
has a value
d
I'm new so I might be wrong. I think you can do something like locations_none: { placeId: null }. I think if you play around in the playground you can find something like that will work.
w
@dardub I think the
_none
thing exists only for array 😞
my location is a to one relation
d
hmm.. sorry I'm not sure. I would post on the forum.
w
np, thanks for helping 😄
d
You can pass the entire filter into the query as a variable, then you can use some logic to decide what filter to use.
w
Thanks, this is very useful. I used the type ItemFilter for the
$filter
variable, works like a charm