Add extra fields to order item query using fieldsHelper
Description
This function is used to add extra fields to the order item query. You can refer this links for the available fields .
Dependencies
json-to-graphql-query package
We use this package to convert the object to graphql query. The current fields you will be getting in the fields
object.
And then you can addFieldsToOrderItem function to add extra fields to the order item query. Example is given below.
Parameters
Parameter | Type | Description |
---|---|---|
fields | Object | This object will be merged with the existing order item query. |
Sample usage
In this example we are adding the totalShippingPrice, shippingDiscountAllocations and subtotalPrice fields to the order item query.
Like the above you can add any fields to the order item query based on the available fields in the order item object.
import { fieldsHelper } from '@appmaker-xyz/shopify';
// you can use this from the theme activate function.
fieldsHelper.addFieldsToOrderItem({
fields: {
totalShippingPrice: {
amount: true,
currencyCode: true,
},
shippingDiscountAllocations: {
allocatedAmount: {
amount: true,
currencyCode: true,
},
discountApplication: {
allocationMethod: true,
targetSelection: true,
targetType: true,
value: {
__on: [
{
__typeName: 'MoneyV2',
amount: true,
currencyCode: true,
},
{
__typeName: 'PricingPercentageValue',
percentage: true,
},
],
},
},
},
subtotalPrice: {
amount: true,
currencyCode: true,
},
},
});