如何查询2张不同的图片?

时间:2020-08-11 15:02:54

标签: graphql gatsby

我想查询2张图片,images/me.jpgimages/boxing.png

不确定在graphql中怎么做:

query AboutQuery {
    file(relativePath: { eq: ("images/me.jpg"|"images.boxing.png") }) {
      childImageSharp {
        fluid {
          ...GatsbyImageSharpFluid
        }
      }
    }
  }

1 个答案:

答案 0 :(得分:1)

这应该有效:

query AboutQuery {
    file(relativePath: { regex: "images" }) {
      childImageSharp {
        fluid {
          ...GatsbyImageSharpFluid
        }
      }
    }
  }

GraphQL Query Reference中可以看到,可以使用正则表达式来匹配relativePath,如果需要,您可以匹配"images"

您也可以选择使用in过滤器(接受数组中的多个值)来匹配["images"]

query AboutQuery {
    file(relativePath: { in: ["images"] }) {
      childImageSharp {
        fluid {
          ...GatsbyImageSharpFluid
        }
      }
    }
  }

作为单个值,正则表达式是最好的方法。