From a1ba60b9e0d28a49e40d1da7cf5a6d2136e307c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juha=20Yrj=C3=B6l=C3=A4?= Date: Fri, 20 Dec 2019 18:08:49 +0200 Subject: [PATCH 1/2] Update graphene and django-graphene testing requirements to newer versions --- dev-env-requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev-env-requirements.txt b/dev-env-requirements.txt index eb1b2ac..2ad8363 100644 --- a/dev-env-requirements.txt +++ b/dev-env-requirements.txt @@ -1,6 +1,6 @@ -r requirements.txt -graphene==2.1.3 -graphene-django==2.2.0 +graphene==2.1.8 +graphene-django==2.7.1 pytest==4.6.3 pytest-django==3.5.0 pytest-cov==2.7.1 From 9e52d3e0393c9e08fc8730f11c22c8141fa9eba0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juha=20Yrj=C3=B6l=C3=A4?= Date: Fri, 20 Dec 2019 18:09:23 +0200 Subject: [PATCH 2/2] 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 @@ def _get_name_from_resolver(self, resolver): 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