magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.56k stars 9.32k forks source link

Field translator removed from \Magento\CatalogGraphQl\Model\Resolver\Product\ProductFieldsSelector #39277

Open pmzandbergen opened 1 month ago

pmzandbergen commented 1 month ago

Preconditions and environment

https://github.com/magento/magento2/commit/912743cb90ad4859b03ec648524ef99e61bb7e56#diff-fecea45cc156bda365fb84d0ac56ecf5689d01847ccb6651d4ae53d2a12e7576R58

This commit removes the field translation, used by the Product (not Products!) resolver (\Magento\CatalogGraphQl\Model\Resolver\Product). This breaks fields depending on other attributes, while they work correctly when using the Products (\Magento\CatalogGraphQl\Model\Resolver\Products) resolver.

Steps to reproduce

  1. Create an attribute depending on another attribute:
    <type name="Magento\Framework\GraphQl\Query\FieldTranslator">
        <arguments>
            <argument name="translationMap" xsi:type="array">
                <item name="aliasField" xsi:type="string">regularField</item>
            </argument>
        </arguments>
    </type>
  1. Create a product with a value for regularField.
  2. Test a query using both the Product and Products resolver for the aliasField

Expected result

Both resolvers should return the same result.

Actual result

Only the Products resolver works as expected.

Additional information

There are more GraphQL bugs regarding product resolving, for example the data could be incomplete if the product is queried as part of the CartItemInterface.

I'm trying to bundle these bugs in a MR (when I've got some spare time).

Release note

No response

Triage and priority

m2-assistant[bot] commented 1 month ago

Hi @pmzandbergen. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce.

engcom-November commented 3 weeks ago

Hello @pmzandbergen,

Thank you for the report and collaboration!

We tried to verify this on 2.4-develop, but the issue is not reproducible. Added regularField and aliasField and made it dependent, but we are getting the same response with product and products query. Here is the module used to reproduce this issue. I39277V.zip

Please let us know if we are missing anything.

Thank you.

pmzandbergen commented 3 weeks ago

Hello @pmzandbergen,

Thank you for the report and collaboration!

We tried to verify this on 2.4-develop, but the issue is not reproducible. Added regularField and aliasField and made it dependent, but we are getting the same response with product and products query. Here is the module used to reproduce this issue. I39277V.zip

Please let us know if we are missing anything.

Thank you.

Did you include the created aliasField in the GraphQL query? If so, it will be available since the underlying collection will include this field. You could update the included test by:

_PS Regarding custom_attributesV2, I don't fully understand the decision for this setup. It does not support GraphQL types and it is impossible to exactly specify the required fields._

pmzandbergen commented 3 weeks ago

A patch for this issue:

--- Model/Resolver/Product/ProductFieldsSelector.php.org    2024-10-21 09:28:29
+++ Model/Resolver/Product/ProductFieldsSelector.php    2024-10-21 09:30:10
@@ -52,8 +52,10 @@
             if ($node->name->value !== $productNodeName) {
                 continue;
             }
-                $queryFields = $this->attributesJoiner->getQueryFields($node, $info);
-                $fieldNames[] = $queryFields;
+            $queryFields = array_map(function (string $fieldName): string {
+                return $this->fieldTranslator->translate($fieldName);
+            }, $this->attributesJoiner->getQueryFields($node, $info));
+            $fieldNames[] = $queryFields;
         }

         return array_merge(...$fieldNames);
engcom-November commented 3 weeks ago

@pmzandbergen,

When querying using both product and products, I am getting null for aliasField using di.xml provided above. Please take a look at the screenshot: Product query:

{
  products(filter: { sku: { eq:"test-prd-1" } } pageSize:100 ) {
    items {
      sku
      name
      alias_field
    }
  }
}
image

Products query:

{
  products(filter: {  } pageSize:100 ) {
    items {
      sku
      name
      alias_field
    }
  }
}
image

Can you give more insight on this.

Thank you.

m2-assistant[bot] commented 1 week ago

Hi @engcom-Hotel. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

pmzandbergen commented 1 week ago

@engcom-November both queries in your example are using \Magento\CatalogGraphQl\Model\Resolver\Products. Usage of the affected resolver \Magento\CatalogGraphQl\Model\Resolver\Product can be found in the following interfaces / types:

engcom-Hotel commented 1 week ago

Hello @pmzandbergen,

Thanks for the further inputs!

We have tried to reproduce the issue with ConfigurableCartItem (field configured_variant) and the issue is reproducible for us.

Hence confirming the issue.

Thanks

github-jira-sync-bot commented 1 week ago

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-13308 is successfully created for this GitHub issue.

m2-assistant[bot] commented 1 week ago

:white_check_mark: Confirmed by @engcom-Hotel. Thank you for verifying the issue.
Issue Available: @engcom-Hotel, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.