Graphql 如何使用Contentful从Gatsby中的查询中检索发布的发布日期?
对于这种请求,使用Graphql 如何使用Contentful从Gatsby中的查询中检索发布的发布日期?,graphql,contentful,gatsby,Graphql,Contentful,Gatsby,对于这种请求,使用gatsby source Contentful插件从Contentful和GraphQL中提取post数据,寻找访问post发布日期(post.sys.publishedAt)或updatedAt的方法 { contentfulPost(id: { eq: 'postId' }) { --> publishedAt ? title image { responsiveResolution(width: 500, height: 500)
gatsby source Contentful
插件从Contentful和GraphQL中提取post数据,寻找访问post发布日期(post.sys.publishedAt)或updatedAt的方法
{
contentfulPost(id: { eq: 'postId' }) {
--> publishedAt ?
title
image {
responsiveResolution(width: 500, height: 500) {
src
srcSet
height
width
}
}
}源内容插件在GraphQL架构中不包含
sys
属性。它只包括字段和id。作为一种解决方法,您可以添加一个保存日期的字段,它将在graphQL中为您提供
我希望这有帮助
编辑---------------
我刚刚提交了一份PR,将这些选项添加到gatsbyjs中
您现在可以访问
updatedAt
和createdAt
属性。Thanx作为您的答案。那么这是否意味着编辑必须填写此字段以获得发布日期,或者您知道如何使用发布的数据自动完成此字段?我创建了一个关于将sys
字段添加到GraphQL Thanx的问题!这可能是有用的博客文章!这周我会尽量找时间来做的