Skip to content

Commit

Permalink
added personalizing parameters to search queries in API
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasLudvik committed Mar 12, 2024
1 parent 7f9dc17 commit 2127289
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/Model/Product/Connection/ProductConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function createConnectionForAll(
ProductFilterData $productFilterData,
?string $orderingMode = null,
): ProductConnection {
$searchText = $argument['search'] ?? '';
$searchText = $argument['searchInput']['search'] ?? '';
$productFilterOptionsClosure = $this->getProductFilterOptionsClosure($productFilterData, $searchText);

return $this->createConnection(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function getArticlesSearchResults(
Argument $argument,
): Promise|array {
return $this->combinedArticleElasticsearchFacade->getArticlesBySearchText(
$argument['search'] ?? '',
$argument['searchInput']['search'] ?? '',
$this->domain->getId(),
ArticlesSearchQuery::ARTICLE_SEARCH_LIMIT,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(
public function getBrandSearchResults(
Argument $argument,
): Promise|array {
$searchText = $argument['search'] ?? '';
$searchText = $argument['searchInput']['search'] ?? '';

return $this->brandFacade->getBrandsBySearchText($searchText);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Model/Resolver/Category/Search/CategoriesSearchQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace Shopsys\FrontendApiBundle\Model\Resolver\Category\Search;

use GraphQL\Executor\Promise\Promise;
use Overblog\GraphQLBundle\Definition\Argument;
use Overblog\GraphQLBundle\Relay\Connection\ConnectionInterface;
use Shopsys\FrameworkBundle\Component\Domain\Domain;
use Shopsys\FrontendApiBundle\Component\Validation\PageSizeValidator;
use Shopsys\FrontendApiBundle\Model\Resolver\AbstractQuery;
Expand All @@ -23,9 +25,9 @@ public function __construct(

/**
* @param \Overblog\GraphQLBundle\Definition\Argument $argument
* @return \Overblog\GraphQLBundle\Relay\Connection\ConnectionInterface|object
* @return \GraphQL\Executor\Promise\Promise|\Overblog\GraphQLBundle\Relay\Connection\ConnectionInterface
*/
public function categoriesSearchQuery(Argument $argument)
public function categoriesSearchQuery(Argument $argument): Promise|ConnectionInterface
{
PageSizeValidator::checkMaxPageSize($argument);
$this->setDefaultFirstOffsetIfNecessary($argument);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(
public function getCategoriesSearchResults(
Argument $argument,
): Promise|ConnectionInterface {
$searchText = $argument['search'] ?? '';
$searchText = $argument['searchInput']['search'] ?? '';

$paginator = new Paginator(function ($offset, $limit) use ($searchText) {
return $this->categoryFacade->getVisibleCategoriesBySearchText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function getProductsSearchResults(
Argument $argument,
ProductFilterData $productFilterData,
): ProductConnection {
$search = $argument['search'] ?? '';
$search = $argument['searchInput']['search'] ?? '';

return $this->productConnectionFactory->createConnectionForAll(
function ($offset, $limit) use ($search, $productFilterData) {
Expand Down
18 changes: 8 additions & 10 deletions src/Resources/config/graphql-types/QueryDecorator.types.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ QueryDecorator:
type: "[Brand!]!"
resolve: "@=query('brandSearchQuery', args)"
args:
search:
type: "String!"
searchInput:
type: "SearchInput!"
description: "Returns list of searched brands"
categories:
type: '[Category!]!'
Expand All @@ -19,8 +19,8 @@ QueryDecorator:
argsBuilder: "Relay::Connection"
resolve: "@=query('categoriesSearchQuery', args)"
args:
search:
type: "String!"
searchInput:
type: "SearchInput!"
description: "Returns list of searched categories that can be paginated using `first`, `last`, `before` and `after` keywords"
products:
type: "ProductConnection"
Expand Down Expand Up @@ -48,10 +48,8 @@ QueryDecorator:
resolve: "@=query('productsSearchQuery', args)"
complexity: "@=dynamicPaginationComplexity(args)"
args:
search:
type: "String!"
isAutocomplete:
type: "Boolean!"
searchInput:
type: "SearchInput!"
description: "Returns list of searched products that can be paginated using `first`, `last`, `before` and `after` keywords"
RegularProduct:
type: 'RegularProduct'
Expand Down Expand Up @@ -125,8 +123,8 @@ QueryDecorator:
type: "[ArticleInterface!]!"
resolve: "@=query('articlesSearchQuery', args)"
args:
search:
type: "String!"
searchInput:
type: "SearchInput!"
description: "Returns list of searched articles and blog articles"
article:
type: 'NotBlogArticleInterface'
Expand Down
14 changes: 14 additions & 0 deletions src/Resources/config/graphql-types/SearchInputDecorator.types.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
SearchInputDecorator:
type: input-object
decorator: true
config:
description: "Represents search input object"
fields:
search:
type: "String!"
userIdentifier:
type: "Uuid!"
description: "Unique identifier of the user who initiated the search in format UUID version 4 (^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[1-8][0-9A-Fa-f]{3}-[ABab89][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$/)"
isAutocomplete:
type: "Boolean!"
defaultValue: false

0 comments on commit 2127289

Please sign in to comment.