Don’t know if this helps, but I will share what I discovered with you and share my code adapted to what I needed
Imagine: I need to check if product XPTO is published at Online Store
First of all, I get the GID of ‘Online Store’. Get all channels, loop and save the ID
Second, search the product using the handle to get the GID
Finally, create a structure with that GID to execute query.
Sorry for all the code:
async function isPublishedIn(channel_name, resource){
let channelsList = await getAllChannels()
let channel_gid = null
// If there are channels,
// lets look for the channel we want
// if the channel exists, save the GID
// IF NOT channel is null
if(channelsList != null){
if(channelsList.length > 0){
for (let channelData of channelsList) {
if(channelData.node.name == channel_name){
channel_gid = channelData.node.id
console.log("INFORMAÇÃO DO CANAL")
console.log(channelData)
}
}
}
}
// if channel_gid is null, the channel is not available or not exist. Return false
if(channel_gid == null)
return false
// Channel exists, we have the GID. Execute QUERY to check
// Generate handle data structure
let searcherVariable = {
"handle": resource.created[0].handle
}
// Get global product to get the GID
let globalProduct = await shopifyHelpers.getSingleSlim(searcherVariable, true)
// Generate handle data structure
searcherVariable = {
"id": globalProduct.id,
"channel_id": channel_gid
}
console.log('***************************')
console.log("CHECK IF PRODUCT IN CHANNEL")
console.log('***************************')
console.log("-> ESTRUTURA: ")
console.log(searcherVariable)
// Check product
let singleProductData = await shopifyHelpers.isProductInChannel(searcherVariable, true)
console.log('***************************')
console.log('***************************')
if(singleProductData == null)
return false
return singleProductData.data.product.publishedOnChannel
}
This is my “helper” that I use as a intermediary between Server and Query:
// CHECK IF PRODUCT EXISTS IN CHANNEL
async function isProductInChannel(variables) {
try {
//COST - 37
await getApiPoints(37);
let result = await axios.post('http://localhost:3060/graphql', {"query": gq.isProductInChannel, "variables":variables}
).then( async (res) => {
console.log(res.data)
return res.data
})
return result
} catch (err) {
throw err
}
}
My query:
// PRODUCT EXISTS IN CHANNEL
const isProductInChannel = `
query ($id: ID!, $channel_id: ID!) {
product(id: $id) {
publishedOnChannel(channelId: $channel_id)
}
}`
I dont know if you can see my other posts, but I have there the solutions to get GID from channel, get all channels, etc