diff --git a/graphene_django/filter/tests/test_fields.py b/graphene_django/filter/tests/test_fields.py index 274f6ac..17b4630 100644 --- a/graphene_django/filter/tests/test_fields.py +++ b/graphene_django/filter/tests/test_fields.py @@ -16,7 +16,7 @@ pytestmark = [] if DJANGO_FILTER_INSTALLED: import django_filters - from django_filters import FilterSet, NumberFilter + from django_filters import FilterSet, NumberFilter, OrderingFilter from graphene_django.filter import ( GlobalIDFilter, @@ -1275,3 +1275,22 @@ def test_filter_string_contains(): assert result.data == { "people": {"edges": [{"node": {"name": "Joe"}}, {"node": {"name": "Bob"}},]} } + + +def test_only_custom_filters(): + class ReporterFilter(FilterSet): + class Meta: + model = Reporter + fields = [] + + some_filter = OrderingFilter(fields=("name",)) + + class ReporterFilterNode(DjangoObjectType): + class Meta: + model = Reporter + interfaces = (Node,) + fields = "__all__" + filterset_class = ReporterFilter + + field = DjangoFilterConnectionField(ReporterFilterNode) + assert_arguments(field, "some_filter") diff --git a/graphene_django/filter/utils.py b/graphene_django/filter/utils.py index d4fc1bf..9922cc8 100644 --- a/graphene_django/filter/utils.py +++ b/graphene_django/filter/utils.py @@ -37,6 +37,7 @@ def get_filtering_args_from_filterset(filterset_class, type): registry = type._meta.registry for name, filter_field in filterset_class.base_filters.items(): filter_type = filter_field.lookup_expr + required = filter_field.extra.get("required", False) field_type = None form_field = None @@ -47,8 +48,6 @@ def get_filtering_args_from_filterset(filterset_class, type): or isinstance(filter_field, ArrayFilter) ): # Get the filter field for filters that are no explicitly declared. - - required = filter_field.extra.get("required", False) if filter_type == "isnull": field = graphene.Boolean(required=required) else: