From 99e0cb8330c9cd667f80380de98b8aef53919aec Mon Sep 17 00:00:00 2001 From: Serhey Dolgushev Date: Fri, 24 Apr 2020 05:57:59 -0400 Subject: [PATCH] EZP-31597: Handled missing Content Types when generating Schema (#82) * Handled missing Content Types when generating Schema * Changed type-hint to rely on API Exception and aligned code style Co-authored-by: Andrew Longosz --- .../RelationFieldDefinitionMapper.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Schema/Domain/Content/Mapper/FieldDefinition/RelationFieldDefinitionMapper.php b/src/Schema/Domain/Content/Mapper/FieldDefinition/RelationFieldDefinitionMapper.php index 9dea9f6b..274fa6d8 100644 --- a/src/Schema/Domain/Content/Mapper/FieldDefinition/RelationFieldDefinitionMapper.php +++ b/src/Schema/Domain/Content/Mapper/FieldDefinition/RelationFieldDefinitionMapper.php @@ -7,6 +7,7 @@ namespace EzSystems\EzPlatformGraphQL\Schema\Domain\Content\Mapper\FieldDefinition; use eZ\Publish\API\Repository\ContentTypeService; +use eZ\Publish\API\Repository\Exceptions\NotFoundException; use eZ\Publish\API\Repository\Values\ContentType\FieldDefinition; use EzSystems\EzPlatformGraphQL\Schema\Domain\Content\NameHelper; @@ -39,11 +40,16 @@ public function mapToFieldValueType(FieldDefinition $fieldDefinition): ?string } $settings = $fieldDefinition->getFieldSettings(); + $type = 'DomainContent'; if (count($settings['selectionContentTypes']) === 1) { - $contentType = $this->contentTypeService->loadContentTypeByIdentifier($settings['selectionContentTypes'][0]); - $type = $this->nameHelper->domainContentName($contentType); - } else { - $type = 'DomainContent'; + try { + $contentType = $this->contentTypeService->loadContentTypeByIdentifier( + $settings['selectionContentTypes'][0] + ); + $type = $this->nameHelper->domainContentName($contentType); + } catch (NotFoundException $e) { + // Nothing to do + } } if ($this->isMultiple($fieldDefinition)) {