GraphQL on metafieldDefinitions doesn't show all metafields, why ?

GraphQL on metafieldDefinitions doesn't show all metafields, why ?

fpeyret
Shopify Partner
1 0 1

Hello,


I'm using the GraphQL API to retrieve the definition of our product metafields.
Unfortunately, I don't understand why, but my GraphQL query doesn't want to return all the fields that are visible in the BackOffice.

 

Here's the query :

query {
    metafieldDefinitions(first: 250, ownerType: PRODUCT) {
        edges {
            node {
                name
                key
                namespace
                description
                ownerType
                type {
                    name
                    category
                }
            }
        }
    }
}

Here's what it returns:

{
    "data": {
        "metafieldDefinitions": {
            "edges": [
                {
                    "node": {
                        "name": "test",
                        "key": "test",
                        "namespace": "custom",
                        "description": "",
                        "ownerType": "PRODUCT",
                        "type": {
                            "name": "multi_line_text_field",
                            "category": "TEXT"
                        }
                    }
                },
                {
                    "node": {
                        "name": "test2",
                        "key": "test2",
                        "namespace": "custom",
                        "description": null,
                        "ownerType": "PRODUCT",
                        "type": {
                            "name": "multi_line_text_field",
                            "category": "TEXT"
                        }
                    }
                }
            ]
        }
    },
    "extensions": {
        "cost": {
            "requestedQueryCost": 24,
            "actualQueryCost": 4,
            "throttleStatus": {
                "maximumAvailable": 20000.0,
                "currentlyAvailable": 19996,
                "restoreRate": 1000.0
            }
        }
    }
}

We see the metafields of the 'custom' namespace, but no other namespace, even though they're present in the BackOffice.

 

Am I making an error in my query or is this an API limitation?

 

thank you for your help.

Reply 1 (1)

ShopifyDevSup
Shopify Staff
1453 238 508

Hey @fpeyret

 

Thanks for sharing that example. That's interesting that not all of the product definitions are being returned. 

 

It's hard to say for sure what's happening without being able to look in to the specific store. The first thing I would check is that the app you're using for the query has access to the metafield definitions you are expecting. This document explains why some types may not be available to certain apps, depending on how they were created: https://shopify.dev/docs/apps/custom-data/metafields#kinds-of-metafields 

 

Once you've reviewed that, the next step I would recommend is to find one of the definitions that isn't being returned and query that definition specifically by the ID. That way you'll be able to test if it's available to your app or not based on the response. https://shopify.dev/docs/api/admin-graphql/2024-01/queries/metafieldDefinition 

 

If you're still finding metafield definitions that you're app should have access too, but they aren't being returned, I'd try logging in to our support center and reaching out so we can securely take a look at the store/app.  

 

Hope that helps, 

- Kyle G.

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog