Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAGENTO-PWA#2190: Fixed dependent GraphQL schema according to best practices #27620

Closed

Conversation

andrewbess
Copy link

Description (*)

This PR fixes GraphQL schema for merging carts according to Magento best practices

Related Pull Requests

Fixed Issues (if relevant)

  1. [bug]: Call mergeCarts to merge guest and customer carts within customer login pwa-studio#2190: Call mergeCarts to merge guest and customer carts within customer login

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Apr 5, 2020

Hi @andrewbess. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Guide documentation.

@andrewbess andrewbess requested a review from naydav April 5, 2020 08:50
@rogyar rogyar self-assigned this Apr 5, 2020
@@ -20,7 +20,7 @@ type Mutation {
setPaymentMethodOnCart(input: SetPaymentMethodOnCartInput): SetPaymentMethodOnCartOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\SetPaymentMethodOnCart")
setGuestEmailOnCart(input: SetGuestEmailOnCartInput): SetGuestEmailOnCartOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\SetGuestEmailOnCart")
setPaymentMethodAndPlaceOrder(input: SetPaymentMethodAndPlaceOrderInput): PlaceOrderOutput @deprecated(reason: "Should use setPaymentMethodOnCart and placeOrder mutations in single request.") @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\SetPaymentAndPlaceOrder")
mergeCarts(source_cart_id: String!, destination_cart_id: String!): Cart! @doc(description:"Merges the source cart into the destination cart") @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\MergeCarts")
mergeCarts(input: MergeCartsInput): Cart! @doc(description:"Merges the source cart into the destination cart") @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\MergeCarts")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the backward compatibility of this change.
@lenaorobei, could you confirm, please, that we may perform such changes?

Thank you

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation of mergeCarts was added based on approved proposal from the architecture repo https://github.com/magento/architecture/blob/master/design-documents/graph-ql/coverage/shared-cart.md

Need to understand how this will help PWA devs.

Addind @cpartica @paliarush

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrewbess could you please explain the isse with using mergeCarts(source_cart_id: String!, destination_cart_id: String!)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the main concern here is extensibility. If we use a separate type for input (as we do in most cases), we may extend this input (add fields, for example) in a separate module. If we have the parameters hardcoded as they are now, the extensibility is compromised.

But the main question here is the backward compatibility. If some merchant already uses the existing mergeCarts mutation somehow, he will be surprised after the upgrade.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @rogyar
The GraphQL for merging carts looks like incorrect. It doesn't use Magento best practices.
I don't understand why it has been changed from the correct code to incorrect.
Please take a look at commits below.
Correct commit (IMHO)
magento/graphql-ce#950
Incorrect commit that changes previous (IMHO)
f19f727
I also want to note that this is a relatively new feature.
It appeared only in version 2.3.4

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @lenaorobei
Thank you for your question.
This mutation isn't written according to Magento best practices.
Currently, I am working on PWA-studio#2190.
So, I think it would be better to change it now and don't alter PWA after changing this mutation in the future.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rogyar regarding your concern about extensibility - both options should work - adding new field and parameter.

@andrewbess there was an issue on the DevDocs page that is already addressed magento/devdocs#7001
This recommendation was outdated.

Please refer to the extensibility approach in the architecture repo https://github.com/magento/architecture/blob/master/design-documents/graph-ql/extensibility.md

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @lenaorobei. Thank you for clarification. We used to use containers for input arguments for merging purposes. So containers with the same name from different modules were supposed to be merged. If you can confirm that the raw input parameters approach (with no containers) has merging capabilities, then we good to go.

Thank you!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rogyar yes, mutations/queries with the same name are supposed to be merged. This is the way of adding new parameters.

I would really appreciate if someone can double check that.

@rogyar rogyar requested a review from lenaorobei April 5, 2020 12:55
@ghost ghost assigned lenaorobei Apr 6, 2020
@lenaorobei
Copy link
Contributor

Closing this PR.
Please see #27620 (comment)

@lenaorobei lenaorobei closed this Apr 8, 2020
@m2-assistant
Copy link

m2-assistant bot commented Apr 8, 2020

Hi @andrewbess, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@andrewbess andrewbess deleted the MAGENTO-PWA/ISSUE-2190 branch October 28, 2020 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants