Skip to content

Commit

Permalink
Merge pull request #794 from rainlanguage/2024-08-26-schema-validator
Browse files Browse the repository at this point in the history
Subgraph schema validator
  • Loading branch information
rouzwelt authored Aug 28, 2024
2 parents 2aba2de + 00dc8d2 commit 6b63050
Show file tree
Hide file tree
Showing 8 changed files with 272 additions and 13 deletions.
53 changes: 45 additions & 8 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ anyhow = "1.0.70"
async-trait = "0.1.77"
clap = { version = "4.2.5", features = ["cargo", "derive"] }
once_cell = "1.17.1"
reqwest = { version = "0.11.17", features = ["json"] }
reqwest = { version = "0.12.5", features = ["json"] }
rust-bigint = "1.2.0"
serde = "1.0.200"
futures = "0.3.17"
Expand All @@ -29,7 +29,7 @@ tracing-subscriber = "0.3.17"
url = "2.5.0"
comfy-table = "7.1.0"
cynic-codegen = { version = "3.4.0", features = ["rkyv"] }
cynic = "3.4.0"
cynic = "3.7.3"
chrono = "0.4.31"
typeshare = { git = "https://github.com/tomjw64/typeshare", rev = "556b44aafd5304eedf17206800f69834e3820b7c" }
thiserror = "1.0.56"
Expand Down
6 changes: 5 additions & 1 deletion crates/cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ mod chart;
mod order;
mod order_take;
mod quote;
mod subgraph;
mod vault;
mod words;

pub use self::{chart::Chart, order::Order, order_take::OrderTake, vault::Vault, words::Words};
pub use self::{
chart::Chart, order::Order, order_take::OrderTake, subgraph::Subgraph, vault::Vault,
words::Words,
};
34 changes: 34 additions & 0 deletions crates/cli/src/commands/subgraph/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use crate::execute::Execute;
use anyhow::Result;
use clap::Parser;
use rain_orderbook_subgraph_client::validate::validate_subgraph_schema;

#[derive(Parser)]
pub enum Subgraph {
#[command(about = "Validates a subgraph schema against this apps subgraph schema")]
Validate {
/// Subgraph url to validate
subgraph_url: String,
},
}

impl Execute for Subgraph {
async fn execute(&self) -> Result<()> {
match self {
Subgraph::Validate { subgraph_url } => Ok(validate_subgraph_schema(subgraph_url)
.await
.map(|v| println!("--- {}valid subgraph ---", if v { "" } else { "in" }))?),
}
}
}

#[cfg(test)]
mod tests {
use super::*;
use clap::CommandFactory;

#[test]
fn verify_command() {
Subgraph::command().debug_assert();
}
}
6 changes: 5 additions & 1 deletion crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::commands::{Chart, Order, OrderTake, Vault, Words};
use crate::commands::{Chart, Order, OrderTake, Subgraph, Vault, Words};
use crate::execute::Execute;
use anyhow::Result;
use clap::Subcommand;
Expand All @@ -22,6 +22,9 @@ pub enum Orderbook {
#[command(subcommand)]
OrderTake(OrderTake),

#[command(subcommand)]
Subgraph(Subgraph),

Chart(Chart),

Quote(Quoter),
Expand All @@ -37,6 +40,7 @@ impl Orderbook {
Orderbook::OrderTake(order_take) => (order_take).execute().await,
Orderbook::Chart(chart) => chart.execute().await,
Orderbook::Quote(quote) => quote.execute().await,
Orderbook::Subgraph(subgraph) => subgraph.execute().await,
Orderbook::Words(words) => words.execute().await,
}
}
Expand Down
4 changes: 3 additions & 1 deletion crates/subgraph/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ serde_json = { workspace = true }
alloy = { workspace = true }
rain_orderbook_bindings = { workspace = true }
chrono = { workspace = true }
cynic-introspection = "3.7.3"

[dev-dependencies]
insta = { workspace = true }
tokio = { workspace = true }
tokio = { workspace = true, features = ["full"] }
httpmock = "0.7.0"

[build-dependencies]
cynic-codegen = { workspace = true }
1 change: 1 addition & 0 deletions crates/subgraph/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod orderbook_client;
mod pagination;
pub mod types;
pub mod utils;
pub mod validate;
mod vault_balance_changes_query;

#[cynic::schema("orderbook")]
Expand Down
Loading

0 comments on commit 6b63050

Please sign in to comment.