Re: GraphQL mutation doesn't work in custom app but does with GraphiQL App

GraphQL mutation doesn't work in custom app but does with GraphiQL App

Andy_Hanson-Dvo
Shopify Partner
5 0 2

I'm trying to build the UI for a product discount extension and store the configuration in a metafield associated with the discount. Whenever I run the mutation

mutation MutateMetafield($discId: ID!, $mfId: ID!, $mfValue: String) {
  discountAutomaticAppUpdate(
    id: $discId
    automaticAppDiscount: {metafields: [{id: $mfId, value: $mfValue}]}
  ) {
    userErrors {
      field
      message
    }
  }
}

I get the error "The discount doesn't exist", but it works if I run the exact same mutation in the GraphiQL App on the store it works. I've double-checked I've already got the write_discounts scope added to the shopify.app.toml file and I'm using the official JS client to run the mutation. Where else should I check next? Thanks in advance for any help!

Replies 3 (3)

Girish_Rajwani
Shopify Partner
82 3 8

Hi Andy_Hanson-Dvo,

 

Try printing ID in console and make sure correct ID is being sent to graph QL 

 

If it gets resolved then please mark it as a solution.

 

Good luck 

Girish | Shopify Expert  
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - My Shopify Apps: App Store | Looking for a solution to a problem in your store? Send me an email

Andy_Hanson-Dvo
Shopify Partner
5 0 2

I figured it out. The discount needed to be written by the custom app originally rather than via the GraphiQL app.

 

Once I deleted the original discount and recreated it through my app I was able to mutate the metafield as expected.

Girish_Rajwani
Shopify Partner
82 3 8

Awesome. Thanks for the update 

Girish | Shopify Expert  
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - My Shopify Apps: App Store | Looking for a solution to a problem in your store? Send me an email