Skip to content

Commit caf3ac7

Browse files
committed
graphql-alt: Query.package, Query.multiGetPackages
## Description Add queries for fetching packages: - Latest version of a package - Package at a specific version - Package at a specific checkpoint Unlike OG GraphQL, where `{ package(address: $P) { ... } }` would fetch the object at that ID as a package, this implementation will fetch the latest version of the package as of the latest checkpoint (this is the package that shares an original ID with `$P`, and whose version is latest among all packages that fit that description, as of the latest checkpoint). This was done to make the API more coherent in two ways: - The new behaviour is the same whether the package is a system package or not. - The behaviour matches how `Query.object` operates, but using a different versioning scheme. It is always possible to replicate the old behaviour with: ```graphql { object(address: $P) { asMovePackage { ... } } } ``` ## Test plan New E2E tests: ``` sui$ cargo nextest run -p sui-indexer-alt-e2e-tests -- graphql/packages ```
1 parent cdea249 commit caf3ac7

File tree

13 files changed

+1160
-3
lines changed

13 files changed

+1160
-3
lines changed
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
// Copyright (c) Mysten Labs, Inc.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
//# init --protocol-version 70 --accounts A --addresses P1=0x0 P2=0x0 P3=0x0 --simulator
5+
6+
//# publish --upgradeable --sender A
7+
module P1::M {
8+
public fun foo(): u64 { 42 }
9+
}
10+
11+
//# create-checkpoint
12+
13+
//# upgrade --package P1 --upgrade-capability 1,1 --sender A
14+
module P2::M {
15+
public fun foo(): u64 { 43 }
16+
}
17+
18+
//# upgrade --package P2 --upgrade-capability 1,1 --sender A
19+
module P3::M {
20+
public fun foo(): u64 { 44 }
21+
}
22+
23+
//# programmable --sender A --inputs 42 @A
24+
//> 0: SplitCoins(Gas, [Input(0)]);
25+
//> 1: TransferObjects([Result(0)], Input(1))
26+
27+
//# create-checkpoint
28+
29+
//# run-graphql
30+
{ # Fetching packages as objects, to confirm their addresses and versions
31+
p1: object(address: "@{obj_1_0}") {
32+
address
33+
version
34+
}
35+
36+
p2: object(address: "@{obj_3_0}") {
37+
address
38+
version
39+
}
40+
41+
p3: object(address: "@{obj_4_0}") {
42+
address
43+
version
44+
}
45+
}
46+
47+
//# run-graphql
48+
{ # Look up packages at checkpoints
49+
50+
# Without a filter, the RPC watermark is used.
51+
latest: package(address: "@{obj_1_0}") {
52+
address
53+
version
54+
}
55+
56+
# This is from before the first version of the package was published, so it
57+
# shouldn't be there
58+
c0: package(address: "@{obj_1_0}", atCheckpoint: 0) {
59+
address
60+
version
61+
}
62+
63+
# First version
64+
c1: package(address: "@{obj_1_0}", atCheckpoint: 1) {
65+
address
66+
version
67+
}
68+
69+
# The package went through two version changes in the next checkpoint
70+
c2: package(address: "@{obj_1_0}", atCheckpoint: 2) {
71+
address
72+
version
73+
}
74+
75+
# Checkpoint 3 does not exist, so the package is unchanged at this version.
76+
c3: package(address: "@{obj_1_0}", atCheckpoint: 3) {
77+
address
78+
version
79+
}
80+
}
81+
82+
//# run-graphql
83+
{ # The ID of any package version works as an anchor
84+
85+
latest: package(address: "@{obj_3_0}") {
86+
address
87+
version
88+
}
89+
90+
c0: package(address: "@{obj_3_0}", atCheckpoint: 0) {
91+
address
92+
version
93+
}
94+
95+
c1: package(address: "@{obj_3_0}", atCheckpoint: 1) {
96+
address
97+
version
98+
}
99+
100+
c2: package(address: "@{obj_3_0}", atCheckpoint: 2) {
101+
address
102+
version
103+
}
104+
105+
c3: package(address: "@{obj_3_0}", atCheckpoint: 3) {
106+
address
107+
version
108+
}
109+
}
110+
111+
//# run-graphql
112+
{ # Works for system packages as well
113+
implicit: package(address: "0x1") {
114+
address
115+
version
116+
}
117+
118+
c0: package(address: "0x1", atCheckpoint: 0) {
119+
address
120+
version
121+
}
122+
123+
c1: package(address: "0x1", atCheckpoint: 1) {
124+
address
125+
version
126+
}
127+
128+
c2: package(address: "0x1", atCheckpoint: 2) {
129+
address
130+
version
131+
}
132+
}
133+
134+
//# run-graphql
135+
{ # If the object is not a move package, then there is no response
136+
implicit: package(address: "@{obj_5_0}") {
137+
address
138+
version
139+
}
140+
141+
explicit: package(address: "@{obj_5_0}", atCheckpoint: 2) {
142+
address
143+
version
144+
}
145+
146+
object(address: "@{obj_5_0}", atCheckpoint: 2) {
147+
address
148+
version
149+
}
150+
}
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
---
2+
source: external-crates/move/crates/move-transactional-test-runner/src/framework.rs
3+
---
4+
processed 12 tasks
5+
6+
init:
7+
A: object(0,0)
8+
9+
task 1, lines 6-9:
10+
//# publish --upgradeable --sender A
11+
created: object(1,0), object(1,1)
12+
mutated: object(0,0)
13+
gas summary: computation_cost: 1000000, storage_cost: 5092000, storage_rebate: 0, non_refundable_storage_fee: 0
14+
15+
task 2, line 11:
16+
//# create-checkpoint
17+
Checkpoint created: 1
18+
19+
task 3, lines 13-16:
20+
//# upgrade --package P1 --upgrade-capability 1,1 --sender A
21+
created: object(3,0)
22+
mutated: object(0,0), object(1,1)
23+
gas summary: computation_cost: 1000000, storage_cost: 5092000, storage_rebate: 2595780, non_refundable_storage_fee: 26220
24+
25+
task 4, lines 18-21:
26+
//# upgrade --package P2 --upgrade-capability 1,1 --sender A
27+
created: object(4,0)
28+
mutated: object(0,0), object(1,1)
29+
gas summary: computation_cost: 1000000, storage_cost: 5092000, storage_rebate: 2595780, non_refundable_storage_fee: 26220
30+
31+
task 5, lines 23-25:
32+
//# programmable --sender A --inputs 42 @A
33+
//> 0: SplitCoins(Gas, [Input(0)]);
34+
//> 1: TransferObjects([Result(0)], Input(1))
35+
created: object(5,0)
36+
mutated: object(0,0)
37+
gas summary: computation_cost: 1000000, storage_cost: 1976000, storage_rebate: 978120, non_refundable_storage_fee: 9880
38+
39+
task 6, line 27:
40+
//# create-checkpoint
41+
Checkpoint created: 2
42+
43+
task 7, lines 29-45:
44+
//# run-graphql
45+
Response: {
46+
"data": {
47+
"p1": {
48+
"address": "0x37c66e5033ffe07f458c76432c64848275451aaeb5d6d4420e14818318b93759",
49+
"version": 1
50+
},
51+
"p2": {
52+
"address": "0x57bf7d91755b58a6b82e41e490bd2f03e803d1c081fe85747312eb016f39314e",
53+
"version": 2
54+
},
55+
"p3": {
56+
"address": "0x50592365811b6d08409158a0917066ca3e822a4c49dd6ae4465150f8aeb9a1da",
57+
"version": 3
58+
}
59+
}
60+
}
61+
62+
task 8, lines 47-80:
63+
//# run-graphql
64+
Response: {
65+
"data": {
66+
"latest": {
67+
"address": "0x50592365811b6d08409158a0917066ca3e822a4c49dd6ae4465150f8aeb9a1da",
68+
"version": 3
69+
},
70+
"c0": null,
71+
"c1": {
72+
"address": "0x37c66e5033ffe07f458c76432c64848275451aaeb5d6d4420e14818318b93759",
73+
"version": 1
74+
},
75+
"c2": {
76+
"address": "0x50592365811b6d08409158a0917066ca3e822a4c49dd6ae4465150f8aeb9a1da",
77+
"version": 3
78+
},
79+
"c3": {
80+
"address": "0x50592365811b6d08409158a0917066ca3e822a4c49dd6ae4465150f8aeb9a1da",
81+
"version": 3
82+
}
83+
}
84+
}
85+
86+
task 9, lines 82-109:
87+
//# run-graphql
88+
Response: {
89+
"data": {
90+
"latest": {
91+
"address": "0x50592365811b6d08409158a0917066ca3e822a4c49dd6ae4465150f8aeb9a1da",
92+
"version": 3
93+
},
94+
"c0": null,
95+
"c1": {
96+
"address": "0x37c66e5033ffe07f458c76432c64848275451aaeb5d6d4420e14818318b93759",
97+
"version": 1
98+
},
99+
"c2": {
100+
"address": "0x50592365811b6d08409158a0917066ca3e822a4c49dd6ae4465150f8aeb9a1da",
101+
"version": 3
102+
},
103+
"c3": {
104+
"address": "0x50592365811b6d08409158a0917066ca3e822a4c49dd6ae4465150f8aeb9a1da",
105+
"version": 3
106+
}
107+
}
108+
}
109+
110+
task 10, lines 111-132:
111+
//# run-graphql
112+
Response: {
113+
"data": {
114+
"implicit": {
115+
"address": "0x0000000000000000000000000000000000000000000000000000000000000001",
116+
"version": 1
117+
},
118+
"c0": {
119+
"address": "0x0000000000000000000000000000000000000000000000000000000000000001",
120+
"version": 1
121+
},
122+
"c1": {
123+
"address": "0x0000000000000000000000000000000000000000000000000000000000000001",
124+
"version": 1
125+
},
126+
"c2": {
127+
"address": "0x0000000000000000000000000000000000000000000000000000000000000001",
128+
"version": 1
129+
}
130+
}
131+
}
132+
133+
task 11, lines 134-150:
134+
//# run-graphql
135+
Response: {
136+
"data": {
137+
"implicit": null,
138+
"explicit": null,
139+
"object": {
140+
"address": "0xa562719ea34a60492a851488cb194ce74d7d7a427d310dc8aa2a14149b2d128c",
141+
"version": 5
142+
}
143+
}
144+
}

0 commit comments

Comments
 (0)