playra
07/09/2018, 7:33 PMasync createDraft(parent, { title, text }, ctx, info) {
const userId = getUserId(ctx)
return ctx.db.mutation.createPost(
{
data: {
title,
text,
isPublished: false,
author: {
connect: { id: userId },
},
},
},
info
)
},
medelman
07/09/2018, 7:50 PMupdatePost(...)
?playra
07/09/2018, 8:09 PMasync updatePost(parent, { id, text, title }, ctx, info) {
const userId = getUserId(ctx)
const postExists = await <http://ctx.db.exists.Post|ctx.db.exists.Post>({
id,
author: { id: userId },
})
if (!postExists) {
throw new Error(`Post not found or you're not the author`)
}
return ctx.db.mutation.updatePost(
{
where: { id },
data: {
title,
text,
isPublished: true,
author: {
connect: { id: userId },
},
},
},
info,
)
},
Thanks, done 😃