From 47186c4eac14be1cba61307e67e07bc2de13a063 Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Thu, 11 May 2017 17:52:07 -0600 Subject: [PATCH] some changes to loaders --- graph/loaders/assets.js | 2 +- graph/loaders/comments.js | 1 - graph/resolvers/asset.js | 7 ------- graph/resolvers/comment.js | 2 +- graph/resolvers/root_query.js | 4 ++-- graph/resolvers/user.js | 2 +- graph/typeDefs.graphql | 12 ++++++------ 7 files changed, 11 insertions(+), 19 deletions(-) diff --git a/graph/loaders/assets.js b/graph/loaders/assets.js index d74199279..3f87b9dfd 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.getByQuery({ids}); + return Comments.getConnection({ids}); }; /** diff --git a/graph/loaders/comments.js b/graph/loaders/comments.js index cc2a5dd09..ed8f56c95 100644 --- a/graph/loaders/comments.js +++ b/graph/loaders/comments.js @@ -447,7 +447,6 @@ const genComments = ({user}, ids) => { module.exports = (context) => ({ Comments: { get: new DataLoader((ids) => genComments(context, ids)), - getByQuery: (query) => getCommentsByQuery(context, query), getConnection: (query) => getCommentsConnection(context, query), getCountByQuery: (query) => getCommentCountByQuery(context, query), countByAssetID: new SharedCounterDataLoader('Comments.totalCommentCount', 3600, (ids) => getCountsByAssetID(context, ids)), diff --git a/graph/resolvers/asset.js b/graph/resolvers/asset.js index 1a959d423..f31782cf6 100644 --- a/graph/resolvers/asset.js +++ b/graph/resolvers/asset.js @@ -1,11 +1,4 @@ const Asset = { - lastComment({id}, _, {loaders: {Comments}}) { - return Comments.getByQuery({ - asset_id: id, - limit: 1, - parent_id: null - }).then((data) => data[0]); - }, recentComments({id}, _, {loaders: {Comments}}) { return Comments.genRecentComments.load(id); }, diff --git a/graph/resolvers/comment.js b/graph/resolvers/comment.js index b52361f40..ef8985922 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.getByQuery({ + return Comments.getConnection({ asset_id, parent_id: id, sort, diff --git a/graph/resolvers/root_query.js b/graph/resolvers/root_query.js index 7faa8cb1d..c57db89c8 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.getByQuery({ids, statuses, asset_id, parent_id, limit, cursor, sort, excludeIgnored}); + return Comments.getConnection({ids, statuses, asset_id, parent_id, limit, cursor, sort, excludeIgnored}); }); } - return Comments.getByQuery(query); + return Comments.getConnection(query); }, comment(_, {id}, {loaders: {Comments}}) { return Comments.get.load(id); diff --git a/graph/resolvers/user.js b/graph/resolvers/user.js index d8ed7ee15..93816223f 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.getByQuery({author_id: id, sort: 'REVERSE_CHRONOLOGICAL'}); + return Comments.getConnection({author_id: id, sort: 'REVERSE_CHRONOLOGICAL'}); } return null; diff --git a/graph/typeDefs.graphql b/graph/typeDefs.graphql index 4a6224ee9..c2413e431 100644 --- a/graph/typeDefs.graphql +++ b/graph/typeDefs.graphql @@ -40,10 +40,10 @@ type User { username: String! # Action summaries against the user. - action_summaries: [ActionSummary]! + action_summaries: [ActionSummary!]! # Actions completed on the parent. - actions: [Action] + actions: [Action!] # the current roles of the user. roles: [USER_ROLES!] @@ -199,7 +199,7 @@ type Comment { user: User # the recent replies made against this comment. - recentReplies: [Comment] + recentReplies: [Comment!] # the replies that were made to the comment. replies(sort: SORT_ORDER = CHRONOLOGICAL, limit: Int = 3, excludeIgnored: Boolean): CommentConnection @@ -438,7 +438,7 @@ type Asset { lastComment: Comment # Returns recent comments - recentComments: [Comment] + recentComments: [Comment!] # The top level comments that are attached to the asset. comments(sort: SORT_ORDER = REVERSE_CHRONOLOGICAL, limit: Int = 10, excludeIgnored: Boolean): CommentConnection @@ -548,7 +548,7 @@ type RootQuery { asset(id: ID, url: String): Asset # Comments returned based on a query. - comments(query: CommentsQuery!): CommentConnection! + comments(query: CommentsQuery!): CommentConnection # 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 +570,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): [Comment!] + commentMetrics(from: Date!, to: Date!, sort: ACTION_TYPE!, limit: Int = 10): CommentConnection } ################################################################################