Skip to content

Commit ce1485f

Browse files
committed
B2B-2658: Implement GraphQL Resolver Cache for Customer query
- added hydration skip procedure
1 parent de0da1b commit ce1485f

File tree

6 files changed

+30
-34
lines changed

6 files changed

+30
-34
lines changed

app/code/Magento/CustomerGraphQl/Model/Customer/ExtractCustomerData.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ function (array $customAttribute) {
101101
$customerData['id'] = null;
102102

103103
$customerData['model'] = $customer;
104+
$customerData['model_id'] = $customer->getId();
104105

105106
//'dob' is deprecated, 'date_of_birth' is used instead.
106107
if (!empty($customerData['dob'])) {

app/code/Magento/CustomerGraphQl/Model/Resolver/CacheKey/FactorProvider/ParentCustomerEntityId.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public function getFactorName(): string
3131
/**
3232
* @inheritDoc
3333
*/
34-
public function getFactorValue(ContextInterface $context, ?array $parentValue = null): string
34+
public function getFactorValue(ContextInterface $context, array $plainParentValue = null): string
3535
{
36-
return (string)$parentValue['model_id'];
36+
return (string)$plainParentValue['model_id'];
3737
}
3838
}

app/code/Magento/GraphQlResolverCache/Model/Resolver/Result/CacheKey/Calculator.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Exception;
1111
use Magento\Framework\ObjectManagerInterface;
1212
use Magento\GraphQl\Model\Query\ContextFactoryInterface;
13-
use Magento\GraphQlResolverCache\Model\Resolver\Result\CacheKey\ParentValue\FactorInterface as ParentValueFactorInterface;
1413
use Magento\GraphQlResolverCache\Model\Resolver\Result\CacheKey\ParentValue\ProcessedValueFactorInterface;
1514
use Magento\GraphQlResolverCache\Model\Resolver\Result\CacheKey\ParentValue\PlainValueFactorInterface;
1615
use Magento\GraphQlResolverCache\Model\Resolver\Result\ValueProcessorInterface;
@@ -89,7 +88,9 @@ public function calculateCacheKey(?array $parentResolverData = null): ?string
8988
$this->initializeFactorProviderInstances();
9089
$keys = [];
9190
foreach ($this->factorProviderInstances as $provider) {
92-
if ($provider instanceof ParentValueFactorInterface) {
91+
if ($provider instanceof ProcessedValueFactorInterface
92+
|| $provider instanceof PlainValueFactorInterface
93+
) {
9394
// trigger data hydration for key calculation if factor needs the hydrated values
9495
if (is_array($parentResolverData) && $provider instanceof ProcessedValueFactorInterface) {
9596
$this->valueProcessor->preProcessParentValue($parentResolverData);

app/code/Magento/GraphQlResolverCache/Model/Resolver/Result/CacheKey/ParentValue/FactorInterface.php

Lines changed: 0 additions & 26 deletions
This file was deleted.

app/code/Magento/GraphQlResolverCache/Model/Resolver/Result/CacheKey/ParentValue/PlainValueFactorInterface.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,20 @@
77

88
namespace Magento\GraphQlResolverCache\Model\Resolver\Result\CacheKey\ParentValue;
99

10+
use Magento\GraphQl\Model\Query\ContextInterface;
11+
use Magento\GraphQlResolverCache\Model\Resolver\Result\CacheKey\GenericFactorInterface;
12+
1013
/**
1114
* Interface for key factors that are used to calculate the resolver cache key.
1215
*/
13-
interface PlainValueFactorInterface extends FactorInterface
16+
interface PlainValueFactorInterface extends GenericFactorInterface
1417
{
15-
18+
/**
19+
* Returns the runtime value that should be used as factor.
20+
*
21+
* @param ContextInterface $context
22+
* @param array|null $plainParentValue
23+
* @return string
24+
*/
25+
public function getFactorValue(ContextInterface $context, array $plainParentValue = null): string;
1626
}

app/code/Magento/GraphQlResolverCache/Model/Resolver/Result/CacheKey/ParentValue/ProcessedValueFactorInterface.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,20 @@
77

88
namespace Magento\GraphQlResolverCache\Model\Resolver\Result\CacheKey\ParentValue;
99

10+
use Magento\GraphQl\Model\Query\ContextInterface;
11+
use Magento\GraphQlResolverCache\Model\Resolver\Result\CacheKey\GenericFactorInterface;
12+
1013
/**
1114
* Interface for key factors that are used to calculate the resolver cache key.
1215
*/
13-
interface ProcessedValueFactorInterface extends FactorInterface
16+
interface ProcessedValueFactorInterface extends GenericFactorInterface
1417
{
15-
18+
/**
19+
* Returns the runtime value that should be used as factor.
20+
*
21+
* @param ContextInterface $context
22+
* @param array|null $processedParentValue
23+
* @return string
24+
*/
25+
public function getFactorValue(ContextInterface $context, ?array $processedParentValue = null): string;
1626
}

0 commit comments

Comments
 (0)