简体   繁体   English

在 Gatsby GraphQL 中检索内容 ID

[英]Retrieving Contentful ID in Gatsby GraphQL

I use graghql to query data from contentful, in gatsby-node.js我在 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
              }
            }
          }
        }
      }
    `
  )
})

The returned id in node does not match my contentful entry's id. node 中返回的 id 与我的内容条目的 id 不匹配。 For example, one return id is 32015820-f327-5085-b5c0-27146850a8f5 , but my entry's id is 2pljYDQAJ8umcV5po5TDK8比如一个return id是32015820-f327-5085-b5c0-27146850a8f5 ,但是我的entry的id是2pljYDQAJ8umcV5po5TDK8

When I use contentful delivery api I can get the correct id, so, what happed?当我使用内容交付 api 时,我可以获得正确的 ID,那么,发生了什么? Who changes the id's format?谁更改了 id 的格式? How to get the correct id?如何获得正确的身份证? The contentful plugin I use is gatsby-source-contentful.我使用的内容丰富的插件是 gatsby-source-contentful。

If you open the GraphiQL explorer on http://localhost:8000/___graphql you can see the entire GraphQL schema.如果您在http://localhost:8000/___graphql上打开 GraphiQL 资源管理器,您可以看到整个 GraphQL 架构。

As you can see there are two ID fields for each item: just id is the Gatsby ID and contentful_id is the Contentful ID.如您所见,每个项目都有两个 ID 字段:只有id是 Gatsby ID,而contentful_id是 Contentful ID。 So contentful_id is what you're looking for.所以contentful_id就是你要找的。

GraphiQL 资源管理器内容模式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM