forked from prisma/prisma1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (39 loc) · 990 Bytes
/
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
const { GraphQLServer } = require("graphql-yoga");
const { Prisma } = require("prisma-binding");
const getPrismaInstance = () => {
return new Prisma({
typeDefs: "generated-schema.graphql",
endpoint: "http://localhost:4466/application-server"
});
};
const resolvers = {
Query: {
posts: (
_,
{ where, orderBy, skip, after, before, first, last },
ctx,
info
) => {
return ctx.db.query.posts(
{ where, orderBy, skip, after, before, first, last },
info
);
}
},
Mutation: {
createPost: (_, { data }, ctx, info) => {
return ctx.db.mutation.createPost({ data }, info);
},
deletePost: (_, { id }, ctx, info) => {
return ctx.db.mutation.deletePost({ where: { id } }, `{ id }`);
}
}
};
const server = new GraphQLServer({
typeDefs: "schema.graphql",
resolvers,
context: {
db: getPrismaInstance()
}
});
server.start(() => console.log("Server is running on localhost:4000"));