Mutations
Here are some examples of making GraphQL mutation calls in Shypyard.

Example: Update product variant

1
const newSKU = 'some-new-sku';
2
await shopify.graphql(`
3
mutation {
4
productVariantUpdate(
5
input: {
6
id: "${variant.admin_graphql_api_id}"
7
sku: "${newSKU}"
8
}
9
) {
10
productVariant {
11
sku
12
}
13
userErrors {
14
field
15
message
16
}
17
}
18
}
19
`);
20
}
21
// print updated data
22
console.log(JSON.stringify(resp, null, 2));
Copied!

Example: Adding tags

1
​
2
const tagsToAdd = ['tag1', 'tag2', 'tag3'];
3
const resp = await shopify.graphql(`
4
mutation {
5
tagsAdd(
6
id: "${order.customer.admin_graphql_api_id}"
7
tags: "${tagsToAdd}"
8
) {
9
node {
10
... on Order {
11
id
12
name
13
tags
14
}
15
}
16
userErrors {
17
field
18
message
19
}
20
}
21
}
22
`);
23
// print updated tags
24
console.log(JSON.stringify(resp, null, 2));
Copied!

Example: Update order note

1
const resp = await shopify.graphql(`
2
mutation {
3
orderUpdate(
4
input: {
5
id: "${order.admin_graphql_api_id}"
6
note: "${note}"
7
}
8
) {
9
userErrors {
10
field
11
message
12
}
13
}
14
}
15
`);
16
​
17
// print updated tags
18
console.log(JSON.stringify(resp, null, 2));
Copied!
  • Bulk update location inventory (see doc)
1
const update_mutations = [
2
{inventoryItemID: 123, quantity: 10},
3
{inventoryItemID: 345, quantity: 5},
4
];
5
​
6
const mutationQuery = `
7
mutation {
8
inventoryBulkAdjustQuantityAtLocation(
9
locationId: "${gql_location}",
10
inventoryItemAdjustments: [
11
${update_mutations
12
.map(
13
(x) =>
14
`{inventoryItemId: "${x.inventoryItemID}", availableDelta: ${x.quantity}}`,
15
)
16
.join(',')}
17
]
18
) {
19
inventoryLevels {
20
id
21
available
22
}
23
userErrors{
24
field
25
message
26
}
27
}
28
}`;
29
​
30
try {
31
let response = await shopify.graphql(mutationQuery);
32
console.log(JSON.stringify(response, null, 2));
33
} catch (error) {
34
console.log(error.message);
35
throw error;
36
}
Copied!