A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hello
Is there a way to publish directy a product to all channels available?
mutation ProductCreate($input: ProductInput!, $media: [CreateMediaInput!] ) {
productCreate(input: $input, media: $media) {
userErrors {
field
message
}
product {
title
handle
id
media (first: 50) {
edges {
cursor
node {
status
... on MediaImage {
id
image {
id
originalSrc
}
}
}
}
pageInfo {
hasNextPage
}
}
variants (first: 25) {
edges {
cursor
node {
id
sku
title
}
}
pageInfo {
hasNextPage
}
}
}
}
}
Or/And directly update:
mutation ProductUpdate($input: ProductInput!) {
productUpdate(input: $input) {
userErrors {
field
message
}
product {
title
id
variants (first: 25) {
edges {
cursor
node {
id
sku
title
}
}
pageInfo {
hasNextPage
}
}
}
}
}
Solved! Go to the solution
This is an accepted solution.
after hours with chat talking with support, and nobody knows and helps, I could publish the solution...
Imagina that I needed to use deprecated fields because the fields that are supposed to be used, didn't work...
mutation publishablePublish($id: ID!, $input: [PublicationInput!]!) {
publishablePublish(id: $id, input: $input) {
publishable {
availablePublicationCount
publicationCount
publishedOnCurrentPublication
}
shop {
id
}
userErrors {
field
message
}
}
}
Call:
async function publishToChannelHelper(variables) {
try {
//COST - 37
await getApiPoints(37);
let myTesting = await axios.post('http://localhost:3060/graphql', {"query": gq.publishChannel, "variables": variables}
).then( async (res) => {
console.log(res.data)
return res.data
})
console.log("THIS IS TESTING")
console.log(myTesting.errors[0])
return myTesting
} catch (err) {
throw err
}
}
The data:
let publishToChannelStructure = {
"id": "gid://shopify/Product/XXXXX",
"input":{
"channelId": "gid://shopify/Channel/XXXX"
}
};
let publisher = await shopifyHelpers
.publishToChannelHelper(publishToChannelStructure)
.then(async (res) => {
console.log("FIM")
})
This is an accepted solution.
after hours with chat talking with support, and nobody knows and helps, I could publish the solution...
Imagina that I needed to use deprecated fields because the fields that are supposed to be used, didn't work...
mutation publishablePublish($id: ID!, $input: [PublicationInput!]!) {
publishablePublish(id: $id, input: $input) {
publishable {
availablePublicationCount
publicationCount
publishedOnCurrentPublication
}
shop {
id
}
userErrors {
field
message
}
}
}
Call:
async function publishToChannelHelper(variables) {
try {
//COST - 37
await getApiPoints(37);
let myTesting = await axios.post('http://localhost:3060/graphql', {"query": gq.publishChannel, "variables": variables}
).then( async (res) => {
console.log(res.data)
return res.data
})
console.log("THIS IS TESTING")
console.log(myTesting.errors[0])
return myTesting
} catch (err) {
throw err
}
}
The data:
let publishToChannelStructure = {
"id": "gid://shopify/Product/XXXXX",
"input":{
"channelId": "gid://shopify/Channel/XXXX"
}
};
let publisher = await shopifyHelpers
.publishToChannelHelper(publishToChannelStructure)
.then(async (res) => {
console.log("FIM")
})