magento / graphql-ce

[ARCHIVED] Please use magento/magento2 project
https://github.com/magento/magento2
Open Software License 3.0
131 stars 156 forks source link

The "ProductInterface" ID field is not always mapped to product entity id (despite the comment implying that it is) #1063

Closed eboxrocks closed 4 years ago

eboxrocks commented 4 years ago

Preconditions (*)

  1. Magento Version 2.3.3

Steps to reproduce (*)

  1. Call the products API and filter by an array of skus, include id as a field in the GraphQL Query
  2. Look at the ProductInterface results. The id field does not populate with the product's entity_id, rather, it populates with the row_id (this apparently is used for content_staging).

Expected result (*)

  1. The schema definition should be clearer about this if this is intended (event the resolver is called "EntityIdToId" which seems misleading
  2. A separate field "entity_id" should be added that always returns the product entity_id (third party GraphQL plugins often require that the product ID be passed rather than sku).

Actual result (*)

Consider this query:

query productURLKeys($sku: [String]) { productDetail: products(filter: {sku: {in: $sku}}) { items { __typename id sku name url_key } } }

variables: { "sku": [ "10007220862927405", "12944793859424825" ] }

In the Filter of the GraphQL Resolver, I var_dump the data to see what's in it, consider this output, the entity_ids are 732145 and 735246 e.g. public function getResult( SearchCriteriaInterface $searchCriteria, ResolveInfo $info, bool $isSearch = false ): SearchResult { $fields = $this->getProductFields($info); $products = $this->productDataProvider->getList($searchCriteria, $fields, $isSearch); $productArray = []; /* @var \Magento\Catalog\Model\Product $product / foreach ($products->getItems() as $product) { $productArray[$product->getId()] = $product->getData(); $productArray[$product->getId()]['model'] = $product; } var_dump($productArray);die; return $this->searchResultFactory->create($products->getTotalCount(), $productArray); }

Output:

/Users/cel2886/Sites/cem2/src/vendor/magento/module-catalog-graph-ql/Model/Resolver/Products/Query/Filter.php:81: array (size=2) 732145 => array (size=20) 'entity_id' => string '732145' (length=6) 'attribute_set_id' => string '13' (length=2) 'type_id' => string 'simple' (length=6) 'sku' => string '10007220862927405' (length=17) 'row_id' => string '1' (length=1) ... 735246 => array (size=20) 'entity_id' => string '735246' (length=6) 'attribute_set_id' => string '13' (length=2) 'type_id' => string 'simple' (length=6) 'sku' => string '12944793859424825' (length=17) 'row_id' => string '3102' (length=4)

Actual Output of GraphQL, notice that the id matches the row_id, not the product entity_id.

{ "data": { "productDetail": { "items": [ { "__typename": "SimpleProduct", "id": 1, "sku": "10007220862927405", "name": "CABLE CAT-5 PANEL MTNT EXTENSION 2''", "url_key": "cable-cat-5-panel-mtnt-extension-2-10007220862927405" }, { "__typename": "SimpleProduct", "id": 3102, "sku": "12944793859424825", "name": "Factory Authorized Parts™ - 550003057 - Kit, Spark Pilot-Nat & Lp", "url_key": "factory-authorized-partsa-550003057-kit-spark-pilot-nat-lp-12944793859424825" } ] } } }

CC @brendanfalkowski