Skip to content

Commit eff2845

Browse files
authored
ENGCOM-4160: Add queries for directory information #313
2 parents 8dfe26a + 4f6081a commit eff2845

File tree

14 files changed

+443
-2
lines changed

14 files changed

+443
-2
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\DirectoryGraphQl\Model\Resolver;
9+
10+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
11+
use Magento\Framework\GraphQl\Config\Element\Field;
12+
use Magento\Framework\GraphQl\Query\ResolverInterface;
13+
use Magento\Framework\Reflection\DataObjectProcessor;
14+
use Magento\Directory\Api\CountryInformationAcquirerInterface;
15+
use Magento\Directory\Api\Data\CountryInformationInterface;
16+
17+
/**
18+
* Countries field resolver, used for GraphQL request processing.
19+
*/
20+
class Countries implements ResolverInterface
21+
{
22+
/**
23+
* @var DataObjectProcessor
24+
*/
25+
private $dataProcessor;
26+
27+
/**
28+
* @var CountryInformationAcquirerInterface
29+
*/
30+
private $countryInformationAcquirer;
31+
32+
/**
33+
* @param DataObjectProcessor $dataProcessor
34+
* @param CountryInformationAcquirerInterface $countryInformationAcquirer
35+
*/
36+
public function __construct(
37+
DataObjectProcessor $dataProcessor,
38+
CountryInformationAcquirerInterface $countryInformationAcquirer
39+
) {
40+
$this->dataProcessor = $dataProcessor;
41+
$this->countryInformationAcquirer = $countryInformationAcquirer;
42+
}
43+
44+
/**
45+
* @inheritdoc
46+
*/
47+
public function resolve(
48+
Field $field,
49+
$context,
50+
ResolveInfo $info,
51+
array $value = null,
52+
array $args = null
53+
) {
54+
$countries = $this->countryInformationAcquirer->getCountriesInfo();
55+
56+
$output = [];
57+
foreach ($countries as $country) {
58+
$output[] = $this->dataProcessor->buildOutputDataArray($country, CountryInformationInterface::class);
59+
}
60+
61+
return $output;
62+
}
63+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\DirectoryGraphQl\Model\Resolver;
9+
10+
use Magento\Framework\Exception\NoSuchEntityException;
11+
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
12+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
13+
use Magento\Framework\GraphQl\Config\Element\Field;
14+
use Magento\Framework\GraphQl\Query\ResolverInterface;
15+
use Magento\Framework\Reflection\DataObjectProcessor;
16+
use Magento\Directory\Api\CountryInformationAcquirerInterface;
17+
use Magento\Directory\Api\Data\CountryInformationInterface;
18+
19+
/**
20+
* Country field resolver, used for GraphQL request processing.
21+
*/
22+
class Country implements ResolverInterface
23+
{
24+
/**
25+
* @var DataObjectProcessor
26+
*/
27+
private $dataProcessor;
28+
29+
/**
30+
* @var CountryInformationAcquirerInterface
31+
*/
32+
private $countryInformationAcquirer;
33+
34+
/**
35+
* @param DataObjectProcessor $dataProcessor
36+
* @param CountryInformationAcquirerInterface $countryInformationAcquirer
37+
*/
38+
public function __construct(
39+
DataObjectProcessor $dataProcessor,
40+
CountryInformationAcquirerInterface $countryInformationAcquirer
41+
) {
42+
$this->dataProcessor = $dataProcessor;
43+
$this->countryInformationAcquirer = $countryInformationAcquirer;
44+
}
45+
46+
/**
47+
* @inheritdoc
48+
*/
49+
public function resolve(
50+
Field $field,
51+
$context,
52+
ResolveInfo $info,
53+
array $value = null,
54+
array $args = null
55+
) {
56+
try {
57+
$country = $this->countryInformationAcquirer->getCountryInfo($args['id']);
58+
} catch (NoSuchEntityException $exception) {
59+
throw new GraphQlNoSuchEntityException(__($exception->getMessage()), $exception);
60+
}
61+
62+
return $this->dataProcessor->buildOutputDataArray(
63+
$country,
64+
CountryInformationInterface::class
65+
);
66+
}
67+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\DirectoryGraphQl\Model\Resolver;
9+
10+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
11+
use Magento\Framework\GraphQl\Config\Element\Field;
12+
use Magento\Framework\GraphQl\Query\ResolverInterface;
13+
use Magento\Framework\Reflection\DataObjectProcessor;
14+
use Magento\Directory\Api\CurrencyInformationAcquirerInterface;
15+
use Magento\Directory\Api\Data\CurrencyInformationInterface;
16+
17+
/**
18+
* Currency field resolver, used for GraphQL request processing.
19+
*/
20+
class Currency implements ResolverInterface
21+
{
22+
/**
23+
* @var DataObjectProcessor
24+
*/
25+
private $dataProcessor;
26+
27+
/**
28+
* @var CurrencyInformationAcquirerInterface
29+
*/
30+
private $currencyInformationAcquirer;
31+
32+
/**
33+
* @param DataObjectProcessor $dataProcessor
34+
* @param CurrencyInformationAcquirerInterface $currencyInformationAcquirer
35+
*/
36+
public function __construct(
37+
DataObjectProcessor $dataProcessor,
38+
CurrencyInformationAcquirerInterface $currencyInformationAcquirer
39+
) {
40+
$this->dataProcessor = $dataProcessor;
41+
$this->currencyInformationAcquirer = $currencyInformationAcquirer;
42+
}
43+
44+
/**
45+
* @inheritdoc
46+
*/
47+
public function resolve(
48+
Field $field,
49+
$context,
50+
ResolveInfo $info,
51+
array $value = null,
52+
array $args = null
53+
) {
54+
return $this->dataProcessor->buildOutputDataArray(
55+
$this->currencyInformationAcquirer->getCurrencyInfo(),
56+
CurrencyInformationInterface::class
57+
);
58+
}
59+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# DirectoryGraphQl
2+
3+
**DirectoryGraphQl** provides type and resolver information for the GraphQl module
4+
to generate directory information endpoints.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Directory Graph Ql Functional Tests
2+
3+
The Functional Test Module for **Magento Directory Graph Ql** module.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "magento/module-directory-graph-ql",
3+
"description": "N/A",
4+
"type": "magento2-module",
5+
"require": {
6+
"php": "~7.1.3||~7.2.0",
7+
"magento/module-directory": "*",
8+
"magento/framework": "*"
9+
},
10+
"suggest": {
11+
"magento/module-graph-ql": "*"
12+
},
13+
"license": [
14+
"OSL-3.0",
15+
"AFL-3.0"
16+
],
17+
"autoload": {
18+
"files": [
19+
"registration.php"
20+
],
21+
"psr-4": {
22+
"Magento\\DirectoryGraphQl\\": ""
23+
}
24+
}
25+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9+
<module name="Magento_DirectoryGraphQl"/>
10+
</config>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright © Magento, Inc. All rights reserved.
2+
# See COPYING.txt for license details.
3+
4+
type Query {
5+
currency: Currency @resolver(class: "Magento\\DirectoryGraphQl\\Model\\Resolver\\Currency") @doc(description: "The currency query returns information about store currency.")
6+
countries: [Country] @resolver(class: "Magento\\DirectoryGraphQl\\Model\\Resolver\\Countries") @doc(description: "The countries query provides information for all countries.")
7+
country (id: String): Country @resolver(class: "Magento\\DirectoryGraphQl\\Model\\Resolver\\Country") @doc(description: "The countries query provides information for a single country.")
8+
}
9+
10+
type Currency {
11+
base_currency_code: String
12+
base_currency_symbol: String
13+
default_display_currecy_code: String
14+
default_display_currecy_symbol: String
15+
available_currency_codes: [String]
16+
exchange_rates: [ExchangeRate]
17+
}
18+
19+
type ExchangeRate {
20+
currency_to: String
21+
rate: Float
22+
}
23+
24+
type Country {
25+
id: String
26+
two_letter_abbreviation: String
27+
three_letter_abbreviation: String
28+
full_name_locale: String
29+
full_name_english: String
30+
available_regions: [Region]
31+
}
32+
33+
type Region {
34+
id: Int
35+
code: String
36+
name: String
37+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\Framework\Component\ComponentRegistrar;
8+
9+
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_DirectoryGraphQl', __DIR__);

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
"magento/module-developer": "*",
143143
"magento/module-dhl": "*",
144144
"magento/module-directory": "*",
145+
"magento/module-directory-graph-ql": "*",
145146
"magento/module-downloadable": "*",
146147
"magento/module-downloadable-graph-ql": "*",
147148
"magento/module-downloadable-import-export": "*",

0 commit comments

Comments
 (0)