Can't set rule for smart collection using GraphQL

Mutation:

mutation updateCollectionRules($input: CollectionInput!) {
  collectionUpdate(input: $input) {
    collection {
      id
      title
      description
      handle
      ruleSet {
        rules {
          column
          relation
          condition
          conditionObject {
            ... on CollectionRuleMetafieldCondition {
              __typename metafieldDefinition { 
                namespace 
                key 
                name 
              }
            }
          }
        }
        appliedDisjunctively
      }
    }
    userErrors { 
      field 
      message 
    } 
  } 
}

Variables:

{
  "input": {
    "id": "gid://shopify/Collection/462636384518",
    "ruleSet": {
      "rules": [
        {
          "column": "TAG", "relation": "EQUALS", "condition": "Sample Tag"
        },
        {
          "column": "PRODUCT_METAFIELD_DEFINITION",
          "condition": "3M",
          "relation": "EQUALS",
          "conditionObject": {
            "__typename": "CollectionRuleMetafieldCondition",
            "metafieldDefinition": {
              "namespace": "app",
              "key": "brand"
            }
          }
        }
      ],
      "appliedDisjunctively": false
    }
  }
}

It says

Variable $input of type CollectionInput! was provided invalid value for ruleSet.rules.1.conditionObject (Field is not defined on CollectionRuleInput)

How to set properly the product metafield rule to attach products to the collection using GraphQl by the

PRODUCT_METAFIELD_DEFINITION column type?

1 Like