Skip to content

Commit

Permalink
sui-graphql-client: change PaginationFilter to use a String vs &str (#43
Browse files Browse the repository at this point in the history
)
  • Loading branch information
stefan-mysten authored Oct 28, 2024
1 parent 1daf680 commit 1c33dd6
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions crates/sui-graphql-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ pub enum Direction {
/// Pagination options for querying the GraphQL server. It defaults to forward pagination with the
/// GraphQL server's default items per page limit.
#[derive(Default)]
pub struct PaginationFilter<'a> {
pub struct PaginationFilter {
/// The direction of pagination.
direction: Direction,
pub direction: Direction,
/// An opaque cursor used for pagination.
cursor: Option<&'a str>,
pub cursor: Option<String>,
/// The maximum number of items to return. Use `service_config` to find the limit.
limit: Option<i32>,
pub limit: Option<i32>,
}

impl<T: Serialize> From<T> for NameValue {
Expand Down Expand Up @@ -297,10 +297,10 @@ impl Client {
}

/// Internal function to handle pagination filters and return the appropriate values.
fn pagination_filter<'a>(
fn pagination_filter(
&self,
pagination_filter: PaginationFilter<'a>,
) -> (Option<&'a str>, Option<&'a str>, Option<i32>, Option<i32>) {
pagination_filter: PaginationFilter,
) -> (Option<String>, Option<String>, Option<i32>, Option<i32>) {
let (after, before, first, last) = match pagination_filter.direction {
Direction::Forward => (
pagination_filter.cursor,
Expand Down Expand Up @@ -403,14 +403,14 @@ impl Client {
pub async fn active_validators<'a>(
&self,
epoch: Option<u64>,
pagination_filter: PaginationFilter<'a>,
pagination_filter: PaginationFilter,
) -> Result<Page<Validator>, Error> {
let (after, before, first, last) = self.pagination_filter(pagination_filter);

let operation = ActiveValidatorsQuery::build(ActiveValidatorsArgs {
id: epoch,
after,
before,
after: after.as_deref(),
before: before.as_deref(),
first,
last,
});
Expand Down Expand Up @@ -537,7 +537,7 @@ impl Client {
&self,
owner: Address,
coin_type: Option<&str>,
pagination_filter: PaginationFilter<'a>,
pagination_filter: PaginationFilter,
) -> Result<Page<Coin>, Error> {
let response = self
.objects(
Expand Down Expand Up @@ -579,7 +579,7 @@ impl Client {
object_keys: None,
}),
PaginationFilter {
cursor: after.as_deref(),
cursor: after,
..Default::default()
},
).await?;
Expand Down Expand Up @@ -658,13 +658,13 @@ impl Client {
/// Get a page of [`CheckpointSummary`] for the provided parameters.
pub async fn checkpoints<'a>(
&self,
pagination_filter: PaginationFilter<'a>,
pagination_filter: PaginationFilter,
) -> Result<Option<Page<CheckpointSummary>>, Error> {
let (after, before, first, last) = self.pagination_filter(pagination_filter);

let operation = CheckpointsQuery::build(CheckpointsArgs {
after,
before,
after: after.as_deref(),
before: before.as_deref(),
first,
last,
});
Expand Down Expand Up @@ -801,13 +801,13 @@ impl Client {
pub async fn dynamic_fields<'a>(
&self,
address: Address,
pagination_filter: PaginationFilter<'a>,
pagination_filter: PaginationFilter,
) -> Result<Page<DynamicFieldOutput>, Error> {
let (after, before, first, last) = self.pagination_filter(pagination_filter);
let operation = DynamicFieldsOwnerQuery::build(DynamicFieldConnectionArgs {
address,
after,
before,
after: after.as_deref(),
before: before.as_deref(),
first,
last,
});
Expand Down Expand Up @@ -887,14 +887,14 @@ impl Client {
pub async fn events(
&self,
filter: Option<EventFilter>,
pagination_filter: PaginationFilter<'_>,
pagination_filter: PaginationFilter,
) -> Result<Page<Event>, Error> {
let (after, before, first, last) = self.pagination_filter(pagination_filter);

let operation = EventsQuery::build(EventsQueryArgs {
filter,
after,
before,
after: after.as_deref(),
before: before.as_deref(),
first,
last,
});
Expand Down Expand Up @@ -985,12 +985,12 @@ impl Client {
pub async fn objects(
&self,
filter: Option<ObjectFilter<'_>>,
pagination_filter: PaginationFilter<'_>,
pagination_filter: PaginationFilter,
) -> Result<Page<Object>, Error> {
let (after, before, first, last) = self.pagination_filter(pagination_filter);
let operation = ObjectsQuery::build(ObjectsQueryArgs {
after,
before,
after: after.as_deref(),
before: before.as_deref(),
filter,
first,
last,
Expand Down Expand Up @@ -1211,13 +1211,13 @@ impl Client {
pub async fn transactions<'a>(
&self,
filter: Option<TransactionsFilter<'a>>,
pagination_filter: PaginationFilter<'a>,
pagination_filter: PaginationFilter,
) -> Result<Page<SignedTransaction>, Error> {
let (after, before, first, last) = self.pagination_filter(pagination_filter);

let operation = TransactionBlocksQuery::build(TransactionBlocksQueryArgs {
after,
before,
after: after.as_deref(),
before: before.as_deref(),
filter,
first,
last,
Expand Down

0 comments on commit 1c33dd6

Please sign in to comment.