Shopify Functions and GraphQL

I am using Shopify Functions and I have this query
query RunInput {
cart {
lines {
id
quantity
merchandise {
… on ProductVariant {
id
product {
id
inCollections(ids: [“gid://shopify/Collection/306253987991”]) {
collectionId
}
}
}
}
}
}
}

The issue is that inCollectiuons returns the id, and therefore true, whether it is present or not.
Is there any way to just get a list of collections that product is part of so I can do a quick filter on it to check.
I am wanting to target cart items that are part of a specific collection.

Thanks

You can use isMember field to check if product is a part of collection.

query RunInput(
  $collectionIdsFuncInput: [ID!]
) {
  cart {
    lines {
      id
      quantity
        merchandise {
          … on ProductVariant {
          id
          product {
            id
            inCollections(ids: $collectionIdsFuncInput) {
              collectionId
              isMember
            }
          }
        }
      }
    }
  }
}
1 Like