From a516c5dc0c9a1da0ea6d430bdba56c9f10e1f765 Mon Sep 17 00:00:00 2001 From: Jonathan Kim Date: Sun, 23 Feb 2020 09:45:11 +0000 Subject: [PATCH] Refactor logic to work with string imports --- graphene_django/fields.py | 21 ++++++++++++--------- graphene_django/tests/test_fields.py | 6 ++++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/graphene_django/fields.py b/graphene_django/fields.py index 388dbf0..fb6b98a 100644 --- a/graphene_django/fields.py +++ b/graphene_django/fields.py @@ -20,20 +20,23 @@ class DjangoListField(Field): if isinstance(_type, NonNull): _type = _type.of_type - if not isinstance(_type, six.string_types): - assert issubclass( - _type, DjangoObjectType - ), "DjangoListField only accepts DjangoObjectType types" - # Django would never return a Set of None vvvvvvv super(DjangoListField, self).__init__(List(NonNull(_type)), *args, **kwargs) + assert issubclass( + self._underlying_type, DjangoObjectType + ), "DjangoListField only accepts DjangoObjectType types" + + @property + def _underlying_type(self): + _type = self._type + while hasattr(_type, "of_type"): + _type = _type.of_type + return _type + @property def model(self): - _type = self.type.of_type - if isinstance(_type, NonNull): - _type = _type.of_type - return _type._meta.model + return self._underlying_type._meta.model @staticmethod def list_resolver(django_object_type, resolver, root, info, **args): diff --git a/graphene_django/tests/test_fields.py b/graphene_django/tests/test_fields.py index 55ccebd..8ea1901 100644 --- a/graphene_django/tests/test_fields.py +++ b/graphene_django/tests/test_fields.py @@ -20,8 +20,10 @@ class TestDjangoListField: list_field = DjangoListField(TestType) def test_only_import_paths(self): - list_field = DjangoListField("graphene_django.tests.models.Reporter") - assert list_field._type.of_type.of_type is ReporterModel + list_field = DjangoListField("graphene_django.tests.schema.Human") + from .schema import Human + + assert list_field._type.of_type.of_type is Human def test_non_null_type(self): class Reporter(DjangoObjectType):