From 405422141b359cb6291d9b2b9b5516f11e17df7c Mon Sep 17 00:00:00 2001 From: ryzetech Date: Thu, 19 Jan 2023 08:51:59 +0100 Subject: [PATCH] made prisma and graphql play nice --- app.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index 34006b2..7855ca5 100644 --- a/app.js +++ b/app.js @@ -17,15 +17,25 @@ const prisma = new PrismaClient(); const cache = new NodeCache({ stdTTL: config.checkperiod * 3 }); let schema = buildSchema(` + type Space { + name: String + id: String! + open: Boolean! + updatedAt: String! + } + type Query { isOpen(id: String): Boolean + spaces: [Space!]! } `); let root = { - isOpen({ id }) { - let open = cache.get(id); - return open; + isOpen: ({ id }) => { + return prisma.space.findUnique({ where: { id: id } }).open; + }, + spaces: () => { + return prisma.space.findMany(); } };