Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
Hi, I want to access some metafiles in the collection using storefront API but I'm not able to do that even after whitelisting meta fields. I'm getting the following error " Field 'metafield' doesn't exist on type 'Collection'".
This is expected behaviour. Collection metafields are not currently exposed in the Storefront API.
https://shopify.dev/docs/storefront-api/reference/common-objects/metafield#types-that-return-metafie...
That’s a bummer. What is the recommended way to add custom fields to collections/pages for headless development then?
You'd need to either store the extra data in your own database. Now that might be something that you still pull from the master product via the Admin API, but it could also be something you store externally to Shopify. The source doesn't matter as you'd just be matching your DB content against that product ID in the lookup.
If metafields are supported later in the storefront API there would be some value in keeping shopify as the master record keeper so you're ready for it.