magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Magento Graph QL : route query product and cms-page caching issue

Open mandarzope opened this issue 3 years ago • 15 comments

Preconditions (*)

  1. Magento 2.4.3-p1
  2. Sample Data is imported

Steps to reproduce (*)

  1. Query using route(url:"<>")

Expected result (*)

  1. Response header should contain X-Magento-Tags and Cache-Control to be public

Actual result (*)

  1. X-Magento-Tags header is missing and Cache-Control is no-cache
  • [ ] Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.

After debugging I have found that vendor/magento/module-cms-url-rewrite-graph-ql/Model/Resolver/UrlRewrite/CmsUrlResolverIdentity.php:26 vendor/magento/module-catalog-url-rewrite-graph-ql/Model/Resolver/UrlRewrite/CatalogUrlResolverIdentity.php:36

expects a key 'id' to be present in $resolvedData $ids = [$selectedCacheTag, sprintf('%s_%s', $selectedCacheTag, $resolvedData['id'])];

A workaround solution is to overwrite the files vendor/magento/module-catalog-url-rewrite-graph-ql/Model/DataProvider/UrlRewrite/ProductDataProvider.php:48 $product = $this->productRepository->getById($id, false, $storeId); $result = $product->getData(); $result['id'] = $product->getId();

vendor/magento/module-cms-url-rewrite-graph-ql/Model/DataProvider/UrlRewrite/Page.php:49 $result = $this->pageDataProvider->getDataByPageId((int)$id); $result['type_id'] = $entity_type; $result['id'] = $result['page_id']

mandarzope avatar Jan 01 '22 06:01 mandarzope