Skip to content

Commit 87ff316

Browse files
authored
feat(customer-order): create injection tokens with factory (#3263)
1 parent e3a6cc1 commit 87ff316

File tree

2 files changed

+36
-43
lines changed

2 files changed

+36
-43
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
import {
2-
InjectionToken,
3-
Provider,
4-
} from '@angular/core';
1+
import { Provider } from '@angular/core';
52
import { DocumentNode } from 'graphql';
63

7-
/**
8-
* A multi-provider injection token for providing extra GraphQL fragments that will be spread into order queries.
9-
* This can be used to retrieve additional data that is not covered by the standard Daffodil interfaces.
10-
*
11-
* Fragment structure is platform-specific and this feature should be used with care.
12-
*
13-
* This can increase query complexity above the Magento default of 300.
14-
* Daffodil only guarantees that stock queries don't exceed the limit of 300.
15-
* Apps using this token should therefore increase the query complexity limit
16-
* to accommodate the extra complexity contributed by the provided fragments.
17-
*/
18-
export const DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_FRAGMENTS = new InjectionToken<DocumentNode[]>(
19-
'DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_FRAGMENTS',
20-
{ factory: () => []},
21-
);
4+
import { createMultiInjectionToken } from '@daffodil/core';
5+
6+
const {
7+
/**
8+
* A multi-provider injection token for providing extra GraphQL fragments that will be spread into order queries.
9+
* This can be used to retrieve additional data that is not covered by the standard Daffodil interfaces.
10+
*
11+
* Fragment structure is platform-specific and this feature should be used with care.
12+
*
13+
* This can increase query complexity above the Magento default of 300.
14+
* Daffodil only guarantees that stock queries don't exceed the limit of 300.
15+
* Apps using this token should therefore increase the query complexity limit
16+
* to accommodate the extra complexity contributed by the provided fragments.
17+
*/
18+
token: DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_FRAGMENTS,
19+
provider,
20+
} = createMultiInjectionToken<DocumentNode>('DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_FRAGMENTS');
2221

2322
/**
2423
* Provides extra GraphQL fragments for the Magento order driver.
@@ -34,9 +33,7 @@ export const DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_FRAGMENTS = new InjectionTo
3433
* ```
3534
*/
3635
export function daffProvideCustomerOrderMagentoExtraOrderFragments(...fragments: DocumentNode[]): Provider[] {
37-
return fragments.map(fragment => ({
38-
provide: DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_FRAGMENTS,
39-
useValue: fragment,
40-
multi: true,
41-
}));
36+
return provider(...fragments);
4237
}
38+
39+
export { DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_FRAGMENTS };
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
import {
2-
InjectionToken,
3-
Provider,
4-
} from '@angular/core';
1+
import { Provider } from '@angular/core';
52

63
// workaround https://github.com/graycoreio/daffodil/issues/1667
4+
import { createMultiInjectionToken } from '@daffodil/core';
75
import { DaffOrder } from '@daffodil/order';
86

97
import { DaffMagentoCustomerOrderExtraTransform } from '../../interfaces/public_api';
108
import { MagentoCustomerOrder } from '../../models/public_api';
119

12-
/**
13-
* A multi-provider injection token for providing extra transform logic in the Order Magento driver.
14-
* 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.
15-
*
16-
* See {@link MagentoCustomerOrder} for more info.
17-
*/
18-
export const DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_TRANSFORMS = new InjectionToken<DaffMagentoCustomerOrderExtraTransform[]>(
19-
'DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_TRANSFORMS',
20-
{ factory: () => []},
21-
);
10+
const {
11+
/**
12+
* A multi-provider injection token for providing extra transform logic in the Order Magento driver.
13+
* 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.
14+
*
15+
* See {@link MagentoCustomerOrder} for more info.
16+
*/
17+
token: DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_TRANSFORMS,
18+
provider,
19+
} = createMultiInjectionToken<DaffMagentoCustomerOrderExtraTransform>('DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_TRANSFORMS');
2220

2321
/**
2422
* Provides extra customer order preview transforms for the Magento customer order driver.
@@ -34,9 +32,7 @@ export const DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_TRANSFORMS = new InjectionT
3432
* ```
3533
*/
3634
export function daffProvideCustomerOrderMagentoExtraOrderTransforms<T extends MagentoCustomerOrder = MagentoCustomerOrder, V extends DaffOrder = DaffOrder>(...transforms: DaffMagentoCustomerOrderExtraTransform<T, V>[]): Provider[] {
37-
return transforms.map(transform => ({
38-
provide: DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_TRANSFORMS,
39-
useValue: transform,
40-
multi: true,
41-
}));
35+
return provider(...transforms);
4236
}
37+
38+
export { DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_TRANSFORMS };

0 commit comments

Comments
 (0)