Skip to content

Commit a74f429

Browse files
committed
MAGETWO-83855: Create wrapper for resolver info
- solving wrappers types
1 parent 69f9ef2 commit a74f429

File tree

12 files changed

+160
-81
lines changed

12 files changed

+160
-81
lines changed

app/code/Magento/GraphQl/Model/Type/Handler/Pool.php

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
namespace Magento\GraphQl\Model\Type\Handler;
88

9-
use Magento\Framework\GraphQl\Type\Definition\ObjectType;
109
use Magento\Framework\GraphQl\Type\Definition\TypeInterface;
1110
use Magento\GraphQl\Model\Type\HandlerFactory;
11+
use Magento\Framework\GraphQl\Type\Definition\ScalarTypeFactory;
1212

1313
/**
1414
* Retrieve type's registered in pool, or generate types yet to be instantiated and register them
@@ -27,27 +27,33 @@ class Pool
2727

2828
/**
2929
* @param HandlerFactory $typeHandlerFactory
30+
* @param ScalarTypeFactory $scalarTypeFactory
3031
*/
31-
public function __construct(\Magento\GraphQl\Model\Type\HandlerFactory $typeHandlerFactory)
32-
{
32+
public function __construct(
33+
HandlerFactory $typeHandlerFactory,
34+
ScalarTypeFactory $scalarTypeFactory
35+
) {
3336
$this->typeHandlerFactory = $typeHandlerFactory;
37+
$this->scalarTypeFactory = $scalarTypeFactory;
3438
}
3539

3640
/**
3741
* @param string $typeName
38-
* @return TypeInterface
42+
* @return TypeInterface|\GraphQL\Type\Definition\Type
43+
* @throws \LogicException
3944
*/
4045
public function getType(string $typeName)
4146
{
42-
if ($type = $this->mapScalarType($typeName)) {
43-
return $type;
47+
if (isset($this->typeRegistry[$typeName])) {
48+
return $this->typeRegistry[$typeName];
4449
}
4550

46-
if ($type = $this->getComplexType($typeName)) {
47-
return $type;
51+
if ($this->scalarTypeFactory->typeExists($typeName)) {
52+
$this->typeRegistry[$typeName] = $this->scalarTypeFactory->create($typeName);
53+
return $this->typeRegistry[$typeName];
54+
} else {
55+
return $this->getComplexType($typeName);
4856
}
49-
50-
throw new \LogicException(sprintf('%s type could not be resolved or generated.', $typeName));
5157
}
5258

5359
/**
@@ -97,28 +103,4 @@ public function isTypeRegistered(string $typeName)
97103
{
98104
return isset($this->typeRegistry[$typeName]);
99105
}
100-
101-
/**
102-
* Map type name to scalar GraphQL type, otherwise return null
103-
*
104-
* @param string $typeName
105-
* @return TypeInterface|null
106-
*/
107-
private function mapScalarType($typeName)
108-
{
109-
$scalarTypes = $this->getInternalTypes();
110-
111-
return isset($scalarTypes[$typeName]) ? $scalarTypes[$typeName] : null;
112-
}
113-
114-
/**
115-
* Get all internal scalar types
116-
*
117-
* @return array
118-
*/
119-
private function getInternalTypes()
120-
{
121-
$object = new ObjectType(['name' => 'fake', 'fields' => 'fake']);
122-
return $object->getInternalTypes();
123-
}
124106
}

lib/internal/Magento/Framework/GraphQl/Argument/SearchCriteria/ArgumentApplierFactory.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function __construct(
3232
*
3333
* @param string $argumentName
3434
* @return ArgumentApplierInterface
35+
* @throws \LogicException
3536
*/
3637
public function create(string $argumentName)
3738
{
@@ -41,6 +42,10 @@ public function create(string $argumentName)
4142
'currentPage' => ArgumentApplier\CurrentPage::class,
4243
'sort' => ArgumentApplier\Sort::class
4344
];
44-
return $this->objectManager->create($appliers[$argumentName]);
45+
if (isset($appliers[$argumentName])) {
46+
return $this->objectManager->create($appliers[$argumentName]);
47+
} else {
48+
throw new \LogicException(sprintf('Applier %s not found', $argumentName));
49+
}
4550
}
4651
}

lib/internal/Magento/Framework/GraphQl/Executor.php

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\GraphQl\Type\Definition;
8+
9+
/**
10+
* Wrapper for GraphQl BooleanType
11+
*/
12+
class BooleanType extends \GraphQL\Type\Definition\BooleanType implements ScalarTypeInterface
13+
{
14+
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\GraphQl\Type\Definition;
8+
9+
/**
10+
* Wrapper for GraphQl FloatType
11+
*/
12+
class FloatType extends \GraphQL\Type\Definition\FloatType implements ScalarTypeInterface
13+
{
14+
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\GraphQl\Type\Definition;
8+
9+
/**
10+
* Wrapper for GraphQl IdType
11+
*/
12+
class IdType extends \GraphQL\Type\Definition\IdType implements ScalarTypeInterface
13+
{
14+
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\GraphQl\Type\Definition;
8+
9+
/**
10+
* Wrapper for GraphQl IntType
11+
*/
12+
class IntType extends \GraphQL\Type\Definition\IntType implements ScalarTypeInterface
13+
{
14+
15+
}

lib/internal/Magento/Framework/GraphQl/Type/Definition/ResolveInfo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* Wrapper for GraphQl ResolveInfo
1111
*/
12-
class ResolveInfo extends \GraphQL\Type\Definition\ResolveInfo implements TypeInterface
12+
class ResolveInfo extends \GraphQL\Type\Definition\ResolveInfo
1313
{
1414

1515
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\GraphQl\Type\Definition;
8+
9+
/**
10+
* Factory class for the creation scalar types
11+
*/
12+
class ScalarTypeFactory
13+
{
14+
/**
15+
* Create a scalar type
16+
*
17+
* @param string $typeName
18+
* @return \GraphQL\Type\Definition\Type
19+
* @throws \LogicException
20+
*/
21+
public function create(string $typeName)
22+
{
23+
$types = \GraphQL\Type\Definition\Type::getInternalTypes();
24+
if (isset($types[$typeName])) {
25+
return $types[$typeName];
26+
} else {
27+
throw new \LogicException(sprintf('Scalar type %s not found', $typeName));
28+
}
29+
}
30+
31+
/**
32+
* Checks if a scalar type exists
33+
*
34+
* @param string $typeName
35+
* @return bool
36+
*/
37+
public function typeExists(string $typeName)
38+
{
39+
$types = \GraphQL\Type\Definition\Type::getInternalTypes();
40+
if (isset($types[$typeName])) {
41+
return true;
42+
} else {
43+
return false;
44+
}
45+
}
46+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\GraphQl\Type\Definition;
8+
9+
/**
10+
* Interface for GraphQl Scalar Type
11+
*/
12+
interface ScalarTypeInterface extends TypeInterface
13+
{
14+
15+
}

0 commit comments

Comments
 (0)