99use Magento \Catalog \Model \Product ;
1010use Magento \Catalog \Model \ResourceModel \Eav \Attribute ;
1111use Magento \CatalogGraphQl \Model \Resolver \Products \Attributes \Collection ;
12+ use Magento \CatalogGraphQl \Model \Resolver \Products \Attributes \CollectionFactory ;
1213use Magento \EavGraphQl \Model \Resolver \Query \Type ;
1314use Magento \Framework \App \Config \ScopeConfigInterface ;
15+ use Magento \Framework \App \ObjectManager ;
1416use Magento \Framework \Config \ReaderInterface ;
1517use Magento \Framework \GraphQl \Exception \GraphQlInputException ;
1618use Magento \Framework \GraphQl \Schema \Type \Entity \MapperInterface ;
@@ -36,9 +38,9 @@ class AttributeReader implements ReaderInterface
3638 private Type $ typeLocator ;
3739
3840 /**
39- * @var Collection
41+ * @var CollectionFactory
4042 */
41- private Collection $ collection ;
43+ private readonly CollectionFactory $ collectionFactory ;
4244
4345 /**
4446 * @var ScopeConfigInterface
@@ -48,18 +50,21 @@ class AttributeReader implements ReaderInterface
4850 /**
4951 * @param MapperInterface $mapper
5052 * @param Type $typeLocator
51- * @param Collection $collection
53+ * @param Collection $collection @deprecated @see $collectionFactory
5254 * @param ScopeConfigInterface $config
55+ * @param CollectionFactory|null $collectionFactory
56+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
5357 */
5458 public function __construct (
5559 MapperInterface $ mapper ,
5660 Type $ typeLocator ,
5761 Collection $ collection ,
58- ScopeConfigInterface $ config
62+ ScopeConfigInterface $ config ,
63+ CollectionFactory $ collectionFactory = null ,
5964 ) {
6065 $ this ->mapper = $ mapper ;
6166 $ this ->typeLocator = $ typeLocator ;
62- $ this ->collection = $ collection ;
67+ $ this ->collectionFactory = $ collectionFactory ?? ObjectManager:: getInstance ()-> get (CollectionFactory::class) ;
6368 $ this ->config = $ config ;
6469 }
6570
@@ -74,12 +79,11 @@ public function __construct(
7479 public function read ($ scope = null ) : array
7580 {
7681 $ config = [];
77-
7882 if ($ this ->config ->isSetFlag (self ::XML_PATH_INCLUDE_DYNAMIC_ATTRIBUTES , ScopeInterface::SCOPE_STORE )) {
7983 $ typeNames = $ this ->mapper ->getMappedTypes (Product::ENTITY );
8084
8185 /** @var Attribute $attribute */
82- foreach ($ this ->collection ->getAttributes () as $ attribute ) {
86+ foreach ($ this ->collectionFactory -> create () ->getAttributes () as $ attribute ) {
8387 $ attributeCode = $ attribute ->getAttributeCode ();
8488 $ locatedType = $ this ->typeLocator ->getType ($ attributeCode , Product::ENTITY ) ?: 'String ' ;
8589 $ locatedType = TypeProcessor::NORMALIZED_ANY_TYPE === $ locatedType ? 'String ' : ucfirst ($ locatedType );
0 commit comments