Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward metadata when processing django type #666

Merged
merged 1 commit into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
g-as marked this conversation as resolved.
Show resolved Hide resolved
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
Loading