diff --git a/resolvers/editor.py b/resolvers/editor.py index 774f7b9c..fdda8fa6 100644 --- a/resolvers/editor.py +++ b/resolvers/editor.py @@ -4,7 +4,7 @@ from sqlalchemy import and_, desc, select from sqlalchemy.orm import joinedload from sqlalchemy.sql.functions import coalesce -from cache.cache import cache_author, cache_topic, invalidate_shouts_cache, invalidate_shout_related_cache +from cache.cache import cache_author, cache_topic, invalidate_shout_related_cache, invalidate_shouts_cache from orm.author import Author from orm.shout import Shout, ShoutAuthor, ShoutTopic from orm.topic import Topic @@ -326,9 +326,11 @@ async def update_shout(_, info, shout_id: int, shout_input=None, publish=False): shout_input["published_at"] = current_time # Проверяем наличие связи с автором logger.info(f"Checking author link for shout#{shout_id} and author#{author_id}") - author_link = session.query(ShoutAuthor).filter( - and_(ShoutAuthor.shout == shout_id, ShoutAuthor.author == author_id) - ).first() + author_link = ( + session.query(ShoutAuthor) + .filter(and_(ShoutAuthor.shout == shout_id, ShoutAuthor.author == author_id)) + .first() + ) if not author_link: logger.info(f"Adding missing author link for shout#{shout_id}") diff --git a/resolvers/reader.py b/resolvers/reader.py index c78ca283..05f83edc 100644 --- a/resolvers/reader.py +++ b/resolvers/reader.py @@ -1,7 +1,7 @@ import json from graphql import GraphQLResolveInfo -from sqlalchemy import nulls_last, text, and_ +from sqlalchemy import and_, nulls_last, text from sqlalchemy.orm import aliased from sqlalchemy.sql.expression import asc, case, desc, func, select @@ -472,6 +472,7 @@ async def load_shouts_random_top(_, info, options): shout = type_("Shout") + @shout.field("media") def resolve_shout_media(shout, _): """ @@ -480,7 +481,7 @@ def resolve_shout_media(shout, _): """ if not shout.media: return [] - + # Если media это строка JSON, парсим её if isinstance(shout.media, str): try: @@ -489,7 +490,7 @@ def resolve_shout_media(shout, _): return [] else: media_data = shout.media - + # Если media_data это словарь, оборачиваем его в список if isinstance(media_data, dict): return [media_data] diff --git a/services/schema.py b/services/schema.py index c6c05d8c..ad05883f 100644 --- a/services/schema.py +++ b/services/schema.py @@ -1,17 +1,18 @@ from asyncio.log import logger import httpx -from ariadne import MutationType, QueryType, ObjectType +from ariadne import MutationType, ObjectType, QueryType from settings import AUTH_URL query = QueryType() mutation = MutationType() + def type_(name: str) -> ObjectType: """ Создает резолвер для объектного типа - + :param name: Имя типа в схеме GraphQL :return: Резолвер объектного типа """ @@ -19,6 +20,7 @@ def type_(name: str) -> ObjectType: resolvers.append(resolver) return resolver + resolvers = [query, mutation]