From b278248ccc6b62e0c8de3a30fdf9853b929eb756 Mon Sep 17 00:00:00 2001 From: matx132 Date: Mon, 1 Jul 2024 15:40:24 +0200 Subject: [PATCH] IBX-7603: A new flag has been introduced that generates a different schema for ezurl --- composer.json | 2 +- src/Resources/config/default_settings.yaml | 2 +- .../config/graphql/FieldValueInput.types.yaml | 4 +- src/Resources/config/services/schema.yaml | 6 ++ .../UrlFieldDefinitionMapper.php | 63 +++++++++++++++++++ 5 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 src/Schema/Domain/Content/Mapper/FieldDefinition/UrlFieldDefinitionMapper.php diff --git a/composer.json b/composer.json index 5e44c2c2..9330febb 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "bdunogier/ezplatform-graphql-bundle": "self.version" }, "require": { - "php": "^7.3 || ^8.0", + "php": "^7.4 || ^8.0", "ext-dom": "*", "ezsystems/ezplatform-kernel": "^1.3@dev", "ezsystems/ezplatform-admin-ui": "^2.0@dev", diff --git a/src/Resources/config/default_settings.yaml b/src/Resources/config/default_settings.yaml index 30d91363..7e0ddd7f 100644 --- a/src/Resources/config/default_settings.yaml +++ b/src/Resources/config/default_settings.yaml @@ -1,4 +1,5 @@ parameters: + ibexa.graphql.schema.should.extend.ezurl: true ezplatform_graphql.schema.content.field_name.override: id: id_ ezplatform_graphql.schema.content.mapping.field_definition_type: @@ -81,5 +82,4 @@ parameters: definition_type: TextBlockFieldDefinition value_type: String ezurl: - value_type: UrlFieldValue input_type: UrlFieldInput diff --git a/src/Resources/config/graphql/FieldValueInput.types.yaml b/src/Resources/config/graphql/FieldValueInput.types.yaml index 91c3c9c4..d2c287fb 100644 --- a/src/Resources/config/graphql/FieldValueInput.types.yaml +++ b/src/Resources/config/graphql/FieldValueInput.types.yaml @@ -26,10 +26,10 @@ UrlFieldInput: config: fields: link: - type: String! + type: String description: "The link's URL" text: - type: String + type: String! description: "The link's name or description" MapLocationFieldInput: diff --git a/src/Resources/config/services/schema.yaml b/src/Resources/config/services/schema.yaml index fb4eacf1..9ff899ee 100644 --- a/src/Resources/config/services/schema.yaml +++ b/src/Resources/config/services/schema.yaml @@ -49,6 +49,12 @@ services: arguments: $innerMapper: '@EzSystems\EzPlatformGraphQL\Schema\Domain\Content\Mapper\FieldDefinition\SelectionFieldDefinitionMapper.inner' + Ibexa\GraphQL\Schema\Domain\Content\Mapper\FieldDefinition\UrlFieldDefinitionMapper: + decorates: EzSystems\EzPlatformGraphQL\Schema\Domain\Content\Mapper\FieldDefinition\FieldDefinitionMapper + arguments: + $innerMapper: '@Ibexa\GraphQL\Schema\Domain\Content\Mapper\FieldDefinition\UrlFieldDefinitionMapper.inner' + $shouldExtendUrlInputType: '%ibexa.graphql.schema.should.extend.ezurl%' + EzSystems\EzPlatformGraphQL\Schema\Domain\Content\Worker\ContentType\AddContentOfTypeConnectionToDomainGroup: ~ EzSystems\EzPlatformGraphQL\Schema\Domain\Content\Worker\ContentType\AddContentTypeToContentTypeIdentifierList: ~ diff --git a/src/Schema/Domain/Content/Mapper/FieldDefinition/UrlFieldDefinitionMapper.php b/src/Schema/Domain/Content/Mapper/FieldDefinition/UrlFieldDefinitionMapper.php new file mode 100644 index 00000000..3730c901 --- /dev/null +++ b/src/Schema/Domain/Content/Mapper/FieldDefinition/UrlFieldDefinitionMapper.php @@ -0,0 +1,63 @@ +innerMapper = $innerMapper; + $this->shouldExtendUrlInputType = $shouldExtendUrlInputType; + } + + public function mapToFieldDefinitionType(FieldDefinition $fieldDefinition): string + { + return $this->innerMapper->mapToFieldDefinitionType($fieldDefinition); + } + + public function mapToFieldValueType(FieldDefinition $fieldDefinition): string + { + $type = $this->innerMapper->mapToFieldValueType($fieldDefinition); + if ($fieldDefinition->fieldTypeIdentifier === self::FIELD_TYPE_IDENTIFIER) { + if ($this->shouldExtendUrlInputType) { + $type = 'UrlFieldValue'; + } else { + @trigger_error( + 'The return type `string` for the URL field has been deprecated since version 3.3 ' . + 'and will be removed in version 5.0. To start receiving `UrlFieldInput` instead of the deprecated ' . + '`string`, set the parameter `ibexa.graphql.schema.should.extend.ezurl` to `true`.', + E_USER_DEPRECATED + ); + } + } + + return $type; + } + + public function mapToFieldValueResolver(FieldDefinition $fieldDefinition): string + { + return $this->innerMapper->mapToFieldValueResolver($fieldDefinition); + } + + public function mapToFieldValueInputType(ContentType $contentType, FieldDefinition $fieldDefinition): ?string + { + return $this->innerMapper->mapToFieldValueInputType($contentType, $fieldDefinition); + } + + public function mapToFieldValueArgsBuilder(FieldDefinition $fieldDefinition): ?string + { + return $this->innerMapper->mapToFieldValueArgsBuilder($fieldDefinition); + } +}