diff --git a/CHANGELOG.md b/CHANGELOG.md index c6551b4..46237e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 3.4.5 - 2019-11-14 + +### Added +- Added native GraphQL support for Address, Notes and Predefined Date fields. + ## 3.4.4 - 2019-08-14 ### Changed diff --git a/composer.json b/composer.json index 15492c6..a7b5665 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "barrelstrength/sprout-fields", "description": "International, Craft-friendly field types.", - "version": "3.4.4", + "version": "3.4.5", "type": "craft-plugin", "keywords": [ "craft", diff --git a/src/fields/Address.php b/src/fields/Address.php index ce8537c..bd21664 100644 --- a/src/fields/Address.php +++ b/src/fields/Address.php @@ -8,9 +8,13 @@ use CommerceGuys\Addressing\Address as CommerceGuysAddress; use CommerceGuys\Addressing\Subdivision\SubdivisionRepository; use CommerceGuys\Addressing\Country\CountryRepository; +use GraphQL\Type\Definition\Type; +use GraphQL\Type\Definition\ObjectType; use craft\base\ElementInterface; use craft\base\Field; use craft\base\PreviewableFieldInterface; +use craft\gql\GqlEntityRegistry; +use craft\gql\TypeLoader; use Craft; use yii\db\Schema; @@ -75,4 +79,31 @@ public function getTableAttributeHtml($value, ElementInterface $element): string return $html; } + + /** + * @inheritdoc + * @since 3.3.0 + */ + public function getContentGqlType() + { + $typeName = $this->handle.'_SproutAddressField'; + + $addressType = GqlEntityRegistry::getEntity($typeName) + ?: GqlEntityRegistry::createEntity($typeName, new ObjectType([ + 'name' => $typeName, + 'fields' => [ + 'countryCode' => Type::string(), + 'administrativeAreaCode' => Type::string(), + 'locality' => Type::string(), + 'postalCode' => Type::string(), + 'address1' => Type::string(), + 'address2' => Type::string(), + ], + ])); + + TypeLoader::registerType($typeName, static function () use ($addressType) { return $addressType ;}); + + return $addressType; + } + } diff --git a/src/fields/Notes.php b/src/fields/Notes.php index a7645f7..a65202a 100644 --- a/src/fields/Notes.php +++ b/src/fields/Notes.php @@ -8,6 +8,7 @@ use barrelstrength\sproutbasefields\web\assets\quill\QuillAsset; use craft\helpers\FileHelper; +use GraphQL\Type\Definition\Type; use Twig\Error\LoaderError; use Twig\Error\RuntimeError; use Twig\Error\SyntaxError; @@ -132,6 +133,22 @@ public function getInputHtml($value, ElementInterface $element = null): string ); } + /** + * @inheritdoc + * @since 3.3.0 + */ + public function getContentGqlType() + { + return [ + 'name' => $this->handle, + 'type' => Type::string(), + 'resolve' => function() { + return $this->notes; + }, + ]; + } + + /** * Returns a css style * diff --git a/src/fields/PredefinedDate.php b/src/fields/PredefinedDate.php index 0b9be8a..f9f4fff 100644 --- a/src/fields/PredefinedDate.php +++ b/src/fields/PredefinedDate.php @@ -5,7 +5,9 @@ use Craft; use craft\base\ElementInterface; use craft\helpers\DateTimeHelper; +use craft\gql\types\DateTime as GqlDateTimeType; use Exception; +use GraphQL\Type\Definition\Type; use Throwable; use Twig\Error\LoaderError; use Twig\Error\RuntimeError; @@ -82,4 +84,17 @@ public function getInputHtml($value, ElementInterface $element = null): string 'value' => $value ]); } + + /** + * @inheritdoc + * @since 3.3.0 + */ + public function getContentGqlType() + { + return [ + 'name' => $this->handle, + 'type' => GqlDateTimeType::getType(), + ]; + } + }