简体   繁体   English

Gatsby GraphQL查询多个图像

[英]Gatsby GraphQL query for multiple images

I'm stuggling to figure out how to query for multiple specific images with GraphQL in Gatsbyjs. 我正在努力弄清楚如何在Gatsbyjs中使用GraphQL查询多个特定图像。 My initial thought was to do something like this: 我最初的想法是做这样的事情:

 file(relativePath: {eq: "images/front.jpg"}) { id } file(relativePath: {eq: "images/front2.jpg"}) { id } 

This throws an error in GraphQL: 这会在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 :) 谢谢 :)

Found out the trick is to use aliases as described in the graphQL docs 发现诀窍是使用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 } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM