made prisma and graphql play nice
This commit is contained in:
parent
bd163f0ccb
commit
405422141b
1 changed files with 13 additions and 3 deletions
16
app.js
16
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();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue