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 });
|
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();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue