made prisma and graphql play nice

This commit is contained in:
ryzetech 2023-01-19 08:51:59 +01:00
parent bd163f0ccb
commit 405422141b
1 changed files with 13 additions and 3 deletions

16
app.js
View File

@ -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();
}
};