我想查询2张图片,images/me.jpg
和images/boxing.png
。
不确定在graphql中怎么做:
query AboutQuery {
file(relativePath: { eq: ("images/me.jpg"|"images.boxing.png") }) {
childImageSharp {
fluid {
...GatsbyImageSharpFluid
}
}
}
}
答案 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
}
}
}
}
作为单个值,正则表达式是最好的方法。