Skip to content
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

Use registry templates to create new app #4703

Merged
merged 16 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Cargo.lock

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

33 changes: 32 additions & 1 deletion lib/backend-api/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use wasmer_config::package::PackageIdent;
use crate::{
types::{
self, CreateNamespaceVars, DeployApp, DeployAppConnection, DeployAppVersion,
DeployAppVersionConnection, DnsDomain, GetCurrentUserWithAppsVars, GetDeployAppAndVersion,
DeployAppVersionConnection, DnsDomain, GetAppTemplateFromSlugVariables,
GetAppTemplatesQueryVariables, GetCurrentUserWithAppsVars, GetDeployAppAndVersion,
GetDeployAppVersionsVars, GetNamespaceAppsVars, GetSignedUrlForPackageUploadVariables, Log,
LogStream, PackageVersionConnection, PublishDeployAppVars, PushPackageReleasePayload,
SignedUrl, TagPackageReleasePayload, UpsertDomainFromZoneFileVars,
Expand Down Expand Up @@ -55,6 +56,36 @@ pub async fn fetch_webc_package(
webc::compat::Container::from_bytes(data).context("failed to parse webc package")
}

/// Fetch app templates.
pub async fn fetch_app_template_from_slug(
client: &WasmerClient,
slug: String,
) -> Result<Option<types::AppTemplate>, anyhow::Error> {
client
.run_graphql_strict(types::GetAppTemplateFromSlug::build(
GetAppTemplateFromSlugVariables { slug },
))
.await
.map(|v| v.get_app_template)
}

/// Fetch app templates.
pub async fn fetch_app_templates(
client: &WasmerClient,
category_slug: String,
first: i32,
) -> Result<Option<types::AppTemplateConnection>, anyhow::Error> {
client
.run_graphql_strict(types::GetAppTemplatesQuery::build(
GetAppTemplatesQueryVariables {
category_slug,
first,
},
))
.await
.map(|r| r.get_app_templates)
}

/// Get a signed URL to upload packages.
pub async fn get_signed_url_for_package_upload(
client: &WasmerClient,
Expand Down
68 changes: 66 additions & 2 deletions lib/backend-api/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,75 @@ mod queries {
pub version: String,
pub created_at: DateTime,
pub pirita_manifest: Option<JSONString>,
pub distribution: PackageDistribution,

pub package: Package,

#[arguments(version: "V3")]
#[cynic(rename = "distribution")]
pub distribution_v3: PackageDistribution,

#[arguments(version: "V2")]
#[cynic(rename = "distribution")]
pub distribution_v2: PackageDistribution,
}

#[derive(cynic::QueryVariables, Debug)]
pub struct GetAppTemplateFromSlugVariables {
pub slug: String,
}

#[derive(cynic::QueryFragment, Debug)]
#[cynic(graphql_type = "Query", variables = "GetAppTemplateFromSlugVariables")]
pub struct GetAppTemplateFromSlug {
#[arguments(slug: $slug)]
pub get_app_template: Option<AppTemplate>,
}
#[derive(cynic::QueryVariables, Debug)]
pub struct GetAppTemplatesQueryVariables {
pub category_slug: String,
pub first: i32,
}

#[derive(cynic::QueryFragment, Debug)]
#[cynic(graphql_type = "Query", variables = "GetAppTemplatesQueryVariables")]
pub struct GetAppTemplatesQuery {
#[arguments(categorySlug: $category_slug, first: $first)]
pub get_app_templates: Option<AppTemplateConnection>,
}

#[derive(cynic::QueryFragment, Debug)]
pub struct AppTemplateConnection {
pub edges: Vec<Option<AppTemplateEdge>>,
pub page_info: PageInfo,
}

#[derive(cynic::QueryFragment, Debug)]
pub struct AppTemplateEdge {
pub node: Option<AppTemplate>,
pub cursor: String,
}

#[derive(cynic::QueryFragment, Debug)]
pub struct AppTemplate {
pub demo_url: String,
pub language: String,
pub name: String,
pub framework: String,
pub created_at: DateTime,
pub description: String,
pub id: cynic::Id,
pub is_public: bool,
pub repo_license: String,
pub readme: String,
pub repo_url: String,
pub slug: String,
pub updated_at: DateTime,
pub use_cases: Jsonstring,
}

#[derive(cynic::Scalar, Debug, Clone)]
#[cynic(graphql_type = "JSONString")]
pub struct Jsonstring(pub String);

#[derive(cynic::QueryVariables, Debug)]
pub struct GetPackageReleaseVars {
pub hash: String,
Expand Down
5 changes: 3 additions & 2 deletions lib/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ wasmer-compiler-singlepass = { version = "=4.3.0", path = "../compiler-singlepas
wasmer-compiler-llvm = { version = "=4.3.0", path = "../compiler-llvm", optional = true }
wasmer-emscripten = { version = "=4.3.0", path = "../emscripten" }
wasmer-vm = { version = "=4.3.0", path = "../vm", optional = true }
wasmer-wasix = { path = "../wasix", version="=0.20.0" , features = [
wasmer-wasix = { path = "../wasix", version = "=0.20.0", features = [
"logging",
"webc_runner_rt_wcgi",
"webc_runner_rt_dcgi",
Expand Down Expand Up @@ -185,7 +185,7 @@ tldextract = "0.6.0"
hex = "0.4.3"
flate2 = "1.0.25"
cargo_metadata = "0.15.2"
tar = "0.4.38"
tar = "0.4.40"
bytes = "1"
thiserror = "1.0.37"
log = "0.4.17"
Expand Down Expand Up @@ -229,6 +229,7 @@ tun-tap = { version = "0.1.3", features = ["tokio"], optional = true }

clap_complete = "4.5.2"
clap_mangen = "0.2.20"
zip = { version = "1.2.3", default-features = false, features = ["deflate"] }

# NOTE: Must use different features for clap because the "color" feature does not
# work on wasi due to the anstream dependency not compiling.
Expand Down
Loading
Loading