Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. createPost(parent,args,ctx,info){
  2. const userExists = ctx.users.some((user)=> user.id === args.author)
  3.  
  4. if(!userExists){
  5. throw new Error('User does not exist!')
  6. }
  7.  
  8. const post = {
  9. id: uuidv4(),
  10. ...args
  11. }
  12.  
  13. ctx.posts.push(post)
  14. if(args.published === true){
  15. pubsub.publish('post', {
  16. post:{
  17. mutation: 'CREATED',
  18. data: post
  19. }
  20. })
  21. }
  22. return post
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement