From 167eed436d48fb67aaf499006843ec952e650d76 Mon Sep 17 00:00:00 2001 From: Untone Date: Fri, 24 Nov 2023 04:13:55 +0300 Subject: [PATCH] my-subs-fix --- resolvers/__init__.py | 6 +++--- resolvers/reader.py | 27 +++++++++++++++++++++++++++ schemas/core.graphql | 5 +++-- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/resolvers/__init__.py b/resolvers/__init__.py index 32da89a4..6e6a26c7 100644 --- a/resolvers/__init__.py +++ b/resolvers/__init__.py @@ -20,7 +20,7 @@ from resolvers.topic import ( ) from resolvers.follower import follow, unfollow -from resolvers.reader import load_shout, load_shouts_by, search +from resolvers.reader import load_shout, load_shouts_by, search, load_my_subscriptions from resolvers.community import get_community, get_communities_all __all__ = [ @@ -33,6 +33,8 @@ __all__ = [ "load_shout", "load_shouts_by", "rate_author", + "load_my_subscriptions", + "search", # follower "follow", "unfollow", @@ -57,6 +59,4 @@ __all__ = [ # community "get_community", "get_communities_all", - # search - "search", ] diff --git a/resolvers/reader.py b/resolvers/reader.py index 4ab7b6bd..2f22cd26 100644 --- a/resolvers/reader.py +++ b/resolvers/reader.py @@ -254,3 +254,30 @@ async def search(_, info, text, limit=50, offset=0): return SearchService.search(text, limit, offset) else: return [] + + +@query.field("loadMySubscriptions") +@login_required +async def load_my_subscriptions(_, info): + user_id = info.context["user_id"] + with local_session() as session: + author = session.query(Author).filter(Author.user == user_id).first() + + authors_query = ( + select(User) + .join(AuthorFollower, AuthorFollower.author == User.id) + .where(AuthorFollower.follower == author.id) + ) + + topics_query = select(Topic).join(TopicFollower).where(TopicFollower.follower == author.id) + + topics = [] + authors = [] + + for [author] in session.execute(authors_query): + authors.append(author) + + for [topic] in session.execute(topics_query): + topics.append(topic) + + return {"topics": topics, "authors": authors} diff --git a/schemas/core.graphql b/schemas/core.graphql index 757ef56a..7607f77b 100644 --- a/schemas/core.graphql +++ b/schemas/core.graphql @@ -314,8 +314,11 @@ type Query { loadShout(slug: String, shout_id: Int): Shout loadShouts(options: LoadShoutsOptions): [Shout] loadFeed(options: LoadShoutsOptions): [Shout] + loadMySubscriptions: Result loadDrafts: [Shout] + search(text: String!, limit: Int, offset: Int): [Shout] + loadReactionsBy(by: ReactionBy!, limit: Int, offset: Int): [Reaction] followedReactions(follower_id: Int!): [Shout] @@ -334,6 +337,4 @@ type Query { communitiesAll: [Community] getCommunity: Community - - search(text: String!, limit: Int, offset: Int): [Shout] }