Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/met-572-typegate-in-meta-de…
Browse files Browse the repository at this point in the history
…v' into met-557-test-upgrade
  • Loading branch information
Natoandro committed Jul 3, 2024
2 parents 1474dd4 + acfffa9 commit b4ebffd
Show file tree
Hide file tree
Showing 17 changed files with 1,500 additions and 147 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions examples/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"imports": {
"@typegraph/sdk": "../typegraph/deno/sdk/src",
"@typegraph/sdk/": "../typegraph/deno/sdk/src/"
}
}
907 changes: 907 additions & 0 deletions examples/deno.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions examples/typegraphs/microservice-orchestration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function getEnvOrDefault(key: string, defaultValue: string) {
}
// skip:end

typegraph(
await typegraph(
{
name: "team-a",
// skip:next-line
Expand All @@ -26,20 +26,20 @@ typegraph(

const deno = new DenoRuntime();
const records = new GraphQLRuntime(
getEnvOrDefault("TG_URL", "http://localhost:7890" + "/team-b")
getEnvOrDefault("TG_URL", "http://localhost:7890" + "/team-b"),
);

g.expose(
{
version_team_b: records.query(t.struct({}), t.integer(), ["version"]),
version_team_a: deno.static(t.integer(), 3),
},
pub
pub,
);
}
},
);

typegraph(
await typegraph(
{
name: "team-b",
// skip:next-line
Expand All @@ -55,7 +55,7 @@ typegraph(
version: deno.static(t.integer(), 12),
record: deno.static(t.struct({ weight: t.integer() }), { weight: 100 }),
},
pub
pub,
);
}
},
);
28 changes: 15 additions & 13 deletions meta-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ repository = "https://github.com/metatypedev/metatype"
include = ["src"]
keywords = ["api", "composition", "typesystem", "graphql", "ecosystem"]
categories = [
"accessibility",
"api-bindings",
"data-structures",
"development-tools",
"wasm",
"accessibility",
"api-bindings",
"data-structures",
"development-tools",
"wasm",
]
build = "build.rs"

Expand Down Expand Up @@ -64,21 +64,22 @@ clap-verbosity-flag = "2.2.0"
ctrlc = "3.4.4"
dialoguer = "0.11.0"
self_update = { version = "0.39.0", features = [
"archive-tar",
"archive-zip",
"compression-flate2",
"compression-zip-deflate",
"compression-zip-bzip2",
"archive-tar",
"archive-zip",
"compression-flate2",
"compression-zip-deflate",
"compression-zip-bzip2",
] }

# codecs
serde.workspace = true
serde_json = { workspace = true, features = ["preserve_order"] }
flate2.workspace = true
tar.workspace = true
base64.workspace = true
# FIXME: deprecated, be on the lookout for alternatives
serde_yaml = "0.9.33"
base64.workspace = true
strip-ansi-escapes = "0.2.0"

# fs
normpath = "1.2.0"
Expand All @@ -91,6 +92,7 @@ ignore = "0.4.20"
globset = "0.4.14"
pathdiff = "0.2.1"
textwrap = "0.16.1"
tempfile.workspace = true

# http
reqwest = { workspace = true, features = ["json"] }
Expand All @@ -110,17 +112,17 @@ prisma-models = { git = "https://github.com/prisma/prisma-engines", tag = "5.6.0
nix = { version = "0.29.0", features = ["signal"] }
lade-sdk = "0.9.1"
git2 = { version = "0.18.3", features = [
"vendored-libgit2",
"vendored-libgit2",
], default-features = false }
process-wrap = { version = "8.0.2", features = ["tokio1"] }
rand = "0.8.5"

[dev-dependencies]
# testing
assert_cmd = "2.0.14"

# fs
project-root = "0.2.2"
tempfile.workspace = true

[build-dependencies]
shadow-rs.workspace = true
24 changes: 24 additions & 0 deletions meta-cli/src/cli/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,20 @@ pub struct DeployOptions {
/// Overrides secrets in the format `[<typegraph-name>:]<secret-name>=<value>`
#[clap(long = "secret")]
pub secrets: Vec<String>,

// FIXME incompatible with non-watch mode
#[cfg(feature = "typegate")]
/// Run a typegate with the current target configuration
#[clap(long)]
pub run_typegate: bool,
}

#[derive(Debug)]
pub struct Deploy {
config: Arc<Config>,
node: Node,
#[cfg(feature = "typegate")]
node_config: crate::config::NodeConfig,
base_dir: Arc<Path>,
options: DeployOptions,
secrets: RawSecrets,
Expand Down Expand Up @@ -115,6 +123,8 @@ impl Deploy {
Ok(Self {
config,
node,
#[cfg(feature = "typegate")]
node_config,
base_dir: dir.clone(),
options,
secrets,
Expand Down Expand Up @@ -283,6 +293,20 @@ mod watch_mode {
deploy.options.allow_destructive,
);

#[cfg(feature = "typegate")]
let _typegate_addr = if deploy.options.run_typegate {
use crate::deploy::actors::typegate::TypegateInit;
info!("starting typegate");
Some(
TypegateInit::new(&deploy.node_config, &deploy.base_dir)
.await?
.start(console.clone())
.await?,
)
} else {
None
};

let mut init = TaskManagerInit::<DeployAction>::new(
deploy.config.clone(),
action_generator.clone(),
Expand Down
7 changes: 7 additions & 0 deletions meta-cli/src/cli/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ pub struct Dev {
/// secrets overload
#[clap(long = "secret")]
secrets: Vec<String>,

#[cfg(feature = "typegate")]
/// Do not run a typegate. By default a typegate is run with the current target configuration
#[clap(long)]
no_typegate: bool,
}

#[async_trait]
Expand All @@ -41,6 +46,8 @@ impl Action for Dev {
no_migration: false,
create_migration: true,
secrets: self.secrets.clone(),
#[cfg(feature = "typegate")]
run_typegate: !self.no_typegate,
};

let deploy = DeploySubcommand::new(
Expand Down
30 changes: 30 additions & 0 deletions meta-cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,36 @@ impl NodeConfig {
}
}

pub async fn get_admin_password(&self, dir: impl AsRef<Path>) -> Result<String> {
let raw_username = self
.username
.clone()
.ok_or_else(|| ferr!("no username in config file metatype.yaml"))?;

let raw_password = self
.password
.clone()
.ok_or_else(|| ferr!("no password in config file metatype.yaml"))?;

let username = lade_sdk::hydrate_one(raw_username, dir.as_ref())
.await
.map_err(anyhow_to_eyre!())
.context("error hydrating username")?;

if &username != "admin" {
return Err(ferr!(
"username in config file metatype.yaml is not 'admin'"
));
}

let password = lade_sdk::hydrate_one(raw_password, dir.as_ref())
.await
.map_err(anyhow_to_eyre!())
.context("error hydrating password")?;

Ok(password)
}

#[tracing::instrument]
pub async fn build<P: AsRef<Path> + core::fmt::Debug>(&self, dir: P) -> Result<Node> {
Node::new(
Expand Down
2 changes: 2 additions & 0 deletions meta-cli/src/deploy/actors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ pub mod discovery;
pub mod task;
mod task_io;
pub mod task_manager;
#[cfg(feature = "typegate")]
pub mod typegate;
pub mod watcher;
Loading

0 comments on commit b4ebffd

Please sign in to comment.