graphql - 如何使用 Contentful 从 Gatsby 中的查询中检索发布的发布日期?

标签 graphql contentful gatsby

有了这种请求,使用GraphQL使用gatsby-source-contentful插件从Contentful中提取帖子数据,寻找一种方法访问帖子发布日期 (post.sys.publishedAt) 或 updatedAt !

 {
  contentfulPost(id: { eq: 'postId' }) {
   --> publishedAt ?
   title
   image {
    responsiveResolution(width: 500, height: 500) {
      src
      srcSet
      height
      width
    }
  }

最佳答案

source-contentful 插件不包含 GraphQL 架构中的 sys 属性。它只包含字段和 id。作为解决方法,您可以添加一个包含日期的字段,它将在 graphQL 中对您可用。

希望对你有帮助

编辑----------------

我刚刚提交了一个 PR,将这些选项添加到 gatsbyjs https://github.com/gatsbyjs/gatsby/pull/2398 您现在可以访问 updatedAtcreatedAt 属性。

关于graphql - 如何使用 Contentful 从 Gatsby 中的查询中检索发布的发布日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46561916/

相关文章:

java - Graphql使用Input类型搜索数据

javascript - Mongoose 异步/等待

node.js - 如何将扩展从一台服务器转发到中间件服务器

android - 如何在 login.vue 中添加标题?

javascript - 如何使用 Contentful 在 Gatsby 中包含轮播组件?

javascript - 数组的内容丰富的 API 查询

reactjs - 如何在 GatsbyJS 项目中显示图像?

graphql - 在 Strapi GraphQL 查询中获取图像格式

reactjs - 在/秒%20post 还没有页面

arrays - GraphQL 过滤器内容丰富的帖子