Graphql Shopify | Query articles with its metafields

Graphql Shopify | Query articles with its metafields


1

Has anyone done a query for Articles that have metafields?
I can query the articles with its title, otherfields etc,
but by default Shopify won’t return the articles metafields in this call. These metafields for these articles have been created by an app. My first goal would be trying to call all articles and view its metafields also.

Currently…

# My Graphql
{
    articles(first:2){
        edges{
            node{
                title
                excerpt
            }
        }
    }
}
# Json Response
{
  "data": {
    "articles": {
      "edges": [
        {
          "node": {
            "title": "First Post",
            "excerpt": ""
          }
        },
        {
          "node": {
            "title": "Second Post",
            "excerpt": ""
          }
        }
      ]
    }
  }
}

What I hope for …

My Graphql:
{
    articles(first:2){
        edges{
            node{
                title
                excerpt
                metafields
            }
        }
    }
}
# Response
{
  "data": {
    "articles": {
      "edges": [
        {
          "node": {
            "title": "First Post",
            "excerpt": "",
            "metafields":[{
                "namespace":"mynamespacehere",
                "key":"mykey",
                "value":"Some Value"
                }

            ]
          }
        }
        ##...all other posts
      ]
    }
  }
}

2 Answers
2


1

Works exactly like described here:

https://shopify.dev/docs/admin-api/graphql/reference/metafields/metafield

if you want to query a certain meta field
its

fieldName: metafield(namespace: "YOUR_NAMESPACE", key: "YOUR_KEY"){
     value
}

As of Nov 2020 it seems like metafield queries only work against the ADMIN GraphQL API. When I try them with the Storefront API it returns null for everything I query.

PS: Seems like you have to enable each metafield you want to access via Storefront:
https://shopify.dev/tutorials/retrieve-metafields-with-storefront-api


-1

I am confused over namespace and key . can someone guide me with example

New contributor

abdul Hadi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1



Leave a Reply

Your email address will not be published. Required fields are marked *