From 1b56753409d3d6e79bd34863fa8d9058846ce9d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Parafi=C5=84ski?= Date: Tue, 19 Sep 2023 17:52:33 +0200 Subject: [PATCH 1/4] IBX-6602: Used Content::getThumbnail directly for obtaining thumbnails --- .../config/graphql/ContentType.types.yaml | 2 +- .../config/graphql/DomainContent.types.yaml | 2 +- .../Resources/config/graphql/Item.types.yaml | 2 +- .../Resources/config/graphql/User.types.yaml | 5 +++- .../Resources/config/services/resolvers.yaml | 4 +++ src/lib/Resolver/ThumbnailResolver.php | 30 +++++++++++++++++++ 6 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 src/lib/Resolver/ThumbnailResolver.php diff --git a/src/bundle/Resources/config/graphql/ContentType.types.yaml b/src/bundle/Resources/config/graphql/ContentType.types.yaml index 78d73d4..74f6ef7 100644 --- a/src/bundle/Resources/config/graphql/ContentType.types.yaml +++ b/src/bundle/Resources/config/graphql/ContentType.types.yaml @@ -107,7 +107,7 @@ ContentTypeGroup: resolve: "@=resolver('UserById', [value.modifierId])" contentTypes: type: "[ContentType]" - resolve: "@=resolver('ContentTypesFromGroup', {'groupId': value.id})" + resolve: "@=resolver('ContentTypesFromGroup', [{'groupId': value.id}])" groups: type: "[ContentTypeGroup]" diff --git a/src/bundle/Resources/config/graphql/DomainContent.types.yaml b/src/bundle/Resources/config/graphql/DomainContent.types.yaml index 21bfdae..8f73076 100644 --- a/src/bundle/Resources/config/graphql/DomainContent.types.yaml +++ b/src/bundle/Resources/config/graphql/DomainContent.types.yaml @@ -72,7 +72,7 @@ AbstractDomainContent: resolve: "@=resolver('MainUrlAlias', [value])" _thumbnail: type: Thumbnail - resolve: "@=resolver('ContentThumbnail', [value])" + resolve: "@=resolver('Thumbnail', [value.getThumbnail()])" UntypedContent: type: object diff --git a/src/bundle/Resources/config/graphql/Item.types.yaml b/src/bundle/Resources/config/graphql/Item.types.yaml index 57d8510..963fb5e 100644 --- a/src/bundle/Resources/config/graphql/Item.types.yaml +++ b/src/bundle/Resources/config/graphql/Item.types.yaml @@ -60,7 +60,7 @@ AbstractItem: resolve: "@=resolver('ItemUrlAlias', [value])" _thumbnail: type: Thumbnail - resolve: "@=resolver('ContentThumbnail', [value.getContent()])" + resolve: "@=resolver('Thumbnail', [value.getContent().getThumbnail()])" UntypedItem: type: object diff --git a/src/bundle/Resources/config/graphql/User.types.yaml b/src/bundle/Resources/config/graphql/User.types.yaml index 423a279..47c6622 100644 --- a/src/bundle/Resources/config/graphql/User.types.yaml +++ b/src/bundle/Resources/config/graphql/User.types.yaml @@ -11,7 +11,7 @@ User: resolve: "@=value.contentInfo.name" content: type: "UserItem" - resolve: "@=value" + resolve: "@=resolver('Item', [{id: value.id}])" version: type: "Version" description: "Current version metadata" @@ -23,6 +23,9 @@ User: groups: type: "[UserGroup]" resolve: "@=resolver('UserGroupsByUserId', [value.id])" + thumbnail: + type: Thumbnail + resolve: "@=resolver('Thumbnail', [value.getThumbnail()])" UserGroup: type: object diff --git a/src/bundle/Resources/config/services/resolvers.yaml b/src/bundle/Resources/config/services/resolvers.yaml index acf710d..8b55469 100644 --- a/src/bundle/Resources/config/services/resolvers.yaml +++ b/src/bundle/Resources/config/services/resolvers.yaml @@ -58,6 +58,10 @@ services: arguments: $thumbnailStrategy: '@Ibexa\Core\Repository\Strategy\ContentThumbnail\ThumbnailChainStrategy' + Ibexa\GraphQL\Resolver\ThumbnailResolver: + tags: + - { name: overblog_graphql.resolver, alias: "Thumbnail", method: "resolveThumbnail" } + Ibexa\GraphQL\Mutation\Authentication: arguments: $authenticator: '@?ibexa.rest.session_authenticator' diff --git a/src/lib/Resolver/ThumbnailResolver.php b/src/lib/Resolver/ThumbnailResolver.php new file mode 100644 index 0000000..354f5cb --- /dev/null +++ b/src/lib/Resolver/ThumbnailResolver.php @@ -0,0 +1,30 @@ + $thumbnail->resource, + 'width' => $thumbnail->width, + 'height' => $thumbnail->height, + 'mimeType' => $thumbnail->mimeType, + 'alternativeText' => '', + ]; + } +} From 2a66c5a018db4d53147a0b3e7d066018c59be8e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Parafi=C5=84ski?= Date: Tue, 19 Sep 2023 17:57:27 +0200 Subject: [PATCH 2/4] Fixed UserGroupItem not being Item object --- src/bundle/Resources/config/graphql/User.types.yaml | 4 ++-- src/lib/Resolver/ThumbnailResolver.php | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/bundle/Resources/config/graphql/User.types.yaml b/src/bundle/Resources/config/graphql/User.types.yaml index 47c6622..cc0e128 100644 --- a/src/bundle/Resources/config/graphql/User.types.yaml +++ b/src/bundle/Resources/config/graphql/User.types.yaml @@ -38,9 +38,9 @@ UserGroup: type: "String" resolve: "@=value.contentInfo.name" content: - description: "The User content item" + description: "The User Group content item" type: "UserGroupItem" - resolve: "@=value" + resolve: "@=resolver('Item', [{id: value.id}])" version: type: "Version" description: "Current version" diff --git a/src/lib/Resolver/ThumbnailResolver.php b/src/lib/Resolver/ThumbnailResolver.php index 354f5cb..3a00d8e 100644 --- a/src/lib/Resolver/ThumbnailResolver.php +++ b/src/lib/Resolver/ThumbnailResolver.php @@ -4,6 +4,8 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); + namespace Ibexa\GraphQL\Resolver; use Ibexa\Contracts\Core\Repository\Values\Content\Thumbnail; From 5a5e32fafe85911eff5aa77f26a80e577a8b8236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Parafi=C5=84ski?= Date: Tue, 19 Sep 2023 18:21:22 +0200 Subject: [PATCH 3/4] Locked code style version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6d6785a..a7f1e24 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,7 @@ "overblog/graphiql-bundle": "^0.2", "phpspec/phpspec": "^7.1", "friendsofphp/php-cs-fixer": "^3.0", - "ibexa/code-style": "^1.0", + "ibexa/code-style": "~1.2.0", "mikey179/vfsstream": "^1.6" }, "autoload": { From 44e62bafc3a36ce34ba878c49ac7c7c898e1e4cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Parafi=C5=84ski?= Date: Wed, 20 Sep 2023 10:31:57 +0200 Subject: [PATCH 4/4] Used query instead of resolver --- composer.json | 1 - src/bundle/Resources/config/graphql/ContentType.types.yaml | 2 +- .../Resources/config/graphql/DomainContent.types.yaml | 2 +- src/bundle/Resources/config/graphql/Item.types.yaml | 2 +- src/bundle/Resources/config/graphql/User.types.yaml | 6 +++--- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index a7f1e24..b86d99a 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,6 @@ "ibexa/http-cache": "~4.5.0@dev", "overblog/graphiql-bundle": "^0.2", "phpspec/phpspec": "^7.1", - "friendsofphp/php-cs-fixer": "^3.0", "ibexa/code-style": "~1.2.0", "mikey179/vfsstream": "^1.6" }, diff --git a/src/bundle/Resources/config/graphql/ContentType.types.yaml b/src/bundle/Resources/config/graphql/ContentType.types.yaml index 74f6ef7..fd7803c 100644 --- a/src/bundle/Resources/config/graphql/ContentType.types.yaml +++ b/src/bundle/Resources/config/graphql/ContentType.types.yaml @@ -107,7 +107,7 @@ ContentTypeGroup: resolve: "@=resolver('UserById', [value.modifierId])" contentTypes: type: "[ContentType]" - resolve: "@=resolver('ContentTypesFromGroup', [{'groupId': value.id}])" + resolve: "@=query('ContentTypesFromGroup', {'groupId': value.id})" groups: type: "[ContentTypeGroup]" diff --git a/src/bundle/Resources/config/graphql/DomainContent.types.yaml b/src/bundle/Resources/config/graphql/DomainContent.types.yaml index 8f73076..e6fd159 100644 --- a/src/bundle/Resources/config/graphql/DomainContent.types.yaml +++ b/src/bundle/Resources/config/graphql/DomainContent.types.yaml @@ -72,7 +72,7 @@ AbstractDomainContent: resolve: "@=resolver('MainUrlAlias', [value])" _thumbnail: type: Thumbnail - resolve: "@=resolver('Thumbnail', [value.getThumbnail()])" + resolve: "@=query('Thumbnail', value.getThumbnail())" UntypedContent: type: object diff --git a/src/bundle/Resources/config/graphql/Item.types.yaml b/src/bundle/Resources/config/graphql/Item.types.yaml index 963fb5e..aee4c5c 100644 --- a/src/bundle/Resources/config/graphql/Item.types.yaml +++ b/src/bundle/Resources/config/graphql/Item.types.yaml @@ -60,7 +60,7 @@ AbstractItem: resolve: "@=resolver('ItemUrlAlias', [value])" _thumbnail: type: Thumbnail - resolve: "@=resolver('Thumbnail', [value.getContent().getThumbnail()])" + resolve: "@=query('Thumbnail', value.getContent().getThumbnail())" UntypedItem: type: object diff --git a/src/bundle/Resources/config/graphql/User.types.yaml b/src/bundle/Resources/config/graphql/User.types.yaml index cc0e128..824d41c 100644 --- a/src/bundle/Resources/config/graphql/User.types.yaml +++ b/src/bundle/Resources/config/graphql/User.types.yaml @@ -11,7 +11,7 @@ User: resolve: "@=value.contentInfo.name" content: type: "UserItem" - resolve: "@=resolver('Item', [{id: value.id}])" + resolve: "@=query('Item', {id: value.id})" version: type: "Version" description: "Current version metadata" @@ -25,7 +25,7 @@ User: resolve: "@=resolver('UserGroupsByUserId', [value.id])" thumbnail: type: Thumbnail - resolve: "@=resolver('Thumbnail', [value.getThumbnail()])" + resolve: "@=query('Thumbnail', value.getThumbnail())" UserGroup: type: object @@ -40,7 +40,7 @@ UserGroup: content: description: "The User Group content item" type: "UserGroupItem" - resolve: "@=resolver('Item', [{id: value.id}])" + resolve: "@=query('Item', {id: value.id})" version: type: "Version" description: "Current version"