Magento 2.4.x
You can check in magento default vendor. Please check this schema.graphqls file at magentoRoot/vendor/magento/module-catalog-graph-ql/etc/schema.graphqls. In this file there are many query and mutation are define which is by default magento provides. In this file we see below code:
products (
search: String @doc(description: "Performs a full-text search using the specified key words."),
filter: ProductAttributeFilterInput @doc(description: "Identifies which product attributes to search for and return."),
pageSize: Int = 20 @doc(description: "Specifies the maximum number of results to return at once. This attribute is optional."),
currentPage: Int = 1 @doc(description: "Specifies which page of results to return. The default value is 1."),
sort: ProductAttributeSortInput @doc(description: "Specifies which attributes to sort on, and whether to return the results in ascending or descending order.")
): Products
@resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Products") @doc(description: "The products query searches for products that match the criteria specified in the search and filter attributes.") @cache(cacheIdentity: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\Identity")
For synonyms, you can modify this query as per your requirement. You can also add one more parameter for adding synonyms or you can modify the resolver file.
Resolver File Path: magentoRoot/vendor/magento/module-catalog-graph-ql/Model/Resolver/Products.php
Example: Overwrite GraphQL Resolver File
app/code/VendoreName/GraphQLCustomize/etc/graphql
di.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\CatalogGraphQl\Model\Resolver\Products" type="VendoreName\GraphQLCustomize\Model\Resolver\Products"/>
</config>
app/code/VendoreName/GraphQLCustomize/Model/Resolver
Products.php
<?php
declare(strict_types=1);
namespace VendoreName\GraphQLCustomize\Model\Resolver;
use Magento\CatalogGraphQl\Model\Resolver\Products\Query\ProductQueryInterface;
use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Catalog\Model\Layer\Resolver;
use Magento\CatalogGraphQl\DataProvider\Product\SearchCriteriaBuilder;
/**
* Products field resolver, used for GraphQL request processing.
*/
class Products implements ResolverInterface
{
/**
* @var ProductQueryInterface
*/
private $searchQuery;
/**
* @var SearchCriteriaBuilder
*/
private $searchApiCriteriaBuilder;
/**
* @param ProductQueryInterface $searchQuery
* @param SearchCriteriaBuilder|null $searchApiCriteriaBuilder
*/
public function __construct(
ProductQueryInterface $searchQuery,
SearchCriteriaBuilder $searchApiCriteriaBuilder = null
) {
$this->searchQuery = $searchQuery;
$this->searchApiCriteriaBuilder = $searchApiCriteriaBuilder ??
\Magento\Framework\App\ObjectManager::getInstance()->get(SearchCriteriaBuilder::class);
}
/**
* @inheritdoc
*/
public function resolve(
Field $field,
$context,
ResolveInfo $info,
array $value = null,
array $args = null
) {
$data = [];
$data[] = "You have been overrited resolver file";
return $data;
}
}
For more Click Here:
- https://magento.stackexchange.com/a/353491/82670
- https://magento.stackexchange.com/a/353494/82670