category query
The category
query has been deprecated. Use the categories query instead.
The category
query allows you to search for a single category definition or the entire category tree.
You cannot return the entire category tree if the total number of nodes in the request exceeds the value specified in the queryDepth
attribute defined in the GraphQL di.xml
file. By default, this value is 20. Query security further describes query depths.
Syntax
Copied to your clipboardcategory (id: int): CategoryTree
Reference
The category
reference provides detailed information about the types and fields defined in this query.
Example usage
Return the category tree of a top-level category
The following query returns information about category ID 20
and four levels of subcategories. In the sample data, category ID 20
is assigned to the Women
category.
Request:
Copied to your clipboard{category(id: 20) {products {total_countpage_info {current_pagepage_size}}children_countchildren {idlevelnamepathchildren {idlevelnamepathchildren {idlevelnamepathchildren {idlevelnamepath}}}}}}
Response:
Copied to your clipboard{"data": {"category": {"products": {"total_count": 0,"page_info": {"current_page": 1,"page_size": 20}},"children_count": "8","children": [{"id": 22,"level": 3,"name": "Bottoms","path": "1/2/20/22","children": [{"id": 27,"level": 4,"name": "Pants","path": "1/2/20/22/27","children": []},{"id": 28,"level": 4,"name": "Shorts","path": "1/2/20/22/28","children": []}]},{"id": 21,"level": 3,"name": "Tops","path": "1/2/20/21","children": [{"id": 23,"level": 4,"name": "Jackets","path": "1/2/20/21/23","children": []},{"id": 24,"level": 4,"name": "Hoodies & Sweatshirts","path": "1/2/20/21/24","children": []},{"id": 25,"level": 4,"name": "Tees","path": "1/2/20/21/25","children": []},{"id": 26,"level": 4,"name": "Bras & Tanks","path": "1/2/20/21/26","children": []}]}]}}}
Return breadcrumb information
The following query returns breadcrumb information about the women's Tops
category (id
= 25).
Request:
Copied to your clipboard{category (id: 25) {idlevelnamebreadcrumbs {category_idcategory_namecategory_levelcategory_url_keycategory_url_path}}}
Response:
Copied to your clipboard{"data": {"category": {"id": 25,"level": 4,"name": "Tees","breadcrumbs": [{"category_id": 20,"category_name": "Women","category_level": 2,"category_url_key": "women","category_url_path": "women"},{"category_id": 21,"category_name": "Tops","category_level": 3,"category_url_key": "tops-women","category_url_path": "women/tops-women"}]}}}
Errors
Error | Description |
---|---|
Category doesn't exist | The specified category ID value does not exist. |
Field "category" argument "id" requires type Int, found "XXX" | The specified id argument value has the wrong type. |