Skip to content

Commit 3a23c1f

Browse files
committed
Filtering options will now be read from the destination node's Meta data
1 parent b4b42db commit 3a23c1f

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

graphene/contrib/django/filter/resolvers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class FilterConnectionResolver(BaseQuerySetConnectionResolver):
1010
def __init__(self, node, on=None, filterset_class=None,
1111
fields=None, order_by=None, extra_filter_meta=None):
1212
self.filterset_class = filterset_class
13-
self.fields = fields
14-
self.order_by = order_by
13+
self.fields = fields or node._meta.filter_fields
14+
self.order_by = order_by or node._meta.filter_order_by
1515
self.extra_filter_meta = extra_filter_meta or {}
1616
self._filterset_class = None
1717
super(FilterConnectionResolver, self).__init__(node, on)

graphene/contrib/django/options.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from ...relay.types import Node
33
from ...relay.utils import is_node
44

5-
VALID_ATTRS = ('model', 'only_fields', 'exclude_fields')
5+
VALID_ATTRS = ('model', 'only_fields', 'exclude_fields',
6+
'filter_fields', 'filter_order_by')
67

78

89
class DjangoOptions(ObjectTypeOptions):
@@ -13,6 +14,8 @@ def __init__(self, *args, **kwargs):
1314
self.valid_attrs += VALID_ATTRS
1415
self.only_fields = None
1516
self.exclude_fields = []
17+
self.filter_fields = None
18+
self.filter_order_by = None
1619

1720
def contribute_to_class(self, cls, name):
1821
super(DjangoOptions, self).contribute_to_class(cls, name)

graphene/contrib/django/tests/filter/test_fields.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,18 @@ def test_filter_shortcut_filterset_extra_meta():
112112
assert_orderable(field)
113113

114114

115+
def test_filter_filterset_information_on_meta():
116+
class ReporterFilterNode(DjangoNode):
117+
class Meta:
118+
model = Reporter
119+
filter_fields = ['first_name', 'articles']
120+
filter_order_by = True
121+
122+
field = DjangoFilterConnectionField(ReporterFilterNode)
123+
assert_arguments(field, 'firstName', 'articles')
124+
assert_orderable(field)
125+
126+
115127
def test_global_id_field_implicit():
116128
field = DjangoFilterConnectionField(ArticleNode, fields=['id'])
117129
filterset_class = field.resolver_fn.get_filterset_class()

0 commit comments

Comments
 (0)