some-more-queries

This commit is contained in:
Untone 2023-10-13 13:59:24 +03:00
parent fed154c7f1
commit d4dbf5c0ae
2 changed files with 20 additions and 5 deletions

View File

@ -143,11 +143,26 @@ async def get_followed_authors(_, _info, slug) -> List[User]:
return await followed_authors(user_id) return await followed_authors(user_id)
@query.field("authorFollowedAuthors") @query.field("authorFollowings")
async def get_followed_authors2(_, info, author_id) -> List[User]: async def author_followings(_, info, author_id: int, limit: int = 20, offset: int = 0) -> List[User]:
return await followed_authors(author_id) 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 # 2. Now, we can use the user_id to get the followed authors
async def followed_authors(user_id): async def followed_authors(user_id):
q = select(User) q = select(User)

View File

@ -234,10 +234,10 @@ type Query {
loadDrafts: [Shout]! loadDrafts: [Shout]!
loadReactionsBy(by: ReactionBy!, limit: Int, offset: Int): [Reaction]! loadReactionsBy(by: ReactionBy!, limit: Int, offset: Int): [Reaction]!
userFollowers(slug: String!): [Author]! userFollowers(slug: String!): [Author]!
authorFollowers(author_id: Int!): [Author]!
userFollowedAuthors(slug: String!): [Author]! userFollowedAuthors(slug: String!): [Author]!
authorFollowedAuthors(author_id: Int!): [Author]!
userFollowedTopics(slug: String!): [Topic]! userFollowedTopics(slug: String!): [Topic]!
authorFollowers(author_id: Int!, limit: Int, offset: Int): [Author]!
authorFollowings(author_id: Int!, limit: Int, offset: Int): [Author]!
authorsAll: [Author]! authorsAll: [Author]!
getAuthorById(author_id: Int!): Author getAuthorById(author_id: Int!): Author
getAuthor(slug: String!): Author getAuthor(slug: String!): Author