Created
June 9, 2019 15:46
-
-
Save desaijay315/41d1366c36b3973a2928900fce8c9933 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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