This repository has been archived by the owner on Jul 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (51 loc) · 1.48 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const { GraphQLServer } = require('graphql-yoga');
const { Prisma } = require('prisma-binding');
const resolvers = {
Query: {
posts(parent, args, ctx, info) {
return ctx.db.query.posts({}, info);
},
post(parent, args, ctx, info) {
return ctx.db.query.post({ where: { id: args.id } }, info);
},
},
Mutation: {
createDraft(parent, { title, content }, ctx, info) {
return ctx.db.mutation.createPost(
{
data: {
title,
content,
},
},
info,
);
},
deletePost(parent, { id }, ctx, info) {
return ctx.db.mutation.deletePost({ where: { id } }, info);
},
publish(parent, { id }, ctx, info) {
return ctx.db.mutation.updatePost(
{
where: { id },
data: { published: true },
},
info,
);
},
},
};
const server = new GraphQLServer({
typeDefs: 'src/schema.graphql',
resolvers,
context: req => ({
...req,
db: new Prisma({
typeDefs: 'src/generated/prisma.graphql', // the generated Prisma DB schema
endpoint: 'https://eu1.prisma.sh/ruben/database/dev', // the endpoint of the Prisma DB service
secret: 'mysecret123', // specified in database/prisma.yml
debug: true, // log all GraphQL queries & mutations
}),
}),
});
server.start(() => console.log('Server is running on http:https://localhost:4000'));