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.55k stars 9.32k forks source link

GraphQL Api layer is converting arrays to null where that should not happen. #39196

Open drazulay opened 1 month ago

drazulay commented 1 month ago

Preconditions and environment

Steps to reproduce

The following GraphQL query is used to retrieve information about products and layered navigation filters:

{
  products(filter: {}) {
    aggregations {
      attribute_code
      count
      label
      position
      options {
        label
        value
        count,
        swatch {
          type,
          value
        }
      }
    }
    items {
      id
      categories {
        id
        is_anchor
      }
      name
      sku
      image {
        url
        label
      }
      related_products {
        id
        name
      }
      crosssell_products {
        id
        name
      }
      upsell_products {
        id
        name
      }
      price_range {
        minimum_price {
          regular_price {
            value
            currency
          }
        }
      }
    }
    page_info {
      page_size
    }
  }
}

Where aggregations->options->swatch has been defined as an extension of AggregationOptionInterface in the file <module>/etc/schema.graphqls:

interface AggregationOptionInterface
{
    swatch: Swatch @doc(description: "Information required to render filter swatches")
}
type Swatch
{
    type: String @doc(description: "Type of swatch (0 - text, 1 - color, 2 - image)")
    value: String @doc(description: "Value for swatch (text, color value or image link)")
}

Expected result

The swatch information is returned as an array with 2 members (value and label), as defined in <module>/etc/schema.graphqls:

{
  "data": {
    "products": {
      "aggregations": [
        {
          "attribute_code": "background_color",
          "count": 10,
          "label": "Background Color",
          "position": 8,
          "options": [
            {
              "label": "Purple",
              "value": "purple",
              "count": 2,
              "swatch": [
                "value": "https://images.com/purple.png",    <---------- correct situation,
                "label": "image"                             <---------- array with members
              ]
            },
            ...
          ]
        }
      ]
    }
  }
}

Actual result

The swatch information which should be an array with 2 members, is converted to null whenever I query the GraphQL api:


{
  "data": {
    "products": {
      "aggregations": [
        {
          "attribute_code": "background_color",
          "count": 10,
          "label": "Background Color",
          "position": 8,
          "options": [
            {
              "label": "Purple",
              "value": "purple",
              "count": 2,
              "swatch": null   <--------- the array has been converted to null!
            },
            ...
          ]
        }
      ]
    }
  }
}

### Additional information

I have no additional information.

### Release note

_No response_

### Triage and priority

- [ ] Severity: **S0** _- Affects critical data or functionality and leaves users without workaround._
- [ ] Severity: **S1** _- Affects critical data or functionality and forces users to employ a workaround._
- [ ] Severity: **S2** _- Affects non-critical data or functionality and forces users to employ a workaround._
- [X] Severity: **S3** _- Affects non-critical data or functionality and does not force users to employ a workaround._
- [X] Severity: **S4** _- Affects aesthetics, professional look and feel, “quality” or “usability”._
m2-assistant[bot] commented 1 month ago

Hi @drazulay. 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.

m2-assistant[bot] commented 3 days ago

Hi @engcom-Delta. 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: