Error using graphQL in Shopify app
I have the following function to add tags to an order:
// GraphQL function to update order tags using the correct query
async function updateOrderTags(shopify, orderId, tags) {
const mutation =
mutation addTags($id: ID!, $tags: [String!]!) {
tagsAdd(id: $id, tags: $tags) {
node {
id
}
userErrors {
message
}
}
}
;
const variables = {
id: gid://shopify/Order/${orderId}
, // Ensure the ID is properly formatted as a global ID
tags: tags // Tags should be a valid array of strings
};
try {
const result = await shopify.graphql(mutation, { variables });
if (result.tagsAdd.userErrors.length > 0) {
const errorMessages = result.tagsAdd.userErrors.map(error => error.message).join(", ");
throw new Error(Failed to update tags: ${errorMessages}
);
}
return result;
} catch (error) {
throw new Error(GraphQL Error: ${error.message}
);
}
}
And it is being used in the code as follows:
...
const shopify = connections.shopify.current;
...
await updateOrderTags(shopify, orderId, newTags);
...
However, it continues t throw the following error:



2 Replies
Hello, it looks like the
id
variable is getting set to null
. If you spread ...variables
or just pass in variables without the {}
does that fix the issue? It seems like id
and tags
are the expected params for the mutation
okay it works now thank you so much I wasted an entire day and all my gpt 4o prompts on this