forked from graycoreio/daffodil
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(product): create injection tokens with factory (graycoreio#3255)
- Loading branch information
1 parent
b8416b9
commit fef6e0e
Showing
23 changed files
with
394 additions
and
456 deletions.
There are no files selected for viewing
55 changes: 22 additions & 33 deletions
55
...driver/in-memory/src/injection-tokens/transforms/product-response/response-extra.token.ts
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 |
---|---|---|
@@ -1,40 +1,29 @@ | ||
import { | ||
InjectionToken, | ||
Provider, | ||
} from '@angular/core'; | ||
|
||
import { createMultiInjectionToken } from '@daffodil/core'; | ||
// workaround https://github.com/graycoreio/daffodil/issues/1667 | ||
import { DaffProduct } from '@daffodil/product'; | ||
import { DaffProductDriverResponse } from '@daffodil/product/driver'; | ||
|
||
import { DaffInMemoryProductResponseExtraTransform } from '../../../interfaces/public_api'; | ||
|
||
/** | ||
* A multi-provider injection token for providing extra transform logic in the Product In-Memory driver. | ||
* It is run after the standard transforms and passed both the current transformed Daffodil response and the In-Memory product response. | ||
*/ | ||
export const DAFF_PRODUCT_IN_MEMORY_EXTRA_PRODUCT_RESPONSE_TRANSFORMS = new InjectionToken<DaffInMemoryProductResponseExtraTransform[]>( | ||
'DAFF_PRODUCT_IN_MEMORY_EXTRA_PRODUCT_RESPONSE_TRANSFORMS', | ||
{ factory: () => []}, | ||
); | ||
export const { | ||
/** | ||
* A multi-provider injection token for providing extra transform logic in the Product In-Memory driver. | ||
* It is run after the standard transforms and passed both the current transformed Daffodil response and the In-Memory product response. | ||
*/ | ||
token: DAFF_PRODUCT_IN_MEMORY_EXTRA_PRODUCT_RESPONSE_TRANSFORMS, | ||
|
||
/** | ||
* Provides extra product transforms for the In-Memory product driver. | ||
* | ||
* See {@link DAFF_PRODUCT_IN_MEMORY_EXTRA_PRODUCT_RESPONSE_TRANSFORMS}. | ||
* | ||
* ```ts | ||
* providers: [ | ||
* ...daffProvideProductInMemoryExtraProductResponseTransforms( | ||
* myExtraProductTransform | ||
* ) | ||
* ] | ||
* ``` | ||
*/ | ||
export function daffProvideProductInMemoryExtraProductResponseTransforms(...transforms: DaffInMemoryProductResponseExtraTransform[]): Provider[] { | ||
return transforms.map(transform => ({ | ||
provide: DAFF_PRODUCT_IN_MEMORY_EXTRA_PRODUCT_RESPONSE_TRANSFORMS, | ||
useValue: transform, | ||
multi: true, | ||
})); | ||
} | ||
/** | ||
* Provides extra product transforms for the In-Memory product driver. | ||
* | ||
* See {@link DAFF_PRODUCT_IN_MEMORY_EXTRA_PRODUCT_RESPONSE_TRANSFORMS}. | ||
* | ||
* ```ts | ||
* providers: [ | ||
* ...daffProvideProductInMemoryExtraProductResponseTransforms( | ||
* myExtraProductTransform | ||
* ) | ||
* ] | ||
* ``` | ||
*/ | ||
provider: daffProvideProductInMemoryExtraProductResponseTransforms, | ||
} = createMultiInjectionToken<DaffInMemoryProductResponseExtraTransform>('DAFF_PRODUCT_IN_MEMORY_EXTRA_PRODUCT_RESPONSE_TRANSFORMS'); |
17 changes: 9 additions & 8 deletions
17
...oduct/driver/in-memory/src/injection-tokens/transforms/product-response/response.token.ts
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
69 changes: 30 additions & 39 deletions
69
libs/product/driver/magento/src/injection-tokens/fragments/product-page.token.ts
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 |
---|---|---|
@@ -1,42 +1,33 @@ | ||
import { | ||
InjectionToken, | ||
Provider, | ||
} from '@angular/core'; | ||
import { DocumentNode } from 'graphql'; | ||
|
||
/** | ||
* A multi-provider injection token for providing extra GraphQL fragments that will be spread into product queries. | ||
* This can be used to retrieve additional data that is not covered by the standard Daffodil interfaces. | ||
* | ||
* Fragment structure is platform-specific and this feature should be used with care. | ||
* | ||
* This can increase query complexity above the Magento default of 300. | ||
* Daffodil only guarantees that stock queries don't exceed the limit of 300. | ||
* Apps using this token should therefore increase the query complexity limit | ||
* to accommodate the extra complexity contributed by the provided fragments. | ||
*/ | ||
export const DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_PAGE_FRAGMENTS = new InjectionToken<DocumentNode[]>( | ||
'DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_PAGE_FRAGMENTS', | ||
{ factory: () => []}, | ||
); | ||
import { createMultiInjectionToken } from '@daffodil/core'; | ||
|
||
/** | ||
* Provides extra GraphQL fragments for the Magento product driver. | ||
* | ||
* See {@link DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_PAGE_FRAGMENTS}. | ||
* | ||
* ```ts | ||
* providers: [ | ||
* ...daffProvideProductMagentoExtraProductPageFragments( | ||
* myExtraProductFragment | ||
* ) | ||
* ] | ||
* ``` | ||
*/ | ||
export function daffProvideProductMagentoExtraProductPageFragments(...fragments: DocumentNode[]): Provider[] { | ||
return fragments.map(fragment => ({ | ||
provide: DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_PAGE_FRAGMENTS, | ||
useValue: fragment, | ||
multi: true, | ||
})); | ||
} | ||
export const { | ||
/** | ||
* A multi-provider injection token for providing extra GraphQL fragments that will be spread into product queries. | ||
* This can be used to retrieve additional data that is not covered by the standard Daffodil interfaces. | ||
* | ||
* Fragment structure is platform-specific and this feature should be used with care. | ||
* | ||
* This can increase query complexity above the Magento default of 300. | ||
* Daffodil only guarantees that stock queries don't exceed the limit of 300. | ||
* Apps using this token should therefore increase the query complexity limit | ||
* to accommodate the extra complexity contributed by the provided fragments. | ||
*/ | ||
token: DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_PAGE_FRAGMENTS, | ||
|
||
/** | ||
* Provides extra GraphQL fragments for the Magento product driver. | ||
* | ||
* See {@link DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_PAGE_FRAGMENTS}. | ||
* | ||
* ```ts | ||
* providers: [ | ||
* ...daffProvideProductMagentoExtraProductPageFragments( | ||
* myExtraProductFragment | ||
* ) | ||
* ] | ||
* ``` | ||
*/ | ||
provider: daffProvideProductMagentoExtraProductPageFragments, | ||
} = createMultiInjectionToken<DocumentNode>('DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_PAGE_FRAGMENTS'); |
77 changes: 34 additions & 43 deletions
77
libs/product/driver/magento/src/injection-tokens/fragments/product-preview.token.ts
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 |
---|---|---|
@@ -1,46 +1,37 @@ | ||
import { | ||
InjectionToken, | ||
Provider, | ||
} from '@angular/core'; | ||
import { DocumentNode } from 'graphql'; | ||
|
||
/** | ||
* A multi-provider injection token for providing extra GraphQL fragments that will be spread into product preview queries. | ||
* This can be used to retrieve additional data that is not covered by the standard Daffodil interfaces. | ||
* Fragments provided here will also be included in the {@link DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_FRAGMENTS}. | ||
* The same fragment should not be provided for both of these tokens. | ||
* | ||
* See {@link MagentoProductPreview} for more info. | ||
* | ||
* Fragment structure is platform-specific and this feature should be used with care. | ||
* | ||
* This can increase query complexity above the Magento default of 300. | ||
* Daffodil only guarantees that stock queries don't exceed the limit of 300. | ||
* Apps using this token should therefore increase the query complexity limit | ||
* to accommodate the extra complexity contributed by the provided fragments. | ||
*/ | ||
export const DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_PREVIEW_FRAGMENTS = new InjectionToken<DocumentNode[]>( | ||
'DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_PREVIEW_FRAGMENTS', | ||
{ factory: () => []}, | ||
); | ||
import { createMultiInjectionToken } from '@daffodil/core'; | ||
|
||
/** | ||
* Provides extra GraphQL fragments for the Magento product preview query. | ||
* | ||
* See {@link DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_PREVIEW_FRAGMENTS}. | ||
* | ||
* ```ts | ||
* providers: [ | ||
* ...daffProvideProductMagentoExtraProductPreviewFragments( | ||
* myExtraProductPreviewFragment | ||
* ) | ||
* ] | ||
* ``` | ||
*/ | ||
export function daffProvideProductMagentoExtraProductPreviewFragments(...fragments: DocumentNode[]): Provider[] { | ||
return fragments.map(fragment => ({ | ||
provide: DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_PREVIEW_FRAGMENTS, | ||
useValue: fragment, | ||
multi: true, | ||
})); | ||
} | ||
export const { | ||
/** | ||
* A multi-provider injection token for providing extra GraphQL fragments that will be spread into product preview queries. | ||
* This can be used to retrieve additional data that is not covered by the standard Daffodil interfaces. | ||
* Fragments provided here will also be included in the {@link DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_FRAGMENTS}. | ||
* The same fragment should not be provided for both of these tokens. | ||
* | ||
* See {@link MagentoProductPreview} for more info. | ||
* | ||
* Fragment structure is platform-specific and this feature should be used with care. | ||
* | ||
* This can increase query complexity above the Magento default of 300. | ||
* Daffodil only guarantees that stock queries don't exceed the limit of 300. | ||
* Apps using this token should therefore increase the query complexity limit | ||
* to accommodate the extra complexity contributed by the provided fragments. | ||
*/ | ||
token: DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_PREVIEW_FRAGMENTS, | ||
|
||
/** | ||
* Provides extra GraphQL fragments for the Magento product preview query. | ||
* | ||
* See {@link DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_PREVIEW_FRAGMENTS}. | ||
* | ||
* ```ts | ||
* providers: [ | ||
* ...daffProvideProductMagentoExtraProductPreviewFragments( | ||
* myExtraProductPreviewFragment | ||
* ) | ||
* ] | ||
* ``` | ||
*/ | ||
provider: daffProvideProductMagentoExtraProductPreviewFragments, | ||
} = createMultiInjectionToken<DocumentNode>('DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_PREVIEW_FRAGMENTS'); |
69 changes: 30 additions & 39 deletions
69
libs/product/driver/magento/src/injection-tokens/fragments/product.token.ts
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 |
---|---|---|
@@ -1,42 +1,33 @@ | ||
import { | ||
InjectionToken, | ||
Provider, | ||
} from '@angular/core'; | ||
import { DocumentNode } from 'graphql'; | ||
|
||
/** | ||
* A multi-provider injection token for providing extra GraphQL fragments that will be spread into product queries. | ||
* This can be used to retrieve additional data that is not covered by the standard Daffodil interfaces. | ||
* | ||
* Fragment structure is platform-specific and this feature should be used with care. | ||
* | ||
* This can increase query complexity above the Magento default of 300. | ||
* Daffodil only guarantees that stock queries don't exceed the limit of 300. | ||
* Apps using this token should therefore increase the query complexity limit | ||
* to accommodate the extra complexity contributed by the provided fragments. | ||
*/ | ||
export const DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_FRAGMENTS = new InjectionToken<DocumentNode[]>( | ||
'DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_FRAGMENTS', | ||
{ factory: () => []}, | ||
); | ||
import { createMultiInjectionToken } from '@daffodil/core'; | ||
|
||
/** | ||
* Provides extra GraphQL fragments for the Magento product driver. | ||
* | ||
* See {@link DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_FRAGMENTS}. | ||
* | ||
* ```ts | ||
* providers: [ | ||
* ...daffProvideProductMagentoExtraProductFragments( | ||
* myExtraProductFragment | ||
* ) | ||
* ] | ||
* ``` | ||
*/ | ||
export function daffProvideProductMagentoExtraProductFragments(...fragments: DocumentNode[]): Provider[] { | ||
return fragments.map(fragment => ({ | ||
provide: DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_FRAGMENTS, | ||
useValue: fragment, | ||
multi: true, | ||
})); | ||
} | ||
export const { | ||
/** | ||
* A multi-provider injection token for providing extra GraphQL fragments that will be spread into product queries. | ||
* This can be used to retrieve additional data that is not covered by the standard Daffodil interfaces. | ||
* | ||
* Fragment structure is platform-specific and this feature should be used with care. | ||
* | ||
* This can increase query complexity above the Magento default of 300. | ||
* Daffodil only guarantees that stock queries don't exceed the limit of 300. | ||
* Apps using this token should therefore increase the query complexity limit | ||
* to accommodate the extra complexity contributed by the provided fragments. | ||
*/ | ||
token: DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_FRAGMENTS, | ||
|
||
/** | ||
* Provides extra GraphQL fragments for the Magento product driver. | ||
* | ||
* See {@link DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_FRAGMENTS}. | ||
* | ||
* ```ts | ||
* providers: [ | ||
* ...daffProvideProductMagentoExtraProductFragments( | ||
* myExtraProductFragment | ||
* ) | ||
* ] | ||
* ``` | ||
*/ | ||
provider: daffProvideProductMagentoExtraProductFragments, | ||
} = createMultiInjectionToken<DocumentNode>('DAFF_PRODUCT_MAGENTO_EXTRA_PRODUCT_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
Oops, something went wrong.