From f495953f6af3f72ed7e6cb15c2019bda32932732 Mon Sep 17 00:00:00 2001 From: Untone Date: Fri, 1 Nov 2024 21:03:09 +0300 Subject: [PATCH] media-item-type --- resolvers/reader.py | 11 ++++++++--- schema/type.graphql | 10 +++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/resolvers/reader.py b/resolvers/reader.py index 501a0a88..9c210221 100644 --- a/resolvers/reader.py +++ b/resolvers/reader.py @@ -61,7 +61,12 @@ def query_with_stat(info): :param info: Информация о контексте GraphQL :return: Запрос с подзапросом статистики. """ - q = select(Shout).group_by(Shout.id) + # Основной запрос без GROUP BY + q = ( + select(Shout) + .distinct(Shout.id) + .join(Author, Author.id == Shout.created_by) + ) # Создаем алиасы для всех таблиц main_author = aliased(Author) @@ -321,9 +326,9 @@ def apply_sorting(q, options): # Сортировка по выбранному статистическому полю в указанном порядке query_order_by = desc(text(order_str)) if options.get("order_by_desc", True) else asc(text(order_str)) # Применение сортировки с размещением NULL значений в конце - q = q.order_by(nulls_last(query_order_by)) + q = q.order_by(Shout.id, nulls_last(query_order_by)) else: - q = q.order_by(Shout.published_at.desc()) + q = q.order_by(Shout.id, Shout.published_at.desc()) return q diff --git a/schema/type.graphql b/schema/type.graphql index 3e997c92..4b9676cb 100644 --- a/schema/type.graphql +++ b/schema/type.graphql @@ -57,6 +57,14 @@ type Reaction { # old_thread: String } +type MediaItem { + url: String + pic: String + title: String + body: String + artist: String +} + type Shout { id: Int! title: String! @@ -87,7 +95,7 @@ type Shout { version_of: Shout # TODO: use version_of somewhere - media: String + media: [MediaItem] stat: Stat score: Float }