diff --git a/libs/navigation/driver/magento/src/queries/fragments/category-node/category-node.ts b/libs/navigation/driver/magento/src/queries/fragments/category-node/category-node.ts index 2e85a47787..dc0ae66fe8 100644 --- a/libs/navigation/driver/magento/src/queries/fragments/category-node/category-node.ts +++ b/libs/navigation/driver/magento/src/queries/fragments/category-node/category-node.ts @@ -6,42 +6,43 @@ import { daffBuildFragmentNameSpread, } from '@daffodil/core/graphql'; - -const CATEGORY_NODE_FRAGMENT_NAME = 'categoryNode'; +/** + * A category tree fragment with no nested children. + */ +const categoryNodeFragment = ` + uid + url_path + url_suffix + level + name + include_in_menu + breadcrumbs { + category_uid + category_name + category_level + category_url_path + } + position + product_count +`; /** * Generates a category tree fragment with the specified number of nested child category trees. * * @param depth The maximum depth to which category children should be added to the fragment. */ +//todo: use nested fragments when this bug is fixed: https://github.com/magento/magento2/issues/31086 export function getCategoryNodeFragment(depth: number = 3, extraFragments: Array = []): DocumentNode { const fragmentBody = new Array(depth).fill(null).reduce(acc => ` - ...${CATEGORY_NODE_FRAGMENT_NAME} + ${categoryNodeFragment} children_count children { ${acc} } - `, `...${CATEGORY_NODE_FRAGMENT_NAME}`); + ${daffBuildFragmentNameSpread(...extraFragments)} + `, categoryNodeFragment); return gql` - fragment ${CATEGORY_NODE_FRAGMENT_NAME} on CategoryTree { - uid - url_path - url_suffix - level - name - include_in_menu - breadcrumbs { - category_uid - category_name - category_level - category_url_path - } - position - product_count - ${daffBuildFragmentNameSpread(...extraFragments)} - } - fragment recursiveCategoryNode on CategoryTree { ${fragmentBody} }