Get all Orders by a Customer
You can retrieve all the orders made by a particular customer in Crystallize. This section details how you can achieve that.
Fetch all Orders
In order to fetch all orders by a customer, you will need to provide the customer identifier to the query. The query below uses getAll and provides the customer identifier argument to it. It then fetches information regarding all the orders the customer has placed until now.
You can slice the list of orders you get back by using the first argument. This argument allows you to fetch only the number of orders you specify. Let's say you only want to grab the first three results, this is how you would do it:
The Order API uses cursor-based pagination. A cursor can be defined as a pointer that is generally an ID representing a specific location in a list. GraphQL uses the concept of connections for this purpose.
A connection in GraphQL acts as a wrapper for the list of results you are paginating. Any connection consists of two fields - edges and pageInfo. Take a look at the following query:
The query above contains the following:
- edges: contains a list of OrderConnectionEdge types.
- node: the object containing the information about an order.
- cursor: a string specifying the location of an item in the list.
- pageInfo: this contains fields such as hasNextPage, hasPreviousPage, endCursor, startCursor, and totalNodes.
To apply pagination to the list of orders, you will be using the first argument and the after input argument which is the cursor. The following query fetches the first two items, starting from the cursor value provided to it.