From 82fe60f76434b0a793d52334df329fc69f990ec7 Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Wed, 13 Jul 2022 18:53:06 +0300 Subject: [PATCH] revised --- resolvers/comments.py | 4 ++++ resolvers/profile.py | 9 +++++---- resolvers/topics.py | 13 +++++++++---- schema.graphql | 39 ++++++++++++++++++++++++--------------- 4 files changed, 42 insertions(+), 23 deletions(-) diff --git a/resolvers/comments.py b/resolvers/comments.py index 2aef4daf..0c23fe0f 100644 --- a/resolvers/comments.py +++ b/resolvers/comments.py @@ -129,3 +129,7 @@ def get_subscribed_shout_comments(slug): all() slugs = [row.shout for row in rows] return slugs + +def get_top10_comments(): + with local_session() as session: + rows = session.query(Comment).limit(10).all() diff --git a/resolvers/profile.py b/resolvers/profile.py index de7960e4..1a8cb59a 100644 --- a/resolvers/profile.py +++ b/resolvers/profile.py @@ -98,17 +98,18 @@ async def user_comments(_, info, slug, page, size): return comments -@query.field("userSubscriptions") +@query.field("userSubscribedAuthors") async def user_subscriptions(_, info, slug): - return _get_user_subscribed_authors(slug) + slugs = _get_user_subscribed_authors(slug) + return slugs @query.field("userSubscribers") async def user_subscribers(_, info, slug): with local_session() as session: - users = session.query(User).\ + slugs = session.query(User.slug).\ join(AuthorSubscription, User.slug == AuthorSubscription.subscriber).\ where(AuthorSubscription.author == slug) - return users + return slugs @query.field("userSubscribedTopics") async def user_subscribed_topics(_, info, slug): diff --git a/resolvers/topics.py b/resolvers/topics.py index 88775231..49123b40 100644 --- a/resolvers/topics.py +++ b/resolvers/topics.py @@ -13,16 +13,21 @@ async def topics_by_slugs(_, info, slugs = None): with local_session() as session: topics = await TopicStorage.get_topics(slugs) all_fields = [node.name.value for node in info.field_nodes[0].selection_set.selections] - if "topicStat" in all_fields: + if "stat" in all_fields: for topic in topics: - topic.topicStat = await TopicStat.get_stat(topic.slug) + topic.stat = await TopicStat.get_stat(topic.slug) return topics @query.field("topicsByCommunity") async def topics_by_community(_, info, community): with local_session() as session: - return await TopicStorage.get_topics_by_community(community) - + topics = await TopicStorage.get_topics_by_community(community) + all_fields = [node.name.value for node in info.field_nodes[0].selection_set.selections] + if "stat" in all_fields: + for topic in topics: + topic.stat = await TopicStat.get_stat(topic.slug) + return topics + @query.field("topicsByAuthor") async def topics_by_author(_, info, author): slugs = set() diff --git a/schema.graphql b/schema.graphql index 6fbf4a5e..c42e6e88 100644 --- a/schema.graphql +++ b/schema.graphql @@ -159,33 +159,46 @@ type Mutation { ################################### Query type Query { + # auth isEmailUsed(email: String!): Boolean! signIn(email: String!, password: String): AuthResult! signOut: Result! + forget(email: String!): Result! + requestPasswordReset(email: String!): Result! + updatePassword(password: String!, token: String!): Result! # profile + userSubscribers(slug: String!): [String]! + userSubscribedAuthors(slug: String!): [String]! + userSubscribedTopics(slug: String!): [String]! getCurrentUser: UserResult! getUsersBySlugs(slugs: [String]!): [User]! getUserRoles(slug: String!): [Role]! - userComments(slug: String!, page: Int!, size: Int!): [Comment]! - userSubscriptions(slug: String!): [User]! - userSubscribers(slug: String!): [User]! - userSubscribedTopics(slug: String!): [String]! - - shoutsRatedByUser(page: Int!, size: Int!): ShoutsResult! - shoutsCommentedByUser(slug: String!, page: Int!, size: Int!): [Shout]! - userUnpublishedShouts(page: Int!, size: Int!): ShoutsResult! # shouts getShoutBySlug(slug: String!): Shout! shoutsByTopics(slugs: [String]!, page: Int!, size: Int!): [Shout]! shoutsByAuthors(slugs: [String]!, page: Int!, size: Int!): [Shout]! shoutsByCommunities(slugs: [String]!, page: Int!, size: Int!): [Shout]! + shoutsRatedByUser(page: Int!, size: Int!): ShoutsResult! + shoutsReviewed(page: Int!, size: Int!): [Shout]! + userUnpublishedShouts(page: Int!, size: Int!): ShoutsResult! + shoutsCommentedByUser(page: Int!, size: Int!): ShoutsResult! + recentCommented(page: Int!, size: Int!): [Shout]! + + # comments getShoutComments(slug: String!): [Comment]! + getAllComments: [Comment]! # top10 + userComments(slug: String!, page: Int!, size: Int!): [Comment]! # collab getShoutProposals(slug: String!): [Proposal]! + createProposal(body: String!, range: String): Proposal! + updateProposal(body: String!, range: String): Proposal! + destroyProposal(id: Int!): Result! + inviteAuthor(slug: String!, author: String!): Result! + removeAuthor(slug: String!, author: String!): Result! # mainpage topViewed(page: Int!, size: Int!): [Shout]! @@ -197,18 +210,14 @@ type Query { recentAll(page: Int!, size: Int!): [Shout]! # topics - topicsAll(slugs: [String]): [Topic]! + topicsAll(page: Int!, size: Int!): [Topic]! topicsByCommunity(community: String!): [Topic]! topicsByAuthor(author: String!): [Topic]! - # getOnlineUsers: [User!]! - # communities getCommunity(slug: String): Community! getCommunities: [Community]! - - shoutsReviewed(page: Int!, size: Int!): [Shout]! - recentCommented(page: Int!, size: Int!): [Shout]! + # TODO: getCommunityMembers(slug: String!): [User]! } ############################################ Subscription @@ -365,7 +374,7 @@ type Topic { parents: [String] # NOTE: topic can have parent topics children: [String] # and children community: String! - topicStat: TopicStat + stat: TopicStat oid: String }