cms-api: Validate PageTreeNode scope DTO name in PageTreeModule - #6173
cms-api: Validate PageTreeNode scope DTO name in PageTreeModule#6173VPS-Obi wants to merge 4 commits into
Conversation
A custom PageTreeNode Scope class relies on GraphQL object/input type names "PageTreeNodeScope"/"PageTreeNodeScopeInput" staying fixed, but nothing enforced this, so an accidental rename would only surface as a confusing runtime GraphQL schema error. Validate the type names at module registration, mirroring the existing check in DamModule. Fixes #6172
|
We should remove the TODO from Demo then. |
PageTreeModule now validates the scope's GraphQL type names at startup, so the reminder to guard against an accidental rename here is redundant.
|
Good call — pushed 7231a84 removing the TODO from Generated by Claude Code |
| @ObjectType("PageTreeNodeScope") // name must not be changed in the app | ||
| @InputType("PageTreeNodeScopeInput") // name must not be changed in the app |
There was a problem hiding this comment.
Since we now validate this, we can remove the comments as well.
PageTreeModule now throws at startup if the scope's GraphQL type names are wrong, so the inline reminder comments are no longer needed.
|
Pushed a59ca2e removing the Generated by Claude Code |
Covers the accepted case and both mismatch cases (wrong ObjectType name, wrong InputType name) added for issue #6172.
|
Pushed 0da79f0 adding unit tests for the scope validation, covering:
One implementation note: All 472 existing tests in Generated by Claude Code |
Description
PageTreeNodeScope/PageTreeNodeScopeInputare the fixed GraphQL type names a project-specificPageTreeNodescope class must use — a comment indemo/api/src/page-tree/dto/page-tree-node-scope.tseven calls this out ("name must not be changed in the app"). Nothing enforced it though, so an accidental rename would only surface later as a confusing runtime GraphQL schema error, instead of failing fast with a clear message.DamModulealready has this exact safeguard for its ownScopeoption (validating against"DamScope"/"DamScopeInput"). This PR adds the equivalent check toPageTreeModule.forRoot().Solution
In
packages/api/cms-api/src/page-tree/page-tree.module.ts, after resolver generation (so the input type metadata is available) and before building providers, validate that a providedScopeclass is decorated with@ObjectType("PageTreeNodeScope")and@InputType("PageTreeNodeScopeInput")viaTypeMetadataStorage, throwing a descriptive error otherwise — mirroringDamModule.register().Example usage
If a project's custom scope class is decorated with the wrong GraphQL type name, e.g.:
PageTreeModule.forRoot({ Scope: MyPageTreeNodeScope, ... })now throws at startup:instead of failing later with an opaque GraphQL schema error.
Further information
DamModule's equivalent validation, so no new test was added here either, to stay consistent.Generated by Claude Code