From 1720f008395fac22e7263ce161d265cba591ae83 Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Thu, 10 Nov 2022 09:51:40 +0300 Subject: [PATCH] getTopic, getAuthor --- resolvers/profile.py | 8 +++++++- resolvers/topics.py | 7 +++++++ schema.graphql | 2 ++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/resolvers/profile.py b/resolvers/profile.py index 6ba21f13..6730ac53 100644 --- a/resolvers/profile.py +++ b/resolvers/profile.py @@ -34,7 +34,6 @@ async def get_author_stat(slug): return { "followers": session.query(AuthorFollower).where(AuthorFollower.author == slug).count(), "rating": session.query(func.sum(UserRating.value)).where(UserRating.user == slug).first() - # TODO: debug } @@ -210,3 +209,10 @@ async def get_authors_all(_, _info): @query.field("topAuthors") def get_top_authors(_, _info, offset, limit): return list(UserStorage.get_top_users())[offset : offset + limit] # type: ignore + + +@query.field("getAuthor") +async def get_author(_, _info, slug): + a = await UserStorage.users[slug] + a.stat = get_author_stat(slug) + return a diff --git a/resolvers/topics.py b/resolvers/topics.py index 9ff2e070..e2216caf 100644 --- a/resolvers/topics.py +++ b/resolvers/topics.py @@ -53,6 +53,13 @@ async def topics_by_author(_, _info, author): return list(author_topics) +@query.field("getTopic") +async def get_topic(_, _info, slug): + t = await TopicStorage.topics[slug] + t.stat = get_topic_stat(slug) + return t + + @mutation.field("createTopic") @login_required async def create_topic(_, _info, inp): diff --git a/schema.graphql b/schema.graphql index af065c3c..c1bf2b05 100644 --- a/schema.graphql +++ b/schema.graphql @@ -214,6 +214,7 @@ type Query { userReactedShouts(slug: String!): [Shout]! # test getUserRoles(slug: String!): [Role]! authorsAll: [User]! + getAuthor(slug: String!): User! # shouts getShoutBySlug(slug: String!): Shout! @@ -244,6 +245,7 @@ type Query { markdownBody(body: String!): String! # topics + getTopic(slug: String!): Topic! topicsAll: [Topic]! topicsRandom(amount: Int): [Topic]! topicsByCommunity(community: String!): [Topic]!