Skip to content
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

[pick][GraphQL] Object DataLoader (#17332) #18384

Conversation

wlmyng
Copy link
Contributor

@wlmyng wlmyng commented Jun 24, 2024

Implement data loaders for fetching historical object versions, objects bounded by their parent versions, and the latest versions of an object at a given checkpoint.

By implementing an Object DataLoader, we also implicitly get support for data-loading all derived types (MoveObject, MovePackage, MoveModule, DynamicField, Coin, etc).

These implementations (particularly historical queries and queries where the version can be bounded by a parent version) can be made even more efficient with the existence of an index/side table that maps an object's ID and version to the checkpoint it is part of. This change has not been included in this PR, but we will follow up on this as part of Object query benchmarking.

As part of this change, I enabled queries for historical objects outside the available range. Later (with the use of an obj_version index) it will also be possible to enable dynamic field look-ups on historical objects as well.

sui$ cargo nextest run -p sui-graphql-rpc
sui$ cargo nextest run -p sui-graphql-e2e-tests --features pg_integration

Run the following query -- after this change, it takes about 8s to complete on the server, fetching about 80 objects, while previously it would either timeout or squeak in just under the 40s timeout. I expect this number to improve further once we have an efficient way to map object ids and versions to a checkpoint sequence number.

query {
  transactionBlocks(last: 5) {
    nodes {
      effects {
        objectChanges(first: 50) {
          pageInfo { hasNextPage }
          nodes {
            idCreated
            idDeleted
            inputState { asMoveObject { contents { json } } }
            outputState { asMoveObject { contents { json } } }
          }
        }
      }
    }
  }
}

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):
  • Indexer:
  • JSON-RPC:
  • GraphQL: Queries for historical versions of objects will now return data even if that version of the object is outside the available range.
  • CLI:
  • Rust SDK:

Description

Describe the changes or additions included in this PR.

Test plan

How did you test the new or updated feature?


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):
  • Indexer:
  • JSON-RPC:
  • GraphQL:
  • CLI:
  • Rust SDK:

Implement data loaders for fetching historical object versions, objects
bounded by their parent versions, and the latest versions of an object
at a given checkpoint.

By implementing an Object DataLoader, we also implicitly get support for
data-loading all derived types (`MoveObject`, `MovePackage`,
`MoveModule`, `DynamicField`, `Coin`, etc).

These implementations (particularly historical queries and queries where
the version can be bounded by a parent version) can be made even more
efficient with the existence of an index/side table that maps an
object's ID and version to the checkpoint it is part of. This change has
not been included in this PR, but we will follow up on this as part of
Object query benchmarking.

As part of this change, I enabled queries for historical objects outside
the available range. Later (with the use of an `obj_version` index) it
will also be possible to enable dynamic field look-ups on historical
objects as well.

```
sui$ cargo nextest run -p sui-graphql-rpc
sui$ cargo nextest run -p sui-graphql-e2e-tests --features pg_integration
```

Run the following query -- after this change, it takes about 8s to
complete on the server, fetching about 80 objects, while previously it
would either timeout or squeak in *just* under the 40s timeout. I expect
this number to improve further once we have an efficient way to map
object ids and versions to a checkpoint sequence number.

```graphql
query {
  transactionBlocks(last: 5) {
    nodes {
      effects {
        objectChanges(first: 50) {
          pageInfo { hasNextPage }
          nodes {
            idCreated
            idDeleted
            inputState { asMoveObject { contents { json } } }
            outputState { asMoveObject { contents { json } } }
          }
        }
      }
    }
  }
}
```

---

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):
- [ ] Indexer:
- [ ] JSON-RPC:
- [x] GraphQL: Queries for historical versions of objects will now
return data even if that version of the object is outside the available
range.
- [ ] CLI:
- [ ] Rust SDK:
Copy link

vercel bot commented Jun 24, 2024

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 Jun 24, 2024 5:28pm
3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview Jun 24, 2024 5:28pm
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview Jun 24, 2024 5:28pm
sui-typescript-docs ⬜️ Ignored (Inspect) Visit Preview Jun 24, 2024 5:28pm

Copy link
Member

@amnn amnn left a comment

Choose a reason for hiding this comment

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

Thanks for noticing this got stomped in the release branch!

@wlmyng wlmyng merged commit 9615c0b into releases/sui-graphql-rpc-v2024.4.0-release Jun 24, 2024
47 of 48 checks passed
@wlmyng wlmyng deleted the gql-cherry-pick-object-dataloader branch June 24, 2024 18:48
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