Dynamically adding collection in the Function input

Hi, I’m building a discount function where I want to apply the discount if the product is part of a specific collection. Is there a way to dynamically put collections in the function input instead of hardcoding the collection ids? The official docs only shows an example of the hardcoded way from what I understand.

Reference: Use variables in input queries

And I also cannot test the RunInput in the Shopify GraphiQL App because “Shopify GraphQL App or Explorer only available for admin or storefront API,
but now you use the Shopify Function input which is not valid”.

Reference: Solved: Re: Error getting graphql RunInput in graphQL preview - Shopify Community

Here is my run.graphq

query RunInput {
  cart {
    lines {
      id
      quantity
      merchandise {
        __typename
        ... on ProductVariant {
          id
          product {
            id
            title
            inCollections(ids: [
              "gid://shopify/Collection/29638****097", 
              "gid://shopify/Collection/29638****777"
            ]) {
              collectionId
              isMember
            }
          }
        }
      }
    }
  }
  discountNode {
.. rest of the run.graphql

Hi @japhet_tdmc

Looks like you have the link to the right docs on how to do this:

I’d recommend reviewing that guide again and its directions. It walks through converting the hardcoded values to dynamic values. You’ll need to use GraphQL variables, set the variable values in a metafield on the discount, and then configure that metafield in your extension toml.

Nick

Hi @NickWesselman, thank you very much much for your reply. I’ve reviewed it but I’m still bit clueless on where and how to make the collections dynamic. :sweat_smile:

Can you be more specific about where you are getting stuck in this tutorial? Which steps have you completed?

The collection values go in a metafield. You can populate that metafield from your own UI or from a UI extension. There’s a full working example with a product discount here: