Skip to main content

Add extra fields to order product line item query using fieldsHelper

Description

​ This function is used to add extra fields to the order product line 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 addFieldsToOrderProductLineItem function to add extra fields to the order product line item query. Example is given below. ​

Parameters

ParameterTypeDescription
fieldsObjectThis object will be merged with the existing order product line item query.

Sample usage

​ In this example we are adding the publishedAt, seo, collections and custom_products_list fields to the product query.

Like the above you can add any fields to the product query based on the available fields in the product object. ​

fieldsHelper.addFieldsToOrderProductLineItem({
fields: {
// add any fields in the required format
publishedAt: true, // adding a simple field
seo: {
title: true,
description: true,
}, // adding a nested object
collections: {
__args: {
first: 100,
},
edges: {
node: {
id: true,
title: true,
handle: true,
},
},
}, // adding a collection field with arguments
custom_products_list: {
__aliasFor: 'metafield',
__args: {
key: 'pair_with',
namespace: 'custom',
},
value: true,
}, // adding a metafield and assigning it to a custom_products_list alias
},
});