fix getShoutComments
This commit is contained in:
parent
d00488a458
commit
5b6545536f
|
@ -353,7 +353,7 @@ async def view_shout(_, info, shout_id):
|
||||||
@query.field("getShoutBySlug")
|
@query.field("getShoutBySlug")
|
||||||
async def get_shout_by_slug(_, info, slug):
|
async def get_shout_by_slug(_, info, slug):
|
||||||
all_fields = [node.name.value for node in info.field_nodes[0].selection_set.selections]
|
all_fields = [node.name.value for node in info.field_nodes[0].selection_set.selections]
|
||||||
selected_fields = set(["authors", "comments", "topics"]).intersection(all_fields)
|
selected_fields = set(["authors", "topics"]).intersection(all_fields)
|
||||||
select_options = [selectinload(getattr(Shout, field)) for field in selected_fields]
|
select_options = [selectinload(getattr(Shout, field)) for field in selected_fields]
|
||||||
|
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
|
@ -367,14 +367,10 @@ async def get_shout_by_slug(_, info, slug):
|
||||||
@query.field("getShoutComments")
|
@query.field("getShoutComments")
|
||||||
async def get_shout_comments(_, info, shout_id):
|
async def get_shout_comments(_, info, shout_id):
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
rows = session.query(Comment, func.sum(CommentRating.value).label("rating")).\
|
comments = session.query(Comment).\
|
||||||
join(CommentRating).\
|
options(selectinload(Comment.ratings)).\
|
||||||
where(Comment.shout == shout_id).\
|
filter(Comment.shout == shout_id).\
|
||||||
group_by(Comment.id).all()
|
group_by(Comment.id).all()
|
||||||
comments = []
|
for comment in comments:
|
||||||
for row in rows:
|
|
||||||
comment = row.Comment
|
|
||||||
comment.author = await UserStorage.get_user(comment.author)
|
comment.author = await UserStorage.get_user(comment.author)
|
||||||
comment.rating = row.rating
|
|
||||||
comments.append(comment)
|
|
||||||
return comments
|
return comments
|
||||||
|
|
|
@ -268,7 +268,6 @@ type Comment {
|
||||||
shout: Int!
|
shout: Int!
|
||||||
deletedAt: DateTime
|
deletedAt: DateTime
|
||||||
deletedBy: Int
|
deletedBy: Int
|
||||||
rating: Int
|
|
||||||
ratings: [CommentRating]
|
ratings: [CommentRating]
|
||||||
views: Int
|
views: Int
|
||||||
old_id: String
|
old_id: String
|
||||||
|
@ -290,7 +289,6 @@ type Shout {
|
||||||
body: String!
|
body: String!
|
||||||
createdAt: DateTime!
|
createdAt: DateTime!
|
||||||
authors: [User!]!
|
authors: [User!]!
|
||||||
comments: [Comment]
|
|
||||||
ratings: [Rating]
|
ratings: [Rating]
|
||||||
visibleFor: [User]
|
visibleFor: [User]
|
||||||
community: Int
|
community: Int
|
||||||
|
|
Loading…
Reference in New Issue
Block a user