fix: fixed issues with sorting

This commit is contained in:
Wyatt Johnson
2018-09-23 17:28:15 -06:00
parent 8589993401
commit a8ccf29bea
4 changed files with 57 additions and 27 deletions
@@ -4,6 +4,7 @@ import {
GQLCommentTypeResolver,
} from "talk-server/graph/tenant/schema/__generated__/types";
import { Comment } from "talk-server/models/comment";
import { createConnection } from "talk-server/models/connection";
const Comment: GQLCommentTypeResolver<Comment> = {
editing: (comment, input, ctx) => ({
@@ -20,10 +21,14 @@ const Comment: GQLCommentTypeResolver<Comment> = {
author: (comment, input, ctx) =>
ctx.loaders.Users.user.load(comment.author_id),
replies: (comment, input, ctx) =>
ctx.loaders.Comments.forParent(comment.asset_id, comment.id, input),
comment.reply_count > 0
? ctx.loaders.Comments.forParent(comment.asset_id, comment.id, input)
: createConnection(),
parentCount: comment =>
comment.parent_id ? comment.grandparent_ids.length + 1 : 0,
replyCount: comment => comment.child_ids.length,
depth: comment =>
comment.parent_id ? comment.grandparent_ids.length + 1 : 0,
replyCount: comment => comment.reply_count,
rootParent: (comment, input, ctx, info) => {
// If there isn't a parent, then return nothing!
if (!comment.parent_id) {
@@ -69,7 +74,10 @@ const Comment: GQLCommentTypeResolver<Comment> = {
return ctx.loaders.Comments.comment.load(comment.parent_id);
},
parents: (comment, input, ctx) =>
ctx.loaders.Comments.parents(comment, input),
// Some resolver optimization.
comment.parent_id
? ctx.loaders.Comments.parents(comment, input)
: createConnection(),
};
export default Comment;
@@ -641,15 +641,21 @@ type Comment {
status: COMMENT_STATUS!
"""
parentCount is the number of direct parents for this Comment.
parentCount is the number of direct parents for this Comment. Currently this
value is the same as depth.
"""
parentCount: Int
parentCount: Int!
"""
depth is the number of levels that a given comment is deep.
"""
depth: Int!
"""
replyCount is the number of replies. Only direct replies to this Comment
are counted. Deleted comments are included in this count.
"""
replyCount: Int
replyCount: Int!
"""
replies will return the replies to this Comment.
@@ -658,7 +664,7 @@ type Comment {
first: Int = 10
orderBy: COMMENT_SORT = CREATED_AT_DESC
after: Cursor
): CommentsConnection
): CommentsConnection!
"""
parent is the immediate parent of a given comment.
@@ -675,7 +681,7 @@ type Comment {
parents returns a CommentsConnection that allows accessing direct parents of
the given Comment.
"""
parents(last: Int = 1, before: Cursor): CommentsConnection
parents(last: Int = 1, before: Cursor): CommentsConnection!
"""
editing returns details about the edit status of a Comment.
@@ -835,11 +841,6 @@ type Query {
"""
comment(id: ID!): Comment
"""
assets returns a AssetsConnection.
"""
assets(cursor: Cursor, limit: Int = 10): AssetsConnection
"""
asset is the Asset specified by its ID/URL.
"""