Skip to content

Commit

Permalink
Adapt ChangesCheckerInterceptor to more strict checking of content …
Browse files Browse the repository at this point in the history
…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 <johannes.obermair@vivid-planet.com>
  • Loading branch information
fraxachun and johnnyomair authored Mar 5, 2024
1 parent 11eaf42 commit b478a8b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/tough-onions-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@comet/cms-api": patch
---

Don't fail in ChangesCheckerInterceptor because of stricter content scope check
19 changes: 18 additions & 1 deletion packages/api/cms-api/src/builds/changes-checker.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ export class ChangesCheckerInterceptor implements NestInterceptor {
this.reflector.get<string[]>(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)) {
Expand All @@ -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");
}
}
}
Expand Down

0 comments on commit b478a8b

Please sign in to comment.