Skip to content

Commit 2da0cd3

Browse files
committed
Add test coverage for optimization of Relay nodes
1 parent 306a1b9 commit 2da0cd3

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/test_query.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,3 +520,40 @@ def test_should_only_use_the_only_and_not_select_related():
520520
items = gql_optimizer.query(qs, info)
521521
optimized_items = qs.only('id', 'name')
522522
assert_query_equality(items, optimized_items)
523+
524+
@pytest.mark.django_db
525+
def test_should_use_only_with_node_interface():
526+
info = create_resolve_info(schema, '''
527+
query {
528+
relayItems {
529+
edges {
530+
node {
531+
id
532+
}
533+
}
534+
}
535+
}
536+
''')
537+
qs = Item.objects.all()
538+
items = gql_optimizer.query(qs, info)
539+
optimized_items = qs.only('id')
540+
assert_query_equality(items, optimized_items)
541+
542+
@pytest.mark.django_db
543+
def test_should_not_try_to_optimize_non_field_model_fields_on_relay_node():
544+
info = create_resolve_info(schema, '''
545+
query {
546+
relayItems {
547+
edges {
548+
node {
549+
id
550+
foo
551+
}
552+
}
553+
}
554+
}
555+
''')
556+
qs = Item.objects.all()
557+
items = gql_optimizer.query(qs, info)
558+
optimized_items = qs
559+
assert_query_equality(items, optimized_items)

0 commit comments

Comments
 (0)