Graphql query for Metaobject (list) #1326
-
How do I know which keys to specify in a graphql query for my custom data metafields? I'm trying to build a graphql query to retrieve my 'grid' metafield which contains a list of images. This is the code I use to get a single image in a custom field called 'hero' which works as expected:
But I'm struggling to adapt the code to retrieve a list of images. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @DaniBitZesty, this is how you would query for a list of metafield references {
page(handle: "about") {
title
heroImages: metafields(identifiers: [{namespace: "custom", key: "hero"}]) {
references(first: 10) {
nodes {
... on MediaImage {
id
image {
...MediaImage
}
}
}
}
}
}
}
fragment MediaImage on Image {
url
width
altText
height
} Rather than using a This would allow you to add multiple types of metafields inside the Hero metaobject e.g Heading, subheading, images etc.. |
Beta Was this translation helpful? Give feedback.
Hi @DaniBitZesty, this is how you would query for a list of metafield references
Rather than using a
metafield
, I would consider creatingHero
as a metaobject definition instead more info.This would allow you to add multiple types of metafields inside the Hero metaobject e.g Heading, subheading, images etc..