Issue using variables in function input queries

I am developing a Shopify Function to apply discounts based on customer tags and product collection memberships.

collectionData (Namespace: discountApp): Holds only the variable selectedCollectionIds with an array of collection IDs.

          {
            "node": {
              "id": "gid://shopify/Metafield/27485936845038",
              "namespace": "discountApp",
              "key": "collectionData",
              "value": "{\"selectedCollectionIds\":[\"gid://shopify/Collection/422046531822\",\"gid://shopify/Collection/421527421166\"]}",
              "type": "json",
            }
          }

I have included this in my shopify.extension.toml file:

[extensions.input.variables]
  namespace = "discountApp"
  key = "collectionData"

and here is my run.graphql:

query Input($selectedCollectionIds: [ID!]) {
  cart {
    lines {
      merchandise {
        ... on ProductVariant {
          product {
            id
            handle
            inAnyCollection(ids: $selectedCollectionIds)
          }
        }
      }
    }
    buyerIdentity {
      customer {
        metafield(namespace: "discountApp", key: "tag") {
          value
        }
      }
    }
  }
  shop {
    metafield(namespace: "discountApp", key: "tags") {
      value
    }
  }
}

Here is what is returned to me from Shopify:

{
  "cart": {
    "lines": [
      {
        "merchandise": {
          "product": {
            "id": "gid://shopify/Product/8212928430318",
            "handle": "hat",
            "inAnyCollection": false
          }
        }
      },
      {
        "merchandise": {
          "product": {
            "id": "gid://shopify/Product/8208496492782",
            "handle": "t-shirt",
            "inAnyCollection": false
          }
        }
      }
    ],
    "buyerIdentity": {
      "customer": {
        "metafield": {
          "value": "Pro"
        }
      }
    }
  },
  "shop": {
    "metafield": {
      "value": "{\"Pro\":{\"collections\":{\"hats\":\"20%\",\"pants\":\"10%\",\"shirts\":\"35%\"}},\"VIP\":{\"collections\":{\"hats\":\"30%\",\"pants\":\"20%\",\"shirts\":\"40%\"}}}"
    }
  }
}

and here is the graphql code I used to create the metafield:

mutation {
  metafieldsSet(metafields: [
    {
      namespace: "discountApp",
      key: "collectionData",
      type: "json",
      value: "{\"selectedCollectionIds\":[\"gid://shopify/Collection/422046531822\",\"gid://shopify/Collection/421527421166\"]}",
      ownerId: "gid://shopify/Shop/61637230830"
    }
  ]) {
    metafields {
      id
    }
  }
}

But no matter what I do, I cannot get inAnyCollection to be true. Any suggestions or help?

This is your issue here:

ownerId: "gid://shopify/Shop/61637230830"

As mentioned in input query docs, the variable values need to be set on a metafield on the function owner, which is your case is probably the discount, based on your metafield naming.

Does this mean that you can read shop metafields in the input query, but you can’t use shop metafields for the input variables?

If so, this is a significant limitation. What do you do if you have several hundred discount codes that all follow the same logic, which changes on a weekly basis?