Skip to content

cms-api: Validate PageTreeNode scope DTO name in PageTreeModule - #6173

Draft
VPS-Obi wants to merge 4 commits into
mainfrom
claude/hopeful-meitner-ubz46t
Draft

cms-api: Validate PageTreeNode scope DTO name in PageTreeModule#6173
VPS-Obi wants to merge 4 commits into
mainfrom
claude/hopeful-meitner-ubz46t

Conversation

@VPS-Obi

@VPS-Obi VPS-Obi commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Description

PageTreeNodeScope/PageTreeNodeScopeInput are the fixed GraphQL type names a project-specific PageTreeNode scope class must use — a comment in demo/api/src/page-tree/dto/page-tree-node-scope.ts even 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.

DamModule already has this exact safeguard for its own Scope option (validating against "DamScope"/"DamScopeInput"). This PR adds the equivalent check to PageTreeModule.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 provided Scope class is decorated with @ObjectType("PageTreeNodeScope") and @InputType("PageTreeNodeScopeInput") via TypeMetadataStorage, throwing a descriptive error otherwise — mirroring DamModule.register().

Example usage

If a project's custom scope class is decorated with the wrong GraphQL type name, e.g.:

@ObjectType("MyScope") // wrong, should be "PageTreeNodeScope"
@InputType("MyScopeInput")
export class MyPageTreeNodeScope { ... }

PageTreeModule.forRoot({ Scope: MyPageTreeNodeScope, ... }) now throws at startup:

Error: Invalid object type name for provided page tree scope class. Make sure to decorate the class with @ObjectType("PageTreeNodeScope")

instead of failing later with an opaque GraphQL schema error.

Further information


Generated by Claude Code

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
@VPS-Obi

VPS-Obi commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

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.
@VPS-Obi

VPS-Obi commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

Good call — pushed 7231a84 removing the TODO from demo/api/src/page-tree/dto/page-tree-node-scope.ts. The validation now added to PageTreeModule covers the concern it was flagging.


Generated by Claude Code

Comment on lines 6 to 7
@ObjectType("PageTreeNodeScope") // name must not be changed in the app
@InputType("PageTreeNodeScopeInput") // name must not be changed in the app

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@VPS-Obi

VPS-Obi commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

Pushed a59ca2e removing the // name must not be changed in the app comments — the PageTreeModule validation now enforces this at startup.


Generated by Claude Code

@VPS-Obi
VPS-Obi marked this pull request as draft August 12, 2026 08:43
Covers the accepted case and both mismatch cases (wrong ObjectType name,
wrong InputType name) added for issue #6172.
@VPS-Obi

VPS-Obi commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

Pushed 0da79f0 adding unit tests for the scope validation, covering:

  • a valid scope (correct @ObjectType/@InputType names) → no throw
  • a scope with the wrong object type name → throws with the expected message
  • a scope with the wrong input type name → throws with the expected message

One implementation note: @InputType() only queues its metadata for the schema builder and it isn't available via TypeMetadataStorage.getInputTypeMetadataByTarget() until a GraphQL schema is actually built (confirmed this empirically — even the real DamScope/PageTreeNodeScope classes show undefined there immediately after decoration). To keep the tests synchronous and independent of schema building, they register the input type metadata directly via TypeMetadataStorage.addInputTypeMetadata() instead of relying on @InputType()'s lazy registration — documented with a comment in the test file.

All 472 existing tests in @comet/cms-api still pass.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add page tree node scope DTO name validation

2 participants