diff --git a/src/GraphQL/AssetType/AssetType.php b/src/GraphQL/AssetType/AssetType.php index 5de9d14a..c32ed60d 100644 --- a/src/GraphQL/AssetType/AssetType.php +++ b/src/GraphQL/AssetType/AssetType.php @@ -98,6 +98,7 @@ public function build(&$config) 'args' => [ 'thumbnail' => ['type' => Type::string()], 'format' => ['type' => Type::string()], + 'deferred' => ['type' => Type::boolean(), 'defaultValue' => false], ], 'resolve' => [$resolver, 'resolvePath'], ], @@ -140,6 +141,7 @@ public function build(&$config) 'args' => [ 'thumbnail' => ['type' => Type::nonNull(Type::string())], 'format' => ['type' => Type::string()], + 'deferred' => ['type' => Type::boolean(), 'defaultValue' => false], ], 'resolve' => [$resolver, 'resolveSrcSet'], ], diff --git a/src/GraphQL/FieldHelper/AssetFieldHelper.php b/src/GraphQL/FieldHelper/AssetFieldHelper.php index 020c734f..85d1eed9 100644 --- a/src/GraphQL/FieldHelper/AssetFieldHelper.php +++ b/src/GraphQL/FieldHelper/AssetFieldHelper.php @@ -41,14 +41,19 @@ public function getVideoThumbnail(Asset\Video $asset, string | Video\Thumbnail\C return null; } - public function getImageDocumentThumbnail(Asset $asset, string | Image\Thumbnail\Config $thumbNailConfig, string $thumbNailFormat = null): mixed + public function getImageDocumentThumbnail( + Asset $asset, + string | Image\Thumbnail\Config $thumbNailConfig, + string $thumbNailFormat = null, + bool $deferred = false + ): mixed { $thumb = null; if ($asset instanceof Asset\Document || $asset instanceof Asset\Video) { - $thumb = $asset->getImageThumbnail($thumbNailConfig); + $thumb = $asset->getImageThumbnail($thumbNailConfig, $deferred); } elseif ($asset instanceof Asset\Image) { - $thumb = $asset->getThumbnail($thumbNailConfig, false); + $thumb = $asset->getThumbnail($thumbNailConfig, $deferred); } if (isset($thumb, $thumbNailFormat) && method_exists($thumb, 'getAsFormat') && !($asset instanceof Asset\Video)) { $thumb = $thumb->getAsFormat($thumbNailFormat); @@ -57,12 +62,17 @@ public function getImageDocumentThumbnail(Asset $asset, string | Image\Thumbnail return $thumb; } - public function getAssetThumbnail(Asset $asset, string | Image\Thumbnail\Config | Video\Thumbnail\Config $thumbNailConfig, string $thumbNailFormat = null): mixed + public function getAssetThumbnail( + Asset $asset, + string | Image\Thumbnail\Config | Video\Thumbnail\Config $thumbNailConfig, + string $thumbNailFormat = null, + bool $deferred = false + ): mixed { if (($asset instanceof Asset\Video) && (is_string($thumbNailConfig) || $thumbNailConfig instanceof Video\Thumbnail\Config)) { return $this->getVideoThumbnail($asset, $thumbNailConfig, $thumbNailFormat); } else { - return $this->getImageDocumentThumbnail($asset, $thumbNailConfig, $thumbNailFormat); + return $this->getImageDocumentThumbnail($asset, $thumbNailConfig, $thumbNailFormat, $deferred); } } diff --git a/src/GraphQL/Resolver/AssetType.php b/src/GraphQL/Resolver/AssetType.php index de82cd7c..3f3a20b7 100644 --- a/src/GraphQL/Resolver/AssetType.php +++ b/src/GraphQL/Resolver/AssetType.php @@ -147,13 +147,14 @@ public function resolvePath($value = null, $args = [], $context = [], ResolveInf $asset = $this->getAssetFromValue($value, $context); $thumbNailConfig = $args['thumbnail'] ?? null; $thumbNailFormat = $args['format'] ?? null; + $deferred = $args['deferred'] ?? false; $assetFieldHelper = $this->getGraphQLService()->getAssetFieldHelper(); if (!isset($thumbNailConfig)) { return $asset->getFullPath(); } - return $assetFieldHelper->getAssetThumbnail($asset, $thumbNailConfig, $thumbNailFormat); + return $assetFieldHelper->getAssetThumbnail($asset, $thumbNailConfig, $thumbNailFormat, $deferred); } /** @@ -170,12 +171,13 @@ public function resolveData($value = null, $args = [], $context = [], ResolveInf $asset = $this->getAssetFromValue($value, $context); $thumbNailConfig = $args['thumbnail'] ?? null; $thumbNailFormat = $args['format'] ?? null; + $deferred = $args['deferred'] ?? false; $assetFieldHelper = $this->getGraphQLService()->getAssetFieldHelper(); if (!isset($thumbNailConfig)) { return base64_encode(stream_get_contents($asset->getStream())); } - $thumb = $assetFieldHelper->getAssetThumbnail($asset, $thumbNailConfig, $thumbNailFormat); + $thumb = $assetFieldHelper->getAssetThumbnail($asset, $thumbNailConfig, $thumbNailFormat, $deferred); return $thumb ? base64_encode(stream_get_contents($thumb->getStream())) : base64_encode(stream_get_contents($asset->getStream())); } @@ -194,12 +196,13 @@ public function resolveSrcSet($value = null, $args = [], $context = [], ResolveI $asset = $this->getAssetFromValue($value, $context); $thumbNailConfig = $args['thumbnail'] ?? null; $thumbNailFormat = $args['format'] ?? null; + $deferred = $args['deferred'] ?? null; $assetFieldHelper = $this->getGraphQLService()->getAssetFieldHelper(); if ($asset instanceof Asset\Image) { $mediaQueries = []; - $thumbnail = $assetFieldHelper->getAssetThumbnail($asset, $thumbNailConfig, $thumbNailFormat); - $thumbnailConfig = $asset->getThumbnail($args['thumbnail'])->getConfig(); + $thumbnail = $assetFieldHelper->getAssetThumbnail($asset, $thumbNailConfig, $thumbNailFormat, $deferred); + $thumbnailConfig = $asset->getThumbnail($args['thumbnail'], $deferred)->getConfig(); if ($thumbnailConfig) { foreach ($thumbnailConfig->getMedias() as $key => $val) { $mediaQueries[] = [