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

[mvr][gql] cherry-pick crate creation and other boilerplate code #20404

Open
wants to merge 5 commits into
base: releases/sui-v1.38.0-release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ members = [
"crates/sui-move",
"crates/sui-move-build",
"crates/sui-move-lsp",
"crates/sui-mvr-graphql-rpc",
"crates/sui-mvr-indexer",
"crates/sui-network",
"crates/sui-node",
Expand Down Expand Up @@ -656,6 +657,7 @@ sui-metric-checker = { path = "crates/sui-metric-checker" }
sui-move = { path = "crates/sui-move" }
sui-move-build = { path = "crates/sui-move-build" }
sui-move-lsp = { path = "crates/sui-move-lsp" }
sui-mvr-graphql-rpc = { path = "crates/sui-mvr-graphql-rpc" }
sui-mvr-indexer = { path = "crates/sui-mvr-indexer" }
sui-network = { path = "crates/sui-network" }
sui-node = { path = "crates/sui-node" }
Expand Down
97 changes: 97 additions & 0 deletions crates/sui-mvr-graphql-rpc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
[package]
name = "sui-mvr-graphql-rpc"
version.workspace = true
authors = ["Mysten Labs <[email protected]>"]
license = "Apache-2.0"
publish = false
edition = "2021"


[dependencies]
anyhow.workspace = true
async-graphql = {workspace = true, features = ["dataloader", "apollo_tracing", "tracing", "opentelemetry"] }
async-graphql-axum.workspace = true
async-graphql-value.workspace = true
async-trait.workspace = true
axum.workspace = true
axum-extra.workspace = true
bin-version.workspace = true
chrono.workspace = true
clap.workspace = true
const-str.workspace = true
diesel = { workspace = true, features = ["i-implement-a-third-party-backend-and-opt-into-breaking-changes"] }
diesel-async = { workspace = true, features = ["postgres"] }
either.workspace = true
fastcrypto = { workspace = true, features = ["copy_key"] }
fastcrypto-zkp.workspace = true
futures.workspace = true
hex.workspace = true
http.workspace = true
hyper.workspace = true
itertools.workspace = true
lru.workspace = true
move-binary-format.workspace = true
move-disassembler.workspace = true
move-ir-types.workspace = true
mysten-metrics.workspace = true
mysten-network.workspace = true
move-core-types.workspace = true
once_cell.workspace = true
prometheus.workspace = true
rand.workspace = true # todo: cleanup test only deps
regex.workspace = true
reqwest.workspace = true
serde.workspace = true
serde_json.workspace = true
serde_with.workspace = true
serde_yaml.workspace = true
shared-crypto.workspace = true
similar.workspace = true
sui-pg-temp-db.workspace = true
sui-sdk.workspace = true
sui-types.workspace = true
tap.workspace = true
telemetry-subscribers.workspace = true
tempfile.workspace = true
tracing.workspace = true
tokio = { workspace = true, features = ["rt-multi-thread"] }
tokio-util = { workspace = true, features = ["rt"] }
toml.workspace = true
tower.workspace = true
tower-http.workspace = true
thiserror.workspace = true
uuid.workspace = true
im.workspace = true
downcast = "0.11.0"

sui-graphql-config.workspace = true
sui-graphql-rpc-headers.workspace = true
sui-graphql-rpc-client.workspace = true


# TODO: put these behind feature flag to prevent leakage
# Used for dummy data
bcs.workspace = true
simulacrum.workspace = true # todo: cleanup test only deps
sui-json-rpc.workspace = true
sui-json-rpc-types.workspace = true
sui-indexer.workspace = true
sui-rest-api.workspace = true
sui-swarm-config.workspace = true
test-cluster.workspace = true
sui-protocol-config.workspace = true
move-bytecode-utils.workspace = true
sui-package-resolver.workspace = true

[dev-dependencies]
expect-test.workspace = true
hyper.workspace = true
insta.workspace = true
serde_json.workspace = true
sui-framework.workspace = true
tower.workspace = true
sui-test-transaction-builder.workspace = true
sui-move-build.workspace = true

[features]
staging = []
78 changes: 78 additions & 0 deletions crates/sui-mvr-graphql-rpc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# sui-mvr-graphql-rpc

## Dev setup
Note that we use compilation flags to determine the backend for Diesel. If you're using VS Code, make sure to update settings.json with the appropriate features - there should at least be a "pg_backend" (or other backend.)
```
"rust-analyzer.cargo.features": ["pg_backend"]
```
Consequently, you'll also need to specify the backend when running cargo commands:
```cargo run --features "pg_backend" --bin sui-mvr-graphql-rpc start-server --db-url <DB_URL>```

The order is important:
1. --features "pg_backend": This part tells Cargo to enable the pg_backend feature.
2. --bin sui-mvr-graphql-rpc: This specifies which binary to run.
3. start-server --db-url: These are arguments to the binary.

## Spinning up locally

### Setting up local db

The graphql service is backed by a db based on the db schema in [sui-indexer](../sui-indexer/src/schema.rs). To spin up a local db, follow the instructions at [sui-indexer](../sui-indexer/README.md) until "Running standalone indexer".

If you have not created a db yet, you can do so as follows:
```sh
psql -U postgres
CREATE DATABASE sui_indexer_v2;
```

You should be able to refer to the db url now:
`psql postgres://postgres:postgrespw@localhost:5432/sui_indexer_v2`

With the new db, run the following commands (also under `sui/crates/sui-indexer`):

```sh
diesel setup --database-url="<DATABASE_URL>" --migration-dir=migrations
diesel migration run --database-url="<DATABASE_URL>" --migration-dir=migrations
```

### Launching the server
See [src/commands.rs](src/commands.rs) for all CLI options.

Example `.toml` config:
```toml
[limits]
max-query-depth = 15
max-query-nodes = 500
max-output-nodes = 100000
max-query-payload-size = 5000
max-db-query-cost = 20000
default-page-size = 5
max-page-size = 10
request-timeout-ms = 15000
max-type-argument-depth = 16
max-type-argument-width = 32
max-type-nodes = 256
max-move-value-depth = 128

[background-tasks]
watermark-update-ms=500
```

This will build sui-mvr-graphql-rpc and start an IDE:
```
cargo run --bin sui-mvr-graphql-rpc start-server [--rpc-url] [--db-url] [--port] [--host] [--config]
```

### Launching the server w/ indexer
For local dev, it might be useful to spin up an indexer as well. Instructions are at [Running standalone indexer](../sui-indexer/README.md#running-standalone-indexer).

## Compatibility with json-rpc

`cargo run --bin sui -- start --with-faucet --force-regenesis --with-indexer --pg-port 5432 --pg-db-name sui_indexer_v2 --with-graphql`

`pnpm --filter @mysten/graphql-transport test:e2e`

## Testing
The full gamut of graphql-specific tests are listed in the [rust.yml](../../.github/workflows/rust.yml).

To run the tests in `sui-mvr-graphql-rpc`, you will need to have postgres running locally.
24 changes: 24 additions & 0 deletions crates/sui-mvr-graphql-rpc/examples/address/address.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Get the address' balance and its coins' id and type
{
address(
address: "0x5094652429957619e6efa79a404a6714d1126e63f551f4b6c7fb76440f8118c9"
) {
address
balance {
coinType {
repr
}
coinObjectCount
totalBalance
}
coins {
nodes {
contents {
type {
repr
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# See examples in Query::transactionBlocks as this is similar behavior
# to the `transactionBlocks` in Query but supports additional
# `AddressTransactionBlockRelationship` filter

# Filtering on package where the signer of the TX is the current
# address and displaying the transaction's sender and the gas price
# and budget.
query transaction_block_with_relation_filter {
address(address: "0x2") {
transactionBlocks(relation: SENT, filter: { function: "0x2" }) {
nodes {
sender {
address
}
gasInput {
gasPrice
gasBudget
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Query the balance for objects of type COIN and then for each coin
# get the coin type, the number of objects, and the total balance
{
address(
address: "0x5094652429957619e6efa79a404a6714d1126e63f551f4b6c7fb76440f8118c9"
) {
balance(
type: "0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN"
) {
coinObjectCount
totalBalance
}
balances {
nodes {
coinType {
repr
}
coinObjectCount
totalBalance
}
pageInfo {
endCursor
}
}
}
}
4 changes: 4 additions & 0 deletions crates/sui-mvr-graphql-rpc/examples/chain_id/chain_id.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Returns the chain identifier for the chain that the server is tracking
{
chainIdentifier
}
22 changes: 22 additions & 0 deletions crates/sui-mvr-graphql-rpc/examples/checkpoint/at_digest.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Get the checkpoint's information at a particular digest
{
checkpoint(id: { digest: "GaDeWEfbSQCQ8FBQHUHVdm4KjrnbgMqEZPuhStoq5njU" }) {
digest
sequenceNumber
validatorSignatures
previousCheckpointDigest
networkTotalTransactions
rollingGasSummary {
computationCost
storageCost
storageRebate
nonRefundableStorageFee
}
epoch {
epochId
referenceGasPrice
startTimestamp
endTimestamp
}
}
}
Loading
Loading