Skip to content

Commit 3bbce2b

Browse files
committed
MAGETWO-81532: Support for Registered Customers
- adding customer module for implementing the field in graphql - adding token based authentication
1 parent f534469 commit 3bbce2b

File tree

22 files changed

+431
-46
lines changed

22 files changed

+431
-46
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Magento\GraphQl\Model\SchemaGeneratorInterface;
1616
use Magento\Framework\GraphQl\RequestProcessor;
1717
use Magento\Framework\GraphQl\ExceptionFormatter;
18-
use Magento\GraphQl\Model\Context;
18+
use Magento\GraphQl\Model\ResolverContext;
1919

2020
/**
2121
* Front controller for web API GraphQL area.
@@ -45,7 +45,7 @@ class GraphQl implements FrontControllerInterface
4545
/** @var ExceptionFormatter */
4646
private $graphQlError;
4747

48-
/** @var Context */
48+
/** @var ResolverContext */
4949
private $context;
5050

5151
/**
@@ -54,15 +54,15 @@ class GraphQl implements FrontControllerInterface
5454
* @param SerializerInterface $jsonSerializer
5555
* @param RequestProcessor $requestProcessor
5656
* @param ExceptionFormatter $graphQlError
57-
* @param Context $context
57+
* @param ResolverContext $context
5858
*/
5959
public function __construct(
6060
Response $response,
6161
SchemaGeneratorInterface $schemaGenerator,
6262
SerializerInterface $jsonSerializer,
6363
RequestProcessor $requestProcessor,
6464
ExceptionFormatter $graphQlError,
65-
Context $context
65+
ResolverContext $context
6666
) {
6767
$this->response = $response;
6868
$this->schemaGenerator = $schemaGenerator;

app/code/Magento/GraphQl/Model/FieldConfig.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ public function getFieldConfig(string $fieldName, array $arguments)
8181
]);
8282
}
8383
}
84-
return $this->instances[$fieldName];
84+
//not all fields have arguments
85+
if (isset($this->instances[$fieldName])) {
86+
return $this->instances[$fieldName];
87+
} else {
88+
return [];
89+
}
8590
}
8691
}

app/code/Magento/GraphQl/Model/Context.php renamed to app/code/Magento/GraphQl/Model/ResolverContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Magento\Framework\Api\AttributeValueFactory;
1111
use Magento\Framework\Api\ExtensionAttributesFactory;
1212

13-
class Context extends \Magento\Framework\Model\AbstractExtensibleModel implements ContextInterface
13+
class ResolverContext extends \Magento\Framework\Model\AbstractExtensibleModel implements ResolverContextInterface
1414
{
1515
/**#@+
1616
* Constants defined for type of context

app/code/Magento/GraphQl/Model/ContextInterface.php renamed to app/code/Magento/GraphQl/Model/ResolverContextInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
use Magento\Framework\Api\ExtensibleDataInterface;
1010

1111
/**
12-
* Context interface.
12+
* Resolver Context interface.
1313
*/
14-
interface ContextInterface extends ExtensibleDataInterface
14+
interface ResolverContextInterface extends ExtensibleDataInterface
1515
{
1616
/**
1717
* Get type of a customer

app/code/Magento/GraphQl/Model/ResolverInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ interface ResolverInterface
1515
* Parse arguments of a field and convert them to an array structure
1616
*
1717
* @param \Magento\Framework\GraphQl\ArgumentInterface[] $args
18-
* @param \Magento\GraphQl\Model\ContextInterface $context
18+
* @param \Magento\GraphQl\Model\ResolverContextInterface $context
1919
* @return array|null
2020
* @throws \Magento\Framework\GraphQl\Exception\GraphQlInputException|\Exception
2121
*/
22-
public function resolve(array $args, \Magento\GraphQl\Model\ContextInterface $context);
22+
public function resolve(array $args, \Magento\GraphQl\Model\ResolverContextInterface $context);
2323
}

app/code/Magento/GraphQl/etc/graphql/di.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,22 @@
1717
</argument>
1818
</arguments>
1919
</type>
20+
<type name="Magento\Authorization\Model\CompositeUserContext">
21+
<arguments>
22+
<argument name="userContexts" xsi:type="array">
23+
<item name="tokenUserContext" xsi:type="array">
24+
<item name="type" xsi:type="object">Magento\Webapi\Model\Authorization\TokenUserContext</item>
25+
<item name="sortOrder" xsi:type="string">10</item>
26+
</item>
27+
<item name="oauthUserContext" xsi:type="array">
28+
<item name="type" xsi:type="object">Magento\Webapi\Model\Authorization\OauthUserContext</item>
29+
<item name="sortOrder" xsi:type="string">40</item>
30+
</item>
31+
<item name="guestUserContext" xsi:type="array">
32+
<item name="type" xsi:type="object">Magento\Webapi\Model\Authorization\GuestUserContext</item>
33+
<item name="sortOrder" xsi:type="string">100</item>
34+
</item>
35+
</argument>
36+
</arguments>
37+
</type>
2038
</config>

app/code/Magento/GraphQlCatalog/Model/Resolver/Products.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
namespace Magento\GraphQlCatalog\Model\Resolver;
88

99
use Magento\Catalog\Api\ProductRepositoryInterface;
10-
use Magento\GraphQlCatalog\Model\Resolver\Products\Product;
10+
use Magento\GraphQlCatalog\Model\Resolver\Products\ProductDataProvider;
1111
use Magento\GraphQl\Model\ResolverInterface;
1212
use Magento\Framework\GraphQl\Argument\SearchCriteria\Builder;
1313
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
14-
use Magento\GraphQl\Model\ContextInterface;
14+
use Magento\GraphQl\Model\ResolverContextInterface;
1515

1616
/**
1717
* Products field resolver, used for GraphQL request processing.
@@ -29,29 +29,29 @@ class Products implements ResolverInterface
2929
private $searchCriteriaBuilder;
3030

3131
/**
32-
* @var Product
32+
* @var ProductDataProvider
3333
*/
34-
private $productResolver;
34+
private $productDataProvider;
3535

3636
/**
3737
* @param ProductRepositoryInterface $productRepository
3838
* @param Builder $searchCriteriaBuilder
39-
* @param \Magento\GraphQlCatalog\Model\Resolver\Products\Product $productResolver
39+
* @param ProductDataProvider $productDataProvider
4040
*/
4141
public function __construct(
4242
ProductRepositoryInterface $productRepository,
4343
Builder $searchCriteriaBuilder,
44-
Product $productResolver
44+
ProductDataProvider $productDataProvider
4545
) {
4646
$this->productRepository = $productRepository;
4747
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
48-
$this->productResolver = $productResolver;
48+
$this->productDataProvider = $productDataProvider;
4949
}
5050

5151
/**
5252
* {@inheritdoc}
5353
*/
54-
public function resolve(array $args, ContextInterface $context)
54+
public function resolve(array $args, ResolverContextInterface $context)
5555
{
5656
$searchCriteria = $this->searchCriteriaBuilder->build($args);
5757
$itemsResults = $this->productRepository->getList($searchCriteria);
@@ -60,7 +60,7 @@ public function resolve(array $args, ContextInterface $context)
6060

6161
$products = [];
6262
foreach ($items as $item) {
63-
$products[] = $this->productResolver->getProduct($item->getSku());
63+
$products[] = $this->productDataProvider->getProduct($item->getSku());
6464
}
6565

6666
$maxPages = ceil($itemsResults->getTotalCount() / $searchCriteria->getPageSize());

app/code/Magento/GraphQlCatalog/Model/Resolver/Products/FindArgument/ClauseConverter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Magento\GraphQl\Model\Type\ServiceContract\TypeGenerator;
1515

1616
/**
17-
* Converts the input value for "find" to a Clause|Connective format
17+
* Converts the input value for "find" to a @see Connective format
1818
*/
1919
class ClauseConverter
2020
{
@@ -113,7 +113,7 @@ private function getClausesFromAst(ReferenceType $referenceType, array $argument
113113
private function getCatalogProductFields()
114114
{
115115
$result = [];
116-
$attributes = $this->management->getAttributes('catalog_product', 4);
116+
$attributes = $this->management->getAttributes(\Magento\Catalog\Model\Product::ENTITY, 4);
117117
foreach ($attributes as $attribute) {
118118
if ((!$attribute->getIsUserDefined()) && !is_array($attribute)) {
119119
$result[$attribute->getAttributeCode()] = 'String';

app/code/Magento/GraphQlCatalog/Model/Resolver/Products/FindArgument/ValueParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(
3636
*/
3737
public function parse($value)
3838
{
39-
$filters = $this->clauseConverter->getFilterFromAst('product', $value);
39+
$filters = $this->clauseConverter->getFilterFromAst(\Magento\Catalog\Model\Product::ENTITY, $value);
4040
return $this->findArgumentValueFactory->create($filters);
4141
}
4242
}

app/code/Magento/GraphQlCatalog/Model/Resolver/Products/MediaGalleryEntries.php renamed to app/code/Magento/GraphQlCatalog/Model/Resolver/Products/MediaGalleryEntriesDataProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/**
1515
* Media gallery field resolver, used for GraphQL request processing.
1616
*/
17-
class MediaGalleryEntries
17+
class MediaGalleryEntriesDataProvider
1818
{
1919
/**
2020
* @var ProductAttributeMediaGalleryManagementInterface

0 commit comments

Comments
 (0)