首页 > 解决方案 > GraphQL Prisma - 在嵌套关系上使用 orderBy

问题描述

我对 GraphQL Prisma 组合相当陌生,我似乎无法毫无错误地对嵌套关系进行排序,因为唯一可用的 orderBy 字段与 ID 有关。

我在操场上的预期目标是创建一个类似于以下内容的查询:

getPosts{
  connections(orderBy: "text_asc"){
   id
   text
  }
}

解析器

getPosts(parent, args, ctx, info){
  return ctx.db.query.posts({}, info)
}

数据模型

type Post {
  id: ID! @id
  isPublished: Boolean! @default(value: false)
  title: String!
  text: String!
  connections: [Connection!]! @relation(name: "ClientConnect")
}

type Link {
  id: ID! @id
  text: String!
  url: String!
}

type Connection {
  id: ID! @unique @id
  client: Link @relation(name: "LinkConnect")
}

标签: graphqlprisma

解决方案


推荐阅读