From 1de069205cf5b9ea2ba41f49911ceab4fd6b5d25 Mon Sep 17 00:00:00 2001 From: Mark Huot Date: Sun, 6 May 2018 18:32:44 -0400 Subject: [PATCH 1/2] cleans up a few of the craftql builder methods --- src/listeners/GetCraftQLSchema.php | 38 ++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/listeners/GetCraftQLSchema.php b/src/listeners/GetCraftQLSchema.php index cb0de108..816e74da 100644 --- a/src/listeners/GetCraftQLSchema.php +++ b/src/listeners/GetCraftQLSchema.php @@ -33,8 +33,28 @@ public function handle($event) $fieldObject = $event->schema->createObjectType('OptimizedImagesData'); + $srcObject = $event->schema->createObjectType('OptimizedImageSrc'); + $srcObject->addStringField('url'); + $srcObject->addIntField('width'); + // Primary getter functions - $fieldObject->addStringField('src'); + $fieldObject->addStringField('src') + ->arguments(function (\markhuot\CraftQL\Builders\Field $field) { + $field->addIntArgument('width'); + }) + ->resolve(function ($root, $args) { + return $root->src(@$args['width'] ?: 0); + }); + $fieldObject->addField('srcUrls') + ->lists() + ->type($srcObject) + ->resolve(function ($root, $args) { + $result = []; + foreach ($root->optimizedImageUrls as $width => $url) { + $result[] = ['width' => $width, 'url' => $url]; + } + return $result; + }); $fieldObject->addStringField('srcset'); $fieldObject->addStringField('srcWebp'); $fieldObject->addStringField('srcsetWebp'); @@ -44,22 +64,14 @@ public function handle($event) $fieldObject->addStringField('placeholderSilhouette'); // Object properties - $fieldObject->addStringField('optimizedImageUrls') - ->lists() - ->type(Type::string()); - $fieldObject->addStringField('optimizedWebPImageUrls') - ->lists() - ->type(Type::string()); - $fieldObject->addIntField('variantSourceWidths') - ->lists() - ->type(Type::int()); + $fieldObject->addStringField('optimizedImageUrls')->lists(); + $fieldObject->addStringField('optimizedWebPImageUrls')->lists(); + $fieldObject->addIntField('variantSourceWidths')->lists(); $fieldObject->addIntField('originalImageWidth'); $fieldObject->addIntField('originalImageHeight'); $fieldObject->addStringField('placeholder'); $fieldObject->addStringField('placeholderSvg'); - $fieldObject->addStringField('colorPalette') - ->lists() - ->type(Type::string()); + $fieldObject->addStringField('colorPalette')->lists(); $fieldObject->addIntField('placeholderWidth'); $fieldObject->addIntField('placeholderHeight'); From fceb56c8ea8afcb702626e8735f2380144fb9652 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Wed, 9 May 2018 18:50:37 -0400 Subject: [PATCH 2/2] Version 1.4.32 Signed-off-by: Andrew Welch --- CHANGELOG.md | 4 ++++ composer.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17df8672..90f3f9ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # ImageOptimize Changelog +## 1.4.32 - 2018.05.09 +### Added +* Improved CraftQL support by allowing parameter passing to `src` and `srcUrls` + ## 1.4.31 - 2018.04.22 ### Added * Added CraftQL support diff --git a/composer.json b/composer.json index 9342051a..923a50c4 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "nystudio107/craft-imageoptimize", "description": "Automatically create & optimize responsive image transforms, using either native Craft transforms or a service like Imgix, with zero template changes.", "type": "craft-plugin", - "version": "1.4.31", + "version": "1.4.32", "keywords": [ "craft", "cms",