Skip to main content
More in Learn

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.

Slicing Results

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:

Pagination

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.

GraphQL Connections

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.

Using Pagination

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.

People showing thumbs up

Need further assistance?

Ask the Crystallize team or other enthusiasts in our slack community.

Join our slack community