From 75cd8b9f7136d73fa92451c92af1fc0527e2a896 Mon Sep 17 00:00:00 2001 From: Untone Date: Thu, 9 May 2024 00:02:59 +0300 Subject: [PATCH] get-author-ref --- resolvers/author.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/resolvers/author.py b/resolvers/author.py index dae367f6..a8bb2809 100644 --- a/resolvers/author.py +++ b/resolvers/author.py @@ -54,9 +54,13 @@ async def get_author(_, _info, slug="", author_id=0): author_dict = None try: # lookup for cached author - author_query = select(Author).filter( - or_(Author.slug == slug, Author.id == author_id) - ) + author_query = select(Author) + if slug: + author_query = author_query.filter(Author.slug == slug) + elif author_id: + author_query = author_query.filter(Author.id == author_id) + else: + raise ValueError("Author not found") lookup_result = local_session().execute(author_query).first() if lookup_result: [found_author] = lookup_result