【发布时间】:2018-09-02 15:57:50
【问题描述】:
我正在使用 apollo graphql 服务器。我有一个很好的无序查询。
query feedQuery {
allPostsFromAllBlogs
{
id
blogId
title
text
likes
createdAt
}
}
我想对结果进行排序([Post] 类型)。这是我用来执行此操作的查询:
query feedQuery {
allPostsFromAllBlogs( orderBy: {field: createdAt, direction:DESC})
{
id
blogId
title
text
likes
createdAt
}
}
在 graphiql 中产生此输出:
{
"errors": [
{
"message": "Unknown argument \"orderBy\" on field \"allPostsFromAllBlogs\" of type \"Query\".",
"locations": [
{
"line": 2,
"column": 25
}
]
}
]
}
这是架构:
scalar DateTime
type Query {
blogInfo(id: String): Blog
post(id: String): Post
topPost(blogId: String): Post
allPosts(blogId: String): [Post]
allPostsFromAllBlogs: [Post]
topPostFromAllBlogs: [BlogWithPost]
comments(postId: String): Comments
allBlogs: [Blog]
}
type Mutation {
createPost(title: String,
content: String,
type: String,
blogId: String,
avatar: String): Post
}
type Blog {
id: String
title: String
description: String
authorName: String
avatar: String
}
type Post {
id: String
blogId: String
title: String
content: String
likes: Int
avatar: String
createdAt: DateTime
type: String
}
type BlogWithPost {
id: String
title: String
description: String
authorName: String
avatar: String
post: Post
}
type Comment {
commenterId: String
text: String
}
type Comments {
postId: String
comments: [Comment]
}
我不确定诊断问题还需要哪些其他信息,但我认为它是查询语法错误。
为什么无法识别 orderBy?是否有其他或更好的方法来对结果进行排序?
【问题讨论】:
-
服务器上的架构是什么样子的?你能控制它吗?
-
我愿意。我将更新架构
-
你找到这个错误的原因了吗?
-
我也有同样的问题。 orderby 上的所有文档都不适用于我
标签: apollo graphql-js apollo-server