i_priz
01/19/2019, 3:25 PMcreateOrder
. A user can only create order if they have less than 5 active ordersVittorio Adamo
01/20/2019, 10:31 AMconst resolvers = {
Mutation: {
createOrder: async (_root, args, ctx) => {
const { prisma } = ctx
const { order } = args
const ordersCountPerUser = await prisma
.ordersConnection({ where: { user: order.userId } })
.aggregate()
.count()
if (ordersCountPerUser >= 5) {
// handle your fail case
throw new Error('Can't place more than 5 orders!')
}
return prisma.createOrder(order)
}
}
}
some examples HowTo:
- https://github.com/prisma/prisma-examples/tree/master/node/graphql-schema-delegation
- https://github.com/prisma/prisma-examples/tree/master/node/rest-express