def create_blog_post(data): title = data.get('title') body = data.get('body') category_id = data.get('category_id') category = Category.query.filter(Category.id == category_id).one() post = Post(title, body, category) post.author = data.get('author') db.session.add(post) db.session.commit()
def mutate(self, info, data): """Mutate method.""" user = User.query.filter_by(username=data['username']).first() if user is None: raise GraphQLError('User not found.') post = Post(title=data['title'], body=data['body']) post.author = user db.session.add(post) db.session.commit() return CreatePosts(post=post)