Skip to content

Graphql query for Metaobject (list) #1326

Answered by juanpprieto
DaniBitZesty asked this question in Help
Discussion options

You must be logged in to vote

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 metafield, I would consider creating Hero 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..

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@DonKoko
Comment options

Answer selected by juanpprieto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
3 participants