Skip to content

Wrong fields selection while using fragments on GraphQL products query #26217

Closed
@phoenix128

Description

@phoenix128

Magento does not return all the required information while using fragments on products query.

Preconditions (*)

Magento 2.3.x and Magento 2.4.x

Steps to reproduce (*)

Run a GraphQL query with fragments like the following one:

query GetProducts {
    products(filter:{category_id:{eq:"3"}}) {
    	items {
       sku
        ...BasicProductInformation
      }
  }
}
  
  fragment BasicProductInformation on ProductInterface {
        sku
        name
        canonical_url
        small_image {
            label
            url
        }
        price {
          regularPrice {
            amount {
              value
              currency
            }
          }
       }
    }

Expected result (*)

The expected result is to have the right image url and product price as well as other fields

Actual result (*)

The actual result always presents placeholders for images and zero price:

{
  "data": {
    "products": {
      "items": [
...
        {
          "sku": "product_dynamic_111",
          "name": null,
          "canonical_url": "http://magento.local/simple-product-111.html",
          "small_image": {
            "label": "Simple Product 111",
            "url": "http://magento.local/static/version1577790407/graphql/_view/en_US/Magento_Catalog/images/product/placeholder/small_image.jpg"
          },
          "thumbnail": {
            "label": "Simple Product 111",
            "url": "http://magento.local/static/version1577790407/graphql/_view/en_US/Magento_Catalog/images/product/placeholder/thumbnail.jpg"
          },
          "special_price": null,
          "price": {
            "maximalPrice": {
              "amount": {
                "value": 0,
                "currency": "EUR"
              }
            },
            "minimalPrice": {
              "amount": {
                "value": 0,
                "currency": "EUR"
              }
            },
            "regularPrice": {
              "amount": {
                "value": 0,
                "currency": "EUR"
              }
            }
          }
        }
...

The problem seems to be located in \Magento\CatalogGraphQl\Model\Resolver\Products\Query\FieldSelection::getProductsFieldSelection for Magento 2.4 and \Magento\CatalogGraphQl\Model\Resolver\Product\ProductFieldsSelector::getProductFieldsFromInfo for Magento 2.3 .

Both methods do not analyze the defined fragments for the fields list and thus skipping their selection.

Metadata

Metadata

Assignees

Labels

Fixed in 2.4.xThe issue has been fixed in 2.4-develop branchIssue: Format is validGate 1 Passed. Automatic verification of issue format passed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions