Query to get data ordered by the number of items in a relation



Hi again!

Let’s say I have this typical datamodel, the one used in many tutorials:

type User {
  id: ID! @unique
  name: String!
  posts: [Post!]!

type Post {
  id: ID! @unique
  title: String!
  content: String!
  published: Boolean! @default(value: "false")
  author: User!

Is there a query I can build to get a list of, let’s say, the 10 Users with more Posts??
Basically I need to query ordering by “count” of Posts… but I haven’t found a way to do it :frowning_face:

Any help will be highly appreciated

Cheers :slight_smile:


Beats me!!! I need solution on this too.


Hey @BenjaminKelly, it’s a pain I know.

I didn’t find any information or help so I ended up adding a field to the User table called numberOfPosts and I’m running a mutation once a day to update this field with the number of posts in the relation…


I would also love to see a solution to this!


This feature is currently not implement in Prisma. Please leave your :+1: on this feature request if you’d like to see it in the Prisma API.


This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.