-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Graphman deploy command #4930
Merged
Merged
Graphman deploy command #4930
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,105 @@ | ||
use std::sync::Arc; | ||
|
||
use graph::prelude::{ | ||
anyhow::{anyhow, bail, Result}, | ||
reqwest, | ||
serde_json::{json, Value}, | ||
SubgraphName, SubgraphStore, | ||
}; | ||
|
||
use crate::manager::deployment::DeploymentSearch; | ||
|
||
// Function to send an RPC request and handle errors | ||
async fn send_rpc_request(url: &str, payload: Value) -> Result<()> { | ||
let client = reqwest::Client::new(); | ||
let response = client.post(url).json(&payload).send().await?; | ||
|
||
if response.status().is_success() { | ||
Ok(()) | ||
} else { | ||
Err(response | ||
.error_for_status() | ||
.expect_err("Failed to parse error response") | ||
.into()) | ||
} | ||
} | ||
|
||
// Function to send subgraph_create request | ||
async fn send_create_request(name: &str, url: &str) -> Result<()> { | ||
// Construct the JSON payload for subgraph_create | ||
let create_payload = json!({ | ||
"jsonrpc": "2.0", | ||
"method": "subgraph_create", | ||
"params": { | ||
"name": name, | ||
}, | ||
"id": "1" | ||
}); | ||
|
||
// Send the subgraph_create request | ||
send_rpc_request(url, create_payload) | ||
.await | ||
.map_err(|e| e.context(format!("Failed to create subgraph with name `{}`", name))) | ||
} | ||
|
||
// Function to send subgraph_deploy request | ||
async fn send_deploy_request(name: &str, deployment: &str, url: &str) -> Result<()> { | ||
// Construct the JSON payload for subgraph_deploy | ||
let deploy_payload = json!({ | ||
"jsonrpc": "2.0", | ||
"method": "subgraph_deploy", | ||
"params": { | ||
"name": name, | ||
"ipfs_hash": deployment, | ||
}, | ||
"id": "1" | ||
}); | ||
|
||
// Send the subgraph_deploy request | ||
send_rpc_request(url, deploy_payload).await.map_err(|e| { | ||
e.context(format!( | ||
"Failed to deploy subgraph `{}` to `{}`", | ||
deployment, name | ||
)) | ||
}) | ||
} | ||
pub async fn run( | ||
subgraph_store: Arc<impl SubgraphStore>, | ||
deployment: DeploymentSearch, | ||
search: DeploymentSearch, | ||
url: String, | ||
create: bool, | ||
) -> Result<()> { | ||
let hash = match deployment { | ||
DeploymentSearch::Hash { hash, shard: _ } => hash, | ||
_ => bail!("The `deployment` argument must be a valid IPFS hash"), | ||
}; | ||
|
||
let name = match search { | ||
DeploymentSearch::Name { name } => name, | ||
_ => bail!("The `name` must be a valid subgraph name"), | ||
}; | ||
|
||
if create { | ||
println!("Creating subgraph `{}`", name); | ||
let subgraph_name = | ||
SubgraphName::new(name.clone()).map_err(|_| anyhow!("Invalid subgraph name"))?; | ||
|
||
let exists = subgraph_store.subgraph_exists(&subgraph_name)?; | ||
|
||
if exists { | ||
bail!("Subgraph with name `{}` already exists", name); | ||
} | ||
|
||
// Send the subgraph_create request | ||
send_create_request(&name, &url).await?; | ||
println!("Subgraph `{}` created", name); | ||
} | ||
|
||
// Send the subgraph_deploy request | ||
println!("Deploying subgraph `{}` to `{}`", hash, name); | ||
send_deploy_request(&name, &hash, &url).await?; | ||
println!("Subgraph `{}` deployed to `{}`", name, url); | ||
|
||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be awesome if we would not need a
url
, but getting away from that might be pretty tough as we would have to instantiate our ownSubgraphRegistrar
; if the default is ok in most cases, I think it's not a big deal.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That didn't cross my mind, just took a look at how that would turn out. We still would need to provide a NodeID when creating a new SubgraphRegistrar.
And the default_value for the url i believe is almost always ok unless the indexer change it explicitly. So we can go with this now and update in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, let's not hold this up because of the URL; just go ahead and merge