Inconsistency on metafield fields returned by queries

Hello,
On my queries requests on metafields, I notice a strange behavior (tested in 2026-04 and unstable).
Query 1:

query getShopMetafield {
  shop {
    metafields(first: 1) {
      nodes {
        namespace
        value
        key
      }
    }
  }
}

Data 1:

{
  "shop": {
    "metafields": {
      "nodes": [
        {
          "namespace": "custom",
          "value": "value",
          "key": "my_metafield"
        }
      ]
    }
  }
}

Query 2:

query getFilteredShopMetafield {
  shop {
    metafields(first: 1, keys: ["custom.my_metafield"]) {
      nodes {
        namespace
        value
        key
      }
    }
  }
}

Data 2:

{
  "shop": {
    "metafields": {
      "nodes": [
        {
          "namespace": "custom",
          "value": "value",
          "key": "custom.my_metafield"
        }
      ]
    }
  }
}

The key is prefixed by the namespace in its field only on second query. I didn’t find any documentation about this. Can it be considered an inconsistency or is there a special meaning to this behavior?

Thank you in advance

Hey @AMillasseau - thanks for flagging this.

I reproduced it and can confirm that filtering with keys: ["custom.my_metafield"] returns custom.my_metafield in the key field, while the unfiltered query returns my_metafield.

The docs partly call this out. The keys argument on Shop.metafields says keys in the namespace.key format “will be returned in the same format,” but the Metafield.key field only describes key as “The unique identifier for the metafield within its namespace” and doesn’t mention that it can include the namespace.

I’m checking whether this is expected, and if it is, I’ll look into clarifying the docs. I’ll update this thread when I know more.