draftOrderUpdate capabilities

New community member here.

I need to be able to update an existing Draft Order via a GraphQL mutation. I can see, using the Shopify GraphiQL App, that there is a draftOrderUpdate mutation available, and I have already created a number of Queries and Mutations (so I am not a total “newbie” wth GQL).

My question is: how exactly does the draftOrderUpdate mutation act? For example, can it handle the following:

  • Adding new order.lineitem entries to the Draft Order, simply by the fact that they are in the input now, but were not in the input when the Draft Order was created? Assume the input we are providing for the order.lineitems are fed in the same sequence as the original order was created.

  • Removing order.lineitem entries that are no longer in the Draft Order, simply by the fact that they are no longer in the input? Same assumption as above.

  • Modifying detail entries on the order header (e.g. order.shippingAddress1) simply by mentioning them in the order, preferably only changing the entries mentioned in the input?

Fortunately, I don’t need to CRUD any metafields on the order.

Many thanks in advance!

Hey @Paul_Roussell, welcome to the developers community!

The draftOrderUpdate mutation can handle all three scenarios you mentioned. There are some important nuances to understand about how different types of updates work.

For your line item questions, draftOrderUpdate completely replaces the existing lineItems array with whatever you provide in the input. This means adding new line items works exactly as you described (include them in your input), and removing items also works as expected (just omit them from the input).

For top-level modifications like tags or email, you only need to include the fields you want to change, and the mutation updates just those specific fields. However, with nested objects like shippingAddress it completely replaces the entire address.

For example, if you only include a phone number, it will try to replace the whole address with just that phone number, which fails validation. You need to provide the complete address object with all existing fields plus any changes you want to make.

Hope that helps!

Brilliant thanks!!! Prayers answered.

Regards

Paul Roussell, Director
Integrators QLD Pty Ltd (T/A ‘The Integrators’)
Email: paul.roussell@theintegrators.com
Mobile: +61 410 487 000
Web: http://www.theintegrators.com
LinkedIn: http://au.linkedin.com/in/proussell

The Integrators Logo White Letters 220 wide

Click to schedule: 30-minute meeting/call or a 60-minute meeting/call in my calendar

or phone for other options

(powered by Zoho CRM)

1 Like