Gatsby: Query multiple images with GrapQL

Created on 20 Apr 2018  路  2Comments  路  Source: gatsbyjs/gatsby

I would like to load all images in a certain folder (e.g. assets/team/) and use them through the gatsby-image plugin.

I currently have it working for 1 single file with this query:

export const query = graphql`
  query BlurUpQuery {
    heroAssets: imageSharp(id: { regex: "/testImage/" }) {
      sizes(maxWidth: 600) {
        ...GatsbyImageSharpSizes_tracedSVG
      }
    }
  }
`

which returns sizes for this asset. Is it possible to grab all assets in a certain folder?

question or discussion

Most helpful comment

you would have to change your query something like this: (this is not tested - just to show to construct query - you probably will need to adjust filter in allFile query (also you shouldn't filter by id, we will be chaning id in gatsby v2 so they won't contain paths)

export const query = graphql`
  query BlurUpQuery {
    heroAssets: allFile(filter: { absolutePath: { regex: "/testImage/" } }) {
      edges {
        node {
          childImageSharp {
            sizes(maxWidth: 600) {
              ...GatsbyImageSharpSizes_tracedSVG
            }
          }
        }
      }
    }
  }
`

All 2 comments

you would have to change your query something like this: (this is not tested - just to show to construct query - you probably will need to adjust filter in allFile query (also you shouldn't filter by id, we will be chaning id in gatsby v2 so they won't contain paths)

export const query = graphql`
  query BlurUpQuery {
    heroAssets: allFile(filter: { absolutePath: { regex: "/testImage/" } }) {
      edges {
        node {
          childImageSharp {
            sizes(maxWidth: 600) {
              ...GatsbyImageSharpSizes_tracedSVG
            }
          }
        }
      }
    }
  }
`

Due to the high volume of issues, we're closing out older ones without recent activity. Please open a new issue if you need help!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Oppenheimer1 picture Oppenheimer1  路  3Comments

totsteps picture totsteps  路  3Comments

jimfilippou picture jimfilippou  路  3Comments

rossPatton picture rossPatton  路  3Comments

dustinhorton picture dustinhorton  路  3Comments