debug-get-author-2
All checks were successful
deploy / deploy (push) Successful in 1m34s

This commit is contained in:
Untone 2023-12-13 22:59:21 +03:00
parent c68900babf
commit c97bd9c784
3 changed files with 12 additions and 6 deletions

View File

@ -2,6 +2,7 @@ from resolvers.editor import create_shout, delete_shout, update_shout
from resolvers.author import (
get_author,
get_author_id,
load_authors_all,
get_author_followers,
get_author_followed,
@ -31,6 +32,7 @@ from resolvers.community import get_community, get_communities_all
__all__ = [
# author
"get_author",
"get_author_id",
"load_authors_all",
"get_author_followers",
"get_author_followed",

View File

@ -161,15 +161,18 @@ async def load_authors_all(_, _info, limit: int = 50, offset: int = 0):
return get_authors_from_query(q)
@query.field("get_author_id")
async def get_author_id(_, _info, user: str):
with local_session() as session:
return session.query(Author).where(Author.user == user).first()
@query.field("get_author")
async def get_author(_, _info, slug="", user=None, author_id=None):
async def get_author(_, _info, slug="", author_id=None):
q = None
if slug or user or author_id:
if slug or author_id:
if slug != "":
q = select(Author).where(Author.slug == slug)
elif user:
q = select(Author).where(Author.user == user)
print(f"[resolvers.author] SQL: {q}")
elif author_id:
q = select(Author).where(Author.id == author_id)
q = add_author_stat_columns(q)

View File

@ -331,7 +331,8 @@ type Mutation {
type Query {
# author
get_author(slug: String, user: String, author_id: Int): Author
get_author(slug: String, author_id: Int): Author
get_author_id(user: String!): 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]