shopify.graphql

Sends a GraphQL request to the specified Shopify API endpoint.

This action is used to make a GraphQL query or mutation (update).

Parameters

url: string API endpoint to call
(optional, it's /admin/api/LOWEST_SUPPORTED_VERSION/graphql.json by default)
query: string GraphQL expression, it can be a query or a mutation

Returns

Promise that is resolved with a GraphQL response object.

The requested or updated resource is in the 'data' property.

Examples

Query the name of the shop
module.exports = async function(payload, actions, context) {
	const shopResult = await actions.shopify.graphql(
		'/admin/api/2023-07/graphql.json',
		'query { shop { name } }'
	);

	console.log('Shop name: ', shopResult.data.shop.name)
}

Query the 'createdAt' and 'description' fields of a product
module.exports = async function(payload, actions, context) {
	const qId = 'gid://shopify/Product/6705843699795';
	const qRes = await actions.shopify.graphql(`query {
		product(id: "${qId}") {
    	createdAt, description
  	}
	}`);

	console.log('Product: ', qRes);
}

Update the 'description' and 'tags' fields of a product
module.exports = async function(payload, actions, context) {
	const mId = 'gid://shopify/Product/6705843699795';

	const mRes = await actions.shopify.graphql(`mutation {
		productUpdate(input: {id: "${mId}",     
			descriptionHtml: "Modified description", 
			tags: ["modifiedProduct"]  
		}) {
			product { descriptionHtml, tags }
		}
	}`);

	console.log('Update result: ', mRes);
}