我正在努力弄清楚如何在 Gatsby Js 中使用 GraphQL 查询多个特定图像。我最初的想法是做这样的事情:
file(relativePath: {eq: "images/front.jpg"}) {
id
}
file(relativePath: {eq: "images/front2.jpg"}) {
id
}
这会在 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
}
]
}
]
}
查询一个特定文件(图像)效果很好:
file(relativePath: {eq: "images/front.jpg"}) {
id
}
有什么建议我在这里做错了什么吗?谢谢 :)
发现诀窍是使用别名,如graphQL 文档 http://graphql.org/learn/queries/
就我而言,将查询更改为此似乎可以解决问题:
front: file(relativePath: {eq: "images/front.jpg"}) {
id
}
front2: file(relativePath: {eq: "images/front2.jpg"}) {
id
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)