0

我正在尝试使用 Gatsby 的 /___graphq 调试器和gatsby-source-prismic的 README 文件说你可以返回切片。所以下面我将返回一个名称为 PrismicProductBodySteps 的切片。

{
  allPrismicHomePage {
        edges {
          node {
        data {
          seo_title
          body {
            __typename
            ... on PrismicProductBodySteps {
              }
            }
          }
        }
       }
    }
  }
}

有人可以向我解释... on PrismicProductBodySteps 是什么意思吗?

在 gatsby 组件中,我将其视为示例。

body {
  ... on PrismicProductsBodySteps {
    ...ProductStepsFragment
}

谁能向我解释 ...ProductStepsFragment 的含义?

4

1 回答 1

1

PrismicProductBodySteps将是表示一系列动态内容块的自定义节点类型名称。该自定义节点类型名称来自 Prismic 数据模型;你的可能会有所不同。

根据gatsby-source-prismic文档,使用自定义节点类型名称需要您首先弄清楚它们是什么:

获取节点类型的最简单方法是使用 /___graphql 调试器并运行以下查询(调整文档类型和字段名称)。

{
  allPrismicPage {
    edges {
      node {
        id
        data {
          body {
            __typename
          }
        }
      }
    }
  }
}

获得自定义节点类型名称后,您可以使用 GraphQL 片段来提取特定于每个片段的数据。同样,这将取决于您如何在数据模型中定义片段,但它看起来像这样:

{
  allPrismicHomePage {
    edges {
      node {
        data {
          seo_title
          body {
            __typename
            ... on PrismicYourContentBlockOne {
              text {
                html
              }
            }
            ... on PrismicYourContentBlockTwo {
              text {
                html
              }
            }
            ... on PrismicYourContentBlockThree {
              text {
                html
              }
            }
          }
        }
      }
    }
  }
}
于 2018-08-23T12:57:27.187 回答