From d3b2eddf58081ca3cff968b5ce2faee956c8e458 Mon Sep 17 00:00:00 2001 From: Untone Date: Sat, 3 Feb 2024 17:31:00 +0300 Subject: [PATCH] return-type-fix --- resolvers/author.py | 6 ++++-- resolvers/editor.py | 5 +++-- resolvers/topic.py | 8 +++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/resolvers/author.py b/resolvers/author.py index 223e9636..6a559126 100644 --- a/resolvers/author.py +++ b/resolvers/author.py @@ -79,14 +79,16 @@ async def update_profile(_, info, profile): Author.update(author, profile) session.add(author) session.commit() - return {'error': None, 'author': author} + return {'error': None, 'author': author} # TODO: caching query @query.field('get_authors_all') async def get_authors_all(_, _info): + authors = [] with local_session() as session: - return session.query(Author).all() + authors = session.query(Author).all() + return authors def count_author_comments_rating(session, author_id) -> int: diff --git a/resolvers/editor.py b/resolvers/editor.py index 3cdc1ba8..62ea1110 100644 --- a/resolvers/editor.py +++ b/resolvers/editor.py @@ -21,6 +21,7 @@ from services.search import search_service @login_required async def get_shouts_drafts(_, info): user_id = info.context['user_id'] + shouts = [] with local_session() as session: author = session.query(Author).filter(Author.user == user_id).first() if author: @@ -34,7 +35,7 @@ async def get_shouts_drafts(_, info): .group_by(Shout.id) ) shouts = [shout for [shout] in session.execute(q).unique()] - return shouts + return shouts @mutation.field('create_shout') @@ -189,7 +190,7 @@ async def update_shout(_, info, shout_id, shout_input=None, publish=False): # main topic main_topic = shout_input.get('main_topic') if main_topic: - patch_main_topic(main_topic) + patch_main_topic(session, main_topic, shout) shout_input['updated_at'] = current_time shout_input['published_at'] = current_time if publish else None diff --git a/resolvers/topic.py b/resolvers/topic.py index 071e4658..026b21ec 100644 --- a/resolvers/topic.py +++ b/resolvers/topic.py @@ -109,11 +109,13 @@ async def get_topic(_, _info, slug): async def create_topic(_, _info, inp): with local_session() as session: # TODO: check user permissions to create topic for exact community + # and actor is permitted to craete it new_topic = Topic(**inp) session.add(new_topic) session.commit() - return {'topic': new_topic} + return {'topic': new_topic} + return {'error': 'cannot create topic'} @mutation.field('update_topic') @@ -130,6 +132,7 @@ async def update_topic(_, _info, inp): session.commit() return {'topic': topic} + return {'error': 'cannot update' } @mutation.field('delete_topic') @@ -149,8 +152,7 @@ async def delete_topic(_, info, slug: str): session.commit() return {} - else: - return {'error': 'access denied'} + return {'error': 'access denied'} def topic_follow(follower_id, slug):