Skip to content

Instantly share code, notes, and snippets.

@desaijay315
Last active June 5, 2019 09:22
Show Gist options
  • Save desaijay315/ccc42803cc91a73472149c1ca72424b8 to your computer and use it in GitHub Desktop.
Save desaijay315/ccc42803cc91a73472149c1ca72424b8 to your computer and use it in GitHub Desktop.
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