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

Coupon Query does not need to be a Cart Fragment #2381

Open
JesseMaxwell opened this issue Oct 10, 2024 · 1 comment
Open

Coupon Query does not need to be a Cart Fragment #2381

JesseMaxwell opened this issue Oct 10, 2024 · 1 comment

Comments

@JesseMaxwell
Copy link

Describe the Bug

The CouponAccordion uses a query: GetCouponDocument. This imports (node_modules/@graphcommerce/magento-cart-coupon/CouponAccordion/GetCoupon.graphql):

query GetCoupon($cartId: String!) {
  cart(cart_id: $cartId) {
    ...Coupon
  }
}

Which imports (node_modules/@graphcommerce/magento-cart-coupon/Api/Coupon.graphql):

fragment Coupon on Cart @injectable {
  id
  __typename
  applied_coupons {
    code
  }
}

Problem

Because Coupon is a cart fragment, it imports more than needed. It also causes the Coupon component to update anytime the cart updates.

Recommendation

Add the Coupon's fragment directly to the GetCoupon for a leaner request and less frequent Coupon component updates.

Expected Behavior

Coupon query does not get shipping addresses and cart prices.

To Reproduce

  1. Navigation to the cart
  2. Make a change to the cart
  3. Notice that the Coupon query is called.
@paales
Copy link
Member

paales commented Oct 15, 2024

Because Coupon is a cart fragment, it imports more than needed. It also causes the Coupon component to update anytime the cart updates.

I wouldn't expect that to happen specifically, but it does seem to happen because of: https://github.com/graphcommerce-org/graphcommerce/blob/canary/packages/magento-cart-checkout/fragments/InjectTotalsIntoCoupon.graphql

I'm not exactly sure why it is there, but then again, the totals do need to be refetched when the coupon changes, right? but it seems that CartTotals fetches a lot which isn't necessary? Coupons can affect shipping method pricing, I think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants