Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

Added ability to download GraphQL responses

Andrew Bastin19dbf7fe13cf
diff --git a/pages/graphql.vue b/pages/graphql.vue
index 3dcdabc4a..2209dae63 100644
--- a/pages/graphql.vue
+++ b/pages/graphql.vue
@@ -221,6 +221,14 @@
<div class="flex-wrap">
<label for="responseField">{{ $t("response") }}</label>
<div>
+ <button
+ class="icon"
+ @click="downloadResponse"
+ ref="downloadResponse"
+ v-tooltip="$t('download_file')"
+ >
+ <i class="material-icons">get_app</i>
+ </button>
<button
class="icon"
@click="copyResponse"
@@ -666,6 +674,25 @@ export default {
this.expandResponse = !this.expandResponse
this.responseBodyMaxLines = this.responseBodyMaxLines == Infinity ? 16 : Infinity
},
+ downloadResponse() {
+ const dataToWrite = this.response
+ const file = new Blob([dataToWrite], { type: "application/json" })
+ const a = document.createElement("a")
+ const url = URL.createObjectURL(file)
+ a.href = url
+ a.download = `Response ${this.url} on ${Date()}.json`.replace(/\./g, "[dot]")
+ document.body.appendChild(a)
+ a.click()
+ this.$refs.downloadResponse.innerHTML = this.doneButton
+ this.$toast.success(this.$t("download_started"), {
+ icon: "done",
+ })
+ setTimeout(() => {
+ document.body.removeChild(a)
+ window.URL.revokeObjectURL(url)
+ this.$refs.downloadResponse.innerHTML = this.downloadButton
+ }, 1000)
+ },
downloadSchema() {
const dataToWrite = JSON.stringify(this.schema, null, 2)
const file = new Blob([dataToWrite], { type: "application/json" })