如何根据 frontmatter 对 GraphQL 查询进行排序

编程入门 行业动态 更新时间:2024-10-28 02:25:37
本文介绍了如何根据 frontmatter 对 GraphQL 查询进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 GraphQL 的新手并且已经使用 allMarkDownRemark 查询成功地对数据进行了排序,但是我需要的是能够为我们提供一个 allFile 查询然后仍然按 frontmatter 排序,这可能吗?

I am new to GraphQL and have successfully sorted data with an allMarkDownRemark query, however what I need is to be able to us a allFile query and then still sort by the frontmatter, is this possible?

这是返回正确数据的查询(已删除排序).

This is the query which (with the sort removed) returns the correct data.

{
    allFile(
      limit: 3
      sort: { fields: [frontmatter___priority], order: DESC }
      filter: { sourceInstanceName: { eq: "key-points" } }
    ) {
      edges {
        node {
          id
          childMarkdownRemark {
            frontmatter {
              title
              content
              priority
            }
          }
        }
      }
    }
  }

当我像上面那样使用排序运行它时,它会引发以下错误

When I run it with the sort in like I above it throws the following error

    {
  "errors": [
    {
      "message": "Expected type FileConnectionSortByFieldsEnum, found frontmatter___priority.",
      "locations": [
        {
          "line": 4,
          "column": 28
        }
      ]
    }
  ]
}

首先有没有办法使用AllFile查询,然后通过frontmatter进行排序?

Firstly is there a way to query using AllFile and then sort via the frontmatter?

如果没有,那么有没有办法在没有 path 字段的情况下使用降价信息过滤特定文件夹?

If not then is there a way to filter a specific folder with markdown info without a path field?

推荐答案

首先有没有办法使用AllFile进行查询,然后通过frontmatter进行排序?

Firstly is there a way to query using AllFile and then sort via the frontmatter?

如果 gatsby-source-filesystem 没有变化,这是不可能的.您应该使用 FileConnectionSortByFieldsEnum 值之一.有 FileConnectionSortByFieldsEnum 值:

Without changes in gatsby-source-filesystem it's not possible. You should use one of FileConnectionSortByFieldsEnum values. There is FileConnectionSortByFieldsEnum values:

id儿童父母内部___contentDigest内部___类型内部___mediaType内部___描述内部___所有者源实例名称绝对路径相对路径扩展尺寸漂亮的尺寸修改时间访问时间更改时间出生时间根目录基础扩展姓名相对目录开发模式nlink用户名gid开发blksizeino块时间女士mtimeMsctimeMs生日女士时间时间ctime出生时间publicURL

如果没有,那么有没有办法在没有路径字段的情况下使用降价信息过滤特定文件夹?

If not then is there a way to filter a specific folder with markdown info without a path field?

将查询更改为使用 allMarkdownRemark,它应该对您有所帮助.

Change query to use allMarkdownRemark, it should help you.

这篇关于如何根据 frontmatter 对 GraphQL 查询进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-03-27 01:46:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/674176.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:frontmatter   GraphQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!