From 8b18b749c2da715b328352dd8a9dc3e4bf9eb02e Mon Sep 17 00:00:00 2001 From: Sunny Chung Date: Mon, 4 Dec 2023 21:46:39 +0800 Subject: [PATCH] fix variables in GraphQL query documents imported from Insomnia and Postman were not resolved --- .../multiplatform/hellohttp/importer/InsomniaV4Importer.kt | 5 +++-- .../multiplatform/hellohttp/importer/PostmanV2ZipImporter.kt | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/jvmMain/kotlin/com/sunnychung/application/multiplatform/hellohttp/importer/InsomniaV4Importer.kt b/src/jvmMain/kotlin/com/sunnychung/application/multiplatform/hellohttp/importer/InsomniaV4Importer.kt index 2b810f74..7310fdc6 100644 --- a/src/jvmMain/kotlin/com/sunnychung/application/multiplatform/hellohttp/importer/InsomniaV4Importer.kt +++ b/src/jvmMain/kotlin/com/sunnychung/application/multiplatform/hellohttp/importer/InsomniaV4Importer.kt @@ -215,10 +215,11 @@ class InsomniaV4Importer { jsonParser.readValue(body) .let { GraphqlBody( - document = it.query, + document = it.query.convertVariables(postFlightBodyVariables), variables = jsonParser.writerWithDefaultPrettyPrinter() .writeValueAsString(it.variables) - .let { if (it == "null") "" else it }, + .let { if (it == "null") "" else it } + .convertVariables(postFlightBodyVariables), operationName = it.operationName, ) } diff --git a/src/jvmMain/kotlin/com/sunnychung/application/multiplatform/hellohttp/importer/PostmanV2ZipImporter.kt b/src/jvmMain/kotlin/com/sunnychung/application/multiplatform/hellohttp/importer/PostmanV2ZipImporter.kt index 5488ad87..06b15d73 100644 --- a/src/jvmMain/kotlin/com/sunnychung/application/multiplatform/hellohttp/importer/PostmanV2ZipImporter.kt +++ b/src/jvmMain/kotlin/com/sunnychung/application/multiplatform/hellohttp/importer/PostmanV2ZipImporter.kt @@ -223,8 +223,8 @@ class PostmanV2ZipImporter { "file" -> FileBody(file?.src) "graphql" -> GraphqlBody( - document = graphql?.query ?: "", - variables = graphql?.variables ?: "", + document = graphql?.query?.convertVariables() ?: "", + variables = graphql?.variables?.convertVariables() ?: "", operationName = null )