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 3 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
193 changes: 191 additions & 2 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
58 changes: 58 additions & 0 deletions lib/backend-api/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,64 @@ mod queries {
pub package: Package,
}

#[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
Loading
Loading