Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement