Skip to content

Convert orderBy value to snake case - #238

Merged
syrusakbary merged 1 commit into
graphql-python:masterfrom
jkimbo:order_by_camelcase
Aug 6, 2016
Merged

syrusakbary merged 1 commit into
graphql-python:masterfrom
jkimbo:order_by_camelcase

Conversation

@jkimbo

@jkimbo jkimbo commented Aug 4, 2016

Copy link
Copy Markdown
Member

I came across then when trying to use orderBy on the DjangoFilterConnectionField and found I had to use the snake case version of the field name for it to actually filter values when I would have expected to be able to use the camel case version. This PR allows you to use camel case for the field name in orderBy.

Not sure if this breaks any current assumptions but the tests seem to pass!

@coveralls

coveralls commented Aug 4, 2016 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.06%) to 96.207% when pulling 05a9078 on jkimbo:order_by_camelcase into bd1fbb6 on graphql-python:master.

@syrusakbary
syrusakbary merged commit b8a9e45 into graphql-python:master Aug 6, 2016
order = self.get_order(args)
if order:
qs = qs.order_by(order)
qs = qs.order_by(to_snake_case(order))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should get_order which is the function designed to handle the API level (args) to the to_snake_case so it would "own" the API layer and let get_queryset deal with qs level things? (separation of concerns / layering).

@slorg1 slorg1 Aug 19, 2016 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other question: what if order is a list? https://docs.djangoproject.com/en/1.10/ref/models/querysets/#django.db.models.query.QuerySet.order_by

To do multi field ordering (in your test order_by('first_name', 'articles'))

django_filters.filterset.BaseFilterSet

qs = qs.order_by(*self.get_order_by(ordered_value))

would handle it, though (since I do not need a nice patch from you for this one) it would not handle the nice to_snake_case you added.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slorg1 you're probably right about moving the snake case translation into get_order as that is probably cleaner. I also don't think graphene currently supports ordering by multiple fields. Possibly raise that as a separate issue/PR with a failing test case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants