mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-09 08:00:39 +03:00
Simplified filter in types and fields. All tests passing
This commit is contained in:
parent
b4f7df3c9d
commit
35d78320e8
|
@ -1,6 +1,7 @@
|
||||||
import warnings
|
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.exceptions import SkipField
|
||||||
from ...core.fields import Field
|
from ...core.fields import Field
|
||||||
from ...core.types.base import FieldType
|
from ...core.types.base import FieldType
|
||||||
|
@ -20,7 +21,6 @@ class DjangoConnectionField(ConnectionField):
|
||||||
|
|
||||||
|
|
||||||
class ConnectionOrListField(Field):
|
class ConnectionOrListField(Field):
|
||||||
connection_field_class = ConnectionField
|
|
||||||
|
|
||||||
def internal_type(self, schema):
|
def internal_type(self, schema):
|
||||||
model_field = self.type
|
model_field = self.type
|
||||||
|
@ -28,7 +28,10 @@ class ConnectionOrListField(Field):
|
||||||
if not field_object_type:
|
if not field_object_type:
|
||||||
raise SkipField()
|
raise SkipField()
|
||||||
if is_node(field_object_type):
|
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:
|
else:
|
||||||
field = Field(List(field_object_type))
|
field = Field(List(field_object_type))
|
||||||
field.contribute_to_class(self.object_type, self.attname)
|
field.contribute_to_class(self.object_type, self.attname)
|
||||||
|
|
|
@ -30,12 +30,9 @@ class DjangoObjectTypeMeta(ObjectTypeMeta):
|
||||||
# We skip this field if we specify only_fields and is not
|
# We skip this field if we specify only_fields and is not
|
||||||
# in there. Or when we exclude this field in exclude_fields
|
# in there. Or when we exclude this field in exclude_fields
|
||||||
continue
|
continue
|
||||||
converted_field = cls.convert_django_field(field)
|
converted_field = convert_django_field(field)
|
||||||
cls.add_to_class(field.name, converted_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):
|
def construct(cls, *args, **kwargs):
|
||||||
cls = super(DjangoObjectTypeMeta, cls).construct(*args, **kwargs)
|
cls = super(DjangoObjectTypeMeta, cls).construct(*args, **kwargs)
|
||||||
if not cls._meta.abstract:
|
if not cls._meta.abstract:
|
||||||
|
@ -50,15 +47,6 @@ class DjangoObjectTypeMeta(ObjectTypeMeta):
|
||||||
return cls
|
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 InstanceObjectType(ObjectType):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -102,13 +90,7 @@ class DjangoConnection(Connection):
|
||||||
return super(DjangoConnection, cls).from_list(iterable, *args, **kwargs)
|
return super(DjangoConnection, cls).from_list(iterable, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
django_filter_metabase = type
|
class DjangoNodeMeta(DjangoObjectTypeMeta, NodeMeta):
|
||||||
# Only include filter functionality if available
|
|
||||||
if DJANGO_FILTER_INSTALLED:
|
|
||||||
django_filter_metabase = DjangoFilterObjectTypeMeta
|
|
||||||
|
|
||||||
|
|
||||||
class DjangoNodeMeta(django_filter_metabase, DjangoObjectTypeMeta, NodeMeta):
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user