Product Tags and GraphQL - Automatic Collection Issue

Solved
New Member
5 0 0

I have added a number of products to my store using the productCreate graphQL endpoint. They exist, they are published, and if I go to the product pages I can see the tags that I added through GraphQL in the tags section. I also have a number of other products added using a .csv file in my store.

 

Now I want to add these products to automatic collections on my store, which I am setting up manually, through the UI. I am setting the criteria for inclusion in the collection based on a tag. When I save the collection, the csv uploaded products are immediately added to the collection, but the GraphQL uploaded products are not.

 

If I upload a new product using GraphQL or I update an existing one using the productUpdate, then that product will appear in the existing collection after I do so. If I go in to the UI and change any slight detail on a product and save it after the collection has already been made it will appear as well. If I modify the collection, however, these products will vanish until they are touched again.

 

Is there a way to get my GraphQL products to show up immediately in these collections? I don't like the idea that I need to re-touch them all if I change the collection image or description. Is it possible I am doing something incorrect when I load these tags using productCreate? I am using the "tag1, tag2, tag3" format that I've seen in examples. Is there an additional call I need to make to set these tags on the product?

 

Thanks.

0 Likes
New Member
5 0 0

I have confirmed my theory: that if, after I finish my GraphQL API call I make a REST API call to update the product with the same set of tags it works as expected when I create automatic collections by tag afterwards.

 

This is my work around for now and what I would recommend to anyone else experiencing this issue, but it definitely seems like there's an issue somewhere in the GraphQL.

0 Likes
Shopify Staff
Shopify Staff
918 55 124

Hey @zheiland , 

 

Thanks a lot for pointing this out, this was definitely one of the more interesting bugs that I have encountered recently. 

 

Interestingly, it also only seems to affect products that were created before the smart collection, if they are created after they seem to add themselves to the collection fine. 

 

I've logged a bug report with the relevant teams here so they can investigate this and hopefully find a quick resolution. 

0 Likes
Shopify Staff
Shopify Staff
918 55 124

Hey again @zheiland , 

 

Would you be able to post an example of the mutation that you've been using for this? Are your tags being submitted as a string, or an array?

 

It looks like if your tags are sent in the mutation as a comma-separated string, we interpret it as a single tag (ex. "tag1, tag2" and not "tag1", "tag2") which causes it to not get picked up by the collection. 

 

We're going to look into fixing that, but in the meantime I've had success avoiding this by wrapping the tags in [] like this: tags: ["tag1", "tag2"]

0 Likes
New Member
5 0 0

Ah, so it's expecting an array of strings and not a string of comma separated values?

 

Sorry about the formatting on this, it's the variables generated by my code before it sends it off to the mutation. I am indeed passing it as "tag1, tag2, tag3"

 

{"input":{"input":{"id":"gid://shopify/Product/2261960654944","handle":"BLANK_OFA_XL","title":"OFA Old Favorite XL Trucker Hat","descriptionHtml":"<p>Iconic – yet humble – it’s the Old Favorite for a reason! With that perfected “Legacy fit”, supersoft mesh, and our trademark dirty wash – this well-loved hat is more than an accessory, it is a badge \nof honor that says: “Yeah, I’m living my Legacy”\n\n</p><ul><li> 100% cotton twill with a proprietary wash to create a \n“dirty” effect \n</li><li> Unstructured low profile fit\n</li><li> Old-school kelly green undervisor & snapback closure\n</li><li> Imported</li></ul>","vendor":"Legacy","productType":"Headwear","tags":"Blank, Headwear, Adjustable, Legacy, Adjustable Collection, Old Favorite Collection","seo":{"title":"Old Favorite","description":"<p>Iconic – yet humble – it’s the Old Favorite for a reason! With that perfected “Legacy fit”, supersoft mesh, and our trademark dirty wash – this well-loved hat is more than an accessory, it is a badge \r\nof honor that says: “Yeah, I’m living my Legacy”\r\n\r\n</p><ul><li> 100% cotton twill with a proprietary wash to create a \r\n“dirty” effect \r\n</li><li> Unstructured low profile fit\r\n</li><li> Old-school kelly green undervisor & snapback closure</li></ul>"},"options":["Color"],"variants":[{"id":"gid://shopify/ProductVariant/20090154778720","imageId":"gid://shopify/ProductImage/11749452349536","sku":"OFA-XL Black","options":["XL Black",""],"price":27.0000,"compareAtPrice":27.0000,"weight":120,"inventoryItem":{"cost":27.0000,"tracked":false},"inventoryPolicy":"DENY"},{"id":"gid://shopify/ProductVariant/20090154811488","imageId":"gid://shopify/ProductImage/11749452382304","sku":"OFA-XL Blue","options":["XL Blue",""],"price":27.0000,"compareAtPrice":27.0000,"weight":120,"inventoryItem":{"cost":27.0000,"tracked":false},"inventoryPolicy":"DENY"},{"id":"gid://shopify/ProductVariant/20090154844256","imageId":"gid://shopify/ProductImage/11749452415072","sku":"OFA-XL Cardinal","options":["XL Cardinal",""],"price":27.0000,"compareAtPrice":27.0000,"weight":120,"inventoryItem":{"cost":27.0000,"tracked":false},"inventoryPolicy":"DENY"},{"id":"gid://shopify/ProductVariant/20090154877024","imageId":"gid://shopify/ProductImage/11749452447840","sku":"OFA-XL Navy","options":["XL Navy",""],"price":27.0000,"compareAtPrice":27.0000,"weight":120,"inventoryItem":{"cost":27.0000,"tracked":false},"inventoryPolicy":"DENY"}],"images":[{"id":"gid://shopify/ProductImage/11749452316768","altText":""},{"id":"gid://shopify/ProductImage/11749452349536","altText":"XL Black"},{"id":"gid://shopify/ProductImage/11749452382304","altText":"XL Blue"},{"id":"gid://shopify/ProductImage/11749452415072","altText":"XL Cardinal"},{"id":"gid://shopify/ProductImage/11749452447840","altText":"XL Navy"}]}}}

 

The mutation I'm using looks like this:

mutation productUpdate($input: ProductInput!) {
                                            productUpdate(input: $input) {
                                                product {
                                                    id
                                                    variants(first: 100) {
                                                        edges {
                                                            node {
                                                                id
                                                                sku
                                                            }
                                                        }
                                                    }
                                                    images(first: 100) {
                                                        edges {
                                                            node {
                                                                id
                                                                originalSrc
                                                            }
                                                        }
                                                    }
                                                }
                                                userErrors {
                                                    field
                                                    message
                                                }
                                            }
                                        }

I have tried it with this input based on your feedback and it seems like it worked as expected:

{"input":{"input":{"id":"gid://shopify/Product/2261960654944","handle":"BLANK_OFA_XL","title":"OFA Old Favorite XL Trucker Hat","descriptionHtml":"<p>Iconic – yet humble – it’s the Old Favorite for a reason! With that perfected “Legacy fit”, supersoft mesh, and our trademark dirty wash – this well-loved hat is more than an accessory, it is a badge \nof honor that says: “Yeah, I’m living my Legacy”\n\n</p><ul><li> 100% cotton twill with a proprietary wash to create a \n“dirty” effect \n</li><li> Unstructured low profile fit\n</li><li> Old-school kelly green undervisor & snapback closure\n</li><li> Imported</li></ul>","vendor":"Legacy","productType":"Headwear","tags":["Blank","Headwear","Adjustable","Legacy","Adjustable Collection","Old Favorite Collection"],"seo":{"title":"Old Favorite","description":"<p>Iconic – yet humble – it’s the Old Favorite for a reason! With that perfected “Legacy fit”, supersoft mesh, and our trademark dirty wash – this well-loved hat is more than an accessory, it is a badge \r\nof honor that says: “Yeah, I’m living my Legacy”\r\n\r\n</p><ul><li> 100% cotton twill with a proprietary wash to create a \r\n“dirty” effect \r\n</li><li> Unstructured low profile fit\r\n</li><li> Old-school kelly green undervisor & snapback closure</li></ul>"},"options":["Color"],"variants":[{"id":"gid://shopify/ProductVariant/20090154778720","imageId":"gid://shopify/ProductImage/11749452349536","sku":"OFA-XL Black","options":["XL Black",""],"price":27.0000,"compareAtPrice":27.0000,"weight":120,"inventoryItem":{"cost":27.0000,"tracked":false},"inventoryPolicy":"DENY"},{"id":"gid://shopify/ProductVariant/20090154811488","imageId":"gid://shopify/ProductImage/11749452382304","sku":"OFA-XL Blue","options":["XL Blue",""],"price":27.0000,"compareAtPrice":27.0000,"weight":120,"inventoryItem":{"cost":27.0000,"tracked":false},"inventoryPolicy":"DENY"},{"id":"gid://shopify/ProductVariant/20090154844256","imageId":"gid://shopify/ProductImage/11749452415072","sku":"OFA-XL Cardinal","options":["XL Cardinal",""],"price":27.0000,"compareAtPrice":27.0000,"weight":120,"inventoryItem":{"cost":27.0000,"tracked":false},"inventoryPolicy":"DENY"},{"id":"gid://shopify/ProductVariant/20090154877024","imageId":"gid://shopify/ProductImage/11749452447840","sku":"OFA-XL Navy","options":["XL Navy",""],"price":27.0000,"compareAtPrice":27.0000,"weight":120,"inventoryItem":{"cost":27.0000,"tracked":false},"inventoryPolicy":"DENY"}],"images":[{"id":"gid://shopify/ProductImage/11749452316768","altText":""},{"id":"gid://shopify/ProductImage/11749452349536","altText":"XL Black"},{"id":"gid://shopify/ProductImage/11749452382304","altText":"XL Blue"},{"id":"gid://shopify/ProductImage/11749452415072","altText":"XL Cardinal"},{"id":"gid://shopify/ProductImage/11749452447840","altText":"XL Navy"}]}}}

 

0 Likes

Success.

Shopify Staff
Shopify Staff
918 55 124

Hey again @zheiland , 

 

Precisely - it's looking for an array of strings. Still something worth fixing at our end though, if we are expecting an array of strings we shouldn't be accepting values that don't align with that expectation. 

 

Thanks for showing me your mutation as well, appreciate it. Going forward you'll want to continue with the array formatting and this shouldn't happen again - but thanks to your report here we'll be able to patch that hole to prevent others from running into the same problem in the future. Thanks again! 

0 Likes