-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add back _on filters or provide a way to sort unions #4825
Comments
Hi @michaeldaudiolo! Thanks for this issue. We may have been overzealous in our removal of |
Hi @darrellwarde, thanks for the reply! Since you don't plan to just add |
I would love to hear more about this use case. Would it be possible for you to give an example of a union which you might sort (especially if they have no common fields), and give an idea of what you would expect the sorting result to be? Struggling to think of a situation where the result would be a mixture of all of the different types in the union! |
Admittedly It's been hard for me to think of a simple example too. But you could have something like this:
Every type has a It could be nice to be able to get shipments for a center sorted by We have a similar situation in our schema with three different implementations of the same interface where the separation between them makes sense, and there's varying degrees of overlap between them. Maybe I only want to see boxes and pouches with specific tracking numbers along with all envelopes, that's where we would use |
Hi @michaeldaudiolo, thanks for providing that example. Honestly, it really sounds like
Just some ideas. We've discussed the idea of adding sorting back in for union types, but have come to the conclusion that it doesn't really make sense. You can't accurately paginate over unions, and adding sorting would make this even less predictable. We won't be adding We appreciate the feedback, and hopefully a workaround with interfaces works for you! |
Just to clarify, are you saying the design work in this previous comment isn't planned anymore? If that's the case, essentially if I want sorting I have to use an interface and if I want accurate filtering across types I have to use a union going forward?
I'm sorry this doesn't really make sense to me. Isn't sorting usually the solution to unpredictable pagination? Especially if the sorting is done after the |
To clarify this, if I want to do what I mentioned here:
With your suggestion here:
It would be something like: query DistroCenters($where: ShipmentWhere) {
distroCenters {
shipments(where: $where) {
tracking
weight
__typename
}
}
}
Which is not the same as
Because going forward it'll return Boxes and Pouches that are null too, instead of only Boxes and Pouches that match tracking numbers 1 or 2. So if I want that kind of filtering I have to use unions, but if I want any kind of sorting I have to use interfaces? |
Sorry for the late reply, when we removed the query DistroCenters {
distroCenters {
shipments(
where: { AND: [{ tracking_IN: ["1", "2"] }, { typename_IN: [Box, Pouch] }] }
) {
tracking
weight
__typename
}
}
} |
Hi @MacondoExpress, thanks for your reply! Unfortunately that still wouldn't satisfy the "along with all envelopes" part of the condition.
Basically, before v5 we have been using interfaces and relied on It seems like after v5 you have to either choose complex filtering or sorting but you can never do both, since interfaces don't support |
Hi @michaeldaudiolo! query DistroCenters {
distroCenters {
shipments(
where: {
OR: [
{ typename_IN: [Envelope] }
{ AND: [{ tracking_IN: ["1", "2"] }, { typename_IN: [Box, Pouch] }] }
]
}
) {
tracking
weight
__typename
}
}
} |
Yes that one would work for that case, thank you! It does still feel a little bad to have to add any fields we might want to filter or sort on to the interface and just make them null for types that really shouldn't have those fields. It feels like a work around that muddies the schema, not a clean solution. I agree with the issues raised about that in #5213. I think this library is amazing and I genuinely really appreciate the work you all put into it regardless though! |
We've been using _on filters with interfaces to filter on specific fields of implementing types, while also being able to sort based on common fields across the implementing types. With version 5.0.0 that's no longer possible, since unions can't be sorted.
I don't understand why _on filters were removed but I'm sure there's a good reason. Could support for sorting with unions be added instead? If so, could _on be deprecated instead of outright removed until that's done?
The text was updated successfully, but these errors were encountered: