Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Allow to query objects linked to a menu item

Marcin Gębala6913b745c58e
diff --git a/saleor/graphql/menu/types.py b/saleor/graphql/menu/types.py
index e8876d12fe..961e3ddef6 100644
--- a/saleor/graphql/menu/types.py
+++ b/saleor/graphql/menu/types.py
@@ -15,7 +15,8 @@ class Menu(CountableDjangoObjectType):
model = models.Menu
def resolve_items(self, info, **kwargs):
- return self.items.filter(level=0)
+ return self.items.filter(level=0).select_related(
+ 'category', 'collection', 'page')
class MenuItem(CountableDjangoObjectType):
@@ -25,7 +26,7 @@ class MenuItem(CountableDjangoObjectType):
description = """Represents a single item of the related menu.
Can store categories, collection or pages."""
interfaces = [relay.Node]
- only_fields = ['children', 'id', 'menu', 'name', 'url']
+ exclude_fields = ['sort_order', 'lft', 'rght', 'tree_id']
filter_fields = {}
model = models.MenuItem
diff --git a/tests/api/test_menu.py b/tests/api/test_menu.py
index 1c9be8dda4..6c1975ea1b 100644
--- a/tests/api/test_menu.py
+++ b/tests/api/test_menu.py
@@ -93,6 +93,15 @@ def test_menu_items_query(user_api_client, menu_item, collection):
children {
totalCount
}
+ collection {
+ name
+ }
+ category {
+ id
+ }
+ page {
+ id
+ }
url
}
}
@@ -109,6 +118,9 @@ def test_menu_items_query(user_api_client, menu_item, collection):
assert data['name'] == menu_item.name
assert data['url'] == menu_item.collection.get_absolute_url()
assert data['children']['totalCount'] == menu_item.children.count()
+ assert data['collection']['name'] == collection.name
+ assert not data['category']
+ assert not data['page']
def test_create_menu(admin_api_client, collection, category, page):