Skip to content
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

sorting on nested fields not working #20

Closed
nyejon opened this issue Jul 3, 2020 · 5 comments
Closed

sorting on nested fields not working #20

nyejon opened this issue Jul 3, 2020 · 5 comments

Comments

@nyejon
Copy link
Contributor

nyejon commented Jul 3, 2020

Hi,

I followed the instructions to set up the nested filters. They seem to work, but the sorting does not.

Are there additional steps required to get the sorting to work?

Thanks!

Jonathan

@art1415926535
Copy link
Owner

What is your environment?

  • SQLAlchemy version
  • Database

Try to give a minimal example if possible.

@nyejon
Copy link
Contributor Author

nyejon commented Jul 4, 2020

Hey,

I'm on:

graphene-sqlalchemy = "^2.3.0"
graphene-sqlalchemy-filter = "^1.11.0"

Using Azure SQL (MSSQL)

A functioning example will be hard to copy, but I will copy some snippets:

The graphQL query is as follows:

query countries {
  locations(sort: TITLE_ASC, filters: {live: true}) {
    edges {
      node {
        title
        guides(sort: TITLE_ASC) {
          edges {
            node {
              title
            }
          }
        }
      }
    }
  }
}


class LocationFilter(FilterSet):

    class Meta:
        model = Location
        fields = {
            "name": ["eq"],
            "live": ["eq"],
            "slug": ["eq"],
        }

class GuideFilter(FilterSet):

    class Meta:
        model = Guide
        fields = {
            "name": ["eq"],
            "live": ["eq"],
            "slug": ["eq"],
            "title": [...],
        }

class CustomFilterableConnection(FilterableConnectionField):
    filters = {
        Guide: GuideFilter(),
        Location: LocationFilter(),
    }

class GuideNode(SQLAlchemyObjectType):
    class Meta:
        model = Guide
        interfaces = (relay.Node,)
        batching = True
        connection_field_factory = CustomFilterableConnection.factory


class LocationNode(SQLAlchemyObjectType):
    class Meta:
        model = Location
        interfaces = (relay.Node,)
        batching = True
        connection_field_factory = CustomFilterableConnection.factory

class LocationConnection(Connection):
    class Meta:
        node = LocationNode


class GuideConnection(Connection):
    class Meta:
        node = GuideNode

class Query(graphene.ObjectType):
    locations = CustomFilterableConnection(LocationConnection)

I can filter on the guides level no problem, only the sort does not work. Please let me know if I can provide any additional detail.

@art1415926535
Copy link
Owner

art1415926535 commented Jul 6, 2020

I do not use MSSQL. In Sqlite and Postgresql, sorting works. I think the problem is that sql ORDER BY is placed in a subquery.

I fixed potential bug in new brunch. Can you test with MSSQL?
You need to add the following line to requiremets.txt

-e git: //github.com/art1415926535/graphene-sqlalchemy-filter.git@4bebe8d9b5098d933f7211f62d637516d9902eeb#egg=graphene_sqlalchemy_filter

@nyejon
Copy link
Contributor Author

nyejon commented Jul 7, 2020

This looks great! I gave it a quick test and it seems to be working exactly as expected now! Thank you :)

@art1415926535
Copy link
Owner

Released!

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

No branches or pull requests

2 participants