14
14
use Magento \Framework \GraphQl \Exception \GraphQlInputException ;
15
15
use Magento \Framework \GraphQl \Query \ResolverInterface ;
16
16
use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
17
- use Magento \EavGraphQl \ Model \ Output \ GetAttributeData ;
17
+ use Magento \Framework \ Exception \ RuntimeException ;
18
18
use Magento \EavGraphQl \Model \Output \GetAttributeDataInterface ;
19
19
20
20
/**
@@ -45,27 +45,27 @@ class AttributesList implements ResolverInterface
45
45
/**
46
46
* @var array
47
47
*/
48
- private array $ resolvers ;
48
+ private array $ searchCriteriaProviders ;
49
49
50
50
/**
51
51
* @param AttributeRepository $attributeRepository
52
52
* @param SearchCriteriaBuilder $searchCriteriaBuilder
53
53
* @param EnumLookup $enumLookup
54
54
* @param GetAttributeDataInterface $getAttributeData
55
- * @param array $resolvers
55
+ * @param array $searchCriteriaProviders
56
56
*/
57
57
public function __construct (
58
58
AttributeRepository $ attributeRepository ,
59
59
SearchCriteriaBuilder $ searchCriteriaBuilder ,
60
60
EnumLookup $ enumLookup ,
61
61
GetAttributeDataInterface $ getAttributeData ,
62
- array $ resolvers = []
62
+ array $ searchCriteriaProviders = []
63
63
) {
64
64
$ this ->attributeRepository = $ attributeRepository ;
65
65
$ this ->searchCriteriaBuilder = $ searchCriteriaBuilder ;
66
66
$ this ->enumLookup = $ enumLookup ;
67
67
$ this ->getAttributeData = $ getAttributeData ;
68
- $ this ->resolvers = $ resolvers ;
68
+ $ this ->searchCriteriaProviders = $ searchCriteriaProviders ;
69
69
}
70
70
71
71
/**
@@ -90,8 +90,13 @@ public function resolve(
90
90
);
91
91
92
92
$ searchCriteria = $ this ->searchCriteriaBuilder ;
93
- foreach ($ this ->resolvers as $ resolver ) {
94
- $ searchCriteria ->addFilter ($ resolver ['name ' ], $ resolver ['object ' ]->execute ());
93
+ foreach ($ this ->searchCriteriaProviders as $ key => $ provider ) {
94
+ if (!$ provider instanceof ResolverInterface) {
95
+ throw new RuntimeException (
96
+ __ ('Configured search criteria provider should implement ResolverInterface ' )
97
+ );
98
+ }
99
+ $ searchCriteria ->addFilter ($ key , $ provider ->resolve ($ field , $ context , $ info ));
95
100
}
96
101
$ searchCriteria = $ searchCriteria ->create ();
97
102
0 commit comments