Skip to content

graphql-alt: Object version pagination #22086

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 0 commits into from
May 19, 2025
Merged

graphql-alt: Object version pagination #22086

merged 0 commits into from
May 19, 2025

Conversation

amnn
Copy link
Contributor

@amnn amnn commented May 9, 2025

Description

Adding infrastructure for pagination, filters and filter intersection, and using it to implement pagination for object versions, exposed in the following fields:

  • Query.objectVersions
  • Object.objectVersionsBefore
  • Object.objectVersionsAfter

Test plan

New unit tests for pagination logic:

sui$ cargo nextest run       \
  -p sui-indexer-alt-graphql \
  -- pagination

New E2E tests for new object pagination methods:

sui$ cargo nextest run         \
  -p sui-indexer-alt-e2e-tests \
  -- graphql/objects/object_versions

Stack


Release notes

Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required.

For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates.

  • Protocol:
  • Nodes (Validators and Full nodes):
  • gRPC:
  • JSON-RPC:
  • GraphQL:
  • CLI:
  • Rust SDK:

@amnn amnn requested review from emmazzz, wlmyng and Copilot May 9, 2025 14:21
@amnn amnn self-assigned this May 9, 2025
Copy link

vercel bot commented May 9, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sui-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 19, 2025 1:57pm
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview May 19, 2025 1:57pm
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview May 19, 2025 1:57pm

@amnn amnn temporarily deployed to sui-typescript-aws-kms-test-env May 9, 2025 14:21 — with GitHub Actions Inactive
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces pagination support for object versions in the GraphQL API, including new schema definitions, resolver functions, and pagination logic.

  • Adds pagination fields (objectVersionsAfter, objectVersionsBefore) to the GraphQL schema and updates related API types.
  • Implements and tests new pagination logic in the pagination module and integrates it into object and package queries.
  • Adds helper functions for filter intersection to support version-bound queries.

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/sui-indexer-alt-schema/src/objects.rs Updated Diesel model attributes for StoredObjVersion.
crates/sui-indexer-alt-graphql/staging.graphql, snapshots, schema.graphql Added pagination fields and updated descriptions for object/package versions.
crates/sui-indexer-alt-graphql/src/pagination.rs Added a new paginate_results method with tests for various paging scenarios.
crates/sui-indexer-alt-graphql/src/api/types/object.rs Implemented new resolver functions for object_versions_after/object_versions_before and integrated filter intersection logic.
crates/sui-indexer-alt-graphql/src/intersect.rs Introduced helper methods for merging filter boundaries.
crates/sui-indexer-alt-e2e-tests/tests/graphql/objects/object_versions.move Added end-to-end tests for object versions pagination.
Comments suppressed due to low confidence (1)

crates/sui-indexer-alt-graphql/src/pagination.rs:271

  • [nitpick] The logic for trimming prefix and suffix using nth and nth_back is complex; consider refactoring or adding explanatory comments to clarify how the edge trimming guarantees correct behavior.
if prefix > 0 { edges.nth(prefix - 1); }

let last = edges.last().map(|(c, _)| c.clone());

let (prev, next, prefix, suffix) =
match (self.after(), first, last, self.before(), self.end) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see, so this represents the result, where we have self.after(), then the first, last from fetched results, self.before()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this is lifted almost verbatim from OG GraphQL. The main difference is it doesn't include scan limit stuff.

Comment on lines 164 to 185
Paginate all versions of this package treated as an object, after this one.
"""
objectVersionsAfter(first: Int, after: String, last: Int, before: String, filter: VersionFilter): ObjectConnection!
"""
Paginate all versions of this package treated as an object, before this one.
"""
objectVersionsBefore(first: Int, after: String, last: Int, before: String, filter: VersionFilter): ObjectConnection!
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whats the rationale for having two methods here, instead of a single objectVersions connection where you could paginate through all versions before or after the current package through the existing first, after, last, before params?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just offering an objectVersions API is less expressive because there is no way to use that to phrase a "before" or "after" query, whereas the opposite is not true (you can phrase an objectVersions query as a combination of a before, after, and self query).

@amnn amnn force-pushed the amnn/gql-indices branch from 2c10980 to cab540d Compare May 17, 2025 12:50
@amnn amnn force-pushed the amnn/gql-obj-vs branch from 5c5bffc to e1efcea Compare May 17, 2025 12:50
@amnn amnn temporarily deployed to sui-typescript-aws-kms-test-env May 17, 2025 12:51 — with GitHub Actions Inactive
@amnn amnn force-pushed the amnn/gql-obj-vs branch from e1efcea to 4e311d0 Compare May 19, 2025 13:45
@amnn amnn requested a review from mystenmark as a code owner May 19, 2025 13:45
@amnn amnn merged commit 4e311d0 into amnn/gql-indices May 19, 2025
38 of 47 checks passed
@amnn amnn force-pushed the amnn/gql-indices branch from cab540d to 4e311d0 Compare May 19, 2025 13:45
@amnn amnn deleted the amnn/gql-obj-vs branch May 19, 2025 13:45
@amnn amnn temporarily deployed to sui-typescript-aws-kms-test-env May 19, 2025 13:45 — with GitHub Actions Inactive
@amnn amnn temporarily deployed to sui-typescript-aws-kms-test-env May 19, 2025 13:45 — with GitHub Actions Inactive
@amnn amnn temporarily deployed to sui-typescript-aws-kms-test-env May 19, 2025 13:45 — with GitHub Actions Inactive
@amnn amnn temporarily deployed to sui-typescript-aws-kms-test-env May 19, 2025 13:45 — with GitHub Actions Inactive
@amnn amnn temporarily deployed to sui-typescript-aws-kms-test-env May 19, 2025 13:45 — with GitHub Actions Inactive
@amnn amnn temporarily deployed to sui-typescript-aws-kms-test-env May 19, 2025 13:46 — with GitHub Actions Inactive
@amnn amnn temporarily deployed to sui-typescript-aws-kms-test-env May 19, 2025 13:46 — with GitHub Actions Inactive
@amnn amnn temporarily deployed to sui-typescript-aws-kms-test-env May 19, 2025 13:46 — with GitHub Actions Inactive
@amnn amnn temporarily deployed to sui-typescript-aws-kms-test-env May 19, 2025 13:46 — with GitHub Actions Inactive
@amnn amnn temporarily deployed to sui-typescript-aws-kms-test-env May 19, 2025 13:46 — with GitHub Actions Inactive
@amnn amnn temporarily deployed to sui-typescript-aws-kms-test-env May 19, 2025 13:46 — with GitHub Actions Inactive
@amnn amnn temporarily deployed to sui-typescript-aws-kms-test-env May 19, 2025 13:46 — with GitHub Actions Inactive
@amnn amnn temporarily deployed to sui-typescript-aws-kms-test-env May 19, 2025 13:46 — with GitHub Actions Inactive
@amnn amnn temporarily deployed to sui-typescript-aws-kms-test-env May 19, 2025 13:47 — with GitHub Actions Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants