diff --git a/graphene/contrib/django/fields.py b/graphene/contrib/django/fields.py index 76a85580..f33cd77e 100644 --- a/graphene/contrib/django/fields.py +++ b/graphene/contrib/django/fields.py @@ -1,6 +1,7 @@ import warnings -from .utils import get_type_for_model +from .utils import get_type_for_model, DJANGO_FILTER_INSTALLED +from .filter.fields import DjangoFilterConnectionField from ...core.exceptions import SkipField from ...core.fields import Field from ...core.types.base import FieldType @@ -20,7 +21,6 @@ class DjangoConnectionField(ConnectionField): class ConnectionOrListField(Field): - connection_field_class = ConnectionField def internal_type(self, schema): model_field = self.type @@ -28,7 +28,10 @@ class ConnectionOrListField(Field): if not field_object_type: raise SkipField() if is_node(field_object_type): - field = self.connection_field_class(field_object_type) + if field_object_type._meta.filter_fields: + field = DjangoFilterConnectionField(field_object_type) + else: + field = ConnectionField(field_object_type) else: field = Field(List(field_object_type)) field.contribute_to_class(self.object_type, self.attname) diff --git a/graphene/contrib/django/types.py b/graphene/contrib/django/types.py index d8fc1b86..b961ceed 100644 --- a/graphene/contrib/django/types.py +++ b/graphene/contrib/django/types.py @@ -30,12 +30,9 @@ class DjangoObjectTypeMeta(ObjectTypeMeta): # We skip this field if we specify only_fields and is not # in there. Or when we exclude this field in exclude_fields continue - converted_field = cls.convert_django_field(field) + converted_field = convert_django_field(field) cls.add_to_class(field.name, converted_field) - def convert_django_field(cls, field): - return convert_django_field(field) - def construct(cls, *args, **kwargs): cls = super(DjangoObjectTypeMeta, cls).construct(*args, **kwargs) if not cls._meta.abstract: @@ -50,15 +47,6 @@ class DjangoObjectTypeMeta(ObjectTypeMeta): return cls -class DjangoFilterObjectTypeMeta(ObjectTypeMeta): - - def convert_django_field(cls, field): - from graphene.contrib.django.filter import DjangoFilterConnectionField - field = super(DjangoFilterObjectTypeMeta, cls).convert_django_field(field) - field.connection_field_class = DjangoFilterConnectionField - return field - - class InstanceObjectType(ObjectType): class Meta: @@ -102,13 +90,7 @@ class DjangoConnection(Connection): return super(DjangoConnection, cls).from_list(iterable, *args, **kwargs) -django_filter_metabase = type -# Only include filter functionality if available -if DJANGO_FILTER_INSTALLED: - django_filter_metabase = DjangoFilterObjectTypeMeta - - -class DjangoNodeMeta(django_filter_metabase, DjangoObjectTypeMeta, NodeMeta): +class DjangoNodeMeta(DjangoObjectTypeMeta, NodeMeta): pass