Skip to content

Commit

Permalink
forward metadata when processing django type
Browse files Browse the repository at this point in the history
  • Loading branch information
g-as committed Dec 2, 2024
1 parent a0c6ab0 commit 2d1a06e
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,7 +56,7 @@ class FruitFilter:
color_id: auto
name: auto
sweetness: auto
color: Optional[ColorFilter]
color: Optional[ColorFilter] = filter_field(filter_none=True)
types: Optional[FruitTypeFilter]

Check failure on line 60 in tests/filters/test_filters_v2.py

View workflow job for this annotation

GitHub Actions / Typing

Fields without default values cannot appear after fields with default values (reportGeneralTypeIssues)

@strawberry_django.filter_field
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 2d1a06e

Please sign in to comment.