如何查询棱镜切片并从每个切片返回数据

how to query prismic slices and returning data from each slice

我正在尝试使用 Gatsby 的 /___graphq 调试器,gatsby-source-prismic 的自述文件说您可以 return 切片。所以在下面,我 return 将切片命名为 PrismicProductBodySteps。

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

谁能给我解释一下……在 PrismicProductBodySteps 上是什么意思?

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

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

任何人都可以向我解释...ProductStepsFragment 的含义吗?

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

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

The easiest way to get the type of nodes is to use the /___graphql debugger and run the below query (adjust the document type and field name).

{
  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
              }
            }
          }
        }
      }
    }
  }
}