带有 Contentful CMS 的 Gatsby Blog,如何按日期对博客文章进行排序

Gatsby Blog with Contentful CMS, how to sort blog posts by date

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

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

终端错误:

GraphQL Error Argument "sort" has invalid value {fields: [node___date], order: DESC}. In field "fields": In element #0: Expected type "ContentfulBlogConnectionSortByFieldsEnum", found node___date.

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

终端截图

浏览器截图

这成功了:

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

我在 Gatsby-Contentful-Starter 中找到了它;我有一个错误的印象,语法需要类似于 fieldName___argumentByWichToSort