【问题标题】:document field returns null when querying groups of Prismic Content-Realtionship fields in graphql在 graphql 中查询 Prismic Content-Realtionship 字段组时,文档字段返回 null
【发布时间】:2020-10-16 12:52:38
【问题描述】:

问题:

我正在使用 Prismic 将数据发送到我的网站。

在 Prismic 中,我有一个类型 (testimonial_list),它由一组内容关系字段 (Prismic Type testimonials) 组成。

要查询内部类型的数据,我需要通过 graphql 中的文档字段访问它们并使用内联片段。

我已按照此处的说明进行操作: https://github.com/angeloashmore/gatsby-source-prismic#Query-Content-Relation-fields

在 graphql 中,我设法导航到 testimonial 数据字段(在 document 字段上),但 document 字段返回 null,这就是我卡住的地方。我不知道为什么它会返回 null,因为内容存在并且在 graphql 中清楚地找到了这些字段。

信息:

我的项目是使用 Gatsby 构建的,我正在使用插件 gatsby-source-prismic v3.1.1

在这里您可以看到我可以访问正确的字段数据,并且返回了正确数量的节点,但 document 为空:

这是 Prismic 上 testimonial_list 类型的 JSON:

{
  "Main" : {
    "prismic_title" : {
      "type" : "StructuredText",
      "config" : {
        "single" : "heading6",
        "label" : "Title (only used to name entry in Prismic list)",
        "placeholder" : "Prismic list title (otherwise \"undefined\")"
      }
    },
    "page" : {
      "type" : "Select",
      "config" : {
        "options" : [ "Homepage", "Option 2", "Option 3" ],
        "label" : "Website page to appear on:"
      }
    },
    "testimonial_list" : {
      "type" : "Group",
      "config" : {
        "fields" : {
          "testimonial" : {
            "type" : "Link",
            "config" : {
              "select" : "document",
              "customtypes" : [ "testimonial" ],
              "label" : "testimonial"
            }
          }
        },
        "label" : "Testimonial List"
      }
    }
  }
}

感谢您的帮助,如果我可以提供更多信息来帮助推断问题,请告诉我。

【问题讨论】:

    标签: graphql gatsby prismic.io


    【解决方案1】:

    最后,问题是我需要架构的 gatsby-config 中的一个错字。

    这是一个愚蠢的错误,但盯着某件事太久,我猜这些事情会发生。

    如果其他人遇到类似问题,您必须确保 gatsby-config 中的 Prismic 模式的属性名称与 Prismic 中的完全相同。

    例如,如果您在 Prismic 中的类型被称为“my_type”,那么您必须使用准确的语法 - 例如,不要使用“myType”。

    【讨论】:

      【解决方案2】:

      嘿,这可能与 gatsby-source-prismic 插件有关 如果我是你,我会直接在这里打开一个问题:https://github.com/angeloashmore/gatsby-source-prismic/issues

      【讨论】:

      • 看起来是这样,在与 Prismic 开发人员交谈后,我认为我们将不得不更深入地研究 :) ty
      猜你喜欢
      • 2019-12-25
      • 2021-04-08
      • 1970-01-01
      • 2019-07-08
      • 2019-05-28
      • 2012-04-29
      • 2019-07-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多