Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions bindings/go/examples/pagination/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package main

import (
"fmt"

sdk "bindings/iota_sdk_ffi"
)

func main() {
client := sdk.GraphQlClientNewDevnet()
address, err := sdk.AddressFromHex("0x611830d3641a68f94a690dcc25d1f4b0dac948325ac18f6dd32564371735f32c")
if err != nil {
panic(err)
}

// Limit to 1 to demonstrate pagination
limit := int32(1)
var allObjects []*sdk.Object
var nextCursor *string
for {
if nextCursor != nil {
fmt.Printf("Fetching page with cursor: %s\n", *nextCursor)
} else {
fmt.Printf("Fetching page with cursor: nil\n")
}
page, err := client.Objects(&sdk.ObjectFilter{Owner: &address}, &sdk.PaginationFilter{Direction: sdk.DirectionForward, Cursor: nextCursor, Limit: &limit})
if err.(*sdk.SdkFfiError) != nil {
panic(err)
}
for _, obj := range page.Data {
allObjects = append(allObjects, obj)
}
if page.PageInfo.HasNextPage {
nextCursor = page.PageInfo.EndCursor
} else {
break
}
}
fmt.Printf("%d objects fetched:\n", len(allObjects))
for _, obj := range allObjects {
fmt.Println(obj.ObjectId().ToHex())
}
}
47 changes: 47 additions & 0 deletions bindings/kotlin/examples/Pagination.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) 2025 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import iota_sdk.Address
import iota_sdk.Direction
import iota_sdk.GraphQlClient
import iota_sdk.Object
import iota_sdk.ObjectFilter
import iota_sdk.PaginationFilter
import kotlinx.coroutines.runBlocking

fun main() = runBlocking {
try {
val client = GraphQlClient.newDevnet()
val address =
Address.fromHex(
"0x611830d3641a68f94a690dcc25d1f4b0dac948325ac18f6dd32564371735f32c"
)
val allObjects = mutableListOf<Object>()
var nextCursor: String? = null
while (true) {
println("Fetching page with cursor: $nextCursor")
val page =
client.objects(
ObjectFilter(owner = address),
PaginationFilter(
direction = Direction.FORWARD,
cursor = nextCursor,
// Limit to 1 to demonstrate pagination
limit = 1
)
)
allObjects.addAll(page.data)
if (page.pageInfo.hasNextPage) {
nextCursor = page.pageInfo.endCursor
} else {
break
}
}
println("${allObjects.size} objects fetched:")
for (obj in allObjects) {
println(obj.objectId().toHex())
}
} catch (e: Exception) {
e.printStackTrace()
}
}
30 changes: 30 additions & 0 deletions bindings/python/examples/pagination.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (c) 2025 IOTA Stiftung
# SPDX-License-Identifier: Apache-2.0

import asyncio
from lib.iota_sdk_ffi import Address, Direction, GraphQlClient, ObjectFilter, PaginationFilter

async def main():
client = GraphQlClient.new_devnet()
address = Address.from_hex("0x611830d3641a68f94a690dcc25d1f4b0dac948325ac18f6dd32564371735f32c")

all_objects = []
next_cursor = None
while True:
print(f"Fetching page with cursor: {next_cursor}")
page = await client.objects(
ObjectFilter(owner=address),
# Limit to 1 to demonstrate pagination
PaginationFilter(direction=Direction.FORWARD, cursor=next_cursor, limit=1)
)
all_objects.extend(page.data)
if page.page_info.has_next_page:
next_cursor = page.page_info.end_cursor
else:
break
print(f"{len(all_objects)} objects fetched:")
for obj_id in all_objects:
print(obj_id.object_id().to_hex())

if __name__ == "__main__":
asyncio.run(main())
47 changes: 47 additions & 0 deletions crates/iota-graphql-client/examples/pagination.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) 2025 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use anyhow::Result;
use iota_graphql_client::{Client, pagination::PaginationFilter, query_types::ObjectFilter};
use iota_types::Address;

#[tokio::main]
async fn main() -> Result<()> {
let client = Client::new_devnet();

let address =
Address::from_hex("0x611830d3641a68f94a690dcc25d1f4b0dac948325ac18f6dd32564371735f32c")?;

let mut all_objects = Vec::new();
let mut next_cursor = None;
while let Some(cursor) = Some(next_cursor.clone()) {
println!("Fetching page with cursor: {cursor:?}");
let owned_objects_page = client
.objects(
Some(ObjectFilter {
owner: Some(address),
..Default::default()
}),
PaginationFilter {
cursor,
// Limit to 1 to demonstrate pagination
limit: Some(1),
..Default::default()
},
)
.await?;
let (page_info, data) = owned_objects_page.into_parts();
all_objects.extend(data);
if page_info.has_next_page {
next_cursor = page_info.end_cursor.clone();
} else {
break;
}
}
println!("{} objects fetched:", all_objects.len());
for obj in &all_objects {
println!("{}", obj.object_id());
}

Ok(())
}