Skip to content

Commit

Permalink
[gql] modify consistent objects query to be more performant (MystenLa…
Browse files Browse the repository at this point in the history
  • Loading branch information
wlmyng authored Feb 16, 2024
1 parent 884b8f2 commit 446153b
Show file tree
Hide file tree
Showing 12 changed files with 950 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,56 @@ Response: {
"data": {
"objects_at_version": {
"objects": {
"nodes": []
"nodes": [
{
"version": 3,
"contents": {
"type": {
"repr": "0x7fa8cc064aa9d56a46411e3e0e5878a6cd740a4edabe2cb3c28ec32d6e314db4::M1::Object"
},
"json": {
"id": "0x5cbc81679b7c3fe2763d6129f752abacd0787935b4a081c341e1cebc571446d5",
"value": "0"
}
}
},
{
"version": 6,
"contents": {
"type": {
"repr": "0x7fa8cc064aa9d56a46411e3e0e5878a6cd740a4edabe2cb3c28ec32d6e314db4::M1::Object"
},
"json": {
"id": "0x81b0f4f8040edbdd1778dac36f4a6c7ebd4d2689c5f9e28ea916ab3542ea6c5e",
"value": "3"
}
}
},
{
"version": 5,
"contents": {
"type": {
"repr": "0x7fa8cc064aa9d56a46411e3e0e5878a6cd740a4edabe2cb3c28ec32d6e314db4::M1::Object"
},
"json": {
"id": "0xb94dc19e08bf7ea2999f22ae8db6ef903d2ace4a08e99d40867064ca10abdf07",
"value": "2"
}
}
},
{
"version": 4,
"contents": {
"type": {
"repr": "0x7fa8cc064aa9d56a46411e3e0e5878a6cd740a4edabe2cb3c28ec32d6e314db4::M1::Object"
},
"json": {
"id": "0xcf941059092fa42fb8bc3c184adaf83083856daa002de4f4aaadfc1e79cfa26a",
"value": "1"
}
}
}
]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ module Test::M1 {
}

//# run-graphql
# No longer accessible, as there are more recent versions owned by address B.
# Historical lookups will still return results at version.
{
objects_at_version: address(address: "@{A}") {
objects(
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

// Transfer 500 objects to A. The first graphql query fetches the last 4 objects owned by A. Then
// transfer the last 3 objects from A to B. Make a graphql query for the `last: 1` - this is to test
// that we return the next valid result even if the first `limit` rows that match the filtering
// criteria are then invalidated by a newer version of the matched object. We set `last: 1` but
// transfer the last 3 objects because we increase the limit by 2 behind the scenes.

//# init --addresses Test=0x0 --accounts A B --simulator

//# publish
module Test::M1 {
use sui::object::{Self, UID};
use sui::tx_context::TxContext;
use sui::transfer;

struct Object has key, store {
id: UID,
value: u64,
}

struct Ledger has key, store {
id: UID,
object_ids: vector<UID>,
}

public entry fun create_many(recipient: address, ctx: &mut TxContext) {
let i = 0;
while (i < 500) {
transfer::public_transfer(

Object { id: object::new(ctx), value: i },
recipient
);
i = i + 1;
}
}
}

//# run Test::M1::create_many --sender A --args @A

//# create-checkpoint 2

//# run-graphql
{
last_2: objects(last: 2, filter: {type: "@{Test}"}) {
nodes {
version
asMoveObject {
owner {
... on AddressOwner {
owner {
address
}
}
}
contents {
json
type {
repr
}
}
}
}
}
last_4_objs_owned_by_A: address(address: "@{A}") {
objects(last: 4) {
nodes {
owner {
... on AddressOwner {
owner {
address
}
}
}
contents {
json
type {
repr
}
}
}
}
}
}

//# transfer-object 2,499 --sender A --recipient B

//# transfer-object 2,498 --sender A --recipient B

//# transfer-object 2,497 --sender A --recipient B

//# view-object 2,498

//# view-object 2,497

//# create-checkpoint

//# run-graphql
{
last_3: objects(last: 3, filter: {type: "@{Test}"}) {
nodes {
version
asMoveObject {
owner {
... on AddressOwner {
owner {
address
}
}
}
contents {
json
type {
repr
}
}
}
}
}
last_obj_owned_by_A: address(address: "@{A}") {
objects(last: 1) {
nodes {
version
owner {
... on AddressOwner {
owner {
address
}
}
}
contents {
json
type {
repr
}
}
}
}
}
}

//# run-graphql
# Test that we correctly return the object at version, both for the `object` and `objects`
# resolvers.
{
a: object(address: "@{obj_2_499}", version: 2) {
asMoveObject {
owner {
... on AddressOwner {
owner {
address
}
}
}
contents {
json
type {
repr
}
}
}
}
b: object(address: "@{obj_2_499}", version: 3) {
asMoveObject {
owner {
... on AddressOwner {
owner {
address
}
}
}
contents {
json
type {
repr
}
}
}
}
objects_a: objects(filter: {objectKeys: [
{objectId: "@{obj_2_499}", version: 2},
{objectId: "@{obj_2_498}", version: 2},
{objectId: "@{obj_2_497}", version: 2},
]}) {
nodes {
asMoveObject {
owner {
... on AddressOwner {
owner {
address
}
}
}
contents {
json
type {
repr
}
}
}
}
}
objects_b: objects(filter: {objectKeys: [
{objectId: "@{obj_2_499}", version: 3},
{objectId: "@{obj_2_498}", version: 4},
{objectId: "@{obj_2_497}", version: 5},
]}) {
nodes {
asMoveObject {
owner {
... on AddressOwner {
owner {
address
}
}
}
contents {
json
type {
repr
}
}
}
}
}
owned_by_b: address(address: "@{B}") {
objects {
nodes {
version
owner {
... on AddressOwner {
owner {
address
}
}
}
contents {
json
type {
repr
}
}
}
}
}
}
Loading

0 comments on commit 446153b

Please sign in to comment.