From 21767ef71410d8f9b0cebb4e9962e4640ff72f56 Mon Sep 17 00:00:00 2001 From: Sebastian Blank Date: Mon, 20 Jul 2026 16:39:15 +0200 Subject: [PATCH 1/2] Make getDocument folder-safe: resolve document folders instead of erroring Mirror of the folder guard used in the relation resolvers; adds the existing _document_folder type to the document union so getDocument on a folder path resolves instead of failing on an unresolvable union type. --- src/GraphQL/DocumentType/DocumentType.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/GraphQL/DocumentType/DocumentType.php b/src/GraphQL/DocumentType/DocumentType.php index bed1d7b..52a63e5 100644 --- a/src/GraphQL/DocumentType/DocumentType.php +++ b/src/GraphQL/DocumentType/DocumentType.php @@ -80,7 +80,9 @@ public function __construct(Service $graphQlService, PageType $pageType, LinkTyp */ public function getTypes(): array { - return array_merge($this->types, $this->customTypes); + $folderType = $this->getGraphQlService()->getDocumentTypeDefinition('_document_folder'); + + return array_merge($this->types, [$folderType], $this->customTypes); } /** @@ -112,6 +114,8 @@ public function resolveType($element, $context, ResolveInfo $info) return $this->hardlinkType; } elseif ($element instanceof Document\Snippet) { return $this->snippetType; + } elseif ($element instanceof Document\Folder) { + return $this->getGraphQlService()->getDocumentTypeDefinition('_document_folder'); } return null; From e5cd89790f82cbbf585b897e0c342a25f4dcd048 Mon Sep 17 00:00:00 2001 From: Sebastian Blank Date: Mon, 20 Jul 2026 17:08:31 +0200 Subject: [PATCH 2/2] Dedupe _document_folder in composed unions (review #1126) 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. --- src/GraphQL/General/AnyDocumentTargetType.php | 10 +--------- src/GraphQL/General/AnyTargetType.php | 4 +++- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/GraphQL/General/AnyDocumentTargetType.php b/src/GraphQL/General/AnyDocumentTargetType.php index df0d89d..96e7652 100644 --- a/src/GraphQL/General/AnyDocumentTargetType.php +++ b/src/GraphQL/General/AnyDocumentTargetType.php @@ -41,17 +41,9 @@ public function __construct(Service $graphQlService, $config = ['name' => 'AnyDo */ public function getTypes(): array { - $types = []; - - $service = $this->getGraphQlService(); - $documentFolderType = $service->getDocumentTypeDefinition('_document_folder'); - - $types[] = $documentFolderType; $documentUnionType = $this->getGraphQlService()->getDocumentTypeDefinition('document'); - $supportedDocumentTypes = $documentUnionType->getTypes(); - $types = array_merge($types, $supportedDocumentTypes); - return $types; + return $documentUnionType->getTypes(); } public function resolveType($element, $context, ResolveInfo $info) diff --git a/src/GraphQL/General/AnyTargetType.php b/src/GraphQL/General/AnyTargetType.php index 9775027..44fac85 100644 --- a/src/GraphQL/General/AnyTargetType.php +++ b/src/GraphQL/General/AnyTargetType.php @@ -61,7 +61,9 @@ public function getTypes(): array $types[] = $assetFolderType; } - if ($service->querySchemaEnabled('document_folder')) { + if ($service->querySchemaEnabled('document_folder') && !$service->querySchemaEnabled('document')) { + // The 'document' union already includes _document_folder; only add it + // separately when the document union itself is not merged below. $documentFolderType = $service->getDocumentTypeDefinition('_document_folder'); $types[] = $documentFolderType; }