【问题标题】:Retrieving Contentful ID in Gatsby GraphQL在 Gatsby GraphQL 中检索内容 ID
【发布时间】:2020-11-02 10:43:11
【问题描述】:

我在 gatsby-node.js 中使用 graghql 从内容中查询数据

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
              }
            }
          }
        }
      }
    `
  )
})

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

当我使用内容交付 api 时,我可以获得正确的 id,那么,发生了什么?谁更改了 id 的格式?如何获得正确的身份证?我使用的内容插件是 gatsby-source-contentful。

【问题讨论】:

  • 您并没有真正指定您想要检索的id 的任何位置,至少在您上面显示的查询中。因此,也许查看架构以找出如何检索特定项目会有所帮助。

标签: graphql gatsby contentful


【解决方案1】:

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

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

【讨论】:

猜你喜欢
  • 2018-03-11
  • 2020-05-03
  • 1970-01-01
  • 2019-01-20
  • 2019-06-29
  • 2020-05-01
  • 2020-03-23
  • 2019-07-19
  • 2020-08-28
相关资源
最近更新 更多