【问题标题】:heroImage field not showing up in GraphiQLheroImage 字段未显示在 GraphiQL 中
【发布时间】:2022-02-19 09:41:03
【问题描述】:

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

原始查询代码:

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

但我收到错误:“无法在类型“ContentfulBlogPost”上查询字段“heroImage”。”,

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

任何帮助都将不胜感激,因为我对此感到很困惑。

【问题讨论】:

  • 愚蠢的问题:你的heroImage 发布了吗?

标签: contentful


【解决方案1】:
  1. 确保发布数据,一直到顶层。如果是博客上的图片,请确保图片和父博客条目都已发布。
  2. 确保至少有一个“heroImage”字段存储了一个文件
  3. 您无法直接在 graphQL 资源管理器中查询图像。最好的选择是在“url”属性出现后使用它。
  4. 通过重新运行 gatsby develop 重新启动/重新查询内容端点。
  5. 如果出现问题,请运行 gatsby clean,然后运行 ​​gatsby develop。

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2018-06-15
      • 1970-01-01
      • 2022-07-25
      • 2021-07-25
      • 1970-01-01
      • 2019-08-24
      • 2020-07-23
      • 2013-08-28
      • 2018-12-03
      相关资源
      最近更新 更多