From 9e52d3e0393c9e08fc8730f11c22c8141fa9eba0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Juha=20Yrj=C3=B6l=C3=A4?= <juha.yrjola@iki.fi>
Date: Fri, 20 Dec 2019 18:09:23 +0200
Subject: [PATCH] Fix compatibility with newer django-graphene

Newer versions of django-graphene have resolver functions with the
model class as the first argument. Make QueryOptimizer._get_name_from_resolver()
more robust by looking for the first function argument that is either
a string or another partial function.
---
 graphene_django_optimizer/query.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/graphene_django_optimizer/query.py b/graphene_django_optimizer/query.py
index f671cfb..ad19028 100644
--- a/graphene_django_optimizer/query.py
+++ b/graphene_django_optimizer/query.py
@@ -271,7 +271,15 @@ class QueryOptimizer(object):
         elif isinstance(resolver, functools.partial):
             resolver_fn = resolver
             if resolver_fn.func != default_resolver:
-                resolver_fn = resolver_fn.args[0]
+                # Some resolvers have the partial function as the second
+                # argument.
+                for arg in resolver_fn.args:
+                    if isinstance(arg, (str, functools.partial)):
+                        break
+                else:
+                    # No suitable instances found, default to first arg
+                    arg = resolver_fn.args[0]
+                resolver_fn = arg
             if isinstance(resolver_fn, functools.partial) and resolver_fn.func == default_resolver:
                 return resolver_fn.args[0]
             return resolver_fn
-- 
GitLab