Variables are not working on shop metafield for cart checkout validation function

Topic summary

A developer is experiencing issues with variables not passing correctly in a cart checkout validation function when using shop metafields.

The Problem:

  • Created a shop metafield that works fine on its own
  • Variables in RunInput (specifically $selectedProducts) are not sending values as expected
  • The GraphQL query attempts to use $selectedProductTags and $selectedCollectionIds variables

Technical Details:

  • Metafield configuration uses namespace $app:my_cart_checkout_shop_namespace and key my_cart_checkout_shop_key
  • JavaScript side creates metafield with JSON type and stringified rules
  • Rules include selectedCollectionIds: ["Home"] and selectedProductTags: ["Accessory"]

Attempted Solution:

  • Developer references Shopify documentation indicating variables need to be declared in the TOML file under [extensions.input.variables]

Status: The issue remains unresolved with no responses yet. The developer needs help understanding why variables aren’t being passed correctly from the metafield to the validation function.

Summarized with AI on November 15. AI used: claude-sonnet-4-5-20250929.

I have created metafiled on shop which is working fine. However am unable to pass the variables.
in RunInput $selectedProducts supposed to send the values but it is not.

query RunInput($selectedProductTags: [String!], $selectedCollectionIds: [ID!]) {
  cart {
    lines {
      quantity
      merchandise {
        __typename
        ... on ProductVariant {
          id
          weight
          product {
         
            hasTags(tags: $selectedProductTags) {
              hasTag
              tag
            }
          }
        }
      }
    }
  }
  shop {
    metafield(
      namespace: "$app:my_cart_checkout_shop_namespace"
      key: "my_cart_checkout_shop_key"
    ) {
      value
    }
  }
}

As mentioned in the doc that variables need to be declared into the toml file is already being declared

  [extensions.input.variables]
   namespace: "$app:my_cart_checkout_shop_namespace"
   key: "my_cart_checkout_shop_key"

at the javascript side , metafiled is created like this

let rules = { };

rules.selectedProductTags = [“Accessory”];
rules.selectedCollectionIds = [“Home”];

await admin.rest.put({
path: ${"metafields/" + metafieldId + ".json"},
data: JSON.stringify({
metafield: {
id: metafieldId,
value: JSON.stringify(rules),
type: “json”,
},
}),
});