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")
|
||||
async def get_shout_by_slug(_, info, slug):
|
||||
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]
|
||||
|
||||
with local_session() as session:
|
||||
|
@ -367,14 +367,10 @@ async def get_shout_by_slug(_, info, slug):
|
|||
@query.field("getShoutComments")
|
||||
async def get_shout_comments(_, info, shout_id):
|
||||
with local_session() as session:
|
||||
rows = session.query(Comment, func.sum(CommentRating.value).label("rating")).\
|
||||
join(CommentRating).\
|
||||
where(Comment.shout == shout_id).\
|
||||
comments = session.query(Comment).\
|
||||
options(selectinload(Comment.ratings)).\
|
||||
filter(Comment.shout == shout_id).\
|
||||
group_by(Comment.id).all()
|
||||
comments = []
|
||||
for row in rows:
|
||||
comment = row.Comment
|
||||
for comment in comments:
|
||||
comment.author = await UserStorage.get_user(comment.author)
|
||||
comment.rating = row.rating
|
||||
comments.append(comment)
|
||||
return comments
|
||||
|
|
|
@ -268,7 +268,6 @@ type Comment {
|
|||
shout: Int!
|
||||
deletedAt: DateTime
|
||||
deletedBy: Int
|
||||
rating: Int
|
||||
ratings: [CommentRating]
|
||||
views: Int
|
||||
old_id: String
|
||||
|
@ -290,7 +289,6 @@ type Shout {
|
|||
body: String!
|
||||
createdAt: DateTime!
|
||||
authors: [User!]!
|
||||
comments: [Comment]
|
||||
ratings: [Rating]
|
||||
visibleFor: [User]
|
||||
community: Int
|
||||
|
|
Loading…
Reference in New Issue
Block a user