eamigo86 / graphene-django-extras

Extras functionalities for Graphene-Django
MIT License
417 stars 108 forks source link

Reverse query is not supported #122

Open grusirna opened 5 years ago

eamigo86 commented 5 years ago

Hi @grusirna, could you provide more info, please?

gghildyal commented 4 years ago

I think he means this (I can open a new issue if that's better). Explained with pseudo code because its usually better.

class Place(model):
   name = CharField()
   country = ForeignKey(Country, related_name='places')
class Country(model):
    name = CharField()

Now defined a countries query as DjangoListObjectField.

A query like this

{
   countries {
       results {
         places {
            name
        }
     }
   }
}

Fails saying PlaceType has no attribute get_queryset. When I defined a places field in the graphql type as a DjangoListObjectField, it does work. So it isn't a big issue.

But the problem there is that the library eagerly loads the place model, so you get duplicate sql queries on the Place model on the above query - Tested by installing nplusone library.

gghildyal commented 4 years ago

Fixed by adding a get_queryset method in DjangoObjectType.