Skip to content

Commit 650bff0

Browse files
committed
MC:18945: Reading deprecated annotation in schema
- Added code for readibg deprecated annotation on schema
1 parent 6f03dd3 commit 650bff0

File tree

16 files changed

+238
-29
lines changed

16 files changed

+238
-29
lines changed

lib/internal/Magento/Framework/GraphQl/Config/Element/Argument.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ class Argument implements FieldInterface
5454
*/
5555
private $defaultValue;
5656

57+
/**
58+
* @var array
59+
*/
60+
private $deprecated;
61+
5762
/**
5863
* @param string $name
5964
* @param string $type
@@ -64,6 +69,8 @@ class Argument implements FieldInterface
6469
* @param string $itemType
6570
* @param bool $itemsRequired
6671
* @param string $defaultValue
72+
* @param array $deprecated
73+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
6774
*/
6875
public function __construct(
6976
string $name,
@@ -74,7 +81,8 @@ public function __construct(
7481
bool $isList,
7582
string $itemType = '',
7683
bool $itemsRequired = false,
77-
string $defaultValue = null
84+
string $defaultValue = null,
85+
array $deprecated = []
7886
) {
7987
$this->name = $name;
8088
$this->type = $isList ? $itemType : $type;
@@ -84,6 +92,7 @@ public function __construct(
8492
$this->isList = $isList;
8593
$this->itemsRequired = $itemsRequired;
8694
$this->defaultValue = $defaultValue;
95+
$this->deprecated = $deprecated;
8796
}
8897

8998
/**
@@ -175,4 +184,14 @@ public function hasDefaultValue() : bool
175184
{
176185
return $this->defaultValue ? true: false;
177186
}
187+
188+
/**
189+
* Return the deprecated
190+
*
191+
* @return array
192+
*/
193+
public function getDeprecated() : array
194+
{
195+
return $this->deprecated;
196+
}
178197
}

lib/internal/Magento/Framework/GraphQl/Config/Element/ArgumentFactory.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Magento\Framework\ObjectManagerInterface;
1111

1212
/**
13-
* {@inheritdoc}
13+
* @inheritdoc
1414
*/
1515
class ArgumentFactory
1616
{
@@ -51,7 +51,8 @@ public function createFromConfigData(
5151
'isList' => isset($argumentData['itemType']),
5252
'itemType' => isset($argumentData['itemType']) ? $argumentData['itemType'] : '',
5353
'itemsRequired' => isset($argumentData['itemsRequired']) ? $argumentData['itemsRequired'] : false,
54-
'defaultValue' => isset($argumentData['defaultValue']) ? $argumentData['defaultValue'] : null
54+
'defaultValue' => isset($argumentData['defaultValue']) ? $argumentData['defaultValue'] : null,
55+
'deprecated' => isset($argumentData['deprecated']) ? $argumentData['deprecated'] : [],
5556
]
5657
);
5758
}

lib/internal/Magento/Framework/GraphQl/Config/Element/EnumFactory.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Magento\Framework\ObjectManagerInterface;
1313

1414
/**
15-
* {@inheritdoc}
15+
* @inheritdoc
1616
*/
1717
class EnumFactory implements ConfigElementFactoryInterface
1818
{
@@ -71,7 +71,8 @@ public function createFromConfigData(array $data): ConfigElementInterface
7171
$values[$item['_value']] = $this->enumValueFactory->create(
7272
$item['name'],
7373
$item['_value'],
74-
isset($item['description']) ? $item['description'] : ''
74+
isset($item['description']) ? $item['description'] : '',
75+
isset($item['deprecationReason']) ? $item['deprecationReason'] : ''
7576
);
7677
}
7778
return $this->create(

lib/internal/Magento/Framework/GraphQl/Config/Element/EnumValue.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,23 @@ class EnumValue implements ConfigElementInterface
2929
*/
3030
private $description;
3131

32+
/**
33+
* @var string
34+
*/
35+
private $deprecationReason;
36+
3237
/**
3338
* @param string $name
3439
* @param string $value
3540
* @param string $description
41+
* @param string deprecationReason
3642
*/
37-
public function __construct(string $name, string $value, string $description = '')
43+
public function __construct(string $name, string $value, string $description = '', string $deprecationReason = '')
3844
{
3945
$this->name = $name;
4046
$this->value = $value;
4147
$this->description = $description;
48+
$this->deprecationReason = $deprecationReason;
4249
}
4350

4451
/**
@@ -70,4 +77,14 @@ public function getDescription() : string
7077
{
7178
return $this->description;
7279
}
80+
81+
/**
82+
* Get the enum value's description.
83+
*
84+
* @return string
85+
*/
86+
public function getDeprecatedReason() : string
87+
{
88+
return $this->deprecationReason;
89+
}
7390
}

lib/internal/Magento/Framework/GraphQl/Config/Element/EnumValueFactory.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,21 @@ public function __construct(
3434
* @param string $name
3535
* @param string $value
3636
* @param string $description
37+
* @param string $deprecationReason
3738
* @return EnumValue
3839
*/
39-
public function create(string $name, string $value, string $description = ''): EnumValue
40-
{
40+
public function create(
41+
string $name, string $value,
42+
string $description = '',
43+
string $deprecationReason = ''
44+
): EnumValue {
4145
return $this->objectManager->create(
4246
EnumValue::class,
4347
[
4448
'name' => $name,
4549
'value' => $value,
46-
'description' => $description
50+
'description' => $description,
51+
'deprecationReason' => $deprecationReason
4752
]
4853
);
4954
}

lib/internal/Magento/Framework/GraphQl/Config/Element/Field.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ class Field implements OutputFieldInterface
5353
*/
5454
private $cache;
5555

56+
/**
57+
* @var array
58+
*/
59+
private $deprecated;
60+
5661
/**
5762
* @param string $name
5863
* @param string $type
@@ -63,6 +68,8 @@ class Field implements OutputFieldInterface
6368
* @param string $description
6469
* @param array $arguments
6570
* @param array $cache
71+
* @param array $deprecated
72+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
6673
*/
6774
public function __construct(
6875
string $name,
@@ -73,7 +80,8 @@ public function __construct(
7380
string $resolver = '',
7481
string $description = '',
7582
array $arguments = [],
76-
array $cache = []
83+
array $cache = [],
84+
array $deprecated = []
7785
) {
7886
$this->name = $name;
7987
$this->type = $isList ? $itemType : $type;
@@ -83,6 +91,7 @@ public function __construct(
8391
$this->description = $description;
8492
$this->arguments = $arguments;
8593
$this->cache = $cache;
94+
$this->deprecated = $deprecated;
8695
}
8796

8897
/**
@@ -156,12 +165,21 @@ public function getDescription() : string
156165
}
157166

158167
/**
159-
* Return the cache tag for the field.
168+
* Return the cache
160169
*
161-
* @return array|null
170+
* @return array
162171
*/
163172
public function getCache() : array
164173
{
165174
return $this->cache;
166175
}
176+
/**
177+
* Return the deprecated
178+
*
179+
* @return array
180+
*/
181+
public function getDeprecated() : array
182+
{
183+
return $this->deprecated;
184+
}
167185
}

lib/internal/Magento/Framework/GraphQl/Config/Element/FieldFactory.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function createFromConfigData(
4646
$isList = false;
4747

4848
//check if type ends with []
49-
if ($fieldType{strlen($fieldType) - 2} == '[' && $fieldType{strlen($fieldType) - 1} == ']') {
49+
if ($fieldType[strlen($fieldType) - 2] == '[' && $fieldType[strlen($fieldType) - 1] == ']') {
5050
$isList = true;
5151
$fieldData['type'] = str_replace('[]', '', $fieldData['type']);
5252
$fieldData['itemType'] = str_replace('[]', '', $fieldData['type']);
@@ -62,8 +62,9 @@ public function createFromConfigData(
6262
'itemType' => isset($fieldData['itemType']) ? $fieldData['itemType'] : '',
6363
'resolver' => isset($fieldData['resolver']) ? $fieldData['resolver'] : '',
6464
'description' => isset($fieldData['description']) ? $fieldData['description'] : '',
65-
'cache' => isset($fieldData['cache']) ? $fieldData['cache'] : [],
6665
'arguments' => $arguments,
66+
'cache' => isset($fieldData['cache']) ? $fieldData['cache'] : [],
67+
'deprecated' => isset($fieldData['deprecated']) ? $fieldData['deprecated'] : [],
6768
]
6869
);
6970
}

lib/internal/Magento/Framework/GraphQl/Config/Element/Input.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,27 @@ class Input implements TypeInterface
2727
*/
2828
private $description;
2929

30+
/**
31+
* @var array
32+
*/
33+
private $deprecated;
34+
3035
/**
3136
* @param string $name
3237
* @param Field[] $fields
3338
* @param string $description
39+
* @param array $deprecated
3440
*/
3541
public function __construct(
3642
string $name,
3743
array $fields,
38-
string $description
44+
string $description,
45+
array $deprecated = []
3946
) {
4047
$this->name = $name;
4148
$this->fields = $fields;
4249
$this->description = $description;
50+
$this->deprecated = $deprecated;
4351
}
4452

4553
/**
@@ -71,4 +79,14 @@ public function getDescription(): string
7179
{
7280
return $this->description;
7381
}
82+
83+
/**
84+
* Return the deprecated
85+
*
86+
* @return array
87+
*/
88+
public function getDeprecated() : array
89+
{
90+
return $this->deprecated;
91+
}
7492
}

lib/internal/Magento/Framework/GraphQl/Config/Element/InputFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ private function create(
7272
[
7373
'name' => $typeData['name'],
7474
'fields' => $fields,
75-
'description' => isset($typeData['description']) ? $typeData['description'] : ''
75+
'description' => isset($typeData['description']) ? $typeData['description'] : '',
76+
'deprecated' => isset($typeData['deprecated']) ? $typeData['deprecated'] : []
7677
]
7778
);
7879
}

lib/internal/Magento/Framework/GraphQl/Schema/Type/Enum/Enum.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ public function __construct(EnumElement $configElement)
2222
{
2323
$config = [
2424
'name' => $configElement->getName(),
25-
'description' => $configElement->getDescription(),
25+
'description' => $configElement->getDescription()
2626
];
2727
foreach ($configElement->getValues() as $value) {
2828
$config['values'][$value->getValue()] = [
2929
'value' => $value->getValue(),
30-
'description' => $value->getDescription()
30+
'description' => $value->getDescription(),
31+
'deprecationReason'=> $value->getDeprecatedReason()
3132
];
3233
}
3334
parent::__construct($config);

0 commit comments

Comments
 (0)