如何根据 frontmatter 对 GraphQL 查询进行排序 [英] How can I sort a GraphQL query based on the frontmatter

查看: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
  • 开发
  • blksize
  • ino
  • 时间女士
  • mtimeMs
  • ctimeMs
  • 生日女士
  • 时间
  • 时间
  • 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆