diff --git a/packages/web-common/src/block-loaders/all-published-content.js b/packages/web-common/src/block-loaders/all-published-content.js index 3493ee67e..9d4fadc4e 100644 --- a/packages/web-common/src/block-loaders/all-published-content.js +++ b/packages/web-common/src/block-loaders/all-published-content.js @@ -14,6 +14,7 @@ const date = (v) => (v instanceof Date ? v.valueOf() : v); * @param {number} params.sectionId The section ID. * @param {number[]} [params.includeTaxonomyIds] An array of taxonomies to include. * @param {string[]} [params.includeLabels] An array of labels to include. + * @param {string[]} [params.excludeLabels] An array of labels to exclude. * @param {string[]} [params.contentTypes] An array of content types to include. * @param {boolean} [params.withSite] Whether the content must belong to the current site. * @param {boolean} [params.requiresImage] Whether the content must have an image. @@ -47,6 +48,7 @@ module.exports = async (apolloClient, { includeTaxonomyIds, includeLabels, + excludeLabels, excludeContentIds, @@ -69,6 +71,7 @@ module.exports = async (apolloClient, { excludeContentTypes, includeTaxonomyIds, includeLabels, + excludeLabels, excludeContentIds, siteId, withSite, diff --git a/services/graphql-server/src/graphql/definitions/platform/content/index.js b/services/graphql-server/src/graphql/definitions/platform/content/index.js index 615fc854b..7900205b1 100644 --- a/services/graphql-server/src/graphql/definitions/platform/content/index.js +++ b/services/graphql-server/src/graphql/definitions/platform/content/index.js @@ -533,10 +533,12 @@ input AllPublishedContentQueryInput { excludeContentTypes: [ContentType!] = [] "Limit results to items matching none of these ids." excludeContentIds: [Int!] = [] - "Limit results to items matching at least one of these ids." + "Limit results to items having at least one of these labels." + excludeLabels: [String!]! = [] + "Limit results to items that have at least one of these taxonomy ids." includeTaxonomyIds: [Int!] = [] "Limit results to items matching at least one of these labels." - includeLabels: [String!] = [] + includeLabels: [String!]! = [] "Limit results to items that have a primary image." requiresImage: Boolean = false "Include child sections when limiting by primary section id." diff --git a/services/graphql-server/src/graphql/resolvers/platform/content.js b/services/graphql-server/src/graphql/resolvers/platform/content.js index 856044a48..16aa14c25 100644 --- a/services/graphql-server/src/graphql/resolvers/platform/content.js +++ b/services/graphql-server/src/graphql/resolvers/platform/content.js @@ -904,6 +904,7 @@ module.exports = { excludeContentIds, includeTaxonomyIds, includeLabels, + excludeLabels, requiresImage, sectionBubbling, sort, @@ -967,9 +968,10 @@ module.exports = { if (includeTaxonomyIds.length) { query['taxonomy.$id'] = { $in: includeTaxonomyIds }; } - if (includeLabels.length) { - query.labels = { $in: includeLabels }; - } + + if (includeLabels.length) query.$and.push({ labels: { $in: includeLabels } }); + if (excludeLabels.length) query.$and.push({ labels: { $nin: excludeLabels } }); + if (requiresIndexed) { query.$and.push({ $or: [{ 'mutations.Website.noIndex': { $exists: false } }, { 'mutations.Website.noIndex': false }] }); }