From 088196a334fd0fbb9e2da71bf84292d6801be1ab Mon Sep 17 00:00:00 2001 From: Christoph Herzog Date: Wed, 7 Feb 2024 11:00:04 +0100 Subject: [PATCH] feat(backend-api): Add get_app_by_id_opt --- lib/backend-api/src/query.rs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/backend-api/src/query.rs b/lib/backend-api/src/query.rs index 99cf751ca..af19fcaaf 100644 --- a/lib/backend-api/src/query.rs +++ b/lib/backend-api/src/query.rs @@ -275,17 +275,31 @@ pub async fn get_app_by_id( client: &WasmerClient, app_id: String, ) -> Result { - client + get_app_by_id_opt(client, app_id) + .await? + .context("app not found") +} + +/// Retrieve an app by its global id. +pub async fn get_app_by_id_opt( + client: &WasmerClient, + app_id: String, +) -> Result, anyhow::Error> { + let app_opt = client .run_graphql(types::GetDeployAppById::build( types::GetDeployAppByIdVars { app_id: app_id.into(), }, )) .await? - .app - .context("app not found")? - .into_deploy_app() - .context("app conversion failed") + .app; + + if let Some(app) = app_opt { + let app = app.into_deploy_app().context("app conversion failed")?; + Ok(Some(app)) + } else { + Ok(None) + } } /// Retrieve an app together with a specific version.