Hi there,
It looks like there’s a bug in the discountAutomaticAppCreate
mutation that’s required to create discount functions.
The latest API version 2025-04
introduced a discountClasses
field in the input.
However, this field doesn’t exist in API versions prior to 2025-04
, yet the mutation is requiring it.
Reproduction steps
For the following steps, I’ll reuse this same mutation definition:
// queries/createAppDiscount.js
import { gql } from "@apollo/client";
export default gql`
mutation discountAutomaticAppCreate(
$automaticAppDiscount: DiscountAutomaticAppInput!
) {
discountAutomaticAppCreate(automaticAppDiscount: $automaticAppDiscount) {
userErrors {
field
message
}
automaticAppDiscount {
discountId
}
}
}
`;
For example, if you use 2024-07
as your API version, and attempt to create a function as described in the documentation:
// Shopify API version 2024-07
await graphql.mutate({
mutation: createAppDiscount,
variables: {
automaticAppDiscount: {
title: "ID verification discount",
functionId: "YOUR FUNCTION ID",
startsAt: new Date().toISOString(),
endsAt: null,
},
},
})
Results in this error that is trying to say that you need to define a discountClasses
field:
"discountAutomaticAppCreate": {
"automaticAppDiscount": null,
"userErrors": [
{
"field": [
"automaticAppDiscount",
"discountClasses"
],
"message": "Discount classes is required for the discount Function.",
"__typename": "DiscountUserError"
}
],
"__typename": "DiscountAutomaticAppCreatePayload"
}
This field cannot be passed, because it doesn’t exist in any version prior to 2025-04
.
If you attempt to pass the discountClasses
, it will yell at you for passing a field that doesn’t exist yet:
// Shopify API version 2024-07
await graphql.mutate({
mutation: createAppDiscount,
variables: {
automaticAppDiscount: {
title: "ID verification discount",
functionId: "YOUR FUNCTION ID",
startsAt: new Date().toISOString(),
endsAt: null,
// adding discount codes like the error suggests to do:
discountClasses: ["ORDER"],
},
},
})
This results in an error as well, because discountCodes
doesn’t exist until the latest API version:
graphQLErrors: [
{
message: 'Variable $automaticAppDiscount of type DiscountAutomaticAppInput! was provided invalid value for discountClasses (Field is not defined on DiscountAutomaticAppInput)',
locations: [Array],
extensions: [Object]
}
],
Is it possible to have this bug addressed?
I’m not even able to find a changelog for 2025-04
to view breaking changes from 2025-01
, so blindly upgrading is a bit too much risk for my taste.