mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-06 05:13:11 +03:00
add test for using queryset with django filters
This commit is contained in:
parent
077b5aa96f
commit
38fc15c481
|
@ -669,7 +669,7 @@ def test_order_by_is_perserved():
|
||||||
assert reverse_result.data == reverse_expected
|
assert reverse_result.data == reverse_expected
|
||||||
|
|
||||||
|
|
||||||
def test_annotation_is_perserved():
|
def test_annotation_is_preserved():
|
||||||
class ReporterType(DjangoObjectType):
|
class ReporterType(DjangoObjectType):
|
||||||
full_name = String()
|
full_name = String()
|
||||||
|
|
||||||
|
@ -714,6 +714,48 @@ def test_annotation_is_perserved():
|
||||||
assert result.data == expected
|
assert result.data == expected
|
||||||
|
|
||||||
|
|
||||||
|
def test_annotation_with_only():
|
||||||
|
class ReporterType(DjangoObjectType):
|
||||||
|
full_name = String()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Reporter
|
||||||
|
interfaces = (Node,)
|
||||||
|
filter_fields = ()
|
||||||
|
|
||||||
|
class Query(ObjectType):
|
||||||
|
all_reporters = DjangoFilterConnectionField(ReporterType)
|
||||||
|
|
||||||
|
def resolve_all_reporters(self, info, **args):
|
||||||
|
return Reporter.objects.only("first_name", "last_name").annotate(
|
||||||
|
full_name=Concat(
|
||||||
|
"first_name", Value(" "), "last_name", output_field=TextField()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
Reporter.objects.create(first_name="John", last_name="Doe")
|
||||||
|
|
||||||
|
schema = Schema(query=Query)
|
||||||
|
|
||||||
|
query = """
|
||||||
|
query NodeFilteringQuery {
|
||||||
|
allReporters(first: 1) {
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
fullName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
expected = {"allReporters": {"edges": [{"node": {"fullName": "John Doe"}}]}}
|
||||||
|
|
||||||
|
result = schema.execute(query)
|
||||||
|
|
||||||
|
assert not result.errors
|
||||||
|
assert result.data == expected
|
||||||
|
|
||||||
|
|
||||||
def test_integer_field_filter_type():
|
def test_integer_field_filter_type():
|
||||||
class PetType(DjangoObjectType):
|
class PetType(DjangoObjectType):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user