diff --git a/packages/api-headless-cms/src/crud/contentEntry/referenceFieldsMapping.ts b/packages/api-headless-cms/src/crud/contentEntry/referenceFieldsMapping.ts index 9f7b2780985..9764b115ff3 100644 --- a/packages/api-headless-cms/src/crud/contentEntry/referenceFieldsMapping.ts +++ b/packages/api-headless-cms/src/crud/contentEntry/referenceFieldsMapping.ts @@ -287,12 +287,14 @@ async function validateReferencedEntries({ /** * Load all models and use only those used in the input references. */ - const models = (await context.cms.listModels()).filter(model => { - const entries = referencesByModel.get(model.modelId); - if (!entries || !entries.length) { - return false; - } - return true; + const models = await context.security.withoutAuthorization(async () => { + return (await context.cms.listModels()).filter(model => { + const entries = referencesByModel.get(model.modelId); + if (!entries?.length) { + return false; + } + return true; + }); }); if (!models.length) { @@ -302,8 +304,10 @@ async function validateReferencedEntries({ /** * Load all the entries by their IDs. */ - const promises = models.map(model => { - return context.cms.getEntriesByIds(model, referencesByModel.get(model.modelId) || []); + const promises = await context.security.withoutAuthorization(async () => { + return models.map(model => { + return context.cms.getEntriesByIds(model, referencesByModel.get(model.modelId) || []); + }); }); const allEntries = await Promise.all(promises).then(res => res.flat()); diff --git a/packages/api-headless-cms/src/graphqlFields/dynamicZone/dynamicZoneField.ts b/packages/api-headless-cms/src/graphqlFields/dynamicZone/dynamicZoneField.ts index ac56eefa44b..8f3c17d143a 100644 --- a/packages/api-headless-cms/src/graphqlFields/dynamicZone/dynamicZoneField.ts +++ b/packages/api-headless-cms/src/graphqlFields/dynamicZone/dynamicZoneField.ts @@ -83,33 +83,24 @@ const remapTemplateValue = (value: any, typeName: string) => { const createResolver = ( endpointType: ApiEndpoint ): CmsModelFieldToGraphQLCreateResolver => { - return ({ model, models, field, fieldTypePlugins, createFieldResolvers, graphQLType }) => { - const templates = getFieldTemplates(field); - - if (!templates.length) { - return false; - } - + return ({ model, models, field, fieldTypePlugins, createFieldResolvers }) => { const resolver = (parent: any) => { const value = parent[field.fieldId]; if (!value) { return value; } - const typeName = `${graphQLType}_${createTypeName(field.fieldId)}`; - // const typeName = `${model.singularApiName}_${createTypeName(field.fieldId)}`; + const typeName = `${model.singularApiName}_${createTypeName(field.fieldId)}`; if (field.multipleValues && Array.isArray(value)) { - const remappedValues = value.map(v => { - return remapTemplateValue(v, typeName); - }); - - return remappedValues; + return value.map(v => remapTemplateValue(v, typeName)); } return remapTemplateValue(value, typeName); }; + const templates = getFieldTemplates(field); + const { templateTypes } = createTypeDefsForTemplates({ models, field, @@ -120,24 +111,17 @@ const createResolver = ( templates }); - const replace = new RegExp(`${model.singularApiName}_`, "g"); - - const typeResolvers = templateTypes - .map(templateType => { - return templateType.replace(replace, `${graphQLType}_`); - }) - .reduce>>( - (typeResolvers, templateType, index) => { - return { - ...typeResolvers, - ...createFieldResolvers({ - graphQLType: templateType, - fields: field.settings.templates[index].fields - }) - }; - }, - {} - ); + const typeResolvers = templateTypes.reduce< + Record> + >((typeResolvers, templateType, index) => { + return { + ...typeResolvers, + ...createFieldResolvers({ + graphQLType: templateType, + fields: field.settings.templates[index].fields + }) + }; + }, {}); return { resolver, @@ -177,10 +161,6 @@ export const createDynamicZoneField = read: { createTypeField({ models, model, field, fieldTypePlugins }) { const templates = getFieldTemplates(field); - if (!templates.length) { - return null; - } - const unionTypeName = createUnionTypeName(model, field); const { typeDefs, templateTypes } = createTypeDefsForTemplates({ @@ -207,11 +187,6 @@ export const createDynamicZoneField = manage: { createTypeField({ models, model, field, fieldTypePlugins }) { const templates = getFieldTemplates(field); - - if (!templates.length) { - return null; - } - const unionTypeName = createUnionTypeName(model, field); const { typeDefs, templateTypes } = createTypeDefsForTemplates({ @@ -244,10 +219,6 @@ export const createDynamicZoneField = createInputField({ models, model, field, fieldTypePlugins }) { const templates = getFieldTemplates(field); - if (!templates.length) { - return null; - } - const { typeDefs, templateTypes } = createTypeDefsForTemplates({ models, field, diff --git a/yarn.lock b/yarn.lock index 126c451aac1..78d94d8272a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -16520,6 +16520,7 @@ __metadata: "@webiny/cli": 0.0.0 "@webiny/project-utils": 0.0.0 find-up: ^5.0.0 + lodash: ^4.17.21 rimraf: ^3.0.2 typescript: 4.7.4 languageName: unknown