0
votes

I use graghql to query data from contentful, in 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
              }
            }
          }
        }
      }
    `
  )
})

The returned id in node does not match my contentful entry's id. For example, one return id is 32015820-f327-5085-b5c0-27146850a8f5, but my entry's id is 2pljYDQAJ8umcV5po5TDK8

When I use contentful delivery api I can get the correct id, so, what happed? Who changes the id's format? How to get the correct id? The contentful plugin I use is gatsby-source-contentful.

1
You're not really specifying anywhere which id you'd like to retrieve, at least in the query you're showing above. So perhaps looking at the schema to figure out how to retrieve a specific item would help. - goto1

1 Answers

1
votes

If you open the GraphiQL explorer on http://localhost:8000/___graphql you can see the entire GraphQL schema.

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. So contentful_id is what you're looking for.

GraphiQL explorer contentful schema