From 2989ff42a77d4ba0c5dbddaa055f2c928a2af573 Mon Sep 17 00:00:00 2001 From: Bryan Nielsen Date: Tue, 1 Oct 2024 14:20:38 -0400 Subject: [PATCH] Change graphql query for rangeslider to support additional fields, closes #15 --- CHANGELOG.md | 1 + src/Fieldtypes/RangeSlider.php | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c96b155..3a87797 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - Relaxed GraphQL handling of fieldtypes during schema generation. Now errors will be logged but schemas can still be built - Default url for ExpressionEngine Control Panel is now `admin` instead of `admin.php`. This can be changed in `config/coilpack.php`. - TemplateOutput now implements the [Stringable](https://www.php.net/manual/en/class.stringable.php) interface +- GraphQL query signature for the Range Slider Fieldtype to support querying `value`, `from`, and `to` fields ## [1.4.2] - 2024-09-26 diff --git a/src/Fieldtypes/RangeSlider.php b/src/Fieldtypes/RangeSlider.php index cffd709..151a964 100644 --- a/src/Fieldtypes/RangeSlider.php +++ b/src/Fieldtypes/RangeSlider.php @@ -2,6 +2,7 @@ namespace Expressionengine\Coilpack\Fieldtypes; +use Expressionengine\Coilpack\Api\Graph\Support\GeneratedType; use Expressionengine\Coilpack\Facades\Coilpack; use Expressionengine\Coilpack\FieldtypeOutput; use Expressionengine\Coilpack\Models\FieldContent; @@ -21,4 +22,32 @@ public function apply(FieldContent $content, $parameters = []) return FieldtypeOutput::for($this)->value($string)->array($array); }); } + + public function graphType() + { + return new GeneratedType([ + 'fields' => function () { + return [ + 'value' => [ + 'type' => \GraphQL\Type\Definition\Type::string(), + 'resolve' => function ($root, array $args) { + return $root; + }, + ], + 'from' => [ + 'type' => \GraphQL\Type\Definition\Type::string(), + 'resolve' => function ($root, array $args) { + return $root->from; + }, + ], + 'to' => [ + 'type' => \GraphQL\Type\Definition\Type::string(), + 'resolve' => function ($root, array $args) { + return $root->to; + }, + ], + ]; + }, + ]); + } }