0

问题:

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

在 Prismic 中,我有一个 Type ( 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-prismicv3.1.1

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

在此处输入图像描述

这是testimonial_listPrismic 类型的 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"
      }
    }
  }
}

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

4

2 回答 2

1

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

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

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

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

于 2020-07-17T08:18:35.450 回答
0

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

于 2020-06-26T14:17:58.873 回答