Skip to content

Instantly share code, notes, and snippets.

@desaijay315
Created June 9, 2019 15:25
Show Gist options
  • Save desaijay315/e43bac6a50ac5a10442ae92d9e43dd5b to your computer and use it in GitHub Desktop.
Save desaijay315/e43bac6a50ac5a10442ae92d9e43dd5b to your computer and use it in GitHub Desktop.
createPost(parent,args,ctx,info){
const userExists = ctx.users.some((user)=> user.id === args.author)
if(!userExists){
throw new Error('User does not exist!')
}
const post = {
id: uuidv4(),
...args
}
ctx.posts.push(post)
if(args.published === true){
pubsub.publish('post', {
post:{
mutation: 'CREATED',
data: post
}
})
}
return post
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment