GraphQL: Is it possible to neste two queries?

Hi,

I want to mutate the customer address with graphql. It needs to do one query to get the address id for the customer, then use the id to update the address. I am wondering if it is possible to combine two query into one.

Query to get address ID:

{customers(first: 1, query: "id:'5044061470926") {
    edges {
      node {
        addresses{
            id
        }
      }
    }
  }
}

Query to use the ID for mutation (The id in address is the result from the previous query):

{
   "query":"mutation customerUpdate($input: CustomerInput!) { customerUpdate(input: $input) { customer { id } userErrors { field message } } }",
   "variables":{
      "input":{
         "id":"gid://shopify/Customer/5044061470926",
         "addresses":[
            {
               "id":"gid://shopify/MailingAddress/6210806939854?model_name=CustomerAddress",
               "address1":"15 queens 22",
            }
         ]
      }
   }

It struggled me for a long time.. Is there a way to combine them into one?

Thanks a lot!

Hello @kevinLi
Yes it is possible to run two queries at a time Please check following code it might help you

mutation {
  updateCustomerAddress(
    input: {
      id: "gid://shopify/CustomerAddress/{ADDRESS_ID}"
      address: {
        address1: "123 Main St"
        city: "Example City"
        province: "Example Province"
        zip: "12345"
      }
    }
  ) {
    customerAddress {
      id
      address1
      city
      province
      zip
    }
  }
  customer(id: "gid://shopify/Customer/{CUSTOMER_ID}") {
    addresses(first: 1) {
      edges {
        node {
          id
        }
      }
    }
  }
}
  • Replace {ADDRESS_ID} with the actual address ID of the customer address you want to update.
  • Replace {CUSTOMER_ID} with the actual customer ID for which you want to retrieve the address ID.

Thanks!!