I want to remove a customer from an order using GraphQL. Currently, I’m using the Admin REST API for this:
const { admin, session } = await authenticate.admin(request);
const order = new admin.rest.resources.Order({ session });
order.id = 450789469;
order.customer = null;
await order.save({ update: true });
This works fine using the REST API, but I can’t find the equivalent way to do this with GraphQL. Specifically, I tried the following mutation suggested by the Shopify docs assistant AI:
mutation UpdateOrderCustomer {
orderUpdate(input: { id: "id", customer: null }) {
order {
id
customer {
id
}
}
userErrors {
field
message
}
}
}
However, this doesn’t work because the customer parameter is not valid for the orderUpdate mutation.
How can I achieve this in GraphQL?
Edit:
I am using 2025-01 shopify remix app template, I have set removeRest: false
in shopify.server.js
,
now this is becoming error
const { admin, session } = await authenticate.admin(request);
const order = new admin.rest.resources.Order({ session });
TypeError: admin.rest.resources.Order is not a constructor
const { admin, session } = await authenticate.admin(request);
console.log(admin.rest.resources)
This is empty.
{}