Prisma1: Aggregation queries ignores pagination

Created on 9 Aug 2018  路  3Comments  路  Source: prisma/prisma1

Describe the bug

Aggregation across nodes ignores pagination.

To Reproduce
Steps to reproduce the behavior:

  1. Deploy this datamodel:
type User {
  id: ID! @unique
  name: String!
}
  1. Create a few user nodes:
mutation a {
  createUser(data: {
    name: "Test"
  }) {
    id
  }
}
  1. Count paginated users
query c {
  usersConnection(first: 3) {
    aggregate {
      count
    }
  }
}
  1. See that count is not 3 but as many users as you created:
{
  "data": {
    "usersConnection": {
      "aggregate": {
        "count": 4
      }
    }
  }
}

Expected behavior

Should return the number of returned nodes:

{
  "data": {
    "usersConnection": {
      "aggregate": {
        "count": 3
      }
    }
  }
}

Versions (please complete the following information):

  • Prisma Server: 1.13.4
bu2-confirmed areengine

Most helpful comment

What the reason of this change? I am asking because this change broke my code.

When I implement pagination, I use count value. Before this change count was equal to total number of items. This value could be used to calculate total number of pages (count / itemsPerPage). But now I forced to use another one query to retrieve total number of items.

All 3 comments

What the reason of this change? I am asking because this change broke my code.

When I implement pagination, I use count value. Before this change count was equal to total number of items. This value could be used to calculate total number of pages (count / itemsPerPage). But now I forced to use another one query to retrieve total number of items.

@braska : We learned that the old behavior was often unintuitive to people. Therefore we changed the behavior to return the number of nodes that match the specified filter (first, where...). If you are concerned about additional roundtrips i suggest to use aliases to send Prisma 2 queries at once. One for the results itself. And one for the total number of nodes. Here is an example:t

query {
  users: usersConnection(first: 3) {
    edges {
      node {
        name
      }
    }
  }
  totalNumberOfUsers: usersConnection {
    aggregate {
      count
    }
  }
}

This workaround works for me. Thanks a lot!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jannone picture jannone  路  3Comments

ragnorc picture ragnorc  路  3Comments

marktani picture marktani  路  3Comments

schickling picture schickling  路  3Comments

marktani picture marktani  路  3Comments