【问题标题】:Sorting a Storyblok GraphQL Query对 Storyblok GraphQL 查询进行排序
【发布时间】:2020-09-24 09:15:52
【问题描述】:

我有以下查询我的 storyblok CMS:

{
  allStoryblokEntry(filter: {field_component: {eq: "blog"}} ) {
    edges {
      node {
        id
        name
        content
        published_at
      }
    }
  }
}

不过,我想对我的节点进行排序,比如按发布日期。 我不知道该怎么做。 GraphiQL 建议使用 sort 参数,但我不知何故无法开始工作。 Storyblok tells me 使用 sort_by=name:asc - 我的 GraphiQL 根本无法识别它,这也给了我一个语法错误。以前有人做过吗?

【问题讨论】:

    标签: javascript graphql gatsby graphql-js storyblok


    【解决方案1】:

    你快到了。试试这个:

    {
      allStoryblokEntry(
        filter: {field_component: {eq: "blog"}}
        sort: { 
          fields: name, 
          order: ASC}){
        edges {
          node {
            id
            name
            content
            published_at
          }
        }
      }
    }
    

    要在 GraphQL 中对元素进行排序,您需要提供有效的 field(甚至不需要查询)和排序顺序 (ASC/DESC)。

    您可以在Gatsby's GraphQL reference查看更多信息。

    【讨论】:

      猜你喜欢
      • 2019-07-16
      • 2020-01-09
      • 1970-01-01
      • 2020-02-19
      • 1970-01-01
      • 1970-01-01
      • 2022-11-11
      • 2016-10-27
      • 2018-09-21
      相关资源
      最近更新 更多