From b478a8b7148aefc8bf4754e4cf92dd38b56a4690 Mon Sep 17 00:00:00 2001 From: Franz Unger Date: Tue, 5 Mar 2024 10:51:29 +0100 Subject: [PATCH] Adapt `ChangesCheckerInterceptor` to more strict checking of content scopes (#1773) It's ugly but since the ChangesCheckerInterceptor will be deleted in v7 anyway this will serve as a workaround meanwhile. --------- Co-authored-by: Johannes Obermair --- .changeset/tough-onions-march.md | 5 +++++ .../src/builds/changes-checker.interceptor.ts | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 .changeset/tough-onions-march.md diff --git a/.changeset/tough-onions-march.md b/.changeset/tough-onions-march.md new file mode 100644 index 0000000000..f957686b3a --- /dev/null +++ b/.changeset/tough-onions-march.md @@ -0,0 +1,5 @@ +--- +"@comet/cms-api": patch +--- + +Don't fail in ChangesCheckerInterceptor because of stricter content scope check diff --git a/packages/api/cms-api/src/builds/changes-checker.interceptor.ts b/packages/api/cms-api/src/builds/changes-checker.interceptor.ts index 90297a3665..14c3adad39 100644 --- a/packages/api/cms-api/src/builds/changes-checker.interceptor.ts +++ b/packages/api/cms-api/src/builds/changes-checker.interceptor.ts @@ -29,7 +29,14 @@ export class ChangesCheckerInterceptor implements NestInterceptor { this.reflector.get(SKIP_BUILD_METADATA_KEY, context.getClass()); if (!skipBuild) { - const scopes = await this.contentScopeService.inferScopesFromExecutionContext(context); + let scopes: ContentScope[] | null; + try { + scopes = await this.contentScopeService.inferScopesFromExecutionContext(context); + } catch (error) { + // We might land here when an @AffectedEntity does not have a @ScopedEntity decorator + // (this was formerly ignored but now throws an error because it's essential for the scope check) + scopes = null; + } if (scopes) { for (const scope of scopes) { if (process.env.NODE_ENV === "development" && this.changeAffectsAllScopes(scope)) { @@ -42,6 +49,16 @@ export class ChangesCheckerInterceptor implements NestInterceptor { await this.buildsService.setChangesSinceLastBuild(scope); } + } else { + if (process.env.NODE_ENV === "development") { + if (operation.name) { + console.warn(`Mutation "${operation.name.value}" affects all scopes. Are you sure this is correct?`); + } else { + console.warn(`Unknown mutation affects all scopes. Are you sure this is correct?`); + } + } + + await this.buildsService.setChangesSinceLastBuild("all"); } } }