问题描述
我是 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:
如果没有,那么有没有办法在没有路径字段的情况下使用降价信息过滤特定文件夹?
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:关键词]
发布评论