Last active
June 5, 2019 09:22
-
-
Save desaijay315/ccc42803cc91a73472149c1ca72424b8 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
const resolvers = { | |
Mutation:{ | |
createPost(parent,args,ctx,info){ | |
const userExists = users.some((user)=> user.id === args.author) | |
if(!userExists){ | |
throw new Error('User does not exist!') | |
} | |
//use this | |
const post = { | |
id: uuidv4(), | |
title: args.title, | |
body: args.body, | |
published: args.published, | |
author:args.author | |
} | |
//OR | |
//use object spread operator | |
const post = { | |
id: uuidv4(), | |
...args | |
} | |
posts.push(post) | |
return post | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment