Skip to content

Commit

Permalink
fix(navgiation): deep fragment fields might not get data (#2889)
Browse files Browse the repository at this point in the history
this is a workaround of magento/magento2#38863
  • Loading branch information
griest024 committed Jun 21, 2024
1 parent 223b304 commit 44d16d7
Showing 1 changed file with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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> = []): 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}
}
Expand Down

0 comments on commit 44d16d7

Please sign in to comment.