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

查看:189
本文介绍了如何根据前题对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?

如果没有,那么是否有一种方法可以过滤带有Markdown信息的特定文件夹而没有 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
  • 孩子
  • 父母
  • internal ___ contentDigest
  • internal ___ type
  • internal ___ mediaType
  • internal ___ description
  • internal ___ owner
  • sourceInstanceName
  • absolutePath
  • relativePath
  • 扩展名
  • 大小
  • prettySize
  • modifiedTime
  • accessTime
  • changeTime
  • birthTime
  • root
  • dir
  • 基地
  • ext
  • 名称
  • relativeDirectory
  • dev
  • 模式
  • nlink
  • uid
  • gid
  • rdev
  • blksize
  • ino
  • atimeMs
  • mtimeMs
  • ctimeMs
  • birthtimeMs
  • 一次
  • mtime
  • ctime
  • 出生时间
  • publicURL

如果没有,是否可以使用带有路径字段的markdown信息过滤特定文件夹?

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.

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

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