17
17
use Magento \Framework \GraphQl \Config \Element \Field ;
18
18
use Magento \Framework \GraphQl \Query \ResolverInterface ;
19
19
use Magento \Framework \GraphQl \Query \Resolver \ValueFactory ;
20
- use Magento \Framework \ Reflection \ DataObjectProcessor ;
20
+ use Magento \CatalogGraphQl \ Model \ Category \ Hydrator as CategoryHydrator ;
21
21
22
22
/**
23
23
* Resolver for category objects the product is assigned to.
@@ -36,11 +36,6 @@ class Categories implements ResolverInterface
36
36
*/
37
37
private $ categoryIds = [];
38
38
39
- /**
40
- * @var DataObjectProcessor
41
- */
42
- private $ dataObjectProcessor ;
43
-
44
39
/**
45
40
* @var AttributesJoiner
46
41
*/
@@ -57,25 +52,29 @@ class Categories implements ResolverInterface
57
52
private $ valueFactory ;
58
53
59
54
/**
60
- * Category constructor.
55
+ * @var CategoryHydrator
56
+ */
57
+ private $ categoryHydrator ;
58
+
59
+ /**
61
60
* @param CollectionFactory $collectionFactory
62
- * @param DataObjectProcessor $dataObjectProcessor
63
61
* @param AttributesJoiner $attributesJoiner
64
62
* @param CustomAttributesFlattener $customAttributesFlattener
65
63
* @param ValueFactory $valueFactory
64
+ * @param CategoryHydrator $categoryHydrator
66
65
*/
67
66
public function __construct (
68
67
CollectionFactory $ collectionFactory ,
69
- DataObjectProcessor $ dataObjectProcessor ,
70
68
AttributesJoiner $ attributesJoiner ,
71
69
CustomAttributesFlattener $ customAttributesFlattener ,
72
- ValueFactory $ valueFactory
70
+ ValueFactory $ valueFactory ,
71
+ CategoryHydrator $ categoryHydrator
73
72
) {
74
73
$ this ->collection = $ collectionFactory ->create ();
75
- $ this ->dataObjectProcessor = $ dataObjectProcessor ;
76
74
$ this ->attributesJoiner = $ attributesJoiner ;
77
75
$ this ->customAttributesFlattener = $ customAttributesFlattener ;
78
76
$ this ->valueFactory = $ valueFactory ;
77
+ $ this ->categoryHydrator = $ categoryHydrator ;
79
78
}
80
79
81
80
/**
@@ -109,8 +108,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
109
108
if (in_array ($ item ->getId (), $ categoryIds )) {
110
109
111
110
// Try to extract all requested fields from the loaded collection data
112
- $ categories [$ item ->getId ()] = $ item ->getData ();
113
- $ categories [$ item ->getId ()]['id ' ] = $ item ->getId ();
111
+ $ categories [$ item ->getId ()] = $ this ->categoryHydrator ->hydrateCategory ($ item , true );
114
112
$ requestedFields = $ that ->attributesJoiner ->getQueryFields ($ info ->fieldNodes [0 ]);
115
113
$ extractedFields = array_keys ($ categories [$ item ->getId ()]);
116
114
$ foundFields = array_intersect ($ requestedFields , $ extractedFields );
@@ -119,13 +117,8 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
119
117
}
120
118
121
119
// If not all requested fields were extracted from the collection, start more complex extraction
122
- $ categories [$ item ->getId ()] = $ this ->dataObjectProcessor ->buildOutputDataArray (
123
- $ item ,
124
- CategoryInterface::class
125
- );
126
- $ categories [$ item ->getId ()] = $ this ->customAttributesFlattener
127
- ->flatten ($ categories [$ item ->getId ()]);
128
- $ categories [$ item ->getId ()]['product_count ' ] = $ item ->getProductCount ();
120
+ $ categories [$ item ->getId ()] = $ this ->categoryHydrator ->hydrateCategory ($ item );
121
+
129
122
}
130
123
}
131
124
0 commit comments