4

我正在 Gatsbyjs 中构建一个站点,该站点通过 gatsby-source-contentful 插件获取信息,但我在 graphql 方面苦苦挣扎。

例如,如果我在 Contentful 中有一个 Content 模型,其中包含一个覆盖默认描述的字段 - 那么如果没有任何内容使用该内容,但如果我尝试将其包含在我的查询中,graphql 会引发错误。

反正有没有短路graphql查询?

例子

{
  allContentfulPage {
    edges {
      node {
        title
        description {
           description
        }
      }
    }
  }
}

如果不存在带有描述的页面模型,这将中断,但是一旦一个页面获得描述,它就会起作用。

4

1 回答 1

2

Gatsby pulls data from Contentful and then it builds an internal "model" of what the data from Contenful looks like. The Contentful API is REST but internally Gatsby uses GraphQL.

If a field does not have a value on Contentful then it will not be a part of the generated GraphQL query in Gatsby. The solution is to push a single value in one of your records.

于 2018-02-14T16:30:09.607 回答