From c5283cf5841982b9e05e5d1f797c91ccf4eede5b Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Sun, 3 Jul 2022 08:43:59 -0400 Subject: [PATCH] Added not table return. --- src/lib.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 855a897..1160337 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -31,8 +31,10 @@ impl Query { .read() .await .to_vec(); - let idx = tbls.binary_search_by(|t| t.name.cmp(&name)).unwrap(); - Ok(Some(tbls[idx].clone())) + match tbls.binary_search_by(|t| t.name.cmp(&name)) { + Ok(idx) => Ok(Some(tbls[idx].clone())), + Err(_) => Ok(None), + } } async fn tables(&self, ctx: &Context<'_>) -> Vec { @@ -109,6 +111,14 @@ mod queries { support::compare(&db, &output, &expected); } + #[async_std::test] + async fn list_no_table() { + let db = Database::new(); + let output = db.execute(r#"{table(name: "slade"){name}}"#).await; + let expected = r#"{"data":{"table":null}}"#; + support::compare(&db, &output, &expected); + } + #[async_std::test] async fn list_tables() { let db = Database::new();