首页 > 解决方案 > 带有“gatsby-source-sanity”的图像资产上缺少“固定”和“流动”字段

问题描述

我正在尝试使用gatsby-source-sanity和从 Sanity 获取图像gatsby-image。在过去,我fluid像这样查询图像资产没有问题:

export const query = graphql`
  query {
    allSanityPicture {
      nodes {
        image {
          asset {
            fluid(maxWidth: 900) {
              ...GatsbySanityImageFluid
            }
          }
        }
      }
    }
  }
`;

但是,由于某种原因,fluid和的fixed字段asset没有出现在 GraphQL 中:

GraphQL 字段

节点上肯定有图像,因为该url字段有效。

我已经根据需要安装并配置了我的 Gatsby 插件:

plugins: [
    {
      resolve: `gatsby-source-sanity`,
      options: {
        projectId: `mhlt1wid`,
        dataset: `production`,
        token: process.env.SANITY_TOKEN,
      }
    },
    `gatsby-plugin-sharp`,
    `gatsby-transformer-sharp`,
  ],

并使用sanity graphql deploy.

我在这里想念什么?现在已经在两个新项目上从头开始尝试了两次,但仍然遇到同样的问题。

标签: graphqlgatsbygatsby-imagesanity

解决方案


推荐阅读