Skip to content

Commit b3c194f

Browse files
committed
GraphQl-93: Implement support for variables in query
-- Fixes after CR
1 parent 0985244 commit b3c194f

File tree

4 files changed

+39
-55
lines changed

4 files changed

+39
-55
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/VariablesSupportQueryTest.php

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,77 +14,69 @@
1414

1515
class VariablesSupportQueryTest extends GraphQlAbstract
1616
{
17-
/**
18-
* @var ObjectManager
19-
*/
20-
private $objectManager;
21-
2217
/**
2318
* @var ProductRepositoryInterface
2419
*/
2520
private $productRepository;
2621

2722
protected function setUp()
2823
{
29-
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
30-
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
24+
$this->productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
3125
}
3226

3327
/**
34-
* Tests that Introspection is disabled when not in developer mode
35-
*
36-
* @magentoApiDataFixture Magento/Catalog/_files/product_simple_with_all_fields.php
37-
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
28+
* @magentoApiDataFixture Magento/Catalog/_files/products_list.php
3829
*/
3930
public function testQueryObjectVariablesSupport()
4031
{
41-
$productSku = 'simple';
32+
$productSku = 'simple-249';
33+
$minPrice = 153;
4234

4335
$query
4436
= <<<'QUERY'
45-
query GetProductsQuery($page: Int, $filterInput: ProductFilterInput){
37+
query GetProductsQuery($pageSize: Int, $filterInput: ProductFilterInput, $priceSort: SortEnum) {
4638
products(
47-
pageSize: 10
48-
currentPage: $page
39+
pageSize: $pageSize
4940
filter: $filterInput
50-
sort: {}
41+
sort: {price: $priceSort}
5142
) {
5243
items {
53-
name
44+
sku
45+
price {
46+
minimalPrice {
47+
amount {
48+
value
49+
currency
50+
}
51+
}
52+
}
5453
}
5554
}
5655
}
5756
QUERY;
57+
5858
$variables = [
59-
'page' => 1,
59+
'pageSize' => 1,
60+
'priceSort' => 'ASC',
6061
'filterInput' => [
61-
'sku' => [
62-
'like' => '%simple%'
63-
]
64-
]
62+
'min_price' => [
63+
'gt' => 150,
64+
],
65+
],
6566
];
6667

6768
$response = $this->graphQlQuery($query, $variables);
6869
/** @var \Magento\Catalog\Model\Product $product */
6970
$product = $this->productRepository->get($productSku, false, null, true);
7071

71-
$this->assertArrayHasKey('products', $response);
72-
$this->assertArrayHasKey('items', $response['products']);
73-
$this->assertEquals(1, count($response['products']['items']));
74-
$this->assertArrayHasKey(0, $response['products']['items']);
75-
$this->assertFields($product, $response['products']['items'][0]);
76-
}
77-
78-
/**
79-
* @param ProductInterface $product
80-
* @param array $actualResponse
81-
*/
82-
private function assertFields($product, $actualResponse)
83-
{
84-
$assertionMap = [
85-
['response_field' => 'name', 'expected_value' => $product->getName()],
86-
];
87-
88-
$this->assertResponseFields($actualResponse, $assertionMap);
72+
self::assertArrayHasKey('products', $response);
73+
self::assertArrayHasKey('items', $response['products']);
74+
self::assertEquals(1, count($response['products']['items']));
75+
self::assertArrayHasKey(0, $response['products']['items']);
76+
self::assertEquals($product->getSku(), $response['products']['items'][0]['sku']);
77+
self::assertEquals(
78+
$minPrice,
79+
$response['products']['items'][0]['price']['minimalPrice']['amount']['value']
80+
);
8981
}
9082
}

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,7 @@ public function __construct(
4848
}
4949

5050
/**
51-
* Get a data object with data pertaining to a GraphQL type's structural makeup.
52-
*
53-
* @param string $configElementName
54-
* @return ConfigElementInterface
55-
* @throws \LogicException
56-
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
51+
* @inheritdoc
5752
*/
5853
public function getConfigElement(string $configElementName) : ConfigElementInterface
5954
{
@@ -81,11 +76,7 @@ public function getConfigElement(string $configElementName) : ConfigElementInter
8176
}
8277

8378
/**
84-
* Return all type names declared in a GraphQL schema's configuration and their type.
85-
*
86-
* Format is ['name' => 'example value', 'type' = 'example value']
87-
*
88-
* @return array $types
79+
* @inheritdoc
8980
*/
9081
public function getDeclaredTypes() : array
9182
{

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ interface ConfigInterface
2525
public function getConfigElement(string $configElementName) : ConfigElementInterface;
2626

2727
/**
28-
* Return all type names from a GraphQL schema's configuration.
28+
* Return all type names declared in a GraphQL schema's configuration and their type.
2929
*
30-
* @return string[]
30+
* Format is ['name' => 'example value', 'type' = 'example value']
31+
*
32+
* @return array $types
3133
*/
32-
public function getDeclaredTypeNames() : array;
34+
public function getDeclaredTypes() : array;
3335
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
use Magento\Framework\GraphQl\ConfigInterface;
1111
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
12-
use Magento\Framework\GraphQl\Schema\Type\InputTypeInterface;
1312
use Magento\Framework\GraphQl\Schema\TypeInterface;
1413
use Magento\Framework\ObjectManagerInterface;
1514
use Magento\Framework\Phrase;

0 commit comments

Comments
 (0)