Skip to content

Commit 35d7832

Browse files
committed
Simplified filter in types and fields. All tests passing
1 parent b4f7df3 commit 35d7832

File tree

2 files changed

+8
-23
lines changed

2 files changed

+8
-23
lines changed

graphene/contrib/django/fields.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import warnings
22

3-
from .utils import get_type_for_model
3+
from .utils import get_type_for_model, DJANGO_FILTER_INSTALLED
4+
from .filter.fields import DjangoFilterConnectionField
45
from ...core.exceptions import SkipField
56
from ...core.fields import Field
67
from ...core.types.base import FieldType
@@ -20,15 +21,17 @@ def __init__(self, *args, **kwargs):
2021

2122

2223
class ConnectionOrListField(Field):
23-
connection_field_class = ConnectionField
2424

2525
def internal_type(self, schema):
2626
model_field = self.type
2727
field_object_type = model_field.get_object_type(schema)
2828
if not field_object_type:
2929
raise SkipField()
3030
if is_node(field_object_type):
31-
field = self.connection_field_class(field_object_type)
31+
if field_object_type._meta.filter_fields:
32+
field = DjangoFilterConnectionField(field_object_type)
33+
else:
34+
field = ConnectionField(field_object_type)
3235
else:
3336
field = Field(List(field_object_type))
3437
field.contribute_to_class(self.object_type, self.attname)

graphene/contrib/django/types.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,9 @@ def construct_fields(cls):
3030
# We skip this field if we specify only_fields and is not
3131
# in there. Or when we exclude this field in exclude_fields
3232
continue
33-
converted_field = cls.convert_django_field(field)
33+
converted_field = convert_django_field(field)
3434
cls.add_to_class(field.name, converted_field)
3535

36-
def convert_django_field(cls, field):
37-
return convert_django_field(field)
38-
3936
def construct(cls, *args, **kwargs):
4037
cls = super(DjangoObjectTypeMeta, cls).construct(*args, **kwargs)
4138
if not cls._meta.abstract:
@@ -50,15 +47,6 @@ def construct(cls, *args, **kwargs):
5047
return cls
5148

5249

53-
class DjangoFilterObjectTypeMeta(ObjectTypeMeta):
54-
55-
def convert_django_field(cls, field):
56-
from graphene.contrib.django.filter import DjangoFilterConnectionField
57-
field = super(DjangoFilterObjectTypeMeta, cls).convert_django_field(field)
58-
field.connection_field_class = DjangoFilterConnectionField
59-
return field
60-
61-
6250
class InstanceObjectType(ObjectType):
6351

6452
class Meta:
@@ -102,13 +90,7 @@ def from_list(cls, iterable, *args, **kwargs):
10290
return super(DjangoConnection, cls).from_list(iterable, *args, **kwargs)
10391

10492

105-
django_filter_metabase = type
106-
# Only include filter functionality if available
107-
if DJANGO_FILTER_INSTALLED:
108-
django_filter_metabase = DjangoFilterObjectTypeMeta
109-
110-
111-
class DjangoNodeMeta(django_filter_metabase, DjangoObjectTypeMeta, NodeMeta):
93+
class DjangoNodeMeta(DjangoObjectTypeMeta, NodeMeta):
11294
pass
11395

11496

0 commit comments

Comments
 (0)