diff --git a/graph/loaders/assets.js b/graph/loaders/assets.js index 3f87b9dfd..d74199279 100644 --- a/graph/loaders/assets.js +++ b/graph/loaders/assets.js @@ -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}); }; /** diff --git a/graph/loaders/comments.js b/graph/loaders/comments.js index ed8f56c95..ccee16ca7 100644 --- a/graph/loaders/comments.js +++ b/graph/loaders/comments.js @@ -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), diff --git a/graph/resolvers/asset.js b/graph/resolvers/asset.js index f31782cf6..96bc8c1bc 100644 --- a/graph/resolvers/asset.js +++ b/graph/resolvers/asset.js @@ -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, diff --git a/graph/resolvers/comment.js b/graph/resolvers/comment.js index ef8985922..b52361f40 100644 --- a/graph/resolvers/comment.js +++ b/graph/resolvers/comment.js @@ -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, diff --git a/graph/resolvers/root_query.js b/graph/resolvers/root_query.js index c57db89c8..7faa8cb1d 100644 --- a/graph/resolvers/root_query.js +++ b/graph/resolvers/root_query.js @@ -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); diff --git a/graph/resolvers/user.js b/graph/resolvers/user.js index 93816223f..d8ed7ee15 100644 --- a/graph/resolvers/user.js +++ b/graph/resolvers/user.js @@ -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; diff --git a/graph/typeDefs.graphql b/graph/typeDefs.graphql index c2413e431..40fc2c189 100644 --- a/graph/typeDefs.graphql +++ b/graph/typeDefs.graphql @@ -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!] } ################################################################################ diff --git a/test/server/graph/queries/asset.js b/test/server/graph/queries/asset.js index f25711809..757b33874 100644 --- a/test/server/graph/queries/asset.js +++ b/test/server/graph/queries/asset.js @@ -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); } });