insolite / graphene-peewee-async

Graphene peewee-async integration
37 stars 9 forks source link

Back reference filter #10

Open art1415926535 opened 6 years ago

art1415926535 commented 6 years ago

What need to do for allow query like this

query {
    authors (filters: {book_set__name: "bar1"}){
        edges {
            node {
                id
                name
                book_set {
                    edges {
                        node {
                            id
                            name
                        }
                    }
                }
            }
        }
    }
}

I get the following error

GraphQLLocatedError('missing FROM-clause entry for table "t3"\nLINE 1: ..."t1"."id", "t1"."name" FROM "author" AS t1 WHERE ("t3"."name...\n                                                             ^\n',)
insolite commented 6 years ago

Unfortunately there's no way to filter parent query by subset's fields at the moment. At the same time as for me it's still quite undefined behavior. Here we have several options we might want to achieve (maybe even more):

However since now subsets are resolved as separate queries, there's an implementation possibility:

query {
    authors {
        edges {
            node {
                id
                name
                book_set (filters: {name: "bar1"}) {
                    edges {
                        node {
                            id
                            name
                        }
                    }
                }
            }
        }
    }
}

Thus we have separated filter for subsets. I've already implemented this so I'll push it soon.

It's still without filtering parent query though. I'm thinking about some kind of subset characteristics lookup like author (book_set__count__gt: 0) but yet, can't figure out how to implement it.

insolite commented 6 years ago

Subset filtering case is ready in b237d4985459c686c71814905b5ee2153d0d42f9, released to 2.2.0

https://github.com/insolite/graphene-peewee-async/blob/b237d4985459c686c71814905b5ee2153d0d42f9/tests/test_api/test_query.py#L101-L122

insolite commented 6 years ago

BTW, I nearly accidentally fixed sync queries necessity at subset fetching :grinning:. So now it's safe to use db.set_allow_sync(False) along with _set fields.

art1415926535 commented 6 years ago

I think Django's style will be better

authors with at least one book with certain name, but selecting all books as a subset

This option will cover most different uses with a separate filter for subsets.