Skip to content

Make getDocument folder-safe (resolve document folders) - #1126

Draft
blankse wants to merge 4 commits into
pimcore:2026.2from
blankse:document-union-folder-safe
Draft

Make getDocument folder-safe (resolve document folders)#1126
blankse wants to merge 4 commits into
pimcore:2026.2from
blankse:document-union-folder-safe

Conversation

@blankse

@blankse blankse commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

getDocument(fullpath) on a folder path currently fails: DocumentType::resolveType returns null for folders, so the document union cannot resolve the abstract type at runtime ("Abstract type Document must resolve to an Object type at runtime ... received null").

This adds the already-existing _document_folder type to the union (getTypes) and resolves it (resolveType), mirroring the folder guard already present in AbstractRelationsType, ObjectsType and AnyDocumentTargetType. No new type is introduced.

Verified against a real Pimcore install: before, getDocument on a folder path errors; after, it returns document_folder. Non-folder documents are unaffected.

Related

Builds on the resolveType() folder guards merged with #1105. Those guards make a document folder resolve to _document_folder; this PR makes _document_folder an actual member of the document union, so the resolved type is a valid possible type. Both halves are needed for the document-folder case — with #1105 merged, this is the remaining one.

Since AbstractRelationsType::getTypes() and PropertyType\ObjectsType::getTypes() merge the types of the document union, the folder-inclusive union propagates to relations and properties automatically; no additional change is needed there (analogous to the object-folder handling in #1054).

Rebased onto 2026.2 after #1105 and #1054 were merged. The previous Automatic frontend build commit was dropped so the build folder matches the base branch.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Makes getDocument(fullpath) resolve document folders correctly.

Changes:

  • Adds _document_folder to the document union.
  • Resolves Document\Folder instances to that type.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/GraphQL/DocumentType/DocumentType.php
blankse added a commit to blankse/data-hub that referenced this pull request Jul 20, 2026
Adding _document_folder to the document union made it appear twice in
AnyDocumentTargetType/AnyTargetType, which prepend it and then merge the
document union's types. GraphQL unions require unique members. Rely on the
document union as the single source: AnyDocumentTargetType returns its types
directly; AnyTargetType only adds _document_folder separately when the
document union itself is not merged.
blankse added a commit to blankse/data-hub that referenced this pull request Jul 22, 2026
Adding _document_folder to the document union made it appear twice in
AnyDocumentTargetType/AnyTargetType, which prepend it and then merge the
document union's types. GraphQL unions require unique members. Rely on the
document union as the single source: AnyDocumentTargetType returns its types
directly; AnyTargetType only adds _document_folder separately when the
document union itself is not merged.
@blankse
blankse force-pushed the document-union-folder-safe branch from 68eb0ed to 51fe9e4 Compare July 22, 2026 17:16
@sonarqubecloud

Copy link
Copy Markdown

…oring

The 'document' union's resolveType returned null for folders, causing
getDocument(fullpath) on a folder path to fail with an unresolvable
abstract type. Add the existing _document_folder type to the union and
resolve it, mirroring the folder guard already used in the relation
resolvers (AbstractRelationsType, ObjectsType, AnyDocumentTargetType).
Adding _document_folder to the document union made it appear twice in
AnyDocumentTargetType/AnyTargetType, which prepend it and then merge the
document union's types. GraphQL unions require unique members. Rely on the
document union as the single source: AnyDocumentTargetType returns its types
directly; AnyTargetType only adds _document_folder separately when the
document union itself is not merged.
@blankse
blankse force-pushed the document-union-folder-safe branch from fce982c to 5b238cc Compare September 7, 2026 11:23
@pimcore-deployments
pimcore-deployments marked this pull request as draft September 7, 2026 11:23
@pimcore-deployments

Copy link
Copy Markdown
Contributor

🚫 Issue-link guardrail failed — this PR has been converted to draft.

Every PR must reference a tracking issue in pimcore/platform-version so the change stays traceable.

  • No issue in pimcore/platform-version is linked.

Add the link with a keyword in the PR description (not in a comment): https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests

When fixed, press Ready for review to re-run the checks.

@blankse

blankse commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

@robertSt7 Can you review this?

blankse added a commit to blankse/data-hub that referenced this pull request Sep 7, 2026
Covers both halves of the fix: DocumentType::getTypes() lists
'_document_folder' as a possible type of the 'document' union and
DocumentType::resolveType() resolves a document folder to it (without
it getDocument() on a folder path fails with "Abstract type Document
must resolve to an Object type at runtime").

Also covers the dedupe: the composed unions AnyDocumentTargetType and
AnyTargetType contain '_document_folder' exactly once when the document
union is enabled, and AnyTargetType still contains it when the document
union is disabled.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Covers both halves of the fix: DocumentType::getTypes() lists the folder
type as a possible type of the 'document' union and
DocumentType::resolveType() resolves a document folder to it (without it
getDocument() on a folder path fails with "Abstract type Document must
resolve to an Object type at runtime").

Also covers the dedupe: the composed unions AnyDocumentTargetType and
AnyTargetType contain the folder type exactly once when the document
union is enabled, and AnyTargetType still contains it when the document
union is disabled.

The union members are compared by GraphQL type name: the container
inlines the tagged type services, so the same type can be a different PHP
instance depending on where it is taken from.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@blankse
blankse force-pushed the document-union-folder-safe branch from a1f4dab to cfc4e80 Compare September 7, 2026 13:39
@sonarqubecloud

sonarqubecloud Bot commented Sep 7, 2026

Copy link
Copy Markdown

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.

4 participants