How to Use Pagination with the Semble Public API
When working with large datasets, like retrieving a list of patients, it can be crucial to paginate the results to ensure performance and usability. Semble's GraphQL API supports pagination, allowing you to retrieve a specific subset of records at a time.
Step 1: Understanding the Pagination Parameters
The pagination is controlled by two main parameters:
page
: The page number you want to retrieve (starting from 1).pageSize
: The number of items you want per page.
Here's how you can use these parameters:
patients(
search: String
pagination: { page: 2, pageSize: 10 }
options: QueryOptions
): PatientData
Step 2: Querying a Specific Page
You can specify both the page
and pageSize
in your query to retrieve the exact subset of data you need.
Example Query:
query {
patients(pagination: { page: 3, pageSize: 5 }) {
data {
id
firstName
lastName
}
}
}
Step 3: Handling the Result
The response will contain the data for the specified page and page size.
Example JSON Response:
{
"data": {
"patients": {
"data": [
{
"id": "11",
"firstName": "Alice",
"lastName": "Johnson"
},
{
"id": "12",
"firstName": "Bob",
"lastName": "Smith"
}
]
}
}
}
Step 4: Navigating Through Pages
You can iterate through pages by incrementing the page
parameter in your subsequent queries.
Step 5: Understanding pageInfo
Along with the patient data, you can also retrieve pageInfo
, which provides information about the pagination state, such as whether there are more pages available.
query {
patients(pagination: { page: 1, pageSize: 5 }) {
data {
id
firstName
lastName
}
pageInfo {
hasMore
}
}
}
This can be useful to determine when to stop paginating (e.g., when hasMore
is false
).
Conclusion
Pagination in the Semble API provides an efficient way to handle large ssets of data, making it easy to build scalable applications. By understanding how to use the page
and pageSize
parameters, and optionally the pageInfo
, you can create a seamless navigation experience through your datasets.