-
Notifications
You must be signed in to change notification settings - Fork 995
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
119 additions
and
3 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
pub mod assign; | ||
pub mod config; | ||
pub mod info; | ||
pub mod query; | ||
pub mod remove; | ||
pub mod txn_speed; | ||
pub mod unused_deployments; |
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,62 @@ | ||
use std::iter::FromIterator; | ||
use std::{collections::HashMap, sync::Arc}; | ||
|
||
use graph::{ | ||
data::query::QueryTarget, | ||
prelude::{ | ||
anyhow::{self, anyhow}, | ||
q, serde_json, GraphQlRunner as _, Query, QueryVariables, SubgraphDeploymentId, | ||
SubgraphName, | ||
}, | ||
}; | ||
use graph_graphql::prelude::GraphQlRunner; | ||
use graph_store_postgres::Store; | ||
|
||
use crate::manager::PanicSubscriptionManager; | ||
|
||
pub async fn run( | ||
runner: Arc<GraphQlRunner<Store, PanicSubscriptionManager>>, | ||
target: String, | ||
query: String, | ||
vars: Vec<String>, | ||
) -> Result<(), anyhow::Error> { | ||
let target = if target.starts_with("Qm") { | ||
let id = SubgraphDeploymentId::new(target) | ||
.map_err(|id| anyhow!("illegal deployment id `{}`", id))?; | ||
QueryTarget::Deployment(id) | ||
} else { | ||
let name = SubgraphName::new(target.clone()) | ||
.map_err(|()| anyhow!("illegal subgraph name `{}`", target))?; | ||
QueryTarget::Name(name) | ||
}; | ||
|
||
let document = graphql_parser::parse_query(&query)?.into_static(); | ||
let vars: Vec<(String, q::Value)> = vars | ||
.into_iter() | ||
.map(|v| { | ||
let mut pair = v.splitn(2, '=').map(|s| s.to_string()); | ||
let key = pair.next(); | ||
let value = pair | ||
.next() | ||
.map(|s| q::Value::String(s)) | ||
.unwrap_or(q::Value::Null); | ||
match key { | ||
Some(key) => Ok((key, value)), | ||
None => Err(anyhow!( | ||
"malformed variable `{}`, it must be of the form `key=value`", | ||
v | ||
)), | ||
} | ||
}) | ||
.collect::<Result<_, _>>()?; | ||
let query = Query::new( | ||
document, | ||
Some(QueryVariables::new(HashMap::from_iter(vars))), | ||
); | ||
|
||
let res = runner.run_query(query, target, false).await; | ||
let json = serde_json::to_string(&res)?; | ||
println!("{}", json); | ||
|
||
Ok(()) | ||
} |
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,18 @@ | ||
use graph::{ | ||
components::store::SubscriptionManager, | ||
prelude::{StoreEventStreamBox, SubscriptionFilter}, | ||
}; | ||
|
||
pub mod catalog; | ||
pub mod commands; | ||
pub mod deployment; | ||
mod display; | ||
|
||
/// A dummy subscription manager that always panics | ||
pub struct PanicSubscriptionManager; | ||
|
||
impl SubscriptionManager for PanicSubscriptionManager { | ||
fn subscribe(&self, _: Vec<SubscriptionFilter>) -> StoreEventStreamBox { | ||
panic!("we were never meant to call `subscribe`"); | ||
} | ||
} |