-
-
Notifications
You must be signed in to change notification settings - Fork 126
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
Improve support for ordering by multiple fields #678
Comments
Wow, your timing is perfect - I was just wondering if we could translate it into a list, too. |
I'm now looking into implementing this. |
Happy to help if the PR becomes quite large.
…On Thu, Dec 19, 2024 at 4:27 PM Take Weiland ***@***.***> wrote:
I'm now looking into implementing this.
—
Reply to this email directly, view it on GitHub
<#678 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ATJ4GLT23DPSEQIPUSW25L32GM25DAVCNFSM6AAAAABT42SEUKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNJVHAYDGMBSHA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Hey @diesieben07 , I am glad that you are willing to try to implement this :) We have discussed this issue before at #615 IMO, instead of I would even change the
What do you think? obs. feel free to ping me on Discord if you need any help with the implementation or to discuss any technical decisions in the code :) Just one more thing:
Actually, since 3.7, the order of python dicts is guaranteed by the language. It used to be like that for CPython only, but now any other implementation must adhere to that rule as well. The issue lies mostly in the conversion of |
That sounds like a good idea, @bellini666! I was already experimenting with adding a
Yes, but also the fact that some languages (other than Python/JavaScript) might not even allow you to modify the order in which things get serialized. I am thinking of more "strictly typed" and "compiled" languages like Kotlin, Java, Swift, .NET, etc. |
I've sent my current work as a draft PR at #679. |
Support a better API for ordering by multiple fields when using
@strawberry_django.order
by allowing it to be generated as a list of orderings.Feature Request Type
Description
As stated in #677 the way
strawberry_django.order
distinguishes "order by name then birthday" vs "order by birthday then name" as follows:vs.
This is problematic, because usually object key order is considered to be not relevant. While object property order is now guaranteed in JavaScript and dict order is guaranteed in Python, this is still far from an ideal API, because usually object key order is considered irrelevant. Creating an object/dict with a required key order and then making sure that order is preserved when being serialized out to JSON can be challenging or might even be impossible in some languages, because the implementations might not preserve the order.
The JSON specification also states that (emphasis mine):
This is also demonstrated by the hoops that the code needs to jump through to even extract this information from the GraphQL Python implementation.
I propose adding an option to
@strawberry_django.order
namedmulti
. If set to true, theorder
parameter would be generated as a list instead, allowing the explicit specification of multiple ordering objects.Upvote & Fund
The text was updated successfully, but these errors were encountered: