GraphQL query Magento 2

Today, we’re going to explain you how to get customer orders list using graphQL in Magento 2. GraphQL is one of the most popular features of Magento 2 that makes it easy to fetch all required data with just one request. GraphQL query retrieves data from the Magento server similarly as a REST GET call. The Sales module performs a wide variety of functions, including order, invoice, and shipment management.

Use the customerOrders query allows a customer to retrive their order lists.

Use the following query returns the order history of the logged in customer.

 

Request:

{
  customerOrders {
    items {
      order_number
      id
      created_at
      grand_total
      status
      created_at
    }
  }
}

 

Response:

{
  "data": {
    "customerOrders": {
      "items": [
        {
          "order_number": "000000001",
          "id": 1,
          "created_at": "2023-04-21 10:54:54",
          "grand_total": 159.99,
          "status": "processing"
        }
      ]
    }
  }
}

here, The CustomerOrders object contains the items attribute.