小编Pan*_*ani的帖子

graphql:按嵌套字段排序

假设我有 2 个表:
- 用户(id、名称、帖子)
- 帖子(id、消息、用户)

如何按用户名(desc)获取前 10 个帖子订单?

这是我的架构的样子:

var PostType = new GraphQLObjectType({
  name: "Post",
  fields: () => ({
    id: { type: GraphQLInt },
    message: { type: GraphQLString },
    user: {
      type: UserType,
      args: {
        orderBy: { type: sortType }
      },
      resolve(parent, args) {
        console.info("Post resolve called.");
        return userMap[parent.user];
      }
    }
  })
});

var RootQuery = new GraphQLObjectType({
  name: "RootQueryType",
  fields: {
    allPosts: {
      type: new GraphQLList(PostType),
      resolve(parentValue, args) {
        console.info("allPosts resolve called.");
        return postData;
      }
    } …
Run Code Online (Sandbox Code Playgroud)

graphql

9
推荐指数
1
解决办法
7025
查看次数

标签 统计

graphql ×1