def resolve_allposts(self, info): result = None with (db.grab_session()) as session: q = session.query(dao.Post) result = [gqlmodel.GQLPost.convert(post) for post in q.all()] return result
def resolve_allusers(self, info): result = None with (db.grab_session()) as session: q = session.query(dao.User) result = [gqlmodel.GQLUser.convert(user) for user in q.all()] return result
def resolve_post(self, info, title=None): result = None with (db.grab_session()) as session: q = session.query(dao.Post) result = gqlmodel.GQLPost.convert( q.filter(dao.Post.title == title).one()) return result
def resolve_user(self, info, username=None): result = None with (db.grab_session()) as session: q = session.query(dao.User) result = gqlmodel.GQLUser.convert( q.filter(dao.User.username == username).one()) return result
def mutate(self, info, username=None, password=None): result = None with (db.grab_session()) as session: user = dao.User(username=username, password=password) session.add(user) session.commit() ok = True result = CreateUser(user=gqlmodel.GQLUser.convert(user), ok=ok) return result
def mutate(self, info, postId=None): result = None with (db.grab_session()) as session: q = session.query(dao.Post).filter(dao.Post.id == postId) post = q.one() if post == None: ok = False else: q.delete() session.commit() ok = True result = DeletePost(post=gqlmodel.GQLPost.convert(post), ok=ok) return result
def mutate(self, info, userId=None): result = None with (db.grab_session()) as session: q = session.query(dao.User).filter(dao.User.id == userId) user = q.one() if user == None: ok = False else: q.delete() session.commit() ok = True result = DeleteUser(user=gqlmodel.GQLUser.convert(user), ok=ok) return result
def mutate(self, info, userId=None, title=None, body=None): result = None with (db.grab_session()) as session: user = session.query(dao.User).filter(dao.User.id == userId).one() if user == None: ok = False post = None else: post = dao.Post(title=title, body=body, created=datetime.datetime.now(), user=user) session.add(post) session.commit() ok = True result = CreatePost(post=gqlmodel.GQLPost.convert(post), ok=ok) return result