【问题标题】:How to query gatsby image using graphiql如何使用 graphiql 查询 gatsby 图像
【发布时间】:2020-09-27 11:47:59
【问题描述】:

我在/src/assests/images/basketball 中有图像,我想使用 graphiql 进行查询。

我尝试将其粘贴到我的 graphiql 中

query {
  placeholderImage: file(relativePath: { eq: "basketball.jpeg" }) {
    childImageSharp {
      fluid(maxWidth: 300) {
        ...GatsbyImageSharpFluid
      }
    }
  }
}

但它一直说...GatsbyImageSharpFluid 未知片段。我对 graphQL 有一个模糊的想法,但有人可以帮我了解如何在 gatsby 中使用 graphiQl 查询查询吗?

这是我的 gatsby.config.js

{
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: `${__dirname}/src/assests/images`,
      },
    },
    `gatsby-transformer-sharp`,
    `gatsby-plugin-sharp`,
    {
      resolve: `gatsby-plugin-manifest`,
      options: {
        name: `gatsby-starter-default`,
        short_name: `starter`,
        start_url: `/`,
        background_color: `#663399`,
        theme_color: `#663399`,
        display: `minimal-ui`,
        // icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site.
      },
    },

还有我的文件所在的文件夹结构

【问题讨论】:

    标签: graphql gatsby


    【解决方案1】:

    Gatsby image fragments limitation

    注意,由于 GraphiQL 的限制,您目前无法在 GraphiQL IDE 中使用这些片段。

    在 GraphiQL 中将您的查询更改为:

    query {
      placeholderImage: file(relativePath: { eq: "basketball.jpeg" }) {
        childImageSharp {
          fluid(maxWidth: 300) {
            base64
            aspectRatio
            src
            srcSet
            sizes
          }
        }
      }
    }
    

    【讨论】:

    • 这给出的数据为null,更准确地说是{ "data": { "file": null } }
    • 我不确定我是否理解您的评论。
    猜你喜欢
    • 2020-06-09
    • 2019-10-19
    • 1970-01-01
    • 2021-06-05
    • 2019-10-04
    • 2019-11-26
    • 2022-01-14
    • 2022-01-02
    • 2018-06-16
    相关资源
    最近更新 更多