diff --git a/libs/navigation/driver/magento/src/navigation.service.ts b/libs/navigation/driver/magento/src/navigation.service.ts index fb2e2b2c7b..98ed4b02b8 100644 --- a/libs/navigation/driver/magento/src/navigation.service.ts +++ b/libs/navigation/driver/magento/src/navigation.service.ts @@ -3,6 +3,7 @@ import { Inject, } from '@angular/core'; import { Apollo } from 'apollo-angular'; +import { DocumentNode } from 'graphql'; import { Observable, of, @@ -24,6 +25,7 @@ import { MagentoNavigationDriverConfig, } from './config/public_api'; import { GetCategoryTreeResponse } from './models/get-category-tree-response'; +import { DAFF_NAVIGATION_MAGENTO_DRIVER_EXTRA_FRAGMENTS } from './queries/fragments/public_api'; import { daffMagentoGetCategoryTree } from './queries/get-category-tree'; import { magentoNavigationGetRootCategoryIdQuery } from './queries/get-root-category-id/public_api'; @@ -38,6 +40,7 @@ export class DaffMagentoNavigationService implements DaffNavigationServiceInterf constructor( private apollo: Apollo, @Inject(DaffNavigationTransformer) private transformer: DaffNavigationTransformerInterface, + @Inject(DAFF_NAVIGATION_MAGENTO_DRIVER_EXTRA_FRAGMENTS) private extraFragments: Array, @Inject(MAGENTO_NAVIGATION_DRIVER_CONFIG) private config: MagentoNavigationDriverConfig, ) {} @@ -57,7 +60,7 @@ export class DaffMagentoNavigationService implements DaffNavigationServiceInterf get(categoryId: string): Observable { return this.apollo.query({ - query: daffMagentoGetCategoryTree(this.config.navigationTreeQueryDepth), + query: daffMagentoGetCategoryTree(this.config.navigationTreeQueryDepth, this.extraFragments), variables: { filters: { category_uid: { eq: categoryId }}, }, diff --git a/libs/navigation/driver/magento/src/public_api.ts b/libs/navigation/driver/magento/src/public_api.ts index 3100176fe1..1f21a7fa7d 100644 --- a/libs/navigation/driver/magento/src/public_api.ts +++ b/libs/navigation/driver/magento/src/public_api.ts @@ -1,7 +1,7 @@ export { DaffNavigationMagentoDriverModule } from './navigation-driver.module'; export { DaffMagentoNavigationService } from './navigation.service'; export { DaffMagentoNavigationTransformerService } from './transformers/navigation-transformer'; -export * from './queries/get-category-tree'; +export * from './queries/public_api'; export * from './config/public_api'; export * from './models/public_api'; export * from './transforms/public_api'; diff --git a/libs/navigation/driver/magento/src/queries/fragments/category-node.spec.ts b/libs/navigation/driver/magento/src/queries/fragments/category-node/category-node.spec.ts similarity index 100% rename from libs/navigation/driver/magento/src/queries/fragments/category-node.spec.ts rename to libs/navigation/driver/magento/src/queries/fragments/category-node/category-node.spec.ts diff --git a/libs/navigation/driver/magento/src/queries/fragments/category-node.ts b/libs/navigation/driver/magento/src/queries/fragments/category-node/category-node.ts similarity index 74% rename from libs/navigation/driver/magento/src/queries/fragments/category-node.ts rename to libs/navigation/driver/magento/src/queries/fragments/category-node/category-node.ts index a1b4f60a20..2e85a47787 100644 --- a/libs/navigation/driver/magento/src/queries/fragments/category-node.ts +++ b/libs/navigation/driver/magento/src/queries/fragments/category-node/category-node.ts @@ -1,6 +1,11 @@ import { gql } from 'apollo-angular'; import { DocumentNode } from 'graphql'; +import { + daffBuildFragmentDefinition, + daffBuildFragmentNameSpread, +} from '@daffodil/core/graphql'; + const CATEGORY_NODE_FRAGMENT_NAME = 'categoryNode'; @@ -9,7 +14,7 @@ const CATEGORY_NODE_FRAGMENT_NAME = 'categoryNode'; * * @param depth The maximum depth to which category children should be added to the fragment. */ -export function getCategoryNodeFragment(depth: number = 3): DocumentNode { +export function getCategoryNodeFragment(depth: number = 3, extraFragments: Array = []): DocumentNode { const fragmentBody = new Array(depth).fill(null).reduce(acc => ` ...${CATEGORY_NODE_FRAGMENT_NAME} children_count @@ -34,10 +39,12 @@ export function getCategoryNodeFragment(depth: number = 3): DocumentNode { } position product_count + ${daffBuildFragmentNameSpread(...extraFragments)} } fragment recursiveCategoryNode on CategoryTree { ${fragmentBody} } + ${daffBuildFragmentDefinition(...extraFragments)} `; } diff --git a/libs/navigation/driver/magento/src/queries/fragments/category-node/extra.token.ts b/libs/navigation/driver/magento/src/queries/fragments/category-node/extra.token.ts new file mode 100644 index 0000000000..b9e51f7b1f --- /dev/null +++ b/libs/navigation/driver/magento/src/queries/fragments/category-node/extra.token.ts @@ -0,0 +1,8 @@ +import { DocumentNode } from 'graphql'; + +import { createMultiInjectionToken } from '@daffodil/core'; + +export const { + token: DAFF_NAVIGATION_MAGENTO_DRIVER_EXTRA_FRAGMENTS, + provider: daffNavigationMagentoDriverExtraFragments, +} = createMultiInjectionToken('DAFF_NAVIGATION_MAGENTO_DRIVER_EXTRA_FRAGMENTS'); diff --git a/libs/navigation/driver/magento/src/queries/fragments/category-node/public_api.ts b/libs/navigation/driver/magento/src/queries/fragments/category-node/public_api.ts new file mode 100644 index 0000000000..8182d07bfa --- /dev/null +++ b/libs/navigation/driver/magento/src/queries/fragments/category-node/public_api.ts @@ -0,0 +1,2 @@ +export * from './category-node'; +export * from './extra.token'; diff --git a/libs/navigation/driver/magento/src/queries/fragments/public_api.ts b/libs/navigation/driver/magento/src/queries/fragments/public_api.ts index e69de29bb2..765e9fc0c2 100644 --- a/libs/navigation/driver/magento/src/queries/fragments/public_api.ts +++ b/libs/navigation/driver/magento/src/queries/fragments/public_api.ts @@ -0,0 +1 @@ +export * from './category-node/public_api'; diff --git a/libs/navigation/driver/magento/src/queries/get-category-tree.ts b/libs/navigation/driver/magento/src/queries/get-category-tree.ts index d8dd761baf..588b96a853 100644 --- a/libs/navigation/driver/magento/src/queries/get-category-tree.ts +++ b/libs/navigation/driver/magento/src/queries/get-category-tree.ts @@ -1,6 +1,7 @@ import { gql } from 'apollo-angular'; +import { DocumentNode } from 'graphql'; -import { getCategoryNodeFragment } from './fragments/category-node'; +import { getCategoryNodeFragment } from './fragments/category-node/category-node'; export const DAFF_MAGENTO_GET_CATEGORY_TREE_QUERY_NAME = 'MagentoGetCategoryTree'; @@ -9,13 +10,13 @@ export const DAFF_MAGENTO_GET_CATEGORY_TREE_QUERY_NAME = 'MagentoGetCategoryTree * * @param depth The maximum depth to which category children should be added to the fragment. */ -export function daffMagentoGetCategoryTree(depth: number = 3) { +export function daffMagentoGetCategoryTree(depth: number = 3, extraFragments: Array = []) { return gql` query ${DAFF_MAGENTO_GET_CATEGORY_TREE_QUERY_NAME}($filters: CategoryFilterInput!){ categoryList(filters: $filters) { ...recursiveCategoryNode } } - ${getCategoryNodeFragment(depth)} + ${getCategoryNodeFragment(depth, extraFragments)} `; } diff --git a/libs/navigation/driver/magento/src/queries/public_api.ts b/libs/navigation/driver/magento/src/queries/public_api.ts new file mode 100644 index 0000000000..452667c7e1 --- /dev/null +++ b/libs/navigation/driver/magento/src/queries/public_api.ts @@ -0,0 +1,3 @@ +export * from './fragments/public_api'; +export * from './get-root-category-id/public_api'; +export * from './get-category-tree'; diff --git a/libs/navigation/testing/src/public_api.ts b/libs/navigation/testing/src/public_api.ts index 660d854b63..0565cfb76a 100644 --- a/libs/navigation/testing/src/public_api.ts +++ b/libs/navigation/testing/src/public_api.ts @@ -1,2 +1,2 @@ -export { DaffNavigationTreeFactory } from './factories/navigation-tree.factory'; +export * from './factories/navigation-tree.factory'; export { isNavigation } from './helpers/navigation-helper';