-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): meta undeploy subcommand (#508)
<!-- Pull requests are squash merged using: - their title as the commit message - their description as the commit body Having a good title and description is important for the users to get readable changelog and understand when they need to update his code and how. --> ### Describe your change Add `undeploy` subcommand to the meta CLI. ### Motivation and context - Allow user to undeploy a typegraph. - We always had resource leak error when deploying a typegraph from a test step. This subcommand would allow us to undeploy the typegraph at the end of the test step. ### Checklist - [x] The change come with new or modified tests - [x] Hard-to-understand functions have explanatory comments - [ ] ~End-user documentation is updated to reflect the change~: *N/A*
- Loading branch information
Showing
15 changed files
with
271 additions
and
161 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
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,66 @@ | ||
// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
use crate::{ | ||
config::Config, | ||
utils::{graphql::Query, Node}, | ||
}; | ||
use anyhow::{Context, Result}; | ||
use async_trait::async_trait; | ||
use clap::Parser; | ||
use indoc::indoc; | ||
|
||
use super::{Action, CommonArgs}; | ||
|
||
#[derive(Parser, Debug)] | ||
pub struct Undeploy { | ||
#[command(flatten)] | ||
node: CommonArgs, | ||
|
||
#[clap(short, long)] | ||
pub target: String, | ||
|
||
/// Typegraph names | ||
#[clap(long = "typegraph")] | ||
pub typegraphs: Vec<String>, | ||
} | ||
|
||
#[async_trait] | ||
impl Action for Undeploy { | ||
async fn run(&self, args: super::GenArgs) -> Result<()> { | ||
let dir = args.dir()?; | ||
let config_path = args.config.clone(); | ||
let config = Config::load_or_find(config_path, &dir)?; | ||
let node_config = config.node(&self.node, &self.target); | ||
let node = node_config.build(&dir).await?; | ||
node.undeploy(&self.typegraphs).await?; | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
impl Node { | ||
async fn undeploy(&self, typegraphs: &[String]) -> Result<()> { | ||
let res = self | ||
.post("/typegate")? | ||
.gql( | ||
indoc! {" | ||
mutation($names: [String!]!) { | ||
removeTypegraphs(names: $names) | ||
}"} | ||
.to_string(), | ||
Some(serde_json::json!({ | ||
"names": typegraphs, | ||
})), | ||
) | ||
.await?; | ||
|
||
let res: bool = res | ||
.data("removeTypegraphs") | ||
.context("removeTypegraph reponse")?; | ||
if !res { | ||
anyhow::bail!("undeploy failed"); | ||
} | ||
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
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
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
Oops, something went wrong.