-
Notifications
You must be signed in to change notification settings - Fork 47
How to have custom ordering method on gql.django.ordering.order class definition #173
Comments
Hey @insomniac34 . Unfortunatly not yet. The filtering/ordering code is based on the functionality provided by https://github.com/strawberry-graphql/strawberry-graphql-django and it doesn't provide that. I'm actually planning on creating a new ordering functionality to solve not only that issue, but also others that are not so apparent. For example, there's no way for you to choose the order of the orderings when defining more than one |
Thanks for the clarification @bellini666 |
I made a working patch for having ordered order-by clauses, but if @bellini666 has something prepared for this, it will be probably better. If you really need this now @insomniac34, tell me and I’ll post my dirty patch here :-) |
@cpontvieux-systra I did not start working on it yet, I only have what I want in mind and how to execute it =P. But feel free to post your patch here and we can discuss the implementation :) |
My patch is in two steps. First, I patch the
This will add an Then the django field using the order type needs to be patched too (it’s a bigger patch as multiple functions need to be patched):
Then you define your order as usual but use the patched
Then in your query:
Most of this code is already in On better way would also to have sorted I’m also not sure There is also no checking for the values in |
That's an interesting solution, and probably the only way to enforce the requested ordering order currently. What I was thinking was to actually deprecate the current With that I also want to make it easier to define custom resolvers for both ordering and filtering. Currently you have to define a |
Hello!
So, I have a Django model,
Invoice
, which let's say has two fields,id
andamount
, a float.Likewise, I use Strawberry Django Plus to define a custom Filter class for this (yes I know it's not particularly efficient, but it does work):
In the above Filter definition, I am able to define custom filtering logic for the Invoice, and I have access to my custom Django InvoiceManager.
Similarly, I am trying to implement custom sorting logic in my
InvoiceOrder
class, in the same fashion as the above filter snippet; however I can't find any documentation or examples on how to do this. Here is what I have so far, which is failing withcannot resolve keyword 'amount'. Choices are: 'id'.
no matter what I try to return fromorder_amount
.Is there a way for me to define custom sorting logic in a
gql.django.ordering.order
class?thank you!
The text was updated successfully, but these errors were encountered: