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

[2.4.5-p1] Argument #1 ($fieldNode) must be of type GraphQL\\Language\\AST\\FieldNode, GraphQL\\Language\\AST\\InlineFragmentNode given #36544

Closed DuckThom closed 1 year ago

DuckThom commented 1 year ago

Preconditions and environment

Steps to reproduce

  1. Create a product with the url key 'a-product'
  2. Create a category with the url key 'a-category'
  3. Run the following GraphQL query:
fragment RouteFields on RoutableInterface {
    redirect_code
    relative_url
    type

    ... on ProductInterface {
        uid
        sku
        name
    }

    ... on CategoryInterface {
        uid
        name
    }
}

query Route {
    product: route(url: "a-product.html") {
        ...RouteFields
    }

    category: route(url: "a-category.html") {
        ...RouteFields
    }
}

Expected result

The routes for the product and category are returned

Actual result

A GraphQL error is returned along with the product data:

{
  "errors": [
    {
      "debugMessage": "Magento\\CatalogGraphQl\\Model\\AttributesJoiner::getQueryFields(): Argument #1 ($fieldNode) must be of type GraphQL\\Language\\AST\\FieldNode, GraphQL\\Language\\AST\\InlineFragmentNode given, called in \/Volumes\/Projects\/<redacted>\/magento\/htdocs\/vendor\/magento\/module-catalog-graph-ql\/Model\/AttributesJoiner.php on line 81",
      "message": "Internal server error",
      "extensions": {
        "category": "internal"
      },
      "locations": [
        {
          "line": 25,
          "column": 5
        }
      ],
      "path": [
        "category"
      ]
    }
  ],
  "data": {
    "product": {
      "redirect_code": 0,
      "relative_url": "a-product",
      "type": "PRODUCT",
      "uid": "NTg=",
      "sku": "533",
      "name": "A Product"
    },
    "category": null
  }
}

Additional information

Possible fix:

Replace the following line:

https://github.com/magento/magento2/blob/6dbb7fc48bd05eb2d00c9951b014aea9da7f73d7/app/code/Magento/CatalogGraphQl/Model/AttributesJoiner.php#L81

With this:

if ($spreadNode->kind === NodeKind::INLINE_FRAGMENT) {
    $fragmentFields[] = $this->addInlineFragmentFields($resolveInfo, $spreadNode);
} else {
    $fragmentFields[] = $this->getQueryFields($spreadNode, $resolveInfo);
}

I've marked it as S2 and S1 as it's critical when using GraphQL endpoints, but it's not critical when your shop doesn't make use of GraphQL.

Release note

No response

Triage and priority

m2-assistant[bot] commented 1 year ago

Hi @DuckThom. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:

Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

m2-assistant[bot] commented 1 year ago

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

engcom-Bravo commented 1 year ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 1 year ago

Hi @engcom-Bravo. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 1 year ago

Hi @engcom-Bravo, unfortunately there is no ability to deploy Magento instance at the moment. Please try again later.

engcom-Bravo commented 1 year ago

Hi @DuckThom,

Thank you for reporting and collaboration.

Verified the issue on Magento 2.4-develop instance and the issue is reproducible.Kindly refer the screenshots.

Steps to reproduce

1.Create a product with the url key 'a-product' 2.Create a category with the url key 'a-category' 3.Run the following GraphQL query:

Screenshot 2022-11-29 at 5 42 53 PM

Error in debug.log

Screenshot 2022-11-29 at 5 43 58 PM

Hence confirming this issue.

Thanks.

github-jira-sync-bot commented 1 year ago

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

m2-assistant[bot] commented 1 year ago

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

engcom-Hotel commented 1 year ago

Hello,

As I can see this issue got fixed in the scope of the internal Jira ticket AC-7114 by the internal team Related commits: https://github.com/magento/magento2/search?q=AC-7114&type=commits

Based on the Jira ticket, the target version is 2.4.7-beta1.

Thanks