Gatsby GraphQL 查询多个图像 [英] Gatsby GraphQL query for multiple images
本文介绍了Gatsby GraphQL 查询多个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在努力弄清楚如何在 Gatsbyjs 中使用 GraphQL 查询多个特定图像.我最初的想法是做这样的事情:
I'm stuggling to figure out how to query for multiple specific images with GraphQL in Gatsbyjs. My initial thought was to do something like this:
file(relativePath: {eq: "images/front.jpg"}) {
id
}
file(relativePath: {eq: "images/front2.jpg"}) {
id
}
这会在 GraphQL 中引发错误:
This throws an error in GraphQL:
{
"errors": [
{
"message": "Fields "file" conflict because they have differing arguments. Use different aliases on the fields to fetch both if this was intentional.",
"locations": [
{
"line": 28,
"column": 1
},
{
"line": 31,
"column": 1
}
]
}
]
}
查询一个特定的文件(图像)工作正常:
Querying for one specific file (image) works fine:
file(relativePath: {eq: "images/front.jpg"}) {
id
}
是否有任何暗示我在这里做错了什么?谢谢:)
Any suggesting of what I'm doing wrong here? Thanks :)
推荐答案
发现诀窍是使用 graphQL 文档
就我而言,将查询更改为此似乎可以解决问题:
In my case changing the query to this seems to do the trick:
front: file(relativePath: {eq: "images/front.jpg"}) {
id
}
front2: file(relativePath: {eq: "images/front2.jpg"}) {
id
}
这篇关于Gatsby GraphQL 查询多个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文