Conversations about creating, managing, and using metafields to store and retrieve custom data for apps and themes.
Hiya, I am having trouble retrieving a custom metafield of a product using the GraphQL API.
I am trying to retrieve metafield supersessions in the namespace custom, so custom.supersessions.
This is my original query:
query getProductsWithMetaField($first: Int!, $cursor: String) { products(first: $first, after: $cursor) { pageInfo { hasNextPage } edges { cursor node { id title vendor variants(first: 1) { edges { node { sku price } } } } } } }
This is how I tried to retrieve te metafields but failed because key and namespace can not be used together in this context:
query getProductsWithMetaField($first: Int!, $cursor: String) { products(first: $first, after: $cursor) { pageInfo { hasNextPage } edges { cursor node { id title vendor variants(first: 1) { edges { node { sku price } } } metafields(first: 1, namespace: "custom", keys: "supersessions") { edges { node { value } } } } } } }
I am however struggling to find a correct way to get this metafield whereas I have tried several options but was not able to find a solution.
Thanks in advance
@OutboardCare in the metafields query block the word keys should be key.
I believe if you run that you would get all products in the particular paginated set. The products that don't have that metafield value you will see null as the value for those products. You will most likely have to use code to filter out the products after you get the results.