From 6c44290cc7e71fcc1b5c543456d45029e664e97b Mon Sep 17 00:00:00 2001 From: stefan-mysten <135084671+stefan-mysten@users.noreply.github.com> Date: Wed, 11 Dec 2024 06:21:07 -0800 Subject: [PATCH] sui-graphql-client: make pagination consistent across queries (#66) --- crates/sui-graphql-client/src/lib.rs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/crates/sui-graphql-client/src/lib.rs b/crates/sui-graphql-client/src/lib.rs index a3196af6d..0b01e4dc1 100644 --- a/crates/sui-graphql-client/src/lib.rs +++ b/crates/sui-graphql-client/src/lib.rs @@ -1293,23 +1293,15 @@ impl Client { /// checkpoints, but only records the latest versions of system packages. pub async fn packages( &self, - after: Option<&str>, - before: Option<&str>, - first: Option, - last: Option, + pagination_filter: PaginationFilter, after_checkpoint: Option, before_checkpoint: Option, ) -> Result> { - if first.is_some() && last.is_some() { - return Err(Error::from_error( - Kind::Other, - "Conflicting arguments: either first or last can be provided, but not both.", - )); - } + let (after, before, first, last) = self.pagination_filter(pagination_filter).await; let operation = PackagesQuery::build(PackagesQueryArgs { - after, - before, + after: after.as_deref(), + before: before.as_deref(), first, last, filter: Some(PackageCheckpointFilter { @@ -2187,7 +2179,9 @@ mod tests { #[tokio::test] async fn test_packages_query() { let client = test_client(); - let packages = client.packages(None, None, None, None, None, None).await; + let packages = client + .packages(PaginationFilter::default(), None, None) + .await; assert!( packages.is_ok(), "Packages query failed for {} network. Error: {}",