New Shopify Certification now available: Liquid Storefronts for Theme Developers

How to fetch metaobject values by Metaobject GID

vanio
Visitor
2 0 0

Hi, I have categories & subcategories in my shop like this structure :

categories : [
basics : [tops, bottom]
accessories : [rings, eyewear]
]

I've created Metaobject as mixed references which has value like this : 

categories : ["gid://shopify/Metaobject/1191280939", "gid://shopify/Metaobject/1259372843"]

I need to fetch the values from each category item from Admin GraphQL

this query returns undefined. can help me with the correct query?

query: `{
      node(id: "${id}") { /* gid://shopify/Metaobject/1191280939 */
        ... on Metaobjects {
          id
          key
          value
        }
      }
    }`

 

 

Replies 2 (2)
oscprofessional
Shopify Partner
15736 2353 3051

Hi @vanio,

You can get metaobject values not by metaobject GID, instead you can try with categories as you have categories and sub-categories.

I have query with collections and collection by id. Do run this query you will get all metaobjects and data.

query Collection_Metaobject {
  collections(first: 10) {
    nodes {
      metafields(first: 5) {
        nodes {
          id
          value          
        }
      }
    }
  }
  collection(id: "gid://shopify/Collection/437261140263") {
    id
    handle
    metafields(first: 10) {
      nodes {
        references(first: 5) {
          nodes {
            ... on Metaobject {
              id
            }
          }
        }
      }
    }
  }
}

 I hope this might be helpful, please let me know if any changes needed, definitely will find out the solution.

 

Thanks... 

Get pass your Store Core Web Vital Free Speed Optimization Audit, Chat on WhatsApp | Skype : oscprofessionals-87 | Email: pallavi@oscprofessionals.com | Custom Pricing Wholesale App : Free | Hire us | Guaranteed Site Speed Optimization | Website Free Audit | Shopify Theme Customization | Build Shopify Private App | Shopify SEO | Digital Marketing
vanio
Visitor
2 0 0

hello @oscprofessional , thanks for this solution. but finally, I found a simpler way.
I've changed the query like this and got the result as I expected

 

 

{
      metaobject(id:"${gid}") {
        id
        fields{
          key
          value
        }
      }
    }