/
index.ts
38 lines (36 loc) · 1.08 KB
/
index.ts
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
import { GraphQLServer } from 'graphql-yoga'
import { prisma } from './generated/prisma-client'
import { Context } from './utils'
const resolvers = {
Query: {
feed(parent, args, context: Context) {
return context.prisma.posts({ where: { published: true } })
},
drafts(parent, args, context: Context) {
return context.prisma.posts({ where: { published: false } })
},
post(parent, { id }, context: Context) {
return context.prisma.post({ id })
},
},
Mutation: {
createDraft(parent, { title, content }, context: Context) {
return context.prisma.createPost({ title, content })
},
deletePost(parent, { id }, context: Context) {
return context.prisma.deletePost({ id })
},
publish(parent, { id }, context: Context) {
return context.prisma.updatePost({
where: { id },
data: { published: true },
})
},
},
}
const server = new GraphQLServer({
typeDefs: './src/schema.graphql',
resolvers,
context: { prisma },
})
server.start(() => console.log('Server is running on http://localhost:4000'))