Wrong documentation of metafields query?

According to documentation here, metafields can be queried by providing a list of keys

However this graphQL query only return the metafield, and not the metafields (queried with keys)
Query:

{
      currentAppInstallation{
        metafield(namespace: "features", key: "gad") {
            key
            value
        }
        metafields(first: 100, keys: ["features.gad"]){
            edges {
                node {
                    namespace
                    jsonValue
                    key
                }
            }
            pageInfo {
                hasNextPage
                endCursor
            }        
        }


      }
    }

Response

{
    "data": {
        "currentAppInstallation": {
            "metafield": {
                "key": "gad",
                "value": "false"
            },
            "metafields": {
                "edges": [],
                "pageInfo": {
                    "hasNextPage": false,
                    "endCursor": null
                }
            }
        }
    },
    "extensions": {
        "cost": {
            "requestedQueryCost": 13,
            "actualQueryCost": 4,
            "throttleStatus": {
                "maximumAvailable": 2000.0,
                "currentlyAvailable": 1996,
                "restoreRate": 100.0
            }
        }
    }
}
1 Like

Anyone encountered the same problem? What did I do wrong?

Hey @Nghia_Huynh

Great question! You definitely didn’t do anything wrong. This is actually a documentation gap on our end that we need to clarify better.

The issue is that when you use the keys parameter without specifying a namespace, the query defaults to searching in the app-reserved namespace rather than your custom “features” namespace.

Since your metafield exists in the “features” namespace, the query with keys: ["features.gad"] returns empty because it’s looking in the wrong place. Additionally, the API doesn’t allow combining the namespace parameter with keys, which adds to the confusion.

To get your metafields from the “features” namespace, use metafields(first: 100, namespace: "features") instead, which will return all metafields in that namespace and you can filter on the client side if needed.

1 Like

Hey Nghia,

I wanted to follow up here to let you know that upon closer review there does seem to be an issue with the behaviour here. We are currently looking in to this and I’ll follow up once I know more.

Hey @Nghia_Huynh,

We were able to fix this, so your queries should be working now.

Hi Kyle,
I can see that it’s working now on our test store. Is it safe to use it in production now? Thanks!

Thanks for confirming that. Yes it is safe to use :slight_smile: