From 05e8d57bdcc3760c4eb26bd2902a3eb6160171bb Mon Sep 17 00:00:00 2001 From: Tony Rewin Date: Thu, 25 Nov 2021 05:45:22 +0300 Subject: [PATCH] authors_by_slugs --- resolvers/__init__.py | 5 +++-- resolvers/profile.py | 8 ++++++++ schema.graphql | 6 ++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/resolvers/__init__.py b/resolvers/__init__.py index d64ba328..c1422e21 100644 --- a/resolvers/__init__.py +++ b/resolvers/__init__.py @@ -2,7 +2,7 @@ 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_authors, top_viewed -from resolvers.profile import get_user_by_slug, get_current_user +from resolvers.profile import get_user_by_slug, get_current_user, authors_by_slugs from resolvers.topics import topic_subscribe, topic_unsubscribe, topics_by_author, \ topics_by_community, topics_by_slugs from resolvers.comments import create_comment @@ -35,5 +35,6 @@ __all__ = [ "create_community", "delete_community", "get_community", - "get_communities" + "get_communities", + "authors_by_slugs" ] diff --git a/resolvers/profile.py b/resolvers/profile.py index 26091326..e0bede31 100644 --- a/resolvers/profile.py +++ b/resolvers/profile.py @@ -25,6 +25,14 @@ async def get_current_user(_, info): user = info.context["request"].user return { "user": user } +@query.field("authorsBySlugs") +@login_required +async def authors_by_slugs(_, info, slugs): + user = info.context["request"].user + with local_session() as session: + users = session.query(User).where(User.slug in slugs) + return { "authors": users } + @query.field("userRoles") @login_required async def user_roles(_, info): diff --git a/schema.graphql b/schema.graphql index 8e17e54d..d4daee09 100644 --- a/schema.graphql +++ b/schema.graphql @@ -120,8 +120,7 @@ type Query { getMessages(count: Int = 100, page: Int = 1): [Message!]! # shouts - getShoutBySlug(slug: String!): Shout! - # NOTE: with .comments: Comments[] + getShoutBySlug(slug: String!): Shout! # NOTE: with .comments: Comments[] shoutsByTopic(topic: String!, limit: Int!): [Shout]! shoutsByAuthor(author: String!, limit: Int!): [Shout]! shoutsByCommunity(community: String!, limit: Int!): [Shout]! @@ -143,6 +142,9 @@ type Query { # communities getCommunity(slug: String): Community! getCommunities: [Community]! + + # my feed + authorsBySlugs(slugs: [String]!): [User]! } ############################################ Subscription