Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Turn Menu.items into list
oldPadavan50bb1447a57e
diff --git a/saleor/graphql/menu/types.py b/saleor/graphql/menu/types.pyindex 9266d47984..feccae6cd4 100644--- a/saleor/graphql/menu/types.py+++ b/saleor/graphql/menu/types.py@@ -5,7 +5,23 @@ from ...menu import modelsfrom ..core.types.common import CountableDjangoObjectType+class MenuItem(CountableDjangoObjectType):+ url = graphene.String(description='URL to the menu item.')++ class Meta:+ description = """Represents a single item of the related menu.+ Can store categories, collection or pages."""+ interfaces = [relay.Node]+ exclude_fields = ['sort_order', 'lft', 'rght', 'tree_id']+ filter_fields = {}+ model = models.MenuItem++class Menu(CountableDjangoObjectType):+ items = graphene.List(+ MenuItem, required=True,+ description='List of menu items of the menu')+class Meta:description = """Represents a single menu - an object that is usedto help navigate through the store."""@@ -16,16 +32,4 @@ class Menu(CountableDjangoObjectType):def resolve_items(self, info, **kwargs):return self.items.filter(level=0).select_related(- 'category', 'collection', 'page')---class MenuItem(CountableDjangoObjectType):- url = graphene.String(description='URL to the menu item.')-- class Meta:- description = """Represents a single item of the related menu.- Can store categories, collection or pages."""- interfaces = [relay.Node]- exclude_fields = ['sort_order', 'lft', 'rght', 'tree_id']- filter_fields = {}- model = models.MenuItem+ 'category', 'collection', 'page').all()diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 86434e92be..dfd9984c88 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -533,7 +533,7 @@ type Margin {type Menu implements Node {id: ID!name: String!- items(before: String, after: String, first: Int, last: Int): MenuItemCountableConnection+ items: [MenuItem]!}type MenuCountableConnection {diff --git a/tests/api/test_menu.py b/tests/api/test_menu.pyindex 919f8268f9..f2d58110d1 100644--- a/tests/api/test_menu.py+++ b/tests/api/test_menu.py@@ -43,16 +43,12 @@ def test_menus_query(user_api_client, menu, menu_item):edges {node {name- items(first: 1) {- edges {- node {- name- menu {- name- }- url- }+ items {+ name+ menu {+ name}+ url}}}@@ -68,10 +64,12 @@ def test_menus_query(user_api_client, menu, menu_item):content = get_graphql_content(response)menu_data = content['data']['menus']['edges'][0]['node']assert menu_data['name'] == menu.name- items = menu_data['items']['edges'][0]['node']- assert items['name'] == menu_item.name- assert items['url'] == menu_item.url- assert items['menu']['name'] == menu.name+ items = menu_data['items']+ assert len(items) == 1+ item = items[0]+ assert item['name'] == menu_item.name+ assert item['url'] == menu_item.url+ assert item['menu']['name'] == menu.namedef test_menu_items_query(user_api_client, menu_item, collection):@@ -152,11 +150,7 @@ def test_create_menu(menu {nameitems {- edges {- node {- id- }- }+ id}}}