Add some comments

This commit is contained in:
Chi Vinh Le
2017-06-01 19:41:08 +07:00
parent ebdd586d1e
commit 5245755d49
3 changed files with 17 additions and 8 deletions
@@ -2,7 +2,7 @@ import {gql} from 'react-apollo';
import {add} from 'coral-framework/services/graphqlRegistry';
import update from 'immutability-helper';
import uuid from 'uuid/v4';
import {insertComment, removeComment} from './utils';
import {insertCommentIntoEmbedQuery, removeCommentFromEmbedQuery} from './utils';
const extension = {
fragments: {
@@ -165,7 +165,7 @@ const extension = {
if (prev.asset.settings.moderation === 'PRE' || comment.status === 'PREMOD' || comment.status === 'REJECTED') {
return prev;
}
return insertComment(prev, parent_id, comment);
return insertCommentIntoEmbedQuery(prev, parent_id, comment);
},
}
}),
@@ -175,7 +175,7 @@ const extension = {
if (!['PREMOD', 'REJECTED'].includes(comment.status)) {
return null;
}
return removeComment(prev, comment.id);
return removeCommentFromEmbedQuery(prev, comment.id);
},
},
}),
@@ -27,7 +27,7 @@ function findAndInsertComment(parent, id, comment) {
});
}
export function insertComment(root, id, comment) {
export function insertCommentIntoEmbedQuery(root, id, comment) {
if (root.comment) {
if (root.comment.parent) {
return update(root, {
@@ -75,24 +75,24 @@ function findAndRemoveComment(parent, id) {
return update(parent, changes);
}
export function removeComment(root, id, comment) {
export function removeCommentFromEmbedQuery(root, id) {
if (root.comment) {
if (root.comment.parent) {
return update(root, {
comment: {
parent: {
$apply: (node) => findAndRemoveComment(node, id, comment),
$apply: (node) => findAndRemoveComment(node, id),
},
},
});
}
return update(root, {
comment: {
$apply: (node) => findAndRemoveComment(node, id, comment),
$apply: (node) => findAndRemoveComment(node, id),
},
});
}
return update(root, {
asset: {$apply: (asset) => findAndRemoveComment(asset, id, comment)},
asset: {$apply: (asset) => findAndRemoveComment(asset, id)},
});
}
+9
View File
@@ -253,10 +253,19 @@ type Comment {
editing: EditInfo
}
# CommentConnection represents a paginable subset of a comment list.
type CommentConnection {
# Indicates that there are more comments after this subset.
hasNextPage: Boolean!
# Cursor of first comment in subset.
startCursor: Date
# Cursor of last comment in subset.
endCursor: Date
# Subset of comments.
nodes: [Comment!]!
}