Skip to content

feat(customer-order): create injection tokens with factory #3263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import {
InjectionToken,
Provider,
} from '@angular/core';
import { 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';

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,
provider,
} = createMultiInjectionToken<DocumentNode>('DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_FRAGMENTS');

/**
* Provides extra GraphQL fragments for the Magento order driver.
@@ -34,9 +33,7 @@ export const DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_FRAGMENTS = new InjectionTo
* ```
*/
export function daffProvideCustomerOrderMagentoExtraOrderFragments(...fragments: DocumentNode[]): Provider[] {
return fragments.map(fragment => ({
provide: DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_FRAGMENTS,
useValue: fragment,
multi: true,
}));
return provider(...fragments);
}

export { DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_FRAGMENTS };
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import {
InjectionToken,
Provider,
} from '@angular/core';
import { 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: () => []},
);
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,
provider,
} = createMultiInjectionToken<DaffMagentoCustomerOrderExtraTransform>('DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_TRANSFORMS');

/**
* 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
* ```
*/
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,
}));
return provider(...transforms);
}

export { DAFF_CUSTOMER_ORDER_MAGENTO_EXTRA_ORDER_TRANSFORMS };