Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Query Shopify products from a Collection and get product tags

Query Shopify products from a Collection and get product tags

njagojevic
Visitor
2 0 0

How can I get product tags by making a query for products in a specific collection? The error I get here: No field of name "tags" found on type "Product" in schema

const query = shopifyClient.graphQLClient.query((root) => {
      root.add(
        "collectionByHandle",
        { args: { handle: "collection-handle" }, alias: "collection" },
        (Collection) => {
          Collection.add("id");
          Collection.addConnection(
            "products",
            {
              args: {
                first: 25,
              },
            },
            (Product) => {
              Product.add("title");
              Product.add("handle");
              Product.add("tags"); /* Couldn't get tags?! */
              Product.addConnection(
                "variants",
                { args: { first: 25 } },
                (Variant) => {
                  Variant.add("price");
                }
              );
              Product.addConnection(
                "images",
                { args: { first: 1 } },
                (Image) => {
                  Image.add("src");
                }
              );
            }
          );
        }
      );
    });

    shopifyClient.graphQLClient
      .send(query)
      .then(({ model }) => {
        // Some logic
      })
      .catch((err) => {
        console.log("err", err);
      });

 Any suggestions here? Thanks in advance.

Replies 3 (3)

Gregarican
Shopify Partner
1033 86 292

Must be a quirk in the client library you are using. If you refer to a post that I replied to just today, you'll see that the GraphQL query in its raw form successfully retrieves the product tags. Tested it out before I hit the Post button!

 

https://community.shopify.com/c/Shopify-APIs-SDKs/When-I-tried-to-get-the-products-under-a-collectio...

 

njagojevic
Visitor
2 0 0

The library I'm using is https://github.com/Shopify/js-buy-sdk

msk
Excursionist
28 5 3

Hello,

can you please share the URl where you are requesting. if its a link for collection like

"/admin/api/2020-07/collections/841564295.json"

then error is good because there is no tag in it. and if you are using

"/admin/api/2020-07/collections/{collection_id}/products.json"

then this error should not come.