From 465ccdd2b2a19edf0dc275662a29728af3cf0c34 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Mon, 29 May 2023 12:31:34 -0700 Subject: [PATCH] Fix graphql instrospection --- src-tauri/Cargo.lock | 263 +++++++++++++++------- src-tauri/Cargo.toml | 2 +- src-tauri/src/main.rs | 5 +- src-tauri/tauri.conf.json | 15 +- src-web/components/core/Editor/Editor.css | 2 +- src-web/hooks/useIntrospectGraphQL.ts | 6 +- src-web/hooks/useResponseBodyBlob.ts | 12 +- src-web/hooks/useResponseBodyText.ts | 15 +- src-web/lib/responseBody.ts | 23 ++ src-web/lib/sendEphemeralRequest.ts | 2 +- 10 files changed, 228 insertions(+), 117 deletions(-) create mode 100644 src-web/lib/responseBody.ts diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 0ccb88ce..a48433de 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -74,7 +74,7 @@ version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70151a5226578411132d798aa248df45b30aa34aea2e580628870b4d87be717b" dependencies = [ - "darling", + "darling 0.13.4", "pmutil", "proc-macro2", "quote", @@ -282,12 +282,13 @@ checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" [[package]] name = "cfb" -version = "0.6.1" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74f89d248799e3f15f91b70917f65381062a01bb8e222700ea0e5a7ff9785f9c" +checksum = "d38f2da7a0a2c4ccf0065be06397cc26a81f4e528be095826eee9d4adbb8c60f" dependencies = [ "byteorder", - "uuid 0.8.2", + "fnv", + "uuid", ] [[package]] @@ -543,6 +544,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "cty" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" + [[package]] name = "cxx" version = "1.0.94" @@ -567,7 +574,7 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn 2.0.12", + "syn 2.0.18", ] [[package]] @@ -584,7 +591,7 @@ checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.12", + "syn 2.0.18", ] [[package]] @@ -593,8 +600,18 @@ version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c" dependencies = [ - "darling_core", - "darling_macro", + "darling_core 0.13.4", + "darling_macro 0.13.4", +] + +[[package]] +name = "darling" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0558d22a7b463ed0241e993f76f09f30b126687447751a8638587b864e4b3944" +dependencies = [ + "darling_core 0.20.1", + "darling_macro 0.20.1", ] [[package]] @@ -611,17 +628,42 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "darling_core" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab8bfa2e259f8ee1ce5e97824a3c55ec4404a0d772ca7fa96bf19f0752a046eb" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.18", +] + [[package]] name = "darling_macro" version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" dependencies = [ - "darling_core", + "darling_core 0.13.4", "quote", "syn 1.0.109", ] +[[package]] +name = "darling_macro" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29a358ff9f12ec09c3e61fef9b5a9902623a695a46a917b07f269bff1445611a" +dependencies = [ + "darling_core 0.20.1", + "quote", + "syn 2.0.18", +] + [[package]] name = "dashmap" version = "5.4.0" @@ -1055,7 +1097,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.12", + "syn 2.0.18", ] [[package]] @@ -1156,6 +1198,20 @@ dependencies = [ "system-deps 6.0.4", ] +[[package]] +name = "gdkwayland-sys" +version = "0.15.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cca49a59ad8cfdf36ef7330fe7bdfbe1d34323220cc16a0de2679ee773aee2c2" +dependencies = [ + "gdk-sys", + "glib-sys", + "gobject-sys", + "libc", + "pkg-config", + "system-deps 6.0.4", +] + [[package]] name = "gdkx11-sys" version = "0.15.1" @@ -1567,9 +1623,9 @@ dependencies = [ [[package]] name = "ico" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "031530fe562d8c8d71c0635013d6d155bbfe8ba0aa4b4d2d24ce8af6b71047bd" +checksum = "e3804960be0bb5e4edb1e1ad67afd321a9ecfd875c3e65c099468fd2717d7cae" dependencies = [ "byteorder", "png", @@ -1636,13 +1692,14 @@ checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", "hashbrown", + "serde", ] [[package]] name = "infer" -version = "0.7.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20b2b533137b9cad970793453d4f921c2e91312a6d88b1085c07bc15fc51bb3b" +checksum = "a898e4b7951673fce96614ce5751d13c40fc5674bc2d759288e46c3ab62598b3" dependencies = [ "cfb", ] @@ -1767,7 +1824,19 @@ checksum = "eb3fa5a61630976fc4c353c70297f2e93f1930e3ccee574d59d618ccbd5154ce" dependencies = [ "serde", "serde_json", - "treediff", + "treediff 3.0.2", +] + +[[package]] +name = "json-patch" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f54898088ccb91df1b492cc80029a6fdf1c48ca0db7c6822a8babad69c94658" +dependencies = [ + "serde", + "serde_json", + "thiserror", + "treediff 4.0.2", ] [[package]] @@ -2220,6 +2289,15 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "num_threads" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44" +dependencies = [ + "libc", +] + [[package]] name = "objc" version = "0.2.7" @@ -2575,7 +2653,7 @@ dependencies = [ "line-wrap", "quick-xml", "serde", - "time 0.3.20", + "time 0.3.15", ] [[package]] @@ -2655,9 +2733,9 @@ checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" [[package]] name = "proc-macro2" -version = "1.0.54" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e472a104799c74b514a57226160104aa483546de37e839ec50e3c2e41dd87534" +checksum = "6aeca18b86b413c660b781aa319e4e2648a3e6f9eadc9b47e9038e6fe9f3451b" dependencies = [ "unicode-ident", ] @@ -2682,9 +2760,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.26" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" +checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" dependencies = [ "proc-macro2", ] @@ -2772,9 +2850,12 @@ dependencies = [ [[package]] name = "raw-window-handle" -version = "0.5.2" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2ff9a1f06a88b01621b7ae906ef0211290d1c8a168a15542486a8f61c0833b9" +checksum = "ed7e3d950b66e19e0c372f3fa3fbbcf85b1746b571f74e0c2af6042a5c93420a" +dependencies = [ + "cty", +] [[package]] name = "redox_syscall" @@ -3123,7 +3204,7 @@ checksum = "4c614d17805b093df4b147b51339e7e44bf05ef59fba1e45d83500bcfb4d8585" dependencies = [ "proc-macro2", "quote", - "syn 2.0.12", + "syn 2.0.18", ] [[package]] @@ -3146,7 +3227,7 @@ checksum = "bcec881020c684085e55a25f7fd888954d56609ef363479dc5a1305eb0d40cab" dependencies = [ "proc-macro2", "quote", - "syn 2.0.12", + "syn 2.0.18", ] [[package]] @@ -3187,24 +3268,30 @@ dependencies = [ [[package]] name = "serde_with" -version = "1.14.0" +version = "2.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678b5a069e50bf00ecd22d0cd8ddf7c236f68581b03db652061ed5eb13a312ff" +checksum = "07ff71d2c147a7b57362cead5e22f772cd52f6ab31cfcd9edcd7f6aeb2a0afbe" dependencies = [ + "base64 0.13.1", + "chrono", + "hex", + "indexmap", "serde", + "serde_json", "serde_with_macros", + "time 0.3.15", ] [[package]] name = "serde_with_macros" -version = "1.5.2" +version = "2.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e182d6ec6f05393cc0e5ed1bf81ad6db3a8feedf8ee515ecdd369809bcce8082" +checksum = "881b6f881b17d13214e5d494c939ebab463d01264ce1811e9d4ac3a882e7695f" dependencies = [ - "darling", + "darling 0.20.1", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.18", ] [[package]] @@ -3435,7 +3522,7 @@ dependencies = [ "sqlx-rt", "stringprep", "thiserror", - "time 0.3.20", + "time 0.3.15", "tokio-stream", "url", "webpki-roots", @@ -3917,9 +4004,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.12" +version = "2.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79d9531f94112cfc3e4c8f5f02cb2b58f72c97b7efd85f70203cc6d8efda5927" +checksum = "32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e" dependencies = [ "proc-macro2", "quote", @@ -3954,9 +4041,9 @@ dependencies = [ [[package]] name = "tao" -version = "0.15.8" +version = "0.16.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac8e6399427c8494f9849b58694754d7cc741293348a6836b6c8d2c5aa82d8e6" +checksum = "6a6d198e01085564cea63e976ad1566c1ba2c2e4cc79578e35d9f05521505e31" dependencies = [ "bitflags", "cairo-rs", @@ -3970,6 +4057,7 @@ dependencies = [ "gdk", "gdk-pixbuf", "gdk-sys", + "gdkwayland-sys", "gdkx11-sys", "gio", "glib", @@ -3988,18 +4076,29 @@ dependencies = [ "objc", "once_cell", "parking_lot 0.12.1", - "paste", "png", "raw-window-handle", "scopeguard", "serde", + "tao-macros", "unicode-segmentation", - "uuid 1.3.0", + "uuid", "windows 0.39.0", "windows-implement", "x11-dl", ] +[[package]] +name = "tao-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b27a4bcc5eb524658234589bdffc7e7bfb996dbae6ce9393bfd39cb4159b445" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "tar" version = "0.4.38" @@ -4013,13 +4112,13 @@ dependencies = [ [[package]] name = "tauri" -version = "1.2.4" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe7e0f1d535e7cbbbab43c82be4fc992b84f9156c16c160955617e0260ebc449" +checksum = "d42ba3a2e8556722f31336a0750c10dbb6a81396a1c452977f515da83f69f842" dependencies = [ "anyhow", "attohttpc", - "base64 0.13.1", + "base64 0.21.0", "cocoa", "dirs-next", "embed_plist", @@ -4055,10 +4154,10 @@ dependencies = [ "tauri-utils", "tempfile", "thiserror", - "time 0.3.20", + "time 0.3.15", "tokio", "url", - "uuid 1.3.0", + "uuid", "webkit2gtk", "webview2-com", "windows 0.39.0", @@ -4074,7 +4173,7 @@ dependencies = [ "anyhow", "cargo_toml", "heck 0.4.1", - "json-patch", + "json-patch 0.2.7", "semver 1.0.17", "serde_json", "tauri-utils", @@ -4083,14 +4182,14 @@ dependencies = [ [[package]] name = "tauri-codegen" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14388d484b6b1b5dc0f6a7d6cc6433b3b230bec85eaa576adcdf3f9fafa49251" +checksum = "e5a2105f807c6f50b2fa2ce5abd62ef207bc6f14c9fcc6b8caec437f6fb13bde" dependencies = [ - "base64 0.13.1", + "base64 0.21.0", "brotli", "ico", - "json-patch", + "json-patch 1.0.0", "plist", "png", "proc-macro2", @@ -4102,16 +4201,16 @@ dependencies = [ "sha2", "tauri-utils", "thiserror", - "time 0.3.20", - "uuid 1.3.0", + "time 0.3.15", + "uuid", "walkdir", ] [[package]] name = "tauri-macros" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "069319e5ecbe653a799b94b0690d9f9bf5d00f7b1d3989aa331c524d4e354075" +checksum = "8784cfe6f5444097e93c69107d1ac5e8f13d02850efa8d8f2a40fe79674cef46" dependencies = [ "heck 0.4.1", "proc-macro2", @@ -4123,9 +4222,9 @@ dependencies = [ [[package]] name = "tauri-runtime" -version = "0.12.1" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c507d954d08ac8705d235bc70ec6975b9054fb95ff7823af72dbb04186596f3b" +checksum = "b3b80ea3fcd5fefb60739a3b577b277e8fc30434538a2f5bba82ad7d4368c422" dependencies = [ "gtk", "http", @@ -4136,16 +4235,17 @@ dependencies = [ "serde_json", "tauri-utils", "thiserror", - "uuid 1.3.0", + "url", + "uuid", "webview2-com", "windows 0.39.0", ] [[package]] name = "tauri-runtime-wry" -version = "0.12.2" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36b1c5764a41a13176a4599b5b7bd0881bea7d94dfe45e1e755f789b98317e30" +checksum = "d1c396950b1ba06aee1b4ffe6c7cd305ff433ca0e30acbc5fa1a2f92a4ce70f1" dependencies = [ "cocoa", "gtk", @@ -4154,7 +4254,7 @@ dependencies = [ "raw-window-handle", "tauri-runtime", "tauri-utils", - "uuid 1.3.0", + "uuid", "webkit2gtk", "webview2-com", "windows 0.39.0", @@ -4163,9 +4263,9 @@ dependencies = [ [[package]] name = "tauri-utils" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5abbc109a6eb45127956ffcc26ef0e875d160150ac16cfa45d26a6b2871686f1" +checksum = "5a6f9c2dafef5cbcf52926af57ce9561bd33bb41d7394f8bb849c0330260d864" dependencies = [ "brotli", "ctor", @@ -4173,7 +4273,7 @@ dependencies = [ "heck 0.4.1", "html5ever", "infer", - "json-patch", + "json-patch 1.0.0", "kuchiki", "memchr", "phf 0.10.1", @@ -4255,7 +4355,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.12", + "syn 2.0.18", ] [[package]] @@ -4281,30 +4381,22 @@ dependencies = [ [[package]] name = "time" -version = "0.3.20" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd0cbfecb4d19b5ea75bb31ad904eb5b9fa13f21079c3b92017ebdf4999a5890" +checksum = "d634a985c4d4238ec39cacaed2e7ae552fbd3c476b552c1deac3021b7d7eaf0c" dependencies = [ "itoa 1.0.6", + "libc", + "num_threads", "serde", - "time-core", "time-macros", ] -[[package]] -name = "time-core" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" - [[package]] name = "time-macros" -version = "0.2.8" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd80a657e71da814b8e5d60d3374fc6d35045062245d80224748ae522dd76f36" -dependencies = [ - "time-core", -] +checksum = "42657b1a6f4d817cda8e7a0ace261fe0cc946cf3a80314390b22cc61ae080792" [[package]] name = "tinyvec" @@ -4503,6 +4595,15 @@ dependencies = [ "serde_json", ] +[[package]] +name = "treediff" +version = "4.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52984d277bdf2a751072b5df30ec0377febdb02f7696d64c2d7d54630bac4303" +dependencies = [ + "serde_json", +] + [[package]] name = "triomphe" version = "0.1.8" @@ -4600,12 +4701,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "uuid" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" - [[package]] name = "uuid" version = "1.3.0" @@ -5164,9 +5259,9 @@ dependencies = [ [[package]] name = "wry" -version = "0.23.4" +version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c1ad8e2424f554cc5bdebe8aa374ef5b433feff817aebabca0389961fc7ef98" +checksum = "33748f35413c8a98d45f7a08832d848c0c5915501803d1faade5a4ebcd258cea" dependencies = [ "base64 0.13.1", "block", @@ -5250,7 +5345,7 @@ dependencies = [ "tauri", "tauri-build", "tokio", - "uuid 1.3.0", + "uuid", ] [[package]] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 53b4432b..a9eff6b3 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -20,7 +20,7 @@ cocoa = "0.24.1" [dependencies] serde_json = { version = "1.0", features = ["raw_value"] } serde = { version = "1.0", features = ["derive"] } -tauri = { version = "1.2", features = ["config-toml", "devtools", "fs-read-file", "os-all", "protocol-asset", "shell-open", "system-tray", "updater", "window-start-dragging"] } +tauri = { version = "1.3", features = ["config-toml", "devtools", "fs-read-file", "os-all", "protocol-asset", "shell-open", "system-tray", "updater", "window-start-dragging"] } http = "0.2.8" reqwest = { version = "0.11.14", features = ["json"] } tokio = { version = "1.25.0", features = ["sync"] } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 07ea4ea3..a0406a70 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -233,7 +233,10 @@ async fn actually_send_ephemeral_request( let dir = app_handle.path_resolver().app_data_dir().unwrap(); let base_dir = dir.join("responses"); create_dir_all(base_dir.clone()).expect("Failed to create responses dir"); - let body_path = base_dir.join(response.id.clone()); + let body_path = match response.id == "" { + false => base_dir.join(response.id.clone()), + true => base_dir.join(uuid::Uuid::new_v4().to_string()), + }; let mut f = File::options() .create(true) .truncate(true) diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 21079d2a..cf3a3c0c 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -8,7 +8,7 @@ }, "package": { "productName": "Yaak", - "version": "0.1.0" + "version": "2023.0.17" }, "tauri": { "windows": [], @@ -49,13 +49,20 @@ "icons/icon.ico" ], "identifier": "co.schier.yaak", - "longDescription": "", + "longDescription": "The best cross-platform visual API client", "resources": [ "plugins/*", "migrations/*" ], - "shortDescription": "", - "targets": "all", + "shortDescription": "The best API client", + "targets": [ + "deb", + "appimage", + "nsis", + "app", + "dmg", + "updater" + ], "deb": { "depends": [] }, diff --git a/src-web/components/core/Editor/Editor.css b/src-web/components/core/Editor/Editor.css index 3fdba064..43bd136d 100644 --- a/src-web/components/core/Editor/Editor.css +++ b/src-web/components/core/Editor/Editor.css @@ -156,7 +156,7 @@ /* NOTE: Extra selector required to override default styles */ .cm-tooltip.cm-tooltip { - @apply shadow-lg bg-gray-50 rounded text-gray-700 border border-gray-200 z-50 pointer-events-auto text-sm; + @apply shadow-lg bg-gray-50 rounded text-gray-700 border border-gray-200 z-50 pointer-events-auto text-[0.75rem]; &.cm-completionInfo-right { @apply ml-1; diff --git a/src-web/hooks/useIntrospectGraphQL.ts b/src-web/hooks/useIntrospectGraphQL.ts index 580ef431..e6674dab 100644 --- a/src-web/hooks/useIntrospectGraphQL.ts +++ b/src-web/hooks/useIntrospectGraphQL.ts @@ -3,6 +3,7 @@ import type { GraphQLSchema } from 'graphql'; import { buildClientSchema, getIntrospectionQuery } from '../components/core/Editor'; import { minPromiseMillis } from '../lib/minPromiseMillis'; import type { HttpRequest } from '../lib/models'; +import { getResponseBodyText } from '../lib/responseBody'; import { sendEphemeralRequest } from '../lib/sendEphemeralRequest'; import { useDebouncedValue } from './useDebouncedValue'; @@ -35,11 +36,12 @@ export function useIntrospectGraphQL(baseRequest: HttpRequest) { ); } - if (response.body === null) { + const body = await getResponseBodyText(response); + if (body === null) { return Promise.reject(new Error('Empty body returned in response')); } - const { data } = JSON.parse(response.body); + const { data } = JSON.parse(body); return buildClientSchema(data); }, }); diff --git a/src-web/hooks/useResponseBodyBlob.ts b/src-web/hooks/useResponseBodyBlob.ts index 1c203b6c..be9ebb0c 100644 --- a/src-web/hooks/useResponseBodyBlob.ts +++ b/src-web/hooks/useResponseBodyBlob.ts @@ -1,20 +1,12 @@ import { useQuery } from '@tanstack/react-query'; -import { readBinaryFile } from '@tauri-apps/api/fs'; import type { HttpResponse } from '../lib/models'; +import { getResponseBodyBlob } from '../lib/responseBody'; export function useResponseBodyBlob(response: HttpResponse) { return useQuery({ enabled: response != null, queryKey: ['response-body-binary', response?.updatedAt], initialData: null, - queryFn: async () => { - if (response.body) { - return Uint8Array.of(...response.body); - } - if (response.bodyPath) { - return readBinaryFile(response.bodyPath); - } - return null; - }, + queryFn: () => getResponseBodyBlob(response), }).data; } diff --git a/src-web/hooks/useResponseBodyText.ts b/src-web/hooks/useResponseBodyText.ts index 5a70b03d..b676942d 100644 --- a/src-web/hooks/useResponseBodyText.ts +++ b/src-web/hooks/useResponseBodyText.ts @@ -1,22 +1,11 @@ import { useQuery } from '@tanstack/react-query'; -import { readTextFile } from '@tauri-apps/api/fs'; import type { HttpResponse } from '../lib/models'; +import { getResponseBodyText } from '../lib/responseBody'; export function useResponseBodyText(response: HttpResponse) { return useQuery({ queryKey: ['response-body-text', response?.updatedAt], initialData: null, - queryFn: async () => { - if (response.body) { - const uint8Array = Uint8Array.of(...response.body); - return new TextDecoder().decode(uint8Array); - } - - if (response.bodyPath) { - return await readTextFile(response.bodyPath); - } - - return null; - }, + queryFn: () => getResponseBodyText(response), }).data; } diff --git a/src-web/lib/responseBody.ts b/src-web/lib/responseBody.ts new file mode 100644 index 00000000..31edb70e --- /dev/null +++ b/src-web/lib/responseBody.ts @@ -0,0 +1,23 @@ +import { readBinaryFile, readTextFile } from '@tauri-apps/api/fs'; +import type { HttpResponse } from './models'; + +export async function getResponseBodyText(response: HttpResponse): Promise { + if (response.body) { + const uint8Array = Uint8Array.of(...response.body); + return new TextDecoder().decode(uint8Array); + } + if (response.bodyPath) { + return await readTextFile(response.bodyPath); + } + return null; +} + +export async function getResponseBodyBlob(response: HttpResponse): Promise { + if (response.body) { + return Uint8Array.of(...response.body); + } + if (response.bodyPath) { + return readBinaryFile(response.bodyPath); + } + return null; +} diff --git a/src-web/lib/sendEphemeralRequest.ts b/src-web/lib/sendEphemeralRequest.ts index 8f429acd..419f6f5a 100644 --- a/src-web/lib/sendEphemeralRequest.ts +++ b/src-web/lib/sendEphemeralRequest.ts @@ -1,7 +1,7 @@ import { invoke } from '@tauri-apps/api'; import type { HttpRequest, HttpResponse } from './models'; -export function sendEphemeralRequest(request: HttpRequest): Promise { +export async function sendEphemeralRequest(request: HttpRequest): Promise { // Remove some things that we don't want to associate const newRequest = { ...request, id: '', requestId: '', workspaceId: '' }; return invoke('send_ephemeral_request', { request: newRequest });