How to fetch metaobject values by Metaobject GID

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
16366 2440 3188

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... 

Hire us | Pass Core Web Vital | B2B Wholesale Experts | Claim Your Free Website Review |
Connect with Us: WhatsApp | Skype: oscprofessionals-87 | Email: pallavi@oscprofessionals.com |
Custom Shopify SolutionsPrivate Apps, Theme Customization & SEO | Digital Marketing |
OSCP Apps: Discount Suite | Wholesale App | Bundle & Upsell | Shipping Discount | and more...
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
        }
      }
    }