-
Notifications
You must be signed in to change notification settings - Fork 222
Add support for more complex orderBy statements #138
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
Comments
Ah yes just as |
This would be wonderful if you could implement such a thing! Support custom SQL functions like length, sum, ascii or what ever function databases support etc... orderBy: { |
Any progress on this? This would be a great feature. |
I was able to resolve the same problem in a pretty 'hacky' way. Join Monster actually accepts any string as a "field name" in the OrderBy array and does not check whether it is an actual field or not, so this means we can craft a long order by list in one single field. The one caveat is that the string must START and END with a real field name. This is because Join Monster prepends the first part of the string with table. and then appends ASC (or whatever direction is set) at the end. Usually there is at least 1 or 2 fields that you can order by first/last which don't really affect the outcome - like say a status field, so we can do something like this (this was my exact example and it works great):
Notice where the back-ticks are to complete the full order-by string. Think of it like SQL injection 😄 The resulting query:
Hopefully a more functional OrderBy feature will come soon anyway but this for now works fine. |
That would be indeed great, I have the same issue currently with jsonb support, basically it should be possible to pass fields that are expressions, like "table"."field"->'jsonfield' |
I'd love to be able to do something similar to
where
functions, where I can construct my own complexorderBy
.The problem is that right now if I want to do something as simple as:
ORDER BY -`table`.`field` DESC
I can't see a way to do this with JM without explicitly defining the field on the schema, and using
alwaysFetch
.In the app I'm working on (we're converting an old code base to GraphQL), we default to natural ordering, but also allow users to explicitly order items, which means the sort field is usually null, unless it's explicitly set to a number (with 0 being the highest sort priority).
In MySQL, null comes before values in an ASC sort, and goes after values in a DESC sort.
So to achieve the desired functionality I need a DESC sort on the field, but this will sort with higher numbers being a higher sort priority.
This can be fixed by the above order by, with a
-
in front of it. But as stated this is unsupported in JM.The text was updated successfully, but these errors were encountered: