diff --git a/src/Model/Product/Connection/ProductConnectionFactory.php b/src/Model/Product/Connection/ProductConnectionFactory.php index efccf1bc1..e34ecb7a2 100644 --- a/src/Model/Product/Connection/ProductConnectionFactory.php +++ b/src/Model/Product/Connection/ProductConnectionFactory.php @@ -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( diff --git a/src/Model/Resolver/Article/Search/ArticlesSearchResultsProvider.php b/src/Model/Resolver/Article/Search/ArticlesSearchResultsProvider.php index bc1d357fc..b7ff6fa0d 100644 --- a/src/Model/Resolver/Article/Search/ArticlesSearchResultsProvider.php +++ b/src/Model/Resolver/Article/Search/ArticlesSearchResultsProvider.php @@ -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, ); diff --git a/src/Model/Resolver/Brand/Search/BrandSearchResultsProvider.php b/src/Model/Resolver/Brand/Search/BrandSearchResultsProvider.php index 894a449d6..0508a9506 100644 --- a/src/Model/Resolver/Brand/Search/BrandSearchResultsProvider.php +++ b/src/Model/Resolver/Brand/Search/BrandSearchResultsProvider.php @@ -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); } diff --git a/src/Model/Resolver/Category/Search/CategoriesSearchQuery.php b/src/Model/Resolver/Category/Search/CategoriesSearchQuery.php index 3c6a8e1ab..587ff5183 100644 --- a/src/Model/Resolver/Category/Search/CategoriesSearchQuery.php +++ b/src/Model/Resolver/Category/Search/CategoriesSearchQuery.php @@ -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; @@ -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); diff --git a/src/Model/Resolver/Category/Search/CategoriesSearchResultsProvider.php b/src/Model/Resolver/Category/Search/CategoriesSearchResultsProvider.php index 7033b3897..6dd75aed3 100644 --- a/src/Model/Resolver/Category/Search/CategoriesSearchResultsProvider.php +++ b/src/Model/Resolver/Category/Search/CategoriesSearchResultsProvider.php @@ -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( diff --git a/src/Model/Resolver/Products/Search/ProductSearchResultsProvider.php b/src/Model/Resolver/Products/Search/ProductSearchResultsProvider.php index c888e95c2..a5279b532 100644 --- a/src/Model/Resolver/Products/Search/ProductSearchResultsProvider.php +++ b/src/Model/Resolver/Products/Search/ProductSearchResultsProvider.php @@ -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) { diff --git a/src/Resources/config/graphql-types/QueryDecorator.types.yaml b/src/Resources/config/graphql-types/QueryDecorator.types.yaml index 0480a55b6..d0a221a6d 100644 --- a/src/Resources/config/graphql-types/QueryDecorator.types.yaml +++ b/src/Resources/config/graphql-types/QueryDecorator.types.yaml @@ -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!]!' @@ -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" @@ -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' @@ -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' diff --git a/src/Resources/config/graphql-types/SearchInputDecorator.types.yaml b/src/Resources/config/graphql-types/SearchInputDecorator.types.yaml new file mode 100644 index 000000000..4a2bcdbc8 --- /dev/null +++ b/src/Resources/config/graphql-types/SearchInputDecorator.types.yaml @@ -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