Skip to content

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

@JesseMaxwell

Description

@JesseMaxwell

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions