Skip to content

Commit 6aad51f

Browse files
author
Oleksii Korshenko
committed
Merge remote-tracking branch 'mainline/develop' into MAGETWO-83562-PR-12155
2 parents 943e6b9 + 2321610 commit 6aad51f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+3403
-292
lines changed

app/code/Magento/Catalog/Model/Category/DataProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,8 @@ private function convertValues($category, $categoryData)
494494

495495
$categoryData[$attributeCode][0]['name'] = $fileName;
496496
$categoryData[$attributeCode][0]['url'] = $category->getImageUrl($attributeCode);
497-
$categoryData['image'][0]['size'] = isset($stat) ? $stat['size'] : 0;
498-
$categoryData['image'][0]['type'] = $mime;
497+
$categoryData[$attributeCode][0]['size'] = isset($stat) ? $stat['size'] : 0;
498+
$categoryData[$attributeCode][0]['type'] = $mime;
499499
}
500500
}
501501
}

app/code/Magento/GraphQl/Controller/GraphQl.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Magento\Framework\App\FrontControllerInterface;
1111
use Magento\Framework\App\RequestInterface;
1212
use Magento\Framework\App\ResponseInterface;
13+
use Magento\Framework\Exception\LocalizedException;
14+
use Magento\Framework\Serialize\SerializerInterface;
1315
use Magento\Framework\Webapi\Response;
1416
use Magento\GraphQl\Model\SchemaGeneratorInterface;
1517

@@ -29,17 +31,23 @@ class GraphQl implements FrontControllerInterface
2931
private $schemaGenerator;
3032

3133
/**
32-
* Initialize dependencies
33-
*
34+
* @var SerializerInterface
35+
*/
36+
private $jsonSerializer;
37+
38+
/**
3439
* @param Response $response
3540
* @param SchemaGeneratorInterface $schemaGenerator
41+
* @param SerializerInterface $jsonSerializer
3642
*/
3743
public function __construct(
3844
Response $response,
39-
SchemaGeneratorInterface $schemaGenerator
45+
SchemaGeneratorInterface $schemaGenerator,
46+
SerializerInterface $jsonSerializer
4047
) {
4148
$this->response = $response;
4249
$this->schemaGenerator = $schemaGenerator;
50+
$this->jsonSerializer = $jsonSerializer;
4351
}
4452

4553
/**
@@ -54,10 +62,10 @@ public function dispatch(RequestInterface $request)
5462
if ($request->getHeader('Content-Type')
5563
&& strpos($request->getHeader('Content-Type'), 'application/json') !== false
5664
) {
57-
$raw = file_get_contents('php://input') ?: '';
58-
$data = json_decode($raw, true);
65+
$content = $request->getContent();
66+
$data = $this->jsonSerializer->unserialize($content);
5967
} else {
60-
$data = $_REQUEST;
68+
throw new LocalizedException(__('Request content type must be application/json'));
6169
}
6270
$schema = $this->schemaGenerator->generate();
6371
$result = \GraphQL\GraphQL::execute(
@@ -71,7 +79,10 @@ public function dispatch(RequestInterface $request)
7179
$result['extensions']['exception'] = FormattedError::createFromException($error);
7280
$this->response->setStatusCode(500);
7381
}
74-
$this->response->setBody(json_encode($result))->setHeader('Content-Type', 'application/json');
82+
$this->response->setBody($this->jsonSerializer->serialize($result))->setHeader(
83+
'Content-Type',
84+
'application/json'
85+
);
7586
return $this->response;
7687
}
7788
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\GraphQl\Model\GraphQl;
7+
8+
use Magento\GraphQl\Model\GraphQl\Clause\ReferenceType;
9+
10+
class Clause
11+
{
12+
/**
13+
* @var ReferenceType
14+
*/
15+
private $referenceType;
16+
17+
/**
18+
* @var string
19+
*/
20+
private $fieldName;
21+
22+
/**
23+
* @var string
24+
*/
25+
private $clauseType;
26+
27+
/**
28+
* @var string
29+
*/
30+
private $clauseValue;
31+
32+
/**
33+
* @param ReferenceType $referenceType
34+
* @param string $fieldName
35+
* @param string $clauseType
36+
* @param string|array $clauseValue
37+
*/
38+
public function __construct(
39+
ReferenceType $referenceType,
40+
string $fieldName,
41+
string $clauseType,
42+
$clauseValue
43+
) {
44+
$this->referenceType = $referenceType;
45+
$this->fieldName = $fieldName;
46+
$this->clauseType = $clauseType;
47+
$this->clauseValue = $clauseValue;
48+
}
49+
50+
/**
51+
* @return ReferenceType
52+
*/
53+
public function getReferencedType()
54+
{
55+
return $this->referenceType;
56+
}
57+
58+
/**
59+
* @return string
60+
*/
61+
public function getFieldName()
62+
{
63+
return $this->fieldName;
64+
}
65+
66+
/**
67+
* @return string
68+
*/
69+
public function getClauseType()
70+
{
71+
return $this->clauseType;
72+
}
73+
74+
/**
75+
* @return string|array
76+
*/
77+
public function getClauseValue()
78+
{
79+
return $this->clauseValue;
80+
}
81+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\GraphQl\Model\GraphQl\Clause;
7+
8+
/**
9+
* Class EntityReference
10+
*/
11+
class ReferenceType
12+
{
13+
/**
14+
* @var ReferenceType
15+
*/
16+
private $referenceType;
17+
18+
/**
19+
* @var string
20+
*/
21+
private $entityType;
22+
23+
/**
24+
* @var string
25+
*/
26+
private $linkField;
27+
28+
/**
29+
* @param string $entityType
30+
* @param string|null $linkField
31+
* @param ReferenceType|null $referenceType
32+
*/
33+
public function __construct(
34+
string $entityType,
35+
string $linkField = null,
36+
ReferenceType $referenceType = null
37+
) {
38+
$this->entityType = $entityType;
39+
$this->linkField = $linkField;
40+
$this->referenceType = $referenceType;
41+
}
42+
43+
/**
44+
* @return ReferenceType
45+
*/
46+
public function getReferenceType()
47+
{
48+
return $this->referenceType;
49+
}
50+
51+
/**
52+
* @return string
53+
*/
54+
public function getLinkField()
55+
{
56+
return $this->linkField;
57+
}
58+
59+
/**
60+
* @return string
61+
*/
62+
public function getEntityType()
63+
{
64+
return $this->entityType;
65+
}
66+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\GraphQl\Model\GraphQl\Clause;
7+
8+
use Magento\Framework\ObjectManagerInterface;
9+
10+
/**
11+
* Class ReferenceTypeFactory
12+
*/
13+
class ReferenceTypeFactory
14+
{
15+
/**
16+
* @var ObjectManagerInterface
17+
*/
18+
private $objectManager;
19+
20+
/**
21+
* @param ObjectManagerInterface $objectManager
22+
*/
23+
public function __construct(
24+
ObjectManagerInterface $objectManager
25+
) {
26+
$this->objectManager = $objectManager;
27+
}
28+
29+
/**
30+
* Create ReferenceType
31+
*
32+
* @param string $entityType
33+
* @param string|null $linkField
34+
* @param ReferenceType|null $referenceType
35+
* @return ReferenceType
36+
*/
37+
public function create(string $entityType, string $linkField = null, ReferenceType $referenceType = null)
38+
{
39+
return $this->objectManager->create(
40+
ReferenceType::class,
41+
[
42+
'entityType' => $entityType,
43+
'linkField' => $linkField,
44+
'referenceType' => $referenceType
45+
]
46+
);
47+
}
48+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\GraphQl\Model\GraphQl;
7+
8+
use Magento\Framework\ObjectManagerInterface;
9+
use Magento\GraphQl\Model\GraphQl\Clause\ReferenceType;
10+
11+
/**
12+
* Class ClauseFactory
13+
*/
14+
class ClauseFactory
15+
{
16+
/**
17+
* @var ObjectManagerInterface
18+
*/
19+
private $objectManager;
20+
21+
/**
22+
* @param ObjectManagerInterface $objectManager
23+
*/
24+
public function __construct(
25+
ObjectManagerInterface $objectManager
26+
) {
27+
$this->objectManager = $objectManager;
28+
}
29+
30+
/**
31+
* Create a clause
32+
*
33+
* @param ReferenceType $referenceType
34+
* @param string $fieldName
35+
* @param string $clauseType
36+
* @param string|array $clauseValue
37+
* @return Clause
38+
*/
39+
public function create(
40+
ReferenceType $referenceType,
41+
string $fieldName,
42+
string $clauseType,
43+
$clauseValue
44+
) {
45+
return $this->objectManager->create(
46+
Clause::class,
47+
[
48+
'referenceType' => $referenceType,
49+
'fieldName' => $fieldName,
50+
'clauseType' => $clauseType,
51+
'clauseValue' => $clauseValue
52+
]
53+
);
54+
}
55+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\GraphQl\Model\GraphQl;
7+
8+
/**
9+
* Class Represents logical connective
10+
*/
11+
class Connective
12+
{
13+
/**
14+
* @var string
15+
*/
16+
private $operator;
17+
18+
/**
19+
* @var array
20+
*/
21+
private $conditions;
22+
23+
/**
24+
* @param Operator $operator
25+
* @param array $conditions
26+
*/
27+
public function __construct(
28+
Operator $operator,
29+
array $conditions
30+
) {
31+
$this->operator = $operator;
32+
$this->conditions = $conditions;
33+
}
34+
35+
/**
36+
* @return Operator
37+
*/
38+
public function getOperator()
39+
{
40+
return $this->operator;
41+
}
42+
43+
/**
44+
* @return Connective[]|Clause[]
45+
*/
46+
public function getConditions()
47+
{
48+
return $this->conditions;
49+
}
50+
}

0 commit comments

Comments
 (0)