Gatsby GraphQL查询多个图像 [英] Gatsby GraphQL query for multiple images

查看:68
本文介绍了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 :)

推荐答案

发现诀窍是使用就我而言,将查询更改为此似乎可以解决问题:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆