Created
June 9, 2019 15:25
-
-
Save desaijay315/e43bac6a50ac5a10442ae92d9e43dd5b 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
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