some changes to loaders

This commit is contained in:
Wyatt Johnson
2017-05-11 17:52:07 -06:00
parent ae5da93730
commit 47186c4eac
7 changed files with 11 additions and 19 deletions
+1 -1
View File
@@ -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});
};
/**
-1
View File
@@ -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)),
-7
View File
@@ -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);
},
+1 -1
View File
@@ -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,
+2 -2
View File
@@ -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);
+1 -1
View File
@@ -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;
+6 -6
View File
@@ -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
}
################################################################################