我有以下查询来查询我的storyblok CMS:
{
allStoryblokEntry(filter: {field_component: {eq: "blog"}} ) {
edges {
node {
id
name
content
published_at
}
}
}
}但是,我想对节点进行排序,比如按published_at日期排序。不过,我不知道该怎么做。GraphiQL建议使用sort参数,但不知何故我无法使用该参数。使用sort_by=name:asc的Storyblok tells me -我的GraphiQL根本不能识别,这也给了我一个语法错误。以前有人这么做过吗?
发布于 2020-06-05 21:09:37
你就快到了。试试这个:
{
allStoryblokEntry(
filter: {field_component: {eq: "blog"}}
sort: {
fields: name,
order: ASC}){
edges {
node {
id
name
content
published_at
}
}
}
}要在GraphQL中对元素进行排序,需要提供一个有效的field (甚至不需要查询它)和一个排序顺序(ASC/DESC)。
您可以在Gatsby's GraphQL reference中查看更多信息。
https://stackoverflow.com/questions/62210695
复制相似问题