在 Gatsby GraphQL 中检索 Contentful ID

Retrieving Contentful ID in Gatsby GraphQL

我使用 graghql 从 contentful 查询数据,在 gatsby-node.js

exports.createPages = async ({ graphql, actions }) =>  {
  ...
  const result = await graphql(
    `
      {
        allContentfulArticle(
          sort: { order: DESC, fields: date },
          limit: 2000
        ) {
          totalCount,
          edges {
            node {
              id
              title
              excerpt
              date
              tag
              content{
                content
              }
            }
          }
        }
      }
    `
  )
})

节点中的 returned id 与我的内容条目的 id 不匹配。比如一个returnid是32015820-f327-5085-b5c0-27146850a8f5,但是我的entry的id是2pljYDQAJ8umcV5po5TDK8

当我使用 contentful delivery api 时,我可以获得正确的 id,那么,发生了什么?谁更改了 id 的格式?如何获得正确的ID?我用的contentful插件是gatsby-source-contentful.

如果您在 http://localhost:8000/___graphql 上打开 GraphiQL 资源管理器,您可以看到整个 GraphQL 架构。

如您所见,每个项目都有两个 ID 字段:id 是 Gatsby ID,contentful_id 是 Contentful ID。所以 contentful_id 就是你要找的。