Open loganswartz opened 8 months ago
get all orders that have line items matching a certain filter
Probably you can look on my @searchBy
directive.
Select all
orders
which havelineItems
withid = xxx
orders(where: { lineItems: { where: { id: { equal: "xxx" } } } }) {
id
lineItems { ... }
}
What problem does this feature proposal attempt to solve?
It'd be really useful to have a directive equivalent of
whereHas
, to limit the result set of a query based on some restrictions on a nested field. I have a schema set up something like this:I have a report that is essentially "get all orders that have line items matching a certain filter". What I'd ideally like to be able to do is something like this:
And then on the server side, I'm imagining something like this:
To be clear, this isn't a simple scope or
@where
on the relation. What I'm after is for the hypothetical@has
directive to take all the filters applied to the relationhas
(in this example,lineItems
), and modify the top-level query to add awhereHas
with the same set of constraints on that relation:That way, any orders that don't have any line items matching the filter would be omitted from the final result set, and all the orders returned would have at least 1 matching line item.
Which possible solutions should be considered?
I looked at
@whereHasConditions
, but it really only lets you filter based on concrete columns, not any arbitrary conditions created by other directives.I've also considered inverting this query, AKA querying
lineItems
and just getting theorder
field off of that, but then to get a list of orders, I need to flatMap the orders out, and re-match-up the line items, and it's just a bit of a pain for something that feels like it should be doable in GQL.