-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add mutation datatype 'input quantity value' (#812)
* Update 20_DataObject_Mutations.md * Create InputQuantityValue.php * Create InputQuantityValue.php * Create InputQuantityValueInputType.php * Update graphql.yml
- Loading branch information
Showing
5 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/GraphQL/DataObjectInputProcessor/InputQuantityValue.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\DataHubBundle\GraphQL\DataObjectInputProcessor; | ||
|
||
use GraphQL\Type\Definition\ResolveInfo; | ||
use Pimcore\Bundle\DataHubBundle\GraphQL\Service; | ||
use Pimcore\Model\DataObject\Concrete; | ||
use Pimcore\Model\DataObject\Fieldcollection\Data\AbstractData; | ||
|
||
class InputQuantityValue extends Base | ||
{ | ||
/** | ||
* @param Concrete|AbstractData $object | ||
* @param array $newValue | ||
* @param array $args | ||
* @param array $context | ||
* @param ResolveInfo $info | ||
* | ||
* @throws \Exception | ||
*/ | ||
public function process($object, $newValue, $args, $context, ResolveInfo $info) | ||
{ | ||
$attribute = $this->getAttribute(); | ||
Service::setValue($object, $attribute, function ($container, $setter) use ($newValue) { | ||
if ($newValue) { | ||
$unit = \Pimcore\Model\DataObject\QuantityValue\Unit::getByAbbreviation($newValue['unit']); | ||
$inputQuantityValue = new \Pimcore\Model\DataObject\Data\InputQuantityValue($newValue['value'], $unit); | ||
|
||
return $container->$setter($inputQuantityValue); | ||
} | ||
|
||
return null; | ||
}); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/GraphQL/DataObjectMutationFieldConfigGenerator/InputQuantityValue.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\DataHubBundle\GraphQL\DataObjectMutationFieldConfigGenerator; | ||
|
||
class InputQuantityValue extends Base | ||
{ | ||
/** {@inheritdoc } */ | ||
public function getGraphQlMutationFieldConfig($nodeDef, $class, $container = null, $params = []) | ||
{ | ||
$processor = new \Pimcore\Bundle\DataHubBundle\GraphQL\DataObjectInputProcessor\InputQuantityValue($nodeDef); | ||
$processor->setGraphQLService($this->getGraphQlService()); | ||
|
||
return [ | ||
'arg' => $this->getGraphQlService()->getDataObjectTypeDefinition('input_quantity_value_input'), | ||
'processor' => [$processor, 'process'] | ||
]; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/GraphQL/DataObjectType/InputQuantityValueInputType.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\DataHubBundle\GraphQL\DataObjectType; | ||
|
||
use GraphQL\Type\Definition\InputObjectType; | ||
use GraphQL\Type\Definition\Type; | ||
use Pimcore\Bundle\DataHubBundle\GraphQL\Service; | ||
use Pimcore\Bundle\DataHubBundle\GraphQL\Traits\ServiceTrait; | ||
|
||
class InputQuantityValueInputType extends InputObjectType | ||
{ | ||
use ServiceTrait; | ||
|
||
/** | ||
* @param Service $graphQlService | ||
* @param array $config | ||
*/ | ||
public function __construct(Service $graphQlService, $config = ['name' => 'InputQuantityValueInput']) | ||
{ | ||
$this->setGraphQLService($graphQlService); | ||
$this->build($config); | ||
parent::__construct($config); | ||
} | ||
|
||
/** | ||
* @param array $config | ||
*/ | ||
public function build(&$config) | ||
{ | ||
$resolver = new \Pimcore\Bundle\DataHubBundle\GraphQL\Resolver\DataObject($this->getGraphQlService()); | ||
$resolver->setGraphQLService($this->getGraphQlService()); | ||
|
||
$config['fields'] = [ | ||
'value' => Type::string(), | ||
'unit' => Type::string(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters