Files
core/services/common_result.py
Untone e78e12eeee
Some checks failed
Deploy on push / deploy (push) Failing after 17s
circular-fix
2025-08-17 16:33:54 +03:00

55 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from dataclasses import dataclass
from typing import Any
from graphql.error import GraphQLError
# Импорт Author отложен для избежания циклических импортов
from orm.community import Community
from orm.draft import Draft
from orm.reaction import Reaction
from orm.shout import Shout
from orm.topic import Topic
from utils.logger import root_logger as logger
# Отложенный импорт Author для избежания циклических импортов
def get_author_model():
"""Возвращает модель Author для использования в common_result"""
from auth.orm import Author
return Author
def handle_error(operation: str, error: Exception) -> GraphQLError:
"""Обрабатывает ошибки в резолверах"""
logger.error(f"Ошибка при {operation}: {error}")
return GraphQLError(f"Не удалось {operation}: {error}")
@dataclass
class CommonResult:
"""Общий результат для GraphQL запросов"""
error: str | None = None
drafts: list[Draft] | None = None # Draft objects
draft: Draft | None = None # Draft object
slugs: list[str] | None = None
shout: Shout | None = None
shouts: list[Shout] | None = None
author: Any | None = None # Author type resolved at runtime
authors: list[Any] | None = None # Author type resolved at runtime
reaction: Reaction | None = None
reactions: list[Reaction] | None = None
topic: Topic | None = None
topics: list[Topic] | None = None
community: Community | None = None
communities: list[Community] | None = None
@dataclass
class AuthorFollowsResult:
"""Результат для get_author_follows запроса"""
topics: list[Any] | None = None # Topic dicts
authors: list[Any] | None = None # Author dicts
communities: list[Any] | None = None # Community dicts
error: str | None = None