I'm trying to get the total count of some items in...
# random
s
I'm trying to get the total count of some items in a resolver but not having any success ... does anyone know what im doing wrong here:
Copy code
cardsCount: async (parent, args, context) => {
            return context.prisma
                .column({ id: parent.id })
                .cards({ aggregate: { count } })
        }
f
I believe you’d need to use the
connection
.. https://www.prisma.io/docs/1.24/prisma-graphql-api/reference/queries-qwe1/
Copy code
const result = await context.prisma.column({ id: parent.id }).cardsConnection().$fragment(`{ aggregate { count } }`)

const cardsCount = result.aggregate.count

return cardsCount;
Not tested but I believe your code should look something like the above. More info: https://github.com/prisma/prisma/issues/3513 https://github.com/prisma/prisma/issues/3997 https://github.com/prisma/prisma/issues/1312
s
Thanks! I'm getting
.cardsConnection is not a function
... maybe I'm missing something, I will go through the provided docs
Solved! Thanks for putting me on the right track. Solution:
Copy code
cardsCount: (parent, args, context) => {
    return context.prisma.cardsConnection({
        where: {
            column: { id: parent.id }
        }
    }).aggregate().count()
}
f
👍 nice