-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[graphql/rpc] schema export and snapshot tests (#13339)
## 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
Showing
9 changed files
with
95 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
crates/sui-graphql-rpc/tests/snapshots/snapshot_tests__test__schema_sdl_export.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|