Skip to content

Commit

Permalink
[graphql/rpc] schema export and snapshot tests (#13339)
Browse files Browse the repository at this point in the history
## Description 

* Adds snapshot tests to ensure schema stability

* Adds command to dump the schema

```
$  ./target/debug/sui-graphql-rpc generate-schema

type Query {
        chainIdentifier: String!
}


schema {
        query: Query
}

```

## Test Plan 

Manual

---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [ ] protocol change
- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
  • Loading branch information
oxade authored and ebmifa committed Aug 10, 2023
1 parent aa2ccac commit babdc0f
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions crates/sui-graphql-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ edition = "2021"

[dependencies]
async-graphql.workspace = true
clap.workspace = true
serde.workspace = true
move-core-types.workspace = true

workspace-hack = { version = "0.1", path = "../workspace-hack" }

[dev-dependencies]
insta.workspace = true
16 changes: 16 additions & 0 deletions crates/sui-graphql-rpc/src/commands.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use clap::*;

#[derive(Parser)]
#[clap(
name = "sui-graphql-rpc",
about = "Sui GraphQL RPC",
rename_all = "kebab-case",
author,
version
)]
pub enum Command {
GenerateSchema,
}
12 changes: 11 additions & 1 deletion crates/sui-graphql-rpc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

mod types;
use async_graphql::*;

pub mod commands;
pub mod types;

use crate::types::query::Query;

pub fn schema_sdl_export() -> String {
let schema = Schema::build(Query, EmptyMutation, EmptySubscription).finish();
schema.sdl()
}
13 changes: 12 additions & 1 deletion crates/sui-graphql-rpc/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

fn main() {}
use clap::Parser;
use sui_graphql_rpc::commands::Command;
use sui_graphql_rpc::schema_sdl_export;

fn main() {
let cmd: Command = Command::parse();
match cmd {
Command::GenerateSchema => {
println!("{}", &schema_sdl_export());
}
}
}
9 changes: 5 additions & 4 deletions crates/sui-graphql-rpc/src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

mod base64;
mod big_int;
mod date_time;
mod sui_address;
pub mod base64;
pub mod big_int;
pub mod date_time;
pub mod query;
pub mod sui_address;
14 changes: 14 additions & 0 deletions crates/sui-graphql-rpc/src/types/query.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use async_graphql::*;

pub struct Query;

#[allow(unreachable_code)]
#[Object]
impl Query {
async fn chain_identifier(&self) -> String {
unimplemented!()
}
}
14 changes: 14 additions & 0 deletions crates/sui-graphql-rpc/tests/snapshot_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use insta::assert_snapshot;

mod test {
use super::*;

#[test]
fn test_schema_sdl_export() {
let sdl = sui_graphql_rpc::schema_sdl_export();
assert_snapshot!(sdl);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
source: crates/sui-graphql-rpc/tests/snapshot_tests.rs
expression: sdl
---




type Query {
chainIdentifier: String!
}


schema {
query: Query
}

0 comments on commit babdc0f

Please sign in to comment.