Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. const resolvers = {
  2. Mutation:{
  3. createPost(parent,args,ctx,info){
  4. const userExists = users.some((user)=> user.id === args.author)
  5.  
  6. if(!userExists){
  7. throw new Error('User does not exist!')
  8. }
  9.  
  10. //use this
  11. const post = {
  12. id: uuidv4(),
  13. title: args.title,
  14. body: args.body,
  15. published: args.published,
  16. author:args.author
  17. }
  18. //OR
  19. //use object spread operator
  20. const post = {
  21. id: uuidv4(),
  22. ...args
  23. }
  24.  
  25. posts.push(post)
  26. return post
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement