-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(category): add injectable fragments and transform support to mag…
…ento driver (#2828)
- Loading branch information
Showing
9 changed files
with
88 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './token'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { DocumentNode } from '@apollo/client/core'; | ||
|
||
import { createMultiInjectionToken } from '@daffodil/core'; | ||
|
||
|
||
export const { | ||
/** | ||
* A multi-provider injection token for providing category tree transform logic in the Magento driver. | ||
* It is run after the standard transforms and passed both the current transformed Daffodil category and the Magento category. | ||
*/ | ||
token: MAGENTO_CATEGORY_EXTRA_FRAGMENTS, | ||
/** | ||
* Provides category tree transforms for the Magento category driver. | ||
* | ||
* See {@link MAGENTO_CATEGORY_EXTRA_FRAGMENTS}. | ||
* | ||
* ```ts | ||
* providers: [ | ||
* ...magentoProvideCategoryExtraFragments( | ||
* myCategoryExtraFragment | ||
* ) | ||
* ] | ||
* ``` | ||
*/ | ||
provider: magentoProvideCategoryExtraFragments, | ||
} = createMultiInjectionToken<DocumentNode>('MAGENTO_CATEGORY_EXTRA_FRAGMENTS'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './token'; | ||
export * from './type'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// workaround https://github.com/graycoreio/daffodil/issues/1667 | ||
import { DaffCategory } from '@daffodil/category'; | ||
import { createMultiInjectionToken } from '@daffodil/core'; | ||
|
||
import { MagentoCategoryTreeTransform } from './type'; | ||
|
||
export const { | ||
/** | ||
* A multi-provider injection token for providing category transform logic in the Magento driver. | ||
* It is run after the standard transforms and passed both the current transformed Daffodil category and the Magento category. | ||
*/ | ||
token: MAGENTO_CATEGORY_EXTRA_TRANSFORMS, | ||
/** | ||
* Provides category transforms for the Magento category driver. | ||
* | ||
* See {@link MAGENTO_CATEGORY_EXTRA_TRANSFORMS}. | ||
* | ||
* ```ts | ||
* providers: [ | ||
* ...magentoProvideCategoryExtraTransforms( | ||
* myCategoryExtraTransform | ||
* ) | ||
* ] | ||
* ``` | ||
*/ | ||
provider: magentoProvideCategoryExtraTransforms, | ||
} = createMultiInjectionToken<MagentoCategoryTreeTransform>('MAGENTO_CATEGORY_EXTRA_TRANSFORMS'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { DaffCategory } from '@daffodil/category'; | ||
import { MagentoProduct } from '@daffodil/product/driver/magento'; | ||
|
||
import { MagentoCategory } from '../models/public_api'; | ||
|
||
/** | ||
* A transform for the Magento driver that can add extra fields or otherwise modify the category driver response. | ||
*/ | ||
export type MagentoCategoryTreeTransform<T extends MagentoCategory = MagentoCategory, V extends DaffCategory = DaffCategory> = | ||
(daffCategory: DaffCategory, magentoCategory: T, products: MagentoProduct[]) => V; |