【问题标题】:Gatsby Blog with Contentful CMS, how to sort blog posts by dateGatsby 博客与 Contentful CMS,如何按日期对博客文章进行排序
【发布时间】:2019-01-13 02:07:56
【问题描述】:

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

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

终端错误:

GraphQL 错误参数“排序”的值无效 {fields: [节点___日期],顺序:DESC}。在字段“字段”中:在元素 #0 中: 找到预期的类型“ContentfulBlogConnectionSortByFieldsEnum” 节点___日期。

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

终端截图

浏览器截图

【问题讨论】:

    标签: reactjs graphql gatsby contentful


    【解决方案1】:

    这成功了:

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

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

    【讨论】:

    • 为了找出正确的查询,我强烈推荐包含的 GraphiQL 界面。 :) 有了这个,你手头就有了一个强大的自动补全功能。 gatsbyjs.org/tutorial/part-five/#introducing-graphiql
    • @stefanjudis GraphiQL 不适用于 filter 或 sort 等参数,当您按 Ctrl + Enter 时也不建议使用它们
    猜你喜欢
    • 2021-04-17
    • 2021-07-11
    • 2023-03-18
    • 2016-06-20
    • 1970-01-01
    • 2021-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多