首页 > 解决方案 > 如何让 Gatsby 插件内容可选字段工作?

问题描述

在 Contentful 的内容类型上有一个可选字段,我试图让 Gatsby-Plugin-Contentful-Optional-Fields 工作。

可选字段是一个图像,我使用新的 Gatsby-Image-Plugin 渲染。在 my 中配置插件后gatsby-config.js,我仍然收到以下错误:

There was an error in your GraphQL query:
Cannot query field "description" on type "Node".

花了几个小时解决它,不幸的是没有成功。我对开发相当陌生,所以对其他人来说,也许只是一个明显的错误。非常感谢任何帮助。

我的 gatsby-config.js 中的插件配置:

{
      resolve: "gatsby-plugin-contentful-optional-fields",
      options: {
        optionalFields: {
          ContentfulNews: {
            image: "Node",
          },
        },
      },
    }, 

我的查询:

query {
    allContentfulNews(sort: { fields: date, order: DESC }) {
      edges {
        node {
          id
          heading
          date(formatString: "DD.MM.YYYY")
          text {
            childMarkdownRemark {
              html
            }
          }
          image {
            gatsbyImageData(
              layout: FULL_WIDTH
              placeholder: BLURRED
              formats: [AUTO, WEBP]
              quality: 100
              width: 1500
            )
            description
          }
        }
      }
    }
  }

标签: graphqlgatsbycontentfulgatsby-imagegatsby-plugin

解决方案


推荐阅读