diff --git a/resolvers/profile.py b/resolvers/profile.py index f3fb384e..a8a0fa29 100644 --- a/resolvers/profile.py +++ b/resolvers/profile.py @@ -143,11 +143,26 @@ async def get_followed_authors(_, _info, slug) -> List[User]: return await followed_authors(user_id) -@query.field("authorFollowedAuthors") -async def get_followed_authors2(_, info, author_id) -> List[User]: - return await followed_authors(author_id) +@query.field("authorFollowings") +async def author_followings(_, info, author_id: int, limit: int = 20, offset: int = 0) -> List[User]: + return await followed_authors(author_id)[offset:(limit+offset)] +@query.field("authorFollowers") +async def author_followers(_, info, author_id: int, limit: int = 20, offset: int = 0) -> List[User]: + + q = select(User) + q = add_author_stat_columns(q) + + aliased_user = aliased(User) + q = ( + q.join(AuthorFollower, AuthorFollower.follower == User.id) + .join(aliased_user, aliased_user.id == AuthorFollower.author) + .where(aliased_user.id == author_id) + ) + + return get_authors_from_query(q) + # 2. Now, we can use the user_id to get the followed authors async def followed_authors(user_id): q = select(User) diff --git a/schemas/core.graphql b/schemas/core.graphql index f85bbecd..c2d5a4dd 100644 --- a/schemas/core.graphql +++ b/schemas/core.graphql @@ -234,10 +234,10 @@ type Query { loadDrafts: [Shout]! loadReactionsBy(by: ReactionBy!, limit: Int, offset: Int): [Reaction]! userFollowers(slug: String!): [Author]! - authorFollowers(author_id: Int!): [Author]! userFollowedAuthors(slug: String!): [Author]! - authorFollowedAuthors(author_id: Int!): [Author]! userFollowedTopics(slug: String!): [Topic]! + authorFollowers(author_id: Int!, limit: Int, offset: Int): [Author]! + authorFollowings(author_id: Int!, limit: Int, offset: Int): [Author]! authorsAll: [Author]! getAuthorById(author_id: Int!): Author getAuthor(slug: String!): Author