尝试使用 DatoCMS 和 Gatsby JS 按位置对 graphQL 顺序进行排序

Attempting to sort graphQL order by position with DatoCMS adn Gatsby JS

我正在使用这个 Gatsby JS 插件来探索 DatoCMS GraphQL API https://github.com/datocms/gatsby-source-datocms In the dato docs it says you can order by position in the cms https://www.datocms.com/docs/content-delivery-api/ordering/

我基本上想保留 cms 中的顺序,而不是根据日期排序。

在 dato API 资源管理器中,我可以像这样按位置排序帖子。

query MyQuery {
  allProjects(orderBy: position_ASC) {
    slug
  }
}

但是在 Gatsby 中,相同的查询暗示了我,我在下面尝试过类似的东西,但它给了我这个 error Expected type SortOrderEnum, found position_ASC

query MyQuery {
  allDatoCmsProject(sort: {order: position_ASC}) {
    edges {
      node {
        slug
      }
    }
  }
}

在 gatsby 插件中,语法与 DatoCMS graphQL 浏览器略有不同。如果我想按特定字段进行排序,这就是插件希望我进行排序的方式。但是我找不到任何允许我按 Dato cms

中的元素位置排序的字段
{
  allDatoCmsBlogPost(sort: { fields: [publicationDate], order: DESC }, limit: 5) {
    edges {
      node {
        title
        excerpt
        publicationDate(formatString: "MM-DD-YYYY")
        author {
          name
          avatar {
            url
          }
        }
      }
    }
  }
}

来自gatsby-source-datocms README

IMPORTANT: If you use this plugin, you will not be able to write queries as described in the DatoCMS Content Delivery API documentation. Content will be exposed using Gatsby's schema-generation. If you want to directly use our GraphQL API in Gatsby, consider using the gatsby-source-graphql plugin instead.

当您的模型有 "visualisation mode" 个 table 时,将添加一个名为 position 的 属性。

我们可以使用此 position 对记录进行排序,如下所示:

allDatoCmsProject(sort: { fields: [position], order: ASC }){
...
}