如何使用Contentful在Gatsby中查询发布的发布日期?

问题描述:

有了这种要求,使用gatsby-source-contentful插件从拉后的数据ContentfulGraphQL,寻找一种方式来访问后发表的日期(post.sys.publishedAt)或updatedAt!如何使用Contentful在Gatsby中查询发布的发布日期?

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

}

源contentful插件不包括在GraphQL架构sys财产。它只包含字段和id。作为解决方法,您可以添加一个包含日期的字段,并且它将在graphQL中为您提供。

我希望这帮助

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

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

+0

Thanx为您的答案。 – wabdsgn

+0

那么这是否意味着编辑必须填写此字段以获取发布日期,或者您是否知道使用publishAt数据自动填充此字段的方法? – wabdsgn

+0

我创建了一个关于将'sys'字段添加到GraphQL的问题https://github.com/gatsbyjs/gatsby/issues/2342 –