From 6b255cc984ec5ad4af58d5a3e50581f787ee73e7 Mon Sep 17 00:00:00 2001 From: Tony Date: Thu, 3 Feb 2022 10:36:39 +0300 Subject: [PATCH] update schema --- resolvers/__init__.py | 8 +++++++- resolvers/zine.py | 33 +++++++++++---------------------- schema.graphql | 6 +++--- 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/resolvers/__init__.py b/resolvers/__init__.py index f313465a..7fa3d745 100644 --- a/resolvers/__init__.py +++ b/resolvers/__init__.py @@ -1,7 +1,8 @@ from resolvers.auth import login, sign_out, is_email_free, register, confirm from resolvers.inbox import create_message, delete_message, update_message, get_messages from resolvers.zine import create_shout, get_shout_by_slug, top_month, top_overall, \ - recent_shouts, top_viewed #, top_authors + recent_shouts, top_viewed, shouts_by_author, shouts_by_topic, \ + shouts_candidates, shouts_reviewed, shouts_subscribed from resolvers.profile import get_users_by_slugs, get_current_user from resolvers.topics import topic_subscribe, topic_unsubscribe, topics_by_author, \ topics_by_community, topics_by_slugs @@ -24,6 +25,11 @@ __all__ = [ "get_users_by_slugs", "get_shout_by_slug", "recent_shouts", + "shouts_by_topic", + "shouts_by_author", + "shouts_subscribed", + "shouts_reviewed", + "shouts_candidates", "top_month", "top_overall", "top_viewed", diff --git a/resolvers/zine.py b/resolvers/zine.py index ed6413c8..27e4adfb 100644 --- a/resolvers/zine.py +++ b/resolvers/zine.py @@ -398,21 +398,17 @@ async def shouts_by_community(_, info, community, page, size): offset(page * size) return shouts -@query.field("shoutsByUserSubscriptions") -async def shouts_by_user_subscriptions(_, info, userSlug, page, size): - user = await UserStorage.get_user_by_slug(userSlug) - if not user: - return - +@query.field("shoutsSubscribed") +async def shouts_subscribed(_, info, page, size): with local_session() as session: shouts_by_topic = session.query(Shout).\ join(ShoutTopic).\ join(TopicSubscription, ShoutTopic.topic == TopicSubscription.topic).\ - where(and_(Shout.publishedAt != None, TopicSubscription.subscriber == userSlug)) + where(and_(Shout.publishedAt != None, TopicSubscription.subscriber == User.slug)) shouts_by_author = session.query(Shout).\ join(ShoutAuthor).\ join(AuthorSubscription, ShoutAuthor.user == AuthorSubscription.author).\ - where(and_(Shout.publishedAt != None, AuthorSubscription.subscriber == userSlug)) + where(and_(Shout.publishedAt != None, AuthorSubscription.subscriber == User.slug)) shouts = shouts_by_topic.union(shouts_by_author).\ order_by(desc(Shout.publishedAt)).\ limit(size).\ @@ -420,19 +416,16 @@ async def shouts_by_user_subscriptions(_, info, userSlug, page, size): return shouts -@query.field("shoutsByUserRatingOrComment") -async def shouts_by_user_rating_or_comment(_, info, userSlug, page, size): - user = await UserStorage.get_user_by_slug(userSlug) - if not user: - return +@query.field("shoutsReviewed") +async def shouts_reviewed(_, info, page, size): with local_session() as session: shouts_by_rating = session.query(Shout).\ join(ShoutRating).\ - where(and_(Shout.publishedAt != None, ShoutRating.rater == userSlug)) + where(and_(Shout.publishedAt != None, ShoutRating.rater == User.slug)) shouts_by_comment = session.query(Shout).\ join(Comment).\ - where(and_(Shout.publishedAt != None, Comment.author == user.id)) + where(and_(Shout.publishedAt != None, Comment.author == User.id)) shouts = shouts_by_rating.union(shouts_by_comment).\ order_by(desc(Shout.publishedAt)).\ limit(size).\ @@ -440,17 +433,13 @@ async def shouts_by_user_rating_or_comment(_, info, userSlug, page, size): return shouts -@query.field("newShoutsWithoutRating") -async def new_shouts_without_rating(_, info, userSlug, size): - user = await UserStorage.get_user_by_slug(userSlug) - if not user: - return - +@query.field("shoutsCandidates") +async def shouts_candidates(_, info, size): #TODO: postgres heavy load with local_session() as session: shouts = session.query(Shout).distinct().\ outerjoin(ShoutRating).\ - where(and_(Shout.publishedAt != None, ShoutRating.rater != userSlug)).\ + where(and_(Shout.publishedAt != None, ShoutRating.rater != User.slug)).\ order_by(desc(Shout.publishedAt)).\ limit(size) diff --git a/schema.graphql b/schema.graphql index 099702e3..f09ea3f3 100644 --- a/schema.graphql +++ b/schema.graphql @@ -197,9 +197,9 @@ type Query { getCommunity(slug: String): Community! getCommunities: [Community]! - shoutsByUserSubscriptions(userSlug: String!, page: Int!, size: Int!): [Shout]! - shoutsByUserRatingOrComment(userSlug: String!, page: Int!, size: Int!): [Shout]! - newShoutsWithoutRating(userSlug: String!, size: Int = 10): [Shout]! + shoutsSubscribed(page: Int!, size: Int!): [Shout]! + shoutsReviewed(page: Int!, size: Int!): [Shout]! + shoutsCandidates(size: Int = 10): [Shout]! } ############################################ Subscription