Skip to content

Commit

Permalink
Merge pull request #5172 from wasmerio/run-470-backend-api-upgrade-sc…
Browse files Browse the repository at this point in the history
…hema-definitions-to-allow-for-optional

chore(backend-api): Update GraphQL schema
  • Loading branch information
syrusakbary authored Oct 24, 2024
2 parents 8549fe5 + 8207f21 commit 61e0b95
Show file tree
Hide file tree
Showing 9 changed files with 268 additions and 44 deletions.
133 changes: 112 additions & 21 deletions lib/backend-api/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,7 @@ type DeployAppVersion implements Node {
sourcePackage: Package!
aggregateMetrics: AggregateMetrics!
volumes: [AppVersionVolume]
gitSource: AutobuildRepository
favicon: URL
screenshot(viewportSize: AppScreenshotViewportSize, appearance: AppScreenshotAppearance): URL
}
Expand All @@ -935,7 +936,7 @@ type DeployApp implements Node & Owner {
createdBy: User!
createdAt: DateTime!
updatedAt: DateTime!
activeVersion: DeployAppVersion!
activeVersion: DeployAppVersion
globalName: String!
globalId: ID!
viewerCan(action: OwnerAction!): Boolean!
Expand All @@ -957,7 +958,7 @@ type DeployApp implements Node & Owner {
deleted: Boolean!
favicon: URL
screenshot(viewportSize: AppScreenshotViewportSize, appearance: AppScreenshotAppearance): URL
deployments(offset: Int, before: String, after: String, first: Int, last: Int): AutobuildRepositoryConnection
deployments(before: String, after: String, first: Int, last: Int): DeploymentConnection
}

enum DeployAppVersionsSortBy {
Expand Down Expand Up @@ -1144,40 +1145,52 @@ enum AppScreenshotAppearance {
DARK
}

type AutobuildRepositoryConnection {
type DeploymentConnection {
"""Pagination data for this connection."""
pageInfo: PageInfo!

"""Contains the nodes in this connection."""
edges: [AutobuildRepositoryEdge]!

"""Total number of items in the connection."""
totalCount: Int
edges: [DeploymentEdge]!
}

"""A Relay edge containing a `AutobuildRepository` and its cursor."""
type AutobuildRepositoryEdge {
"""A Relay edge containing a `Deployment` and its cursor."""
type DeploymentEdge {
"""The item at the end of the edge"""
node: AutobuildRepository
node: Deployment

"""A cursor for use in pagination"""
cursor: String!
}

union Deployment = NakedDeployment | AutobuildRepository

type NakedDeployment implements Node {
"""The ID of the object"""
id: ID!
createdAt: DateTime!
updatedAt: DateTime!
appVersion: DeployAppVersion
}

type AutobuildRepository implements Node {
"""The ID of the object"""
id: ID!
user: User!
name: String!
namespace: String!
app: DeployApp
createdAt: DateTime!
updatedAt: DateTime!
appName: String
appVersion: DeployAppVersion
buildId: UUID!
buildCmd: String!
installCmd: String!
repoUrl: String!
prevCommitHash: String!
commitHash: String!
commitMessage: String!
commitAuthorUsername: String!
status: StatusEnum!
appVersion: DeployAppVersion
logUrl: String
}

Expand All @@ -1190,6 +1203,7 @@ scalar UUID
enum StatusEnum {
SUCCESS
WORKING
RUNNING
FAILURE
QUEUED
TIMEOUT
Expand Down Expand Up @@ -2456,6 +2470,12 @@ type Query {
getAppTemplate(slug: String!): AppTemplate
getAppTemplateCategories(offset: Int, before: String, after: String, first: Int, last: Int): AppTemplateCategoryConnection
getBuildKinds(offset: Int, before: String, after: String, first: Int, last: Int): BuildKindConnection!

"""Specify if the database name is valid or not."""
canDeployDbWithName(
"""Name of the database"""
name: String!
): Boolean!
viewer: User
getUser(username: String!): User
getPasswordResetToken(token: String!): GetPasswordResetToken
Expand Down Expand Up @@ -3184,6 +3204,18 @@ type Mutation {

"""Delete a database for an app."""
deleteAppDb(input: DeleteAppDBInput!): DeleteAppDBPayload

"""Get the autobuild config for a given repo"""
autobuildConfigForRepo(input: AutobuildConfigForRepoInput!): AutobuildConfigForRepoPayload

"""Add a new github app installation"""
installGithubApp(input: InstallGithubAppInput!): InstallGithubAppPayload

"""Detach autobuild from app."""
detachAppFromAutobuild(input: DetachAppFromAutobuildInput!): DetachAppFromAutobuildPayload

"""Update autobuild config for an app."""
updateAutobuildConfigForApp(input: UpdateAutobuildConfigForAppInput!): UpdateAutobuildConfigForAppPayload
tokenAuth(input: ObtainJSONWebTokenInput!): ObtainJSONWebTokenPayload
generateDeployToken(input: GenerateDeployTokenInput!): GenerateDeployTokenPayload
verifyAccessToken(token: String): Verify
Expand Down Expand Up @@ -3708,6 +3740,74 @@ input DeleteAppDBInput {
clientMutationId: String
}

"""Get the autobuild config for a given repo"""
type AutobuildConfigForRepoPayload {
"""The build configuration"""
buildConfig: BuildConfig

"""List of apps deployed with this repo."""
deployedApps: [DeployApp]
clientMutationId: String
}

"""The Build Configuration for a given repo"""
type BuildConfig {
buildCmd: String!
installCmd: String!
setupDb: Boolean!
presetName: String!
appName: String!
}

input AutobuildConfigForRepoInput {
"""The repo URL"""
repoUrl: String!
clientMutationId: String
}

"""Add a new github app installation"""
type InstallGithubAppPayload {
success: Boolean!
user: User!
clientMutationId: String
}

input InstallGithubAppInput {
"""Github app Installation ID"""
installationId: ID!
clientMutationId: String
}

"""Detach autobuild from app."""
type DetachAppFromAutobuildPayload {
app: DeployApp!
clientMutationId: String
}

input DetachAppFromAutobuildInput {
"""The ID of the App"""
appId: ID!
clientMutationId: String
}

"""Update autobuild config for an app."""
type UpdateAutobuildConfigForAppPayload {
app: DeployApp!
clientMutationId: String
}

input UpdateAutobuildConfigForAppInput {
"""The ID of the App"""
appId: ID!

"""Build command for the app"""
buildCmd: String

"""Install command for the app"""
installCmd: String
clientMutationId: String
}

type ObtainJSONWebTokenPayload {
payload: GenericScalar!
refreshExpiresIn: Int!
Expand Down Expand Up @@ -4560,7 +4660,6 @@ type Subscription {
appIsPublishedFromRepo(repoId: ID!): DeployAppVersion!
publishAppFromRepoAutobuild(repoUrl: String!, appName: String!, owner: String, buildCmd: String, installCmd: String, databaseName: String, secrets: [SecretInput]): AutobuildLog
fetchBuildLogs(buildId: String!): String
autobuildConfigForRepo(repoUrl: String!): BuildConfig
packageVersionCreated(publishedBy: ID, ownerId: ID): PackageVersion!

"""Subscribe to package version ready"""
Expand All @@ -4586,14 +4685,6 @@ enum AutoBuildDeployAppLogKind {
COMPLETE
}

"""Log entry for Deploying app from github repo"""
type BuildConfig {
buildCmd: String!
installCmd: String!
setupDb: Boolean!
presetName: String!
}

type PackageVersionReadyResponse {
state: PackageVersionState!
packageVersion: PackageVersion!
Expand Down
4 changes: 2 additions & 2 deletions lib/backend-api/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ pub async fn get_app_volumes(
.get_deploy_app
.context("app not found")?
.active_version
.volumes
.and_then(|v| v.volumes)
.unwrap_or_default()
.into_iter()
.flatten()
Expand Down Expand Up @@ -1015,7 +1015,7 @@ pub async fn get_deploy_app_versions(
pub async fn app_deployments(
client: &WasmerClient,
vars: types::GetAppDeploymentsVariables,
) -> Result<Vec<types::AutobuildRepository>, anyhow::Error> {
) -> Result<Vec<types::Deployment>, anyhow::Error> {
let res = client
.run_graphql_strict(types::GetAppDeployments::build(vars))
.await?;
Expand Down
35 changes: 27 additions & 8 deletions lib/backend-api/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ mod queries {
#[derive(cynic::QueryFragment, Debug)]
#[cynic(graphql_type = "DeployApp")]
pub(crate) struct AppVolumes {
pub active_version: AppVersionVolumes,
pub active_version: Option<AppVersionVolumes>,
}

#[derive(cynic::QueryFragment, Debug)]
Expand Down Expand Up @@ -938,7 +938,7 @@ mod queries {
pub created_at: DateTime,
pub updated_at: DateTime,
pub description: Option<String>,
pub active_version: DeployAppVersion,
pub active_version: Option<DeployAppVersion>,
pub admin_url: String,
pub owner: Owner,
pub url: String,
Expand Down Expand Up @@ -1205,21 +1205,38 @@ mod queries {
pub struct DeployAppDeployments {
// FIXME: add $offset, $after, currently causes an error from the backend
// #[arguments(first: $first, after: $after, offset: $offset)]
pub deployments: Option<AutobuildRepositoryConnection>,
pub deployments: Option<DeploymentConnection>,
}

#[derive(cynic::QueryFragment, Debug)]
pub struct AutobuildRepositoryConnection {
pub struct DeploymentConnection {
pub page_info: PageInfo,
pub edges: Vec<Option<AutobuildRepositoryEdge>>,
pub edges: Vec<Option<DeploymentEdge>>,
}

#[derive(cynic::QueryFragment, Debug)]
pub struct AutobuildRepositoryEdge {
pub node: Option<AutobuildRepository>,
pub struct DeploymentEdge {
pub node: Option<Deployment>,
}

#[derive(cynic::QueryFragment, serde::Serialize, Debug)]
#[allow(clippy::large_enum_variant)]
#[derive(cynic::InlineFragments, Debug, Clone, Serialize)]
pub enum Deployment {
AutobuildRepository(AutobuildRepository),
NakedDeployment(NakedDeployment),
#[cynic(fallback)]
Other,
}

#[derive(cynic::QueryFragment, serde::Serialize, Debug, Clone)]
pub struct NakedDeployment {
pub id: cynic::Id,
pub created_at: DateTime,
pub updated_at: DateTime,
pub app_version: Option<DeployAppVersion>,
}

#[derive(cynic::QueryFragment, serde::Serialize, Debug, Clone)]
pub struct AutobuildRepository {
pub id: cynic::Id,
pub build_id: Uuid,
Expand All @@ -1239,6 +1256,7 @@ mod queries {
Timeout,
InternalError,
Cancelled,
Running,
}

impl StatusEnum {
Expand All @@ -1251,6 +1269,7 @@ mod queries {
Self::Timeout => "timeout",
Self::InternalError => "internal_error",
Self::Cancelled => "cancelled",
Self::Running => "running",
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/src/commands/app/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ pub async fn wait_app(

tracing::debug!(
current=%header,
expected=%app.active_version.id.inner(),
expected=%version.id.inner(),
"app is not at the right version yet",
);
}
Expand Down
5 changes: 4 additions & 1 deletion lib/cli/src/commands/app/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ impl AsyncCliCommand for CmdAppInfo {
let (_ident, app) = self.ident.load_app(&client).await?;

let app_url = app.url;
let versioned_url = app.active_version.url;
let versioned_url = app
.active_version
.as_ref()
.map_or("n/a", |version| &version.url);
let dashboard_url = app.admin_url;

println!(" App Info ");
Expand Down
4 changes: 3 additions & 1 deletion lib/cli/src/commands/app/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,12 @@ impl crate::commands::AsyncCliCommand for CmdAppLogs {
.from
.unwrap_or_else(|| OffsetDateTime::now_utc() - time::Duration::minutes(10));

let version = app.active_version.as_ref().map_or("n/a", |v| &v.version);

tracing::info!(
app.name=%app.name,
app.owner=%app.owner.global_name,
app.version=app.active_version.version,
app.version=version,
range.start=%from,
range.end=self.until.map(|ts| ts.to_string()),
"Fetching logs",
Expand Down
9 changes: 8 additions & 1 deletion lib/cli/src/commands/app/purge_cache.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Get information about an edge app.

use anyhow::Context;

use super::util::AppIdentOpts;
use crate::{commands::AsyncCliCommand, config::WasmerEnv, opts::ItemFormatOpts};

Expand Down Expand Up @@ -29,7 +31,12 @@ impl AsyncCliCommand for CmdAppPurgeCache {
let client = self.env.client()?;
let (_ident, app) = self.ident.load_app(&client).await?;

let version_id = app.active_version.id;
let version_id = app
.active_version
.as_ref()
.context("Could not purge cache: app has no active version!")?
.id
.clone();

let name = format!("{} ({})", app.name, app.owner.global_name);

Expand Down
Loading

0 comments on commit 61e0b95

Please sign in to comment.