Yireo_HyvaWithoutGraphQl
Replaces the GraphQL calls of various Hyvä templates with regular Magento controllers.
What it does
A few Hyvä templates fetch their data from the GraphQL endpoint. This module replaces those calls with regular Magento frontend controllers, so that the storefront no longer depends on the GraphQL API for these features.
| Hyvä template | Alpine component | Method | How |
|---|---|---|---|
| Magento_Review::customer/list.phtml | initReviewList | getReviewsList | JS proxy |
| Magento_Catalog::product/widget/viewed/js/recently-viewed-products.phtml | initRecentlyViewedProductsComponent | fetchProducts | JS proxy |
| Magento_Review::form.phtml | initReviewForm | placeReview | JS proxy |
| Magento_Theme::elements/slider.phtml | initSliderComponent<uniqid> | getProducts | template replacement |
The first three are left intact: an extra template is rendered right after the original one, which wraps the global component factory and swaps out that single method. The deprecated GraphQL product slider is replaced entirely, because its query is built from block arguments that only exist server side.
Both are done from a single plugin on Magento\Framework\View\TemplateEngine\Php, so widgets and
dynamically named blocks are covered as well. The template maps are DI arguments of
Yireo\HyvaWithoutGraphQl\Plugin\TemplateEngine\SwapGraphQlTemplates, so individual entries can be
removed in a project.
The controllers answer with exactly the same data structure as the GraphQL responses they replace, which is why the Hyvä templates keep rendering unchanged.
| Route | Method | Replaces |
|---|---|---|
| hyva-without-graphql/reviews/customer | GET | customer.reviews |
| hyva-without-graphql/reviews/save | POST | createProductReview |
| hyva-without-graphql/products/skus | GET | products(filter: {sku: {in: []}}) |
| hyva-without-graphql/products/slider | GET | the slider products query |
Installation
Install this package via composer (provided you have properly configured our composer API first):
composer require yireo/magento2-hyva-without-graph-ql
Next, enable this module:
bin/magento module:enable Yireo_HyvaWithoutGraphQl bin/magento setup:upgrade
Configuration
Stores > Configuration > General > Hyvä Without GraphQL > Settings > Enabled
(yireo_hyva_without_graph_ql/settings/enabled, default 1). When switched off, the templates are
left untouched and the controllers answer with a 404.
Security
reviews/savevalidates the Magento form key itself and answers with JSON instead of a redirect, and validates reCAPTCHA for form idproduct_reviewwhen it is configured.reviews/customeronly ever returns the reviews of the customer in the current session.- The slider parameters travel over the URL. The page size is capped at 100 and the sort attribute is limited to a whitelist.
- All responses are sent with
Cache-Control: no-store, since they depend on store, currency, customer group or customer session.
Notes and limitations
- A slider block that is configured with a custom
graphql_queryargument is no longer honoured. The structured arguments (product_skus,category_ids,price_from,price_to,page_size,sort_attribute,sort_direction,type) andproduct_filtersare supported.product_filtersis parsed byYireo\HyvaWithoutGraphQl\Model\ProductFilterParser, which understandseq,neq,in,nin,from,to,gt,gteq,lt,lteq,likeandmatch. Anything else is ignored and logged. - The recently viewed proxy only comes into play when
catalog/recently_products/synchronize_with_backendis enabled. Without it, Hyvä renders the widget straight from browser storage and never calls GraphQL in the first place. - The customer review list no longer waits for the GraphQL
signin_tokenof the private content section; the session cookie is enough for a regular controller. price_range.minimum_price.base_pricestays absent, matching the original GraphQL query.- The replacement slider template fixes two typos of the original:
getprevButtonClasses(nowgetPrevButtonClasses) andfillerSlideNumer(nowfillerSlideNumber). It also usesx-textinstead ofx-htmlfor the product name.
Current status
@dev
to the composer command.
Support
For getting support, create an Issue under the following project URL:
https://gitlab.yireo.com/loki-checkout/Yireo_HyvaWithoutGraphQl.git
Composer details
Yireo_HyvaWithoutGraphQlyireo/magento2-hyva-without-graph-ql
php: ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0
magento/framework: *
magento/module-catalog: *
magento/module-config: *
magento/module-customer: *
magento/module-review: *
magento/module-store: *
magento/module-theme: *
Releases
Changelog
Added
- Plugin
SwapGraphQlTemplatesonMagento\Framework\View\TemplateEngine\Phpthat replaces or extends Hyvä templates containing a GraphQL call. - JS proxies for
initReviewList::getReviewsList,initReviewForm::placeReviewandinitRecentlyViewedProductsComponent::fetchProducts. - GraphQL-free replacement of
Magento_Theme::elements/slider.phtml. - Frontend controllers
hyva-without-graphql/reviews/customer,hyva-without-graphql/reviews/save,hyva-without-graphql/products/skusandhyva-without-graphql/products/slider. - Store configuration
yireo_hyva_without_graph_ql/settings/enabledto switch the module off per store. - Unit tests for the filter parser, the request normalizer and the template plugin, plus integration tests for the four controllers.
Changed
- Added
phpandmagento/module-themerequirements tocomposer.json. - Synchronised
MODULE.jsonsequence withetc/module.xmland enabled PHPStan level 5 and PHPCS severity 6 in CI. - Made the GraphQL marker detection in
SwapGraphQlTemplatescase-insensitive. - Documented the CSRF bypass in
Reviews\Saveand clarifiedCustomerReviewProviderPHPDoc.