Sortable API Collections

Introduction

Numerous GraphQL queries that return collections of objects (such as self-hosted wallet proofs or VASP-to-VASP transactions) accept identically structured sorting parameters that can be used to impose a custom order on the returned items. This section explains how those sorting parameters are structured, and walks through an example.

It may also be instructive to see how the 21 Compliance Dashboard leverages these sorting APIs to present numerous sorting options to the user. This is explained in the corresponding GUI section.

The sortOrder parameter

If a collection supports custom sorting, the corresponding query will accept a sortOrder parameter, where a list of sorting conditions can be specified. Taking the aopd { proofs } query as an example, the corresponding parameter is sortOrder: [AopdProofSortInput!]. The definition of AopdProofSortInput is:

input AopdProofSortInput {
	property: AopdProofSortColumn!
	order: TravelSortOrder!
}

where AopdProofSortColumn is an enumeration of possible columns to sort on, and TravelSortOrder specifies the sort order as either ascending or descending.

When multiple sort criteria are supplied, earlier ones take precedence over later ones. Thus, the following example:

aopd {
  proofs(..., sortOrder: [
    { property: ADDRESS, order: ASCENDING },
    { property: CREATED_AT, order: DESCENDING }
  ])
}

will sort proofs by ascending address, and sort proofs over the same address as most recent ones first.