mirror of
https://github.com/wassname/talk.git
synced 2026-07-13 03:53:33 +08:00
reverted pagination work
This commit is contained in:
@@ -49,7 +49,7 @@ const getAssetsForMetrics = async ({loaders: {Actions, Comments}}) => {
|
||||
|
||||
const ids = actions.map(({item_id}) => item_id);
|
||||
|
||||
return Comments.getConnection({ids});
|
||||
return Comments.getByQuery({ids});
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -290,27 +290,6 @@ const getCommentsByQuery = async ({user}, {ids, statuses, asset_id, parent_id, a
|
||||
.limit(limit);
|
||||
};
|
||||
|
||||
const getCommentsConnection = async ({user}, query) => {
|
||||
let {limit} = query;
|
||||
|
||||
// Increate the limit by one.
|
||||
query.limit++;
|
||||
|
||||
let comments = await getCommentsByQuery({user}, query);
|
||||
|
||||
if (!comments) {
|
||||
comments = [];
|
||||
}
|
||||
|
||||
return {
|
||||
edges: comments.slice(0, limit),
|
||||
pageInfo: {
|
||||
hasNextPage: Boolean(comments.length > limit),
|
||||
cursor: comments.length > 0 ? comments[comments.length - 1].created_at : null
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the recent replies.
|
||||
* @param {Object} context graph context
|
||||
@@ -447,7 +426,7 @@ const genComments = ({user}, ids) => {
|
||||
module.exports = (context) => ({
|
||||
Comments: {
|
||||
get: new DataLoader((ids) => genComments(context, ids)),
|
||||
getConnection: (query) => getCommentsConnection(context, query),
|
||||
getByQuery: (query) => getCommentsByQuery(context, query),
|
||||
getCountByQuery: (query) => getCommentCountByQuery(context, query),
|
||||
countByAssetID: new SharedCounterDataLoader('Comments.totalCommentCount', 3600, (ids) => getCountsByAssetID(context, ids)),
|
||||
countByAssetIDPersonalized: (query) => getCountsByAssetIDPersonalized(context, query),
|
||||
|
||||
@@ -3,7 +3,7 @@ const Asset = {
|
||||
return Comments.genRecentComments.load(id);
|
||||
},
|
||||
comments({id}, {sort, limit, excludeIgnored}, {loaders: {Comments}}) {
|
||||
return Comments.getConnection({
|
||||
return Comments.getByQuery({
|
||||
asset_id: id,
|
||||
sort,
|
||||
limit,
|
||||
|
||||
@@ -15,7 +15,7 @@ const Comment = {
|
||||
return Comments.genRecentReplies.load(id);
|
||||
},
|
||||
replies({id, asset_id}, {sort, limit, excludeIgnored}, {loaders: {Comments}}) {
|
||||
return Comments.getConnection({
|
||||
return Comments.getByQuery({
|
||||
asset_id,
|
||||
parent_id: id,
|
||||
sort,
|
||||
|
||||
@@ -27,11 +27,11 @@ const RootQuery = {
|
||||
.then((ids) => {
|
||||
|
||||
// Perform the query using the available resolver.
|
||||
return Comments.getConnection({ids, statuses, asset_id, parent_id, limit, cursor, sort, excludeIgnored});
|
||||
return Comments.getByQuery({ids, statuses, asset_id, parent_id, limit, cursor, sort, excludeIgnored});
|
||||
});
|
||||
}
|
||||
|
||||
return Comments.getConnection(query);
|
||||
return Comments.getByQuery(query);
|
||||
},
|
||||
comment(_, {id}, {loaders: {Comments}}) {
|
||||
return Comments.get.load(id);
|
||||
|
||||
@@ -15,7 +15,7 @@ const User = {
|
||||
// If the user is not an admin, only return comment list for the owner of
|
||||
// the comments.
|
||||
if (user && (user.hasRoles('ADMIN') || user.id === id)) {
|
||||
return Comments.getConnection({author_id: id, sort: 'REVERSE_CHRONOLOGICAL'});
|
||||
return Comments.getByQuery({author_id: id, sort: 'REVERSE_CHRONOLOGICAL'});
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
+4
-19
@@ -1,12 +1,3 @@
|
||||
################################################################################
|
||||
## Pagination
|
||||
################################################################################
|
||||
|
||||
type PageInfo {
|
||||
hasNextPage: Boolean!
|
||||
cursor: String
|
||||
}
|
||||
|
||||
################################################################################
|
||||
## Custom Scalar Types
|
||||
################################################################################
|
||||
@@ -87,12 +78,6 @@ input UsersQuery {
|
||||
## Comments
|
||||
################################################################################
|
||||
|
||||
# CommentConnection provides Comments with PageInfo.
|
||||
type CommentConnection {
|
||||
edges: [Comment!]
|
||||
pageInfo: PageInfo!
|
||||
}
|
||||
|
||||
# The statuses that a comment may have.
|
||||
enum COMMENT_STATUS {
|
||||
|
||||
@@ -202,7 +187,7 @@ type Comment {
|
||||
recentReplies: [Comment!]
|
||||
|
||||
# the replies that were made to the comment.
|
||||
replies(sort: SORT_ORDER = CHRONOLOGICAL, limit: Int = 3, excludeIgnored: Boolean): CommentConnection
|
||||
replies(sort: SORT_ORDER = CHRONOLOGICAL, limit: Int = 3, excludeIgnored: Boolean): [Comment!]
|
||||
|
||||
# The count of replies on a comment.
|
||||
replyCount(excludeIgnored: Boolean): Int
|
||||
@@ -441,7 +426,7 @@ type Asset {
|
||||
recentComments: [Comment!]
|
||||
|
||||
# The top level comments that are attached to the asset.
|
||||
comments(sort: SORT_ORDER = REVERSE_CHRONOLOGICAL, limit: Int = 10, excludeIgnored: Boolean): CommentConnection
|
||||
comments(sort: SORT_ORDER = REVERSE_CHRONOLOGICAL, limit: Int = 10, excludeIgnored: Boolean): [Comment!]
|
||||
|
||||
# The count of top level comments on the asset.
|
||||
commentCount(excludeIgnored: Boolean): Int
|
||||
@@ -548,7 +533,7 @@ type RootQuery {
|
||||
asset(id: ID, url: String): Asset
|
||||
|
||||
# Comments returned based on a query.
|
||||
comments(query: CommentsQuery!): CommentConnection
|
||||
comments(query: CommentsQuery!): [Comment!]
|
||||
|
||||
# Return the count of comments satisfied by the query. Note that this edge is
|
||||
# expensive as it is not batched. Requires the `ADMIN` role.
|
||||
@@ -570,7 +555,7 @@ type RootQuery {
|
||||
|
||||
# Comment metrics related to user actions are saturated into the comments
|
||||
# returned. Parameters `from` and `to` are related to the action created_at field.
|
||||
commentMetrics(from: Date!, to: Date!, sort: ACTION_TYPE!, limit: Int = 10): CommentConnection
|
||||
commentMetrics(from: Date!, to: Date!, sort: ACTION_TYPE!, limit: Int = 10): [Comment!]
|
||||
}
|
||||
|
||||
################################################################################
|
||||
|
||||
@@ -45,17 +45,15 @@ describe('graph.queries.asset', () => {
|
||||
query assetCommentsQuery($id: ID!) {
|
||||
asset(id: $id) {
|
||||
comments(limit: 10) {
|
||||
edges {
|
||||
id
|
||||
body
|
||||
}
|
||||
id
|
||||
body
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
const res = await graphql(schema, assetCommentsQuery, {}, context, {id: asset.id});
|
||||
expect(res.erros).is.empty;
|
||||
const comments = res.data.asset.comments.edges;
|
||||
const comments = res.data.asset.comments;
|
||||
expect(comments.length).to.equal(2);
|
||||
});
|
||||
|
||||
@@ -75,10 +73,8 @@ describe('graph.queries.asset', () => {
|
||||
query assetCommentsQuery($id: ID!, $url: String!, $excludeIgnored: Boolean!) {
|
||||
asset(id: $id, url: $url) {
|
||||
comments(limit: 10, excludeIgnored: $excludeIgnored) {
|
||||
edges {
|
||||
id
|
||||
body
|
||||
}
|
||||
id
|
||||
body
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,7 +90,7 @@ describe('graph.queries.asset', () => {
|
||||
console.error(res.errors);
|
||||
}
|
||||
expect(res.errors).is.empty;
|
||||
const comments = res.data.asset.comments.edges;
|
||||
const comments = res.data.asset.comments;
|
||||
expect(comments.length).to.equal(1);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user