condef5
09/18/2018, 3:41 PMnilan
09/18/2018, 3:46 PMcondef5
09/18/2018, 3:51 PMconst resolvers = {
Query: {
publishedPosts(root, args, context) {
return context.prisma.posts({ where: { published: true } })
},
post(root, args, context) {
return <http://context.prisma.post|context.prisma.post>({ id: args.postId })
},
postsByUser(root, args, context) {
return context.prisma.user({
id: args.userId
}).posts()
}
},
Mutation: {
createDraft(root, args, context) {
return context.prisma.createPost(
{
data: {
title: args.title,
author: {
connect: { id: args.userId }
}
},
},
)
},
publish(root, args, context) {
return context.prisma.updatePost(
{
where: { id: args.postId },
data: { published: true },
},
)
},
createUser(root, args, context) {
return context.prisma.createUser(
{ name: args.name },
)
}
},
User: {
posts(root, args, context) {
return context.prisma.user({
id: root.id
}).posts()
}
},
Post: {
author(root, args, context) {
return <http://context.prisma.post|context.prisma.post>({
id: root.id
}).author()
}
}
}
nilan
09/18/2018, 3:58 PMcreateDraft
mutation from your schema? 🙂 Please exclude other mutations or queries, it just makes it harder to find.condef5
09/18/2018, 4:01 PMcreateDraft
nilan
09/18/2018, 4:02 PMnilan
09/18/2018, 4:02 PMcondef5
09/18/2018, 4:03 PMtype Mutation {
createUser(name: String!): User
createDraft(title: String!, userId: ID!): Post
publish(postId: ID!): Post
}
condef5
09/18/2018, 4:03 PMnilan
09/18/2018, 4:05 PMcondef5
09/18/2018, 4:06 PMnilan
09/18/2018, 4:33 PM