From 360f0125e63dde9771101fc36fdd65da1d72aea2 Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Thu, 23 Mar 2023 14:14:56 +0100 Subject: [PATCH] IBX-5329: Fixed empty fields resolving (#134) * IBX-5329: Fixed empty fields resolving * IBX-5329: CS --- src/GraphQL/Resolver/DomainContentResolver.php | 6 +++++- src/GraphQL/Resolver/ImageAssetFieldResolver.php | 6 +++++- src/GraphQL/Resolver/SelectionFieldResolver.php | 6 +++++- src/Resources/config/default_settings.yaml | 14 +++++++------- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/GraphQL/Resolver/DomainContentResolver.php b/src/GraphQL/Resolver/DomainContentResolver.php index c9addc0..75b5cd8 100644 --- a/src/GraphQL/Resolver/DomainContentResolver.php +++ b/src/GraphQL/Resolver/DomainContentResolver.php @@ -136,8 +136,12 @@ public function resolveDomainFieldValue(Content $content, $fieldDefinitionIdenti return Field::fromField($content->getField($fieldDefinitionIdentifier, $args['language'] ?? null)); } - public function resolveDomainRelationFieldValue(Field $field, $multiple = false) + public function resolveDomainRelationFieldValue(?Field $field, $multiple = false) { + if ($field === null) { + return null; + } + $destinationContentIds = $this->getContentIds($field); if (empty($destinationContentIds) || array_key_exists(0, $destinationContentIds) && null === $destinationContentIds[0]) { diff --git a/src/GraphQL/Resolver/ImageAssetFieldResolver.php b/src/GraphQL/Resolver/ImageAssetFieldResolver.php index 7f6a60c..7e32caf 100644 --- a/src/GraphQL/Resolver/ImageAssetFieldResolver.php +++ b/src/GraphQL/Resolver/ImageAssetFieldResolver.php @@ -29,8 +29,12 @@ public function __construct(iterable $strategies) } } - public function resolveDomainImageAssetFieldValue(Field $field): ?Field + public function resolveDomainImageAssetFieldValue(?Field $field): ?Field { + if ($field === null) { + return null; + } + $destinationContentId = $field->value->destinationContentId; if ($destinationContentId === null) { diff --git a/src/GraphQL/Resolver/SelectionFieldResolver.php b/src/GraphQL/Resolver/SelectionFieldResolver.php index a3aa08f..17753ac 100644 --- a/src/GraphQL/Resolver/SelectionFieldResolver.php +++ b/src/GraphQL/Resolver/SelectionFieldResolver.php @@ -34,8 +34,12 @@ public function __construct( $this->domainContentResolver = $domainContentResolver; } - public function resolveSelectionFieldValue(Field $field, Content $content) + public function resolveSelectionFieldValue(?Field $field, Content $content) { + if ($field === null) { + return null; + } + $fieldDefinition = $this ->contentTypeLoader->load($content->contentInfo->contentTypeId) ->getFieldDefinition($field->fieldDefIdentifier); diff --git a/src/Resources/config/default_settings.yaml b/src/Resources/config/default_settings.yaml index 3717c0c..cc01bbe 100644 --- a/src/Resources/config/default_settings.yaml +++ b/src/Resources/config/default_settings.yaml @@ -4,7 +4,7 @@ parameters: ezplatform_graphql.schema.content.mapping.field_definition_type: ezauthor: value_type: "[AuthorFieldValue]" - value_resolver: 'field.authors' + value_resolver: 'field !== null ? field.authors : null' input_type: '[AuthorInput]' ezbinaryfile: definition_type: BinaryFieldDefinition @@ -13,7 +13,7 @@ parameters: ezboolean: definition_type: CheckboxFieldDefinition value_type: Boolean - value_resolver: 'field.bool' + value_resolver: 'field !== null ? field.bool : null' input_type: Boolean ezcountry: definition_type: CountryFieldDefinition @@ -21,11 +21,11 @@ parameters: input_type: '[String]' ezdate: value_type: DateTime - value_resolver: 'field.date' + value_resolver: 'field !== null ? field.date : null' input_type: DateFieldInput ezdatetime: value_type: DateTime - value_resolver: 'field.value' + value_resolver: 'field !== null ? field.value : null' input_type: DateFieldInput ezemail: value_type: String @@ -35,7 +35,7 @@ parameters: ezfloat: definition_type: FloatFieldDefinition value_type: Float - value_resolver: 'field.value' + value_resolver: 'field !== null ? field.value : null' input_type: Float ezgmaplocation: value_type: MapLocationFieldValue @@ -50,11 +50,11 @@ parameters: ezinteger: definition_type: IntegerFieldDefinition value_type: Int - value_resolver: 'field.value' + value_resolver: 'field !== null ? field.value : null' input_type: Int ezkeyword: value_type: '[String]' - value_resolver: 'field.values' + value_resolver: 'field !== null ? field.values : null' input_type: '[String]' ezmedia: definition_type: MediaFieldDefinition