-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GraphQl-93: Implement support for variables in query
- Loading branch information
Showing
17 changed files
with
338 additions
and
345 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
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
74 changes: 74 additions & 0 deletions
74
lib/internal/Magento/Framework/GraphQl/Config/Element/Input.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,74 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Framework\GraphQl\Config\Element; | ||
|
||
/** | ||
* Class representing 'input' GraphQL config element. | ||
*/ | ||
class Input implements TypeInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $name; | ||
|
||
/** | ||
* @var Field[] | ||
*/ | ||
private $fields; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $description; | ||
|
||
/** | ||
* @param string $name | ||
* @param Field[] $fields | ||
* @param string $description | ||
*/ | ||
public function __construct( | ||
string $name, | ||
array $fields, | ||
string $description | ||
) { | ||
$this->name = $name; | ||
$this->fields = $fields; | ||
$this->description = $description; | ||
} | ||
|
||
/** | ||
* Get the type name. | ||
* | ||
* @return string | ||
*/ | ||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* Get a list of fields that make up the possible return or input values of a type. | ||
* | ||
* @return Field[] | ||
*/ | ||
public function getFields(): array | ||
{ | ||
return $this->fields; | ||
} | ||
|
||
/** | ||
* Get a human-readable description of the type. | ||
* | ||
* @return string | ||
*/ | ||
public function getDescription(): string | ||
{ | ||
return $this->description; | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
lib/internal/Magento/Framework/GraphQl/Config/Element/InputFactory.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,97 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Framework\GraphQl\Config\Element; | ||
|
||
use Magento\Framework\GraphQl\Config\ConfigElementFactoryInterface; | ||
use Magento\Framework\GraphQl\Config\ConfigElementInterface; | ||
use Magento\Framework\ObjectManagerInterface; | ||
|
||
/** | ||
* Factory for config elements of 'input' type. | ||
*/ | ||
class InputFactory implements ConfigElementFactoryInterface | ||
{ | ||
/** | ||
* @var ObjectManagerInterface | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* @var ArgumentFactory | ||
*/ | ||
private $argumentFactory; | ||
|
||
/** | ||
* @var FieldFactory | ||
*/ | ||
private $fieldFactory; | ||
|
||
/** | ||
* @param ObjectManagerInterface $objectManager | ||
* @param ArgumentFactory $argumentFactory | ||
* @param FieldFactory $fieldFactory | ||
*/ | ||
public function __construct( | ||
ObjectManagerInterface $objectManager, | ||
ArgumentFactory $argumentFactory, | ||
FieldFactory $fieldFactory | ||
) { | ||
$this->objectManager = $objectManager; | ||
$this->argumentFactory = $argumentFactory; | ||
$this->fieldFactory = $fieldFactory; | ||
} | ||
|
||
/** | ||
* Instantiate an object representing 'input' GraphQL config element. | ||
* | ||
* @param array $data | ||
* @return ConfigElementInterface | ||
*/ | ||
public function createFromConfigData(array $data): ConfigElementInterface | ||
{ | ||
$fields = []; | ||
$data['fields'] = isset($data['fields']) ? $data['fields'] : []; | ||
foreach ($data['fields'] as $field) { | ||
$arguments = []; | ||
foreach ($field['arguments'] as $argument) { | ||
$arguments[$argument['name']] = $this->argumentFactory->createFromConfigData($argument); | ||
} | ||
$fields[$field['name']] = $this->fieldFactory->createFromConfigData( | ||
$field, | ||
$arguments | ||
); | ||
} | ||
return $this->create( | ||
$data, | ||
$fields | ||
); | ||
} | ||
|
||
/** | ||
* Create type object based off array of configured GraphQL InputType data. | ||
* | ||
* Type data must contain name and the type's fields. Optional data includes description. | ||
* | ||
* @param array $typeData | ||
* @param array $fields | ||
* @return Input | ||
*/ | ||
private function create( | ||
array $typeData, | ||
array $fields | ||
): Input { | ||
return $this->objectManager->create( | ||
Input::class, | ||
[ | ||
'name' => $typeData['name'], | ||
'fields' => $fields, | ||
'description' => isset($typeData['description']) ? $typeData['description'] : '' | ||
] | ||
); | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.