Skip to content

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

Change MenuItem.children to List

oldPadavan6b861e125576
diff --git a/saleor/graphql/menu/types.py b/saleor/graphql/menu/types.py
index feccae6cd4..9950b1fb5a 100644
--- a/saleor/graphql/menu/types.py
+++ b/saleor/graphql/menu/types.py
@@ -7,6 +7,9 @@ from ..core.types.common import CountableDjangoObjectType
class MenuItem(CountableDjangoObjectType):
url = graphene.String(description='URL to the menu item.')
+ children = graphene.List(
+ lambda: MenuItem, required=True,
+ description='List of menu item children items')
class Meta:
description = """Represents a single item of the related menu.
@@ -16,6 +19,9 @@ class MenuItem(CountableDjangoObjectType):
filter_fields = {}
model = models.MenuItem
+ def resolve_children(self, info, **kwargs):
+ return self.children.all()
+
class Menu(CountableDjangoObjectType):
items = graphene.List(
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index dfd9984c88..20664917c5 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -576,7 +576,7 @@ type MenuItem implements Node {
collection: Collection
page: Page
level: Int!
- children(before: String, after: String, first: Int, last: Int): MenuItemCountableConnection
+ children: [MenuItem]!
}
type MenuItemCountableConnection {
diff --git a/tests/api/test_menu.py b/tests/api/test_menu.py
index f2d58110d1..8e133339ee 100644
--- a/tests/api/test_menu.py
+++ b/tests/api/test_menu.py
@@ -2,6 +2,7 @@ import pytest
import graphene
from saleor.graphql.menu.mutations import NavigationType
+from saleor.menu.models import MenuItem
from tests.api.utils import get_graphql_content
from .utils import assert_no_permission
@@ -78,7 +79,7 @@ def test_menu_items_query(user_api_client, menu_item, collection):
menuItem(id: $id) {
name
children {
- totalCount
+ name
}
collection {
name
@@ -96,12 +97,16 @@ def test_menu_items_query(user_api_client, menu_item, collection):
menu_item.collection = collection
menu_item.url = None
menu_item.save()
+ child_menu = MenuItem.objects.create(
+ menu=menu_item.menu, name='Link 2', url='http://example2.com/',
+ parent=menu_item)
variables = {'id': graphene.Node.to_global_id('MenuItem', menu_item.pk)}
response = user_api_client.post_graphql(query, variables)
content = get_graphql_content(response)
data = content['data']['menuItem']
assert data['name'] == menu_item.name
- assert data['children']['totalCount'] == menu_item.children.count()
+ assert len(data['children']) == 1
+ assert data['children'][0]['name'] == child_menu.name
assert data['collection']['name'] == collection.name
assert not data['category']
assert not data['page']