Skip to content

Commit 3ef709f

Browse files
author
Eric Bohanon
committed
MAGETWO-81034: Address CR issues
- Make description imperative on methods - Reduce nesting level on SchemaGenerator - Re-word descriptions for clarity - Add description of structure for return type of generate on SchemaGenerator
1 parent 63476a3 commit 3ef709f

File tree

5 files changed

+18
-15
lines changed

5 files changed

+18
-15
lines changed

app/code/Magento/GraphQl/Model/Type/Generator.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,13 @@ public function generateTypes(string $typeName)
5757
$mappedFields = $this->typeMap[$typeName];
5858
foreach ($mappedFields['fields'] as $fieldName => $values) {
5959
$arguments = [];
60-
if (isset($values['args'])) {
61-
foreach ($values['args'] as $argName => $argType) {
62-
// Replace '[]' with an 's' to express plurality
63-
$realArgName = str_replace('!', '', str_replace('[]', 's', $argName));
64-
$arguments[$realArgName] = ['type' => $this->decorateType($argName, $argType)];
65-
}
60+
if (!isset($values['args'])) {
61+
$values['args'] = [];
62+
}
63+
foreach ($values['args'] as $argName => $argType) {
64+
// Replace '[]' with an 's' to express plurality
65+
$realArgName = str_replace('!', '', str_replace('[]', 's', $argName));
66+
$arguments[$realArgName] = ['type' => $this->decorateType($argName, $argType)];
6667
}
6768

6869
$fields[$fieldName] = ['type' => $this->typePool->getType($values['type']), 'args' => $arguments];

app/code/Magento/GraphQl/Model/Type/GeneratorInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
namespace Magento\GraphQl\Model\Type;
88

99
/**
10-
* Generate configured top level GraphQL types, and their children types as defined by type handlers
10+
* Generate configured GraphQL type schema and top-level fields of base query object
1111
*/
1212
interface GeneratorInterface
1313
{
1414
/**
1515
* Generate type definitions for all fields of given GraphQl query or mutation name
1616
*
1717
* @param string $typeName
18-
* @return array
18+
* @return array Represented as ['fields' => ['fieldName' => Type, {...}], 'types' => Types[]]
1919
*/
2020
public function generateTypes(string $typeName);
2121
}

app/code/Magento/GraphQl/Model/Type/HandlerFactory.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66

77
namespace Magento\GraphQl\Model\Type;
88

9+
use Magento\Framework\Exception\InputException;
910
use Magento\Framework\ObjectManagerInterface;
1011

1112
/**
12-
* Create TypeHandler from its name
13+
* Create type handler from its name
1314
*/
1415
class HandlerFactory
1516
{
@@ -31,12 +32,13 @@ public function __construct(ObjectManagerInterface $objectManager)
3132
*
3233
* @param string $typeClassName
3334
* @return HandlerInterface
35+
* @throws InputException
3436
*/
3537
public function create($typeClassName)
3638
{
3739
$typeHandlerClass = $this->objectManager->create($typeClassName);
3840
if (!($typeHandlerClass instanceof HandlerInterface)) {
39-
throw new \InvalidArgumentException(__('Invalid type name. Type handler does not exist.'));
41+
throw new InputException(__('Invalid type name. Type handler does not exist.'));
4042
}
4143

4244
return $typeHandlerClass;

app/code/Magento/GraphQl/Model/Type/HandlerInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
use GraphQL\Type\Definition\Type;
1010

1111
/**
12-
* Define a method for generating or retrieving a GraphQL's type
12+
* Define a method for generating or retrieving a type for GraphQL
1313
*/
1414
interface HandlerInterface
1515
{
1616
/**
17-
* Returns GraphQL configuration of type.
17+
* Return GraphQL configuration of type.
1818
*
1919
* @return Type
2020
* @throws \InvalidArgumentException No implementation found or type not implemented for interface with resolve type

app/code/Magento/GraphQl/Model/Type/Helper/ServiceContract/TypeGenerator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function generate(
8484
}
8585

8686
/**
87-
* Gets service contract type data from associative service contract name
87+
* Get service contract type data from associative service contract name
8888
*
8989
* @param string $type
9090
* @return array
@@ -190,7 +190,7 @@ private function generateNestedTypes(
190190
}
191191

192192
/**
193-
* Checks if array is associative
193+
* Check if array is associative
194194
*
195195
* @param $arr
196196
* @return bool
@@ -201,7 +201,7 @@ private function isAssociativeArray($arr)
201201
}
202202

203203
/**
204-
* Transforms string from underscore to camelcase
204+
* Transform string from underscore to camelcase
205205
*
206206
* @param string $value
207207
* @return string

0 commit comments

Comments
 (0)