diff --git a/resolvers/__init__.py b/resolvers/__init__.py index 0e62d2a7..e31ad198 100644 --- a/resolvers/__init__.py +++ b/resolvers/__init__.py @@ -1,6 +1,7 @@ from resolvers.author import ( get_author, get_author_follows, + get_author_followers, get_author_id, get_authors_all, load_authors_by, @@ -14,7 +15,6 @@ from resolvers.follower import ( unfollow, get_topic_followers, get_shout_followers, - get_author_followers, ) from resolvers.reaction import ( create_reaction, diff --git a/resolvers/author.py b/resolvers/author.py index aa5cb479..e63575f8 100644 --- a/resolvers/author.py +++ b/resolvers/author.py @@ -307,3 +307,18 @@ async def create_author(user_id: str, slug: str, name: str = ""): session.add(new_author) session.commit() logger.info(f"author created by webhook {new_author.dict()}") + + +@query.field("get_author_followers") +async def get_author_followers(_, _info, slug) -> List[Author]: + q = select(Author) + q = add_author_stat_columns(q) + + aliased_author = aliased(Author) + q = ( + q.join(AuthorFollower, AuthorFollower.follower == Author.id) + .join(aliased_author, aliased_author.id == AuthorFollower.author) + .where(aliased_author.slug == slug) + ) + + return await get_authors_from_query(q) diff --git a/resolvers/follower.py b/resolvers/follower.py index 76a0b441..11819b64 100644 --- a/resolvers/follower.py +++ b/resolvers/follower.py @@ -10,7 +10,6 @@ from orm.author import Author, AuthorFollower from orm.reaction import Reaction from orm.shout import Shout, ShoutReactionsFollower from orm.topic import Topic, TopicFollower -from resolvers.author import add_author_stat_columns, get_authors_from_query from resolvers.community import community_follow, community_unfollow from resolvers.topic import ( topic_follow, @@ -238,21 +237,6 @@ async def get_topic_followers(_, _info, slug: str, topic_id: int) -> List[Author return await get_topics_from_query(q) -@query.field("get_author_followers") -async def get_author_followers(_, _info, slug) -> List[Author]: - q = select(Author) - q = add_author_stat_columns(q) - - aliased_author = aliased(Author) - q = ( - q.join(AuthorFollower, AuthorFollower.follower == Author.id) - .join(aliased_author, aliased_author.id == AuthorFollower.author) - .where(aliased_author.slug == slug) - ) - - return await get_authors_from_query(q) - - @query.field("get_shout_followers") def get_shout_followers( _, _info, slug: str = "", shout_id: int | None = None