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; 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; }