Skip to content

add graphman config check, place, pools to graphql api #5751

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

Closed
Prev Previous commit
Next Next commit
server: add tests for graphman config check graphql api
  • Loading branch information
shiyasmohd committed Jan 4, 2025
commit cd629221cb0cdf8c7c6237fdcac04037e3338361
101 changes: 101 additions & 0 deletions server/graphman/tests/config_query.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
pub mod util;

use graph::log::logger;
use graphman::config::Config;
use serde_json::json;

use self::util::client::send_graphql_request;
use self::util::run_test;
use self::util::server::VALID_TOKEN;

#[test]
fn graphql_can_validate_config_and_subgraphs_settings_config() {
run_test(|| async {
let curr_dir = std::env::current_dir()
.unwrap()
.to_str()
.unwrap()
.to_string();
let config_dir = format!("{}/tests/test_config.toml", curr_dir);
let subgraph_settings_dir = format!("{}/tests/test_subgraph_settings.toml", curr_dir);
std::env::set_var("GRAPH_NODE_CONFIG", config_dir);
std::env::set_var(
"GRAPH_EXPERIMENTAL_SUBGRAPH_SETTINGS",
subgraph_settings_dir,
);

let resp = send_graphql_request(
json!({
"query": r#"{
config {
check {
configValidated
subgraphSettingsValidated
}
}
}"#
}),
VALID_TOKEN,
)
.await;

let expected_resp = json!({
"data": {
"config": {
"check": {
"configValidated": true,
"subgraphSettingsValidated": true
}
}
}
});

assert_eq!(resp, expected_resp);
});
}

#[test]
fn graphql_can_return_config_as_json_string() {
run_test(|| async {
let curr_dir = std::env::current_dir()
.unwrap()
.to_str()
.unwrap()
.to_string();
let config_dir = format!("{}/tests/test_config.toml", curr_dir);
std::env::set_var("GRAPH_NODE_CONFIG", config_dir.clone());

let resp = send_graphql_request(
json!({
"query": r#"{
config {
check {
config
}
}
}"#
}),
VALID_TOKEN,
)
.await;

let config = Config::from_file(&logger(true), &config_dir, "default")
.unwrap()
.to_json()
.unwrap();

assert_eq!(
resp.get("data")
.unwrap()
.get("config")
.unwrap()
.get("check")
.unwrap()
.get("config")
.unwrap()
.as_str()
.unwrap(),
config
);
});
}
71 changes: 71 additions & 0 deletions server/graphman/tests/test_config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
[general]
query = "query_node_.*"

[store]
[store.primary]
connection = "postgresql://postgres:1.1.1.1@test/primary"
pool_size = [
{ node = "index_node_1_.*", size = 2 },
{ node = "index_node_2_.*", size = 10 },
{ node = "index_node_3_.*", size = 10 },
{ node = "index_node_4_.*", size = 2 },
{ node = "query_node_.*", size = 10 }
]

[store.shard_a]
connection = "postgresql://postgres:1.1.1.1@test/shard-a"
pool_size = [
{ node = "index_node_1_.*", size = 2 },
{ node = "index_node_2_.*", size = 10 },
{ node = "index_node_3_.*", size = 10 },
{ node = "index_node_4_.*", size = 2 },
{ node = "query_node_.*", size = 10 }
]

[deployment]
# Studio subgraphs
[[deployment.rule]]
match = { name = "^prefix/" }
shard = "shard_a"
indexers = [ "index_prefix_0",
"index_prefix_1" ]

[[deployment.rule]]
match = { name = "^custom/.*" }
indexers = [ "index_custom_0" ]

[[deployment.rule]]
shards = [ "primary", "shard_a" ]
indexers = [ "index_node_1_a",
"index_node_2_a",
"index_node_3_a" ]

[chains]
ingestor = "index_0"

[chains.mainnet]
shard = "primary"
provider = [
{ label = "mainnet-0", url = "http://rpc.mainnet.io", features = ["archive", "traces"] },
{ label = "mainnet-1", details = { type = "web3call", url = "http://rpc.mainnet.io", features = ["archive", "traces"] }},
{ label = "firehose", details = { type = "firehose", url = "http://localhost:9000", features = [] }},
{ label = "substreams", details = { type = "substreams", url = "http://localhost:9000", features = [] }},
]

[chains.ropsten]
shard = "primary"
provider = [
{ label = "ropsten-0", url = "http://rpc.ropsten.io", transport = "rpc", features = ["archive", "traces"] }
]

[chains.goerli]
shard = "primary"
provider = [
{ label = "goerli-0", url = "http://rpc.goerli.io", transport = "ipc", features = ["archive"] }
]

[chains.kovan]
shard = "primary"
provider = [
{ label = "kovan-0", url = "http://rpc.kovan.io", transport = "ws", features = [] }
]
11 changes: 11 additions & 0 deletions server/graphman/tests/test_subgraph_settings.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[[setting]]
match = { name = ".*" }
history_blocks = 10000

[[setting]]
match = { name = "xxxxx" }
history_blocks = 10000

[[setting]]
match = { name = ".*!$" }
history_blocks = 10000
Loading