heroImage 字段未显示在 GraphiQL 中

问题描述 投票:0回答:3

在 GraphiQL 中,我试图从 Contentful 博客文章中查询 heroImage 字段,该文章默认存在于我的博客文章内容类型中:

原始查询代码:

{
    allContentfulBlogPost {
      edges {
        node {
          id
          title
          slug
          body {
             childMarkdownRemark {
                excerpt
            }
          }
          heroImage {
             gatsbyImageData(
             layout: CONSTRAINED
             placeholder:BLURRED
             width: 300
            )
          }
        }
      } 
    }
  }

但我收到错误消息:“无法查询类型为“ContentfulBlogPost”的字段“heroImage”。,

事实上,heroImage 字段甚至没有出现在我的 GraphiQL 资源管理器中(见下图),我不明白为什么。这个领域确实存在,我什至确保每篇博文都有与之相关的英雄形象。

任何帮助将不胜感激,因为我对这个很困惑。

contentful
3个回答
0
投票
  1. 确保数据一直发布到顶层。如果它是博客上的图片,请确保图片和父博客条目都已发布。
  2. 确保至少有一个“heroImage”字段存储了一个文件
  3. 无法直接在 graphQL 资源管理器中查询图像。一旦出现,最好的选择是选择“url”属性。
  4. 通过重新运行 gatsby develop 重新启动/重新查询内容端点。
  5. 如果有什么东西卡住了,运行 gatsby clean,然后 gatsby develop。

0
投票

我遇到了同样的问题。我运行命令 'npm install gatsby-transformer-remark' 并重新运行 gatsby develop。现在 heroImage 出现了


0
投票

我遇到了同样的问题。运行 gatsby clean 对我有用

© www.soinside.com 2019 - 2024. All rights reserved.