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 ff129752d..d3090a7a6 100644 --- a/services/graphql-server/src/graphql/definitions/platform/content/index.js +++ b/services/graphql-server/src/graphql/definitions/platform/content/index.js @@ -485,6 +485,8 @@ input AllPublishedContentQueryInput { sectionId: Int "Deprecated. Use includeContentTypes instead." contentTypes: [ContentType!] = [] + "Limit results to items matching specific custom attribute key value pairs" + customAttributes: [ContentCustomAttributeQueryInput!] = [] "Limit results to items matching at least one of these types." includeContentTypes: [ContentType!] = [] "Limit results to items matching none of these types." @@ -566,6 +568,13 @@ input ContentCustomAttributeInput { path: String! } +input ContentCustomAttributeQueryInput { + "The object property key to query against" + key: String! + "The value of that property key to query against" + value: String! +} + input AllContentQueryInput { siteId: ObjectID status: ModelStatus = active diff --git a/services/graphql-server/src/graphql/resolvers/platform/content.js b/services/graphql-server/src/graphql/resolvers/platform/content.js index 8c72e34f5..ebcdeb42d 100644 --- a/services/graphql-server/src/graphql/resolvers/platform/content.js +++ b/services/graphql-server/src/graphql/resolvers/platform/content.js @@ -861,6 +861,7 @@ module.exports = { beginning, ending, withSite, + customAttributes, } = input; // @deprecated Prefer includeContentTypes over contentTypes. @@ -874,6 +875,10 @@ module.exports = { excludeContentTypes, }); + customAttributes.forEach(({ key, value }) => { + query.$and.push({ [`customAttributes.${key}`]: value }); + }); + const siteId = input.siteId || site.id(); if (withSite && siteId) query['mutations.Website.primarySite'] = siteId;