Describe the bug
Aggregation across nodes ignores pagination.
To Reproduce
Steps to reproduce the behavior:
type User {
id: ID! @unique
name: String!
}
mutation a {
createUser(data: {
name: "Test"
}) {
id
}
}
query c {
usersConnection(first: 3) {
aggregate {
count
}
}
}
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):
1.13.4What 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!
Most helpful comment
What the reason of this change? I am asking because this change broke my code.
When I implement pagination, I use
countvalue. Before this changecountwas 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.