From f52db8f9e55ba7e19a57de8f29705afebf0c1703 Mon Sep 17 00:00:00 2001 From: Untone Date: Tue, 19 Dec 2023 11:09:50 +0300 Subject: [PATCH] get-authors-all --- CHANGELOG.txt | 1 + resolvers/__init__.py | 2 ++ resolvers/author.py | 7 +++++++ schemas/core.graphql | 1 + 4 files changed, 11 insertions(+) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 18c9df95..a7828e25 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -4,6 +4,7 @@ - resolvers: added reader.load_shouts_top_random - resolvers: added reader.load_shouts_unrated - resolvers: community follower id property name is .author +- resolvers: get_authors_all and load_authors_all - services: auth connector upgraded diff --git a/resolvers/__init__.py b/resolvers/__init__.py index e8f31440..97c18202 100644 --- a/resolvers/__init__.py +++ b/resolvers/__init__.py @@ -3,6 +3,7 @@ from resolvers.author import ( get_author_followed, get_author_followers, get_author_id, + get_authors_all, load_authors_all, load_authors_by, rate_author, @@ -32,6 +33,7 @@ __all__ = [ # author "get_author", "get_author_id", + "get_authors_all", "load_authors_all", "get_author_followers", "get_author_followed", diff --git a/resolvers/author.py b/resolvers/author.py index ee7d39f4..83b54acf 100644 --- a/resolvers/author.py +++ b/resolvers/author.py @@ -152,6 +152,13 @@ def author_unfollow(follower_id, slug): return False +# TODO: caching query +@query.field("get_authors_all") +async def get_authors_all(_, _info): + with local_session() as session: + return session.query(Author).join(ShoutAuthor, Author.id == ShoutAuthor.author).all() + + @query.field("load_authors_all") async def load_authors_all(_, _info, limit: int = 50, offset: int = 0): q = select(Author) diff --git a/schemas/core.graphql b/schemas/core.graphql index 95773810..046bad76 100644 --- a/schemas/core.graphql +++ b/schemas/core.graphql @@ -330,6 +330,7 @@ type Query { # author get_author(slug: String, author_id: Int): Author get_author_id(user: String!): Author + get_authors_all: [Author] load_authors_all(limit: Int, offset: Int): [Author] get_author_followers(slug: String, user: String, author_id: Int): [Author] get_author_followed(slug: String, user: String, author_id: Int): [Author]