diff --git a/graphene/contrib/django/filter/resolvers.py b/graphene/contrib/django/filter/resolvers.py index 5f696a08..c2204d6c 100644 --- a/graphene/contrib/django/filter/resolvers.py +++ b/graphene/contrib/django/filter/resolvers.py @@ -10,8 +10,8 @@ class FilterConnectionResolver(BaseQuerySetConnectionResolver): def __init__(self, node, on=None, filterset_class=None, fields=None, order_by=None, extra_filter_meta=None): self.filterset_class = filterset_class - self.fields = fields - self.order_by = order_by + self.fields = fields or node._meta.filter_fields + self.order_by = order_by or node._meta.filter_order_by self.extra_filter_meta = extra_filter_meta or {} self._filterset_class = None super(FilterConnectionResolver, self).__init__(node, on) diff --git a/graphene/contrib/django/options.py b/graphene/contrib/django/options.py index 61dd37a3..f8c08e38 100644 --- a/graphene/contrib/django/options.py +++ b/graphene/contrib/django/options.py @@ -2,7 +2,8 @@ from ...core.classtypes.objecttype import ObjectTypeOptions from ...relay.types import Node from ...relay.utils import is_node -VALID_ATTRS = ('model', 'only_fields', 'exclude_fields') +VALID_ATTRS = ('model', 'only_fields', 'exclude_fields', + 'filter_fields', 'filter_order_by') class DjangoOptions(ObjectTypeOptions): @@ -13,6 +14,8 @@ class DjangoOptions(ObjectTypeOptions): self.valid_attrs += VALID_ATTRS self.only_fields = None self.exclude_fields = [] + self.filter_fields = None + self.filter_order_by = None def contribute_to_class(self, cls, name): super(DjangoOptions, self).contribute_to_class(cls, name) diff --git a/graphene/contrib/django/tests/filter/test_fields.py b/graphene/contrib/django/tests/filter/test_fields.py index d33b8d32..127b0588 100644 --- a/graphene/contrib/django/tests/filter/test_fields.py +++ b/graphene/contrib/django/tests/filter/test_fields.py @@ -112,6 +112,18 @@ def test_filter_shortcut_filterset_extra_meta(): assert_orderable(field) +def test_filter_filterset_information_on_meta(): + class ReporterFilterNode(DjangoNode): + class Meta: + model = Reporter + filter_fields = ['first_name', 'articles'] + filter_order_by = True + + field = DjangoFilterConnectionField(ReporterFilterNode) + assert_arguments(field, 'firstName', 'articles') + assert_orderable(field) + + def test_global_id_field_implicit(): field = DjangoFilterConnectionField(ArticleNode, fields=['id']) filterset_class = field.resolver_fn.get_filterset_class()