forked from tfoxy/graphene-django-optimizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_field.py
48 lines (43 loc) · 1.17 KB
/
test_field.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import pytest
import graphene_django_optimizer as gql_optimizer
from .graphql_utils import create_resolve_info
from .models import Item
from .schema import schema
from .test_utils import assert_query_equality
@pytest.mark.django_db
def test_should_optimize_non_django_field_if_it_has_an_optimization_hint_in_the_field():
info = create_resolve_info(
schema,
"""
query {
items(name: "bar") {
id
foo
father {
id
}
}
}
""",
)
qs = Item.objects.filter(name="bar")
items = gql_optimizer.query(qs, info)
optimized_items = qs.select_related("parent")
assert_query_equality(items, optimized_items)
@pytest.mark.django_db
def test_should_optimize_with_only_hint():
info = create_resolve_info(
schema,
"""
query {
items(name: "foo") {
id
title
}
}
""",
)
qs = Item.objects.filter(name="foo")
items = gql_optimizer.query(qs, info)
optimized_items = qs.only("id", "name")
assert_query_equality(items, optimized_items)