Remove Customer from Order: Graphql

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.

{}

Hi Walker,

I’ll connect with the orders team on this - in the meantime, what is the use case for removing a customer from an order?

Currently my app creates partial payment order so one order will be in partial payment, after completing checkout another order is created by my app and for the customer they only need to see one order which will be “Partially Paid”, I am migrating a my old app to graphql, using graphql i can edit orders but I need manage order edit permission. So to be compatible with the those users until they approve the permission.

Why is admin.rest.resources is empty?
Atleast I want to use rest api for removing customer until a solution for the same is found in graphql. Feb 1 is the deadline for changing to graphql for product queries. I want to push the new changes before then. Please help.

Hi again,

The orders team have this in their backlog to support, but there’s no ETA I can share on this right now. It shouldn’t be a blocker in migrating to use the new GraphQL Product APIs though - the order endpoint is not affected by the REST product deprecation, so you shouldn’t need to make this change for the Feb 1st deadline.

Ok, But admin.rest.resources is empty if I want to call Orders
Edit:

console.log(admin.rest)
RemixRestClient {
   session: Session {
    ...
   },
   params: {
     api: {
       config: [Object],
       clients: [Object],
       auth: [Object],
       session: [Object],
       utils: [Object],
       webhooks: [Object],
       billing: [Object],
       flow: [Object],
       fulfillmentService: [Object],
       logger: [Object],
       rest: {}
     },
     config: {
       apiKey: '',
       apiSecretKey: '',
       apiVersion: '2025-01',
       scopes: [AuthScopes],
       authPathPrefix: '/auth',
       sessionStorage: [PrismaSessionStorage],
       distribution: 'app_store',
       future: [Object],
       hostScheme: 'https',
       isEmbeddedApp: true,
       isCustomStoreApp: false,
       isEmbeddedApp: true,
       isCustomStoreApp: false,
       isEmbeddedApp: true,
       isCustomStoreApp: false,
       logger: [Object],
       _logDisabledFutureFlags: false,
       restResources: undefined,
       adminApiAccessToken: undefined,
       userAgentPrefix: 'Shopify Remix Library v3.5.1',       
       privateAppStorefrontAccessToken: undefined,
       customShopDomains: undefined,
       billing: undefined,
       idempotentPromiseHandler: [IdempotentPromiseHandler],  
       canUseLoginForm: true,
       useOnlineTokens: false,
       hooks: {},
       auth: [Object]
     },
     logger: {
       log: [Function: log],
       debug: [Function: debug],
       info: [Function: info],
       warning: [Function: warningFunction],
       error: [Function: error],
       deprecated: [Function (anonymous)]
     }
   },
   handleClientError: [AsyncFunction: handleClientError],     
   resources: {}
 }

resources is empty

Are you importing and adding restResources in shopify.server.ts in remix template?

Like this

import { restResources } from "@shopify/shopify-api/rest/admin/2024-10";

const shopify = shopifyApp({
  restResources,
  ... // other options
});

Thank you, You were a big help!!

1 Like