Merge branch 'master' into coral-plugin-permalink

This commit is contained in:
Kim Gardner
2017-06-27 13:40:15 +01:00
committed by GitHub
4 changed files with 29 additions and 5 deletions
+14 -1
View File
@@ -63,18 +63,31 @@ const getAssetsForMetrics = async ({loaders: {Actions, Comments}}) => {
.then((connection) => connection.nodes);
};
const findByUrl = async (context, asset_url) => {
// Verify that the asset_url is parsable.
let parsed_asset_url = url.parse(asset_url);
if (!parsed_asset_url.protocol) {
throw errors.ErrInvalidAssetURL;
}
return AssetsService.findByUrl(asset_url);
};
/**
* Creates a set of loaders based on a GraphQL context.
* @param {Object} context the context of the GraphQL request
* @return {Object} object of loaders
*/
module.exports = (context) => ({
Assets: {
// TODO: decide whether we want to move these to mutators or not, as in fact
// this operation create a new asset if one isn't found.
getByURL: (url) => findOrCreateAssetByURL(context, url),
findByUrl: (url) => findByUrl(context, url),
search: (query) => getAssetsByQuery(context, query),
getByID: new DataLoader((ids) => genAssetsByID(context, ids)),
getForMetrics: () => getAssetsForMetrics(context),
+1 -1
View File
@@ -14,7 +14,7 @@ const Asset = {
});
},
commentCount({id, commentCount}, {excludeIgnored}, {user, loaders: {Comments}}) {
// TODO: remove
if (user && excludeIgnored) {
return Comments.parentCountByAssetIDPersonalized({assetId: id, excludeIgnored});
+11 -3
View File
@@ -40,17 +40,25 @@ const RootQuery = {
return Comments.get.load(id);
},
async commentCount(_, {query}, {user, loaders: {Actions, Comments}}) {
async commentCount(_, {query}, {user, loaders: {Actions, Comments, Assets}}) {
if (user == null || !user.can(SEARCH_OTHERS_COMMENTS)) {
return null;
}
const {action_type} = query;
const {action_type, asset_url} = query;
if (action_type) {
query.ids = await Actions.getByTypes({action_type, item_type: 'COMMENTS'});
}
if (asset_url) {
let asset = await Assets.findByUrl(asset_url);
if (asset) {
query.asset_id = asset.id;
}
}
return Comments.getCountByQuery(query);
},
+3
View File
@@ -255,6 +255,9 @@ input CommentCountQuery {
# Asset that a comment is on.
asset_id: ID
# The URL that the asset is located on.
asset_url: String
# the parent of the comment that we want to retrieve.
parent_id: ID