made prisma and graphql play nice

This commit is contained in:
ryzetech 2023-01-19 08:51:59 +01:00
parent bd163f0ccb
commit 405422141b

16
app.js
View file

@ -17,15 +17,25 @@ const prisma = new PrismaClient();
const cache = new NodeCache({ stdTTL: config.checkperiod * 3 }); const cache = new NodeCache({ stdTTL: config.checkperiod * 3 });
let schema = buildSchema(` let schema = buildSchema(`
type Space {
name: String
id: String!
open: Boolean!
updatedAt: String!
}
type Query { type Query {
isOpen(id: String): Boolean isOpen(id: String): Boolean
spaces: [Space!]!
} }
`); `);
let root = { let root = {
isOpen({ id }) { isOpen: ({ id }) => {
let open = cache.get(id); return prisma.space.findUnique({ where: { id: id } }).open;
return open; },
spaces: () => {
return prisma.space.findMany();
} }
}; };