具有ContentCMS的Gatsby Blog,如何按日期对博客帖子进行排序

时间:2018-08-06 06:58:57

标签: reactjs graphql gatsby contentful

我的查询看起来像这样(我遗漏了一些变量):

allContentfulBlog(
      filter: { node_locale: { eq: "en-US" } }
      sort: { fields: [node___date], order: DESC }
    ) {
      edges {
        node {
          id
          date(formatString: "DD MMMM, YYYY")                            
        }
      }
    }

终端错误:

  

GraphQL错误参数“ sort”具有无效的值{字段:   [node___date],订单:DESC}。在字段“字段”中:在元素#0中:   找到预期的类型“ ContentfulBlogConnectionSortByFieldsEnum”   node ___ date。

为进行排序,我尝试了在教程中看到或想到的所有参数。我认为这与Contentful有关,它是我的gatsby应用程序使用的数据格式。

终端屏幕截图

terminal screenshot 浏览器屏幕截图

browser output

1 个答案:

答案 0 :(得分:1)

这可以解决问题:

排序:{字段:[日期],顺序:DESC}

我在Gatsby-Contentful-Starter中找到了它;我有一个错误的印象,语法必须像fieldName ___ argumentByWichToSort