Unexpected discount type in subscription draft

Looking at the docs, one could think that the discount on a fresh subscription draft of a contract that was checked out using a subscription-only code discount would contain a SubscriptionAppliedCodeDiscount discount. To my surprise, that is not true.

Querying a fresh subscription draft:

{
        "subscriptionDraft": {
            "id": "gid://shopify/SubscriptionDraft/5364745699708",
            "status": "ACTIVE",
            "discounts": {
                "nodes": [
                    {
                        "__typename": "SubscriptionManualDiscount",
                        "id": "gid://shopify/SubscriptionManualDiscount/7a9241fa-b74d-4616-a932-d36d5e814b88",
                        "type": "CODE_DISCOUNT",
                        "title": "SPECIALDISCOUNT",
                        "targetType": "LINE_ITEM",
                        "value": {
                            "percentage": 17
                        },
                        "entitledLines": {
                            "all": false,
                            "lines": {
                                "edges": [
                                    {
                                        "node": {
                                            "id": "gid://shopify/SubscriptionLine/bc505946-5393-48ca-a64f-774780c2c829",
                                            "title": "new product 1",
                                            "variantTitle": "Gold"
                                        }
                                    }
                                ]
                            }
                        }
                    }
                ]
            }
        }

Steps to reproduce

  1. Create a discount in Shopify that applies to subscription products and all billing cycles
  2. Add a product with a selling plan to the cart, then apply the discount code. Proceed with checkout
  3. Create a subscription draft for the contract
  4. Fetch the draft, especially the discounts and check for the __typename

Questions

  1. If not in this example, when would a subscription draft contain a SubscriptionAppliedCodeDiscount discount?
  2. Why is the discount spread on each line item explicitly (see entitledLines), instead of using the all boolean?

Hi @mgtmn, thanks for the clear replication steps! I used them to do some testing in my own environment and found the following:

The SubscriptionDiscount union has two members, and which one you get depends on how the discount landed on the contract. SubscriptionAppliedCodeDiscount only appears when you explicitly apply a code to a draft using subscriptionDraftDiscountCodeApply. When a code discount comes through checkout instead, it gets materialized as a SubscriptionManualDiscount with type: CODE_DISCOUNT. The contract snapshots the discount details at that point so it’s self-contained and isn’t affected if someone later modifies or deletes the original discount code in the admin.

I reproduced this on a test store to confirm: same discount code, applied via checkout gives SubscriptionManualDiscount, applied to a draft via the mutation gives SubscriptionAppliedCodeDiscount.

For your entitledLines question, that reflects how the original discount was configured, not the cart contents at checkout. If the discount targets “all items,” you’ll get entitledLines.all: true. If it was scoped to specific products or collections, you get all: false with the matching lines listed explicitly. Your discount was likely set up to target specific products rather than everything, which is why you’re seeing individual lines instead of the all boolean.

Let me know if I can clarify anything further here!