tfoxy / graphene-django-optimizer

Optimize database access inside graphene queries

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

If two different resolvers of a DjangoObjectType have hints with the same value in to_attr arg of Prefetch, Django raises an exception

felixmeziere opened this issue · comments

If two different resolvers of a DjangoObjectType have hints with the same value in to_attr of Prefetch, then Django will raise an exception ("Lookup was already seen with a different queryset" from django.db.models.query.prefetch_related_objects).

What we would like instead is that graphene-django-optimizer lets us add those two hints but makes sure that, if both resolvers are needed in a query, it only adds the "common hint" once (therefore not leading to a duplicate prefetch that will raise an error).

The benefit of this is that we would be able to add duplicate hints where we want, to make sure the hints are triggered even when one of the fields is queried and not the other, while also allowing for both fields being queried together without duplicate prefetches nor exceptions being risen.

This PR solves the problem #76