Slide 17
Slide 17 text
v n o v i c k . c o m
Resolvers
Mutation: {
createDraft: (parent, args) => {
const post = {
id: `post_${idCount++}`,
title: args.title,
content: args.content,
comments: [],
author: {
id: `author_${new Date().getMilliseconds()}`,
name: args.author
},
published: false,
}
posts.push(post)
return post
},
const resolvers = {
Query: {
posts: () => posts,
post: (parent, args) => posts.find(post => post.id === args.id),
},