-
-
Notifications
You must be signed in to change notification settings - Fork 276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Are GraphQL mutations supported? #338
Comments
this is how I implemented mutations: const query = gql.mutation({
operation: operation,
variables: variables,
fields: [
{product: ['id']}, {userErrors: ['field', 'message']},
],
})
// shopifyAdapter?.query is shopify.graphql(query, variables)
const promise = this.shopifyAdapter?.query(query.query, query.variables)
const response = await promise |
@mjsilva Thanks for the hack Could we get a look into this from a maintainer please to support it directly? |
I've had luck with this: const shopify = new Shopify({
shopName: shop,
accessToken: accessToken
});
const productMutation = `mutation productCreate($input: ProductInput!) {
productCreate(input: $input) {
product {
id
}
userErrors {
field
message
}
}
}`;
const variables = {
"input": {
"title": params.title,
"descriptionHtml": params.description,
"variants": [{
"price": params.price,
"barcode": params.barcode,
"requiresShipping": false,
"taxable": true
}],
"published": true,
}
};
try {
let response = await shopify.graphql(productMutation, variables);
return response;
}
catch(error) {
console.log(error.message);
} |
Thanks @tomredman Just noting that this doesn't work with the Shopify Bulk API. This is what I tried: const bulkImportMutation = `mutation {
bulkOperationRunQuery(
query: """
{
products {
edges {
node {
id
title
}
}
}
}
"""
) {
bulkOperation {
id
status
}
userErrors {
field
message
}
}
}`
const shopify = new Shopify({
shopName: storeName,
accessToken
})
try {
let response = await shopify.graphql(bulkImportMutation, {})
console.log(response)
} catch (e) {
console.error(e)
} What I get is an error saying:
I tried the same mutation using the Shopify Graphiql app and it launches a job sucessfully. I think I'll fall back to a simple POST request directly to the endpoint. |
I came across this, and there was a few things I found. {
"id": "an ID"
} My mutations worked after that :) |
I can confirm that setting the apiVersion to "2023-04" fixed the problem in my case too ( |
Im having the same issue with productCreate mutation, using Next.js eCommerce template and trying to create product having error like this ` const query = |
I was trying a simple mutation the other day to update a collections descriptionHtml. I could only get it to work with fetch. I noticed that body assumes query. Could that be the issue or is it normal to wrap query around mutation?
Shopify-api-node/index.js
Line 225 in fe7eee0
The text was updated successfully, but these errors were encountered: