mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-26 19:43:56 +03:00
Filtering options will now be read from the destination node's Meta data
This commit is contained in:
parent
b4b42db73e
commit
3a23c1f940
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue
Block a user