8
8
namespace Magento \CatalogGraphQl \Model \Resolver ;
9
9
10
10
use 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 ;
14
11
use Magento \Framework \GraphQl \Config \Element \Field ;
12
+ use Magento \Framework \GraphQl \Exception \GraphQlAuthorizationException ;
15
13
use 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 ;
18
14
use Magento \Framework \GraphQl \Query \ResolverInterface ;
15
+ use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
19
16
use Magento \Catalog \Model \Layer \Resolver ;
20
17
use Magento \CatalogGraphQl \DataProvider \Product \SearchCriteriaBuilder ;
21
18
@@ -57,17 +54,7 @@ public function resolve(
57
54
array $ value = null ,
58
55
array $ args = null
59
56
) {
60
- if ($ args ['currentPage ' ] < 1 ) {
61
- throw new GraphQlInputException (__ ('currentPage value must be greater than 0. ' ));
62
- }
63
- if ($ args ['pageSize ' ] < 1 ) {
64
- throw new GraphQlInputException (__ ('pageSize value must be greater than 0. ' ));
65
- }
66
- if (!isset ($ args ['search ' ]) && !isset ($ args ['filter ' ])) {
67
- throw new GraphQlInputException (
68
- __ ("'search' or 'filter' input argument is required. " )
69
- );
70
- }
57
+ $ this ->validateInput ($ args );
71
58
72
59
$ searchResult = $ this ->searchQuery ->getResult ($ args , $ info , $ context );
73
60
@@ -94,4 +81,29 @@ public function resolve(
94
81
95
82
return $ data ;
96
83
}
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
+ }
97
109
}
0 commit comments