88namespace Magento \CatalogGraphQl \Model \Resolver ;
99
1010use Magento \CatalogGraphQl \Model \Resolver \Products \Query \ProductQueryInterface ;
11- use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
12- use Magento \CatalogGraphQl \Model \Resolver \Products \Query \Filter ;
13- use Magento \CatalogGraphQl \Model \Resolver \Products \Query \Search ;
1411use Magento \Framework \GraphQl \Config \Element \Field ;
12+ use Magento \Framework \GraphQl \Exception \GraphQlAuthorizationException ;
1513use Magento \Framework \GraphQl \Exception \GraphQlInputException ;
16- use Magento \Framework \GraphQl \Query \Resolver \Argument \SearchCriteria \Builder ;
17- use Magento \Framework \GraphQl \Query \Resolver \Argument \SearchCriteria \SearchFilter ;
1814use Magento \Framework \GraphQl \Query \ResolverInterface ;
15+ use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
1916use Magento \Catalog \Model \Layer \Resolver ;
2017use Magento \CatalogGraphQl \DataProvider \Product \SearchCriteriaBuilder ;
2118
@@ -57,20 +54,7 @@ public function resolve(
5754 array $ value = null ,
5855 array $ args = null
5956 ) {
60- if (isset ($ args ['searchAllowed ' ]) && $ args ['searchAllowed ' ] === false ) {
61- throw new GraphQlInputException (__ ('Product search has been disabled. ' ));
62- }
63- if ($ args ['currentPage ' ] < 1 ) {
64- throw new GraphQlInputException (__ ('currentPage value must be greater than 0. ' ));
65- }
66- if ($ args ['pageSize ' ] < 1 ) {
67- throw new GraphQlInputException (__ ('pageSize value must be greater than 0. ' ));
68- }
69- if (!isset ($ args ['search ' ]) && !isset ($ args ['filter ' ])) {
70- throw new GraphQlInputException (
71- __ ("'search' or 'filter' input argument is required. " )
72- );
73- }
57+ $ this ->validateInput ($ args );
7458
7559 $ searchResult = $ this ->searchQuery ->getResult ($ args , $ info , $ context );
7660
@@ -97,4 +81,29 @@ public function resolve(
9781
9882 return $ data ;
9983 }
84+
85+ /**
86+ * Validate input arguments
87+ *
88+ * @param array $args
89+ * @throws GraphQlAuthorizationException
90+ * @throws GraphQlInputException
91+ */
92+ private function validateInput (array $ args )
93+ {
94+ if (isset ($ args ['searchAllowed ' ]) && $ args ['searchAllowed ' ] === false ) {
95+ throw new GraphQlAuthorizationException (__ ('Product search has been disabled. ' ));
96+ }
97+ if ($ args ['currentPage ' ] < 1 ) {
98+ throw new GraphQlInputException (__ ('currentPage value must be greater than 0. ' ));
99+ }
100+ if ($ args ['pageSize ' ] < 1 ) {
101+ throw new GraphQlInputException (__ ('pageSize value must be greater than 0. ' ));
102+ }
103+ if (!isset ($ args ['search ' ]) && !isset ($ args ['filter ' ])) {
104+ throw new GraphQlInputException (
105+ __ ("'search' or 'filter' input argument is required. " )
106+ );
107+ }
108+ }
100109}
0 commit comments