Martin Hunt
11/03/2018, 4:17 PMquery GET_CATEGORIES{
categories {
name
id
description
posts {
id
}
}
}
What I really need from the posts is the total count of the posts assigned to each category. Right now I'm just calling posts.length on the returned array of ID's but I'm guessing that's not particularly future proof / scalable.
Any help would be massively appreciated!jamiehalvorson
11/03/2018, 4:36 PMaggregate for this, docs are here: https://www.prisma.io/docs/prisma-client/basic-data-access/reading-data-TYPESCRIPT-rsc3/#aggregations
Example
catgeoriesCount(parent, args, ctx: Context, info) {
return ctx.db.query.catgeoriesConnection({}, info);
}
query categoriesCount {
categoriesCount {
aggregate {
count
}
}
}
Hope that helps!Martin Hunt
11/03/2018, 4:52 PMyolen
11/04/2018, 11:55 AMwhere . e.g. where: {category : "horses"}Martin Hunt
11/05/2018, 9:36 PM