-
-
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(customer-order): create injection tokens with factory (#3242)
- Loading branch information
Showing
5 changed files
with
73 additions
and
90 deletions.
There are no files selected for viewing
69 changes: 30 additions & 39 deletions
69
libs/customer-order/driver/magento/2-4-5/src/injection-tokens/fragments/order.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 order 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_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_FRAGMENTS = new InjectionToken<DocumentNode[]>( | ||
'DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_FRAGMENTS', | ||
{ factory: () => []}, | ||
); | ||
import { createMultiInjectionToken } from '@daffodil/core'; | ||
|
||
/** | ||
* Provides extra GraphQL fragments for the Magento order driver. | ||
* | ||
* See {@link DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_FRAGMENTS}. | ||
* | ||
* ```ts | ||
* providers: [ | ||
* ...daffProvideCustomerOrderMagentoExtraOrderFragments( | ||
* myExtraOrderFragment | ||
* ) | ||
* ] | ||
* ``` | ||
*/ | ||
export function daffProvideCustomerOrderMagentoExtraOrderFragments(...fragments: DocumentNode[]): Provider[] { | ||
return fragments.map(fragment => ({ | ||
provide: DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_FRAGMENTS, | ||
useValue: fragment, | ||
multi: true, | ||
})); | ||
} | ||
export const { | ||
/** | ||
* A multi-provider injection token for providing extra GraphQL fragments that will be spread into order 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_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_FRAGMENTS, | ||
|
||
/** | ||
* Provides extra GraphQL fragments for the Magento order driver. | ||
* | ||
* See {@link DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_FRAGMENTS}. | ||
* | ||
* ```ts | ||
* providers: [ | ||
* ...daffProvideCustomerOrderMagentoExtraOrderFragments( | ||
* myExtraOrderFragment | ||
* ) | ||
* ] | ||
* ``` | ||
*/ | ||
provider: daffProvideCustomerOrderMagentoExtraOrderFragments, | ||
} = createMultiInjectionToken<DocumentNode>('DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_FRAGMENTS'); |
59 changes: 24 additions & 35 deletions
59
libs/customer-order/driver/magento/2-4-5/src/injection-tokens/transforms/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,42 +1,31 @@ | ||
import { | ||
InjectionToken, | ||
Provider, | ||
} from '@angular/core'; | ||
|
||
// workaround https://github.com/graycoreio/daffodil/issues/1667 | ||
import { createMultiInjectionToken } from '@daffodil/core'; | ||
import { DaffOrder } from '@daffodil/order'; | ||
|
||
import { DaffMagentoCustomerOrderExtraTransform } from '../../interfaces/public_api'; | ||
import { MagentoCustomerOrder } from '../../models/public_api'; | ||
|
||
/** | ||
* A multi-provider injection token for providing extra transform logic in the Order Magento driver. | ||
* It is run after the standard transforms for each customer order preview and passed both the current transformed Daffodil customer order and the Magento customer order. | ||
* | ||
* See {@link MagentoCustomerOrder} for more info. | ||
*/ | ||
export const DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_TRANSFORMS = new InjectionToken<DaffMagentoCustomerOrderExtraTransform[]>( | ||
'DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_TRANSFORMS', | ||
{ factory: () => []}, | ||
); | ||
export const { | ||
/** | ||
* A multi-provider injection token for providing extra transform logic in the Order Magento driver. | ||
* It is run after the standard transforms for each customer order preview and passed both the current transformed Daffodil customer order and the Magento customer order. | ||
* | ||
* See {@link MagentoCustomerOrder} for more info. | ||
*/ | ||
token: DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_TRANSFORMS, | ||
|
||
/** | ||
* Provides extra customer order preview transforms for the Magento customer order driver. | ||
* | ||
* See {@link DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_TRANSFORMS}. | ||
* | ||
* ```ts | ||
* providers: [ | ||
* ...daffProvideCustomerOrderMagentoExtraOrderTransforms( | ||
* myExtraOrderTransform | ||
* ) | ||
* ] | ||
* ``` | ||
*/ | ||
export function daffProvideCustomerOrderMagentoExtraOrderTransforms<T extends MagentoCustomerOrder = MagentoCustomerOrder, V extends DaffOrder = DaffOrder>(...transforms: DaffMagentoCustomerOrderExtraTransform<T, V>[]): Provider[] { | ||
return transforms.map(transform => ({ | ||
provide: DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_TRANSFORMS, | ||
useValue: transform, | ||
multi: true, | ||
})); | ||
} | ||
/** | ||
* Provides extra customer order preview transforms for the Magento customer order driver. | ||
* | ||
* See {@link DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_TRANSFORMS}. | ||
* | ||
* ```ts | ||
* providers: [ | ||
* ...daffProvideCustomerOrderMagentoExtraOrderTransforms( | ||
* myExtraOrderTransform | ||
* ) | ||
* ] | ||
* ``` | ||
*/ | ||
provider: daffProvideCustomerOrderMagentoExtraOrderTransforms, | ||
} = createMultiInjectionToken<DaffMagentoCustomerOrderExtraTransform>('DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_TRANSFORMS'); |
17 changes: 9 additions & 8 deletions
17
libs/customer-order/driver/magento/2-4-5/src/injection-tokens/transforms/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
16 changes: 9 additions & 7 deletions
16
libs/customer-order/state/src/injection-tokens/error-matcher.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,12 +1,14 @@ | ||
import { InjectionToken } from '@angular/core'; | ||
|
||
import { createSingleInjectionToken } from '@daffodil/core'; | ||
import { daffTransformErrorToStateError } from '@daffodil/core/state'; | ||
|
||
/** | ||
* Transforms `DaffError`s into `DaffStateError`s before they are serialized into state. | ||
* Can be used to further refine Daffodil errors into more specific app errors. | ||
*/ | ||
export const DAFF_CUSTOMER_ORDER_ERROR_MATCHER = new InjectionToken<typeof daffTransformErrorToStateError>( | ||
export const { | ||
/** | ||
* Transforms `DaffError`s into `DaffStateError`s before they are serialized into state. | ||
* Can be used to further refine Daffodil errors into more specific app errors. | ||
*/ | ||
token: DAFF_CUSTOMER_ORDER_ERROR_MATCHER, | ||
provider: daffProvideCustomerOrderErrorMatcher, | ||
} = createSingleInjectionToken<typeof daffTransformErrorToStateError>( | ||
'DAFF_CUSTOMER_ORDER_ERROR_MATCHER', | ||
{ factory: () => daffTransformErrorToStateError }, | ||
); |
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 +1 @@ | ||
export { DAFF_CUSTOMER_ORDER_ERROR_MATCHER } from './error-matcher.token'; | ||
export * from './error-matcher.token'; |