Download the PHP package hyva-themes/magento2-graphql-view-model without Composer
On this page you can find all versions of the php package hyva-themes/magento2-graphql-view-model. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hyva-themes/magento2-graphql-view-model
More information about hyva-themes/magento2-graphql-view-model
Files in hyva-themes/magento2-graphql-view-model
Package magento2-graphql-view-model
Short Description Provide ability to customize GraphQL queries and mutations for Hyvä themes.
License BSD-3-Clause
Informations about the package magento2-graphql-view-model
Hyvä Themes - GraphQL ViewModel module
hyva-themes/magento2-graphql-view-model
This module adds a GraphQL ViewModel to allow GraphQL queries and mutations to be customized before they are rendered in the output.
Compatible with Magento 2.3.4 and higher.
What does it do?
It provides:
\Hyva\GraphqlViewModel\ViewModel\GraphqlViewModel
, to be accessed via the view model registry (or injected via Layout XML).\Hyva\GraphqlViewModel\Model\GraphqlQueryEditor
which can be used to add fields and arguments to GraphQL queries.- The event
hyva_graphql_render_before_
+ query identifier Event observers receive the query string and can manipulate it with theGraphqlQueryEditor
Usage
In .phtml
templates, to make queries customizable, wrap them with the GraphqlViewModel::query()
method:
The first argument is the event name suffix.
The second argument is the query or mutation as a string.
The third argument is optional and - if specified - will be merged into the event arguments.
In the above example the full event name would be hyva_graphql_render_before_product_list_query
To manipulate a query in an event observer, the GraphqlQueryEditor can be used:
The result of the example method call
is that in the query the fields at the specified path are set:
Both the addFieldIn
and the addArgumentIn
methods are idempotent, so if the specified values already exist in the
query string they are not changed.
The addArgumentIn
method can be used to add new arguments to queries or mutations, or to overwrite values of existing arguments.
For more examples including inline fragments please have a look at the \Hyva\GraphqlViewModel\Model\GraphqlQueryEditorTest
class.
Installation
-
Install via composer
- Enable module
Configuration
No configuration needed.
License
The BSD-3-Clause License. Please see License File for more information.
All versions of magento2-graphql-view-model with dependencies
magento/framework Version ^101.0.0 || ^102.0.0 || ^103.0.0
webonyx/graphql-php Version ^14.0.0 || ^15.0.0