2020-09-03 18:28:29 +03:00
|
|
|
import HttpError from '@wasp/core/HttpError.js'
|
2020-09-19 17:11:09 +03:00
|
|
|
import Prisma from '@prisma/client'
|
|
|
|
|
|
|
|
// TODO(matija): is it ok to create a new instance in every file? See if it needs to be a
|
|
|
|
// singleton somewhere, if it isn't already.
|
|
|
|
const prisma = new Prisma.PrismaClient()
|
2020-09-03 18:28:29 +03:00
|
|
|
|
2020-08-31 15:41:49 +03:00
|
|
|
export const getTasks = async (args, context) => {
|
|
|
|
if (Math.random() < 0.5) {
|
2020-09-03 18:28:29 +03:00
|
|
|
throw new HttpError(400, 'Random error: getting tasks failed.')
|
2020-08-31 15:41:49 +03:00
|
|
|
}
|
2020-09-19 17:11:09 +03:00
|
|
|
|
|
|
|
const tasks = await prisma.task.findMany({})
|
|
|
|
|
|
|
|
return tasks
|
2020-08-25 21:10:59 +03:00
|
|
|
}
|