Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- createPost(parent,args,ctx,info){
- const userExists = ctx.users.some((user)=> user.id === args.author)
- if(!userExists){
- throw new Error('User does not exist!')
- }
- const post = {
- id: uuidv4(),
- ...args
- }
- ctx.posts.push(post)
- if(args.published === true){
- pubsub.publish('post', {
- post:{
- mutation: 'CREATED',
- data: post
- }
- })
- }
- return post
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement