Moritz
08/11/2018, 3:40 PMjaga_santagostino
08/11/2018, 5:48 PMasync randomLineItem(parent, args, ctx: Context, info) {
const connection = await ctx.db.query.lineItemsConnection(
{},
`{
aggregate {
count
}
}`,
)
const randomIndex = getRandom({
min: 0,
max: connection.aggregate.count, // this is the current number or lineItems in the db
})
const lis = await ctx.db.query.lineItems({ skip: randomIndex, first: 1 }, info)
return lis[0]
}
jaga_santagostino
08/11/2018, 5:49 PMjaga_santagostino
08/11/2018, 5:51 PMMoritz
08/12/2018, 8:06 AM