Skip to main content

Add extra fields to cart line item query using fieldsHelper

Description

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

Parameters

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

Sample usage

​ In this example we are adding the variant, collections and custom_products_list fields to the cart line item query. Also we are adding the selectedOptions, also under the product object we are adding the custom_product_tat field which is a metafield. ​ ​ ​

import { fieldsHelper } from '@appmaker-xyz/shopify';

fieldsHelper.addFieldsToCartLineItem({
fields: {
variant: {
selectedOptions: {
name: true,
value: true,
},
product: {
// here you can add any product field
custom_product_tat: {
__aliasFor: 'metafield',
__args: {
key: 'product_tat', // here you add the key of the metafield
namespace: 'custom', // here you add the namespace of the metafield
},
value: true,
},
},
},
},
});