The Home for Magento 2 Excellence

Quality-tested Magento 2 modules. Explore. Evaluate. Elevate. #magento2

1090 Modules
617 Ready
473 Need Help
🏆 Leaderboard
Stable v0.1.2

SSR GraphQL for Magento 2

neutromelabs/magento2-ssr-graphql

Adds server-side rendering of GraphQL queries to any Magento 2 frontend, preloading a query's response at page render so JavaScript has instant data without a first AJAX round-trip, with a simplified fetch() to repeat queries. Works well with AlpineJS.

14
Downloads
Below average
5
GitHub Stars
Below average
5mo ago
Last Release
0
Open Issues
Build Passing
Ready to install

Build Tests

Composer Install
DI Compile
Templates

Code Quality

CS Coding Standard
2 errors , 31 warnings
L1 PHPStan

Tested on Magento 2.4.9

Recent Test History

Each release is tested against the latest Magento version at that time.

v0.1.2 on Magento 2.4.9
Jun 1, 2026

Share This Module's Status

SSR GraphQL for Magento 2 Magento compatibility status badge

README

Loaded from GitHub
There should not be one to choose between PHP and GraphQL. 
Revolutionize your customer's experience with the best from both.

Magento 2 SSR GraphQL Module

Adds SSR GraphQL resolving capabilities to any Magento 2 frontend. Compatible with any theme. Works best with AlpineJS.

Overview

The idea is to write a normal GraphQL query, (which will be used on the frontend via JS,) AND automatically preload it's response at the page render, providing JS code with instant data/errors - without executing the "first" Ajax request.

Then, JS should operate as normal, with the access both to the query string, ssr data (variables, response) and simplified fetch(), to repeat the query, optionally passing new parameters.

Where To Use

Anywhere on your pages, when the same [available via GraphQL] content needs to be available to the customer at the page render time (PHP), while could be updated later (JS).

Typical use-cases:

  • pagination/lazy-load - the first set of the items could be preloaded at the page render, and paginated later, with the same GraphQL query and different variables
  • double-check - the "Add To Cart" button is rendered if the product is available for sale, and the same query is refresh-ed on click, to prevent stock races

How To Use

Simple example - paginated product list, over GraphQL.

  1. The phtml view must call the makeSsrGqlCall(query, variables) method, from the NeutromeLabs\SsrGraphql\ViewModel\SsrGraphqlViewModel view model, which returns JS fragment string representing object, to insert into the page html script tag.
var ssrGqlExampleObject = <?= $gql->makeSsrGqlCall(<<<GRAPHQL
query productsQuery(\$currentPage: Int!) {
    products (search: "", pageSize: 3, currentPage: \$currentPage) {
        items {
            sku
        }
    }
}
GRAPHQL, ['currentPage' => 1]) ?>;
renderData(); // some logic to present ssrGqlExampleObject to the customer
  1. While rendering this page, Magento will resolve the passed query and provide ssrGqlExampleObject JS variable with a special SSR GraphQL object
{
    // indicates, if the response is SSR-generated. true, if no "refresh" calls were made
    fresh: boolean,
    // "current" response data
    data?: object,
     // "current" response errors
    errors?: object[],
    ssr: {
        query: string, // GraphQL query string
        variables: object, // GraphQL variables, passed at the step 1
        response: object, // SSR GraphQL response
    },
    // fetches the same query with the merged variables from the ssr.variables and parameter
    fetch: (variables?: object) => Promise<object>, 
    // fetch(), then update the inner data and errors fields with the new response
    refresh: (variables?: object) => Promise<void>,
}
  1. The data from the JS variable could be presented to the customer right after the page load, with no "loaders" on the screen. Then those data could be updated, without the need to repeat the same GraphQL query again
currentPage++;

ssrGqlExampleObject.refresh({
    currentPage: currentPage
}).then(() => {
    renderData();
})

See the full example at https://your-magento-instance.test/ssrgql/example, and src/SsrGraphql/view/frontend/templates/example/1.phtml

This content is fetched directly from the module's GitHub repository. We are not the authors of this content and take no responsibility for its accuracy, completeness, or any consequences arising from its use.