Skip to content

Commit

Permalink
Forward metadata when processing django type (#666)
Browse files Browse the repository at this point in the history
  • Loading branch information
g-as authored Dec 8, 2024
1 parent 1dd34ad commit 3e64009
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions strawberry_django/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ def _process_type(
permission_classes=getattr(f, "permission_classes", ()),
default=getattr(f, "default", dataclasses.MISSING),
default_factory=getattr(f, "default_factory", dataclasses.MISSING),
metadata=getattr(f, "metadata", None),
deprecation_reason=getattr(f, "deprecation_reason", None),
directives=getattr(f, "directives", ()),
pagination=getattr(f, "pagination", UNSET),
Expand Down
23 changes: 22 additions & 1 deletion tests/filters/test_filters_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from strawberry_django.fields.filter_order import (
FilterOrderField,
FilterOrderFieldResolver,
filter_field,
)
from strawberry_django.filters import process_filters, resolve_value
from tests import models, utils
Expand Down Expand Up @@ -55,8 +56,8 @@ class FruitFilter:
color_id: auto
name: auto
sweetness: auto
color: Optional[ColorFilter]
types: Optional[FruitTypeFilter]
color: Optional[ColorFilter] = filter_field(filter_none=True)

@strawberry_django.filter_field
def types_number(
Expand Down Expand Up @@ -420,6 +421,26 @@ def test_filter_distinct(query, db, fruits):
assert len(result.data["fruits"]) == 1


def test_filter_none(query, db):
yellow = models.Color.objects.create(name="yellow")
models.Fruit.objects.create(name="banana", color=yellow)

f1 = models.Fruit.objects.create(name="unknown")
f2 = models.Fruit.objects.create(name="unknown2")

result = query("""
{
fruits(filters: {color: null}) { id }
}
""")

assert not result.errors
assert result.data["fruits"] == [
{"id": str(f1.id)},
{"id": str(f2.id)},
]


def test_empty_resolver_filter():
@strawberry.type
class Query:
Expand Down

0 comments on commit 3e64009

Please sign in to comment.