Skip to content

Instantly share code, notes, and snippets.

@desaijay315
Created June 9, 2019 15:46
Show Gist options
  • Save desaijay315/41d1366c36b3973a2928900fce8c9933 to your computer and use it in GitHub Desktop.
Save desaijay315/41d1366c36b3973a2928900fce8c9933 to your computer and use it in GitHub Desktop.
updatePost(parent,args, ctx, info){
const post = ctx.posts.find((post) => post.id === args.id)
const originalPost = {...post} //spread operator
if (!post) {
throw new Error('Post not found')
}
if (typeof args.body === 'string') {
post.body = args.body
}
if (typeof args.published === 'boolean') {
post.published = args.published
pubsub.publish('post', {
post:{
mutation: 'UPDATED',
data: post
}
})
}
return post
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment