RequestOptions.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. <template>
  2. <div class="flex flex-col flex-1 h-full">
  3. <SmartTabs
  4. v-model="selectedOptionTab"
  5. styles="sticky bg-primary top-upperPrimaryStickyFold z-10"
  6. >
  7. <SmartTab
  8. :id="'query'"
  9. :label="`${t('tab.query')}`"
  10. :indicator="gqlQueryString && gqlQueryString.length > 0 ? true : false"
  11. >
  12. <div
  13. class="sticky z-10 flex items-center justify-between pl-4 border-b bg-primary border-dividerLight top-upperSecondaryStickyFold gqlRunQuery"
  14. >
  15. <label class="font-semibold text-secondaryLight">
  16. {{ t("request.query") }}
  17. </label>
  18. <div class="flex">
  19. <ButtonSecondary
  20. v-tippy="{ theme: 'tooltip', delay: [500, 20], allowHTML: true }"
  21. :title="`${t(
  22. 'request.run'
  23. )} <xmp>${getSpecialKey()}</xmp><xmp>G</xmp>`"
  24. :label="`${t('request.run')}`"
  25. svg="play"
  26. class="rounded-none !text-accent !hover:text-accentDark"
  27. @click.native="runQuery()"
  28. />
  29. <ButtonSecondary
  30. ref="saveRequest"
  31. v-tippy="{ theme: 'tooltip', delay: [500, 20], allowHTML: true }"
  32. :title="`${t(
  33. 'request.save'
  34. )} <xmp>${getSpecialKey()}</xmp><xmp>S</xmp>`"
  35. :label="`${t('request.save')}`"
  36. svg="save"
  37. class="rounded-none"
  38. @click.native="saveRequest"
  39. />
  40. <ButtonSecondary
  41. v-tippy="{ theme: 'tooltip' }"
  42. to="https://docs.hoppscotch.io/graphql"
  43. blank
  44. :title="t('app.wiki')"
  45. svg="help-circle"
  46. />
  47. <ButtonSecondary
  48. v-tippy="{ theme: 'tooltip' }"
  49. :title="t('action.clear_all')"
  50. svg="trash-2"
  51. @click.native="clearGQLQuery()"
  52. />
  53. <ButtonSecondary
  54. v-tippy="{ theme: 'tooltip' }"
  55. :title="t('action.prettify')"
  56. :svg="`${prettifyQueryIcon}`"
  57. @click.native="prettifyQuery"
  58. />
  59. <ButtonSecondary
  60. v-tippy="{ theme: 'tooltip' }"
  61. :title="t('action.copy')"
  62. :svg="`${copyQueryIcon}`"
  63. @click.native="copyQuery"
  64. />
  65. </div>
  66. </div>
  67. <div ref="queryEditor" class="flex flex-col flex-1"></div>
  68. </SmartTab>
  69. <SmartTab
  70. :id="'variables'"
  71. :label="`${t('tab.variables')}`"
  72. :indicator="variableString && variableString.length > 0 ? true : false"
  73. >
  74. <div
  75. class="sticky z-10 flex items-center justify-between pl-4 border-b bg-primary border-dividerLight top-upperSecondaryStickyFold"
  76. >
  77. <label class="font-semibold text-secondaryLight">
  78. {{ t("request.variables") }}
  79. </label>
  80. <div class="flex">
  81. <ButtonSecondary
  82. v-tippy="{ theme: 'tooltip' }"
  83. to="https://docs.hoppscotch.io/graphql"
  84. blank
  85. :title="t('app.wiki')"
  86. svg="help-circle"
  87. />
  88. <ButtonSecondary
  89. v-tippy="{ theme: 'tooltip' }"
  90. :title="t('action.clear_all')"
  91. svg="trash-2"
  92. @click.native="clearGQLVariables()"
  93. />
  94. <ButtonSecondary
  95. ref="prettifyRequest"
  96. v-tippy="{ theme: 'tooltip' }"
  97. :title="t('action.prettify')"
  98. :svg="prettifyVariablesIcon"
  99. @click.native="prettifyVariableString"
  100. />
  101. <ButtonSecondary
  102. v-tippy="{ theme: 'tooltip' }"
  103. :title="t('action.copy')"
  104. :svg="`${copyVariablesIcon}`"
  105. @click.native="copyVariables"
  106. />
  107. </div>
  108. </div>
  109. <div ref="variableEditor" class="flex flex-col flex-1"></div>
  110. </SmartTab>
  111. <SmartTab
  112. :id="'headers'"
  113. :label="`${t('tab.headers')}`"
  114. :info="activeGQLHeadersCount === 0 ? null : `${activeGQLHeadersCount}`"
  115. >
  116. <div
  117. class="sticky z-10 flex items-center justify-between pl-4 border-b bg-primary border-dividerLight top-upperSecondaryStickyFold"
  118. >
  119. <label class="font-semibold text-secondaryLight">
  120. {{ t("tab.headers") }}
  121. </label>
  122. <div class="flex">
  123. <ButtonSecondary
  124. v-tippy="{ theme: 'tooltip' }"
  125. to="https://docs.hoppscotch.io/graphql"
  126. blank
  127. :title="t('app.wiki')"
  128. svg="help-circle"
  129. />
  130. <ButtonSecondary
  131. v-tippy="{ theme: 'tooltip' }"
  132. :title="t('action.clear_all')"
  133. svg="trash-2"
  134. @click.native="clearContent()"
  135. />
  136. <ButtonSecondary
  137. v-tippy="{ theme: 'tooltip' }"
  138. :title="t('state.bulk_mode')"
  139. svg="edit"
  140. :class="{ '!text-accent': bulkMode }"
  141. @click.native="bulkMode = !bulkMode"
  142. />
  143. <ButtonSecondary
  144. v-tippy="{ theme: 'tooltip' }"
  145. :title="t('add.new')"
  146. svg="plus"
  147. :disabled="bulkMode"
  148. @click.native="addHeader"
  149. />
  150. </div>
  151. </div>
  152. <div
  153. v-if="bulkMode"
  154. ref="bulkEditor"
  155. class="flex flex-col flex-1"
  156. ></div>
  157. <div v-else>
  158. <draggable
  159. v-model="workingHeaders"
  160. animation="250"
  161. handle=".draggable-handle"
  162. draggable=".draggable-content"
  163. ghost-class="cursor-move"
  164. chosen-class="bg-primaryLight"
  165. drag-class="cursor-grabbing"
  166. >
  167. <div
  168. v-for="(header, index) in workingHeaders"
  169. :key="`header-${header.id}-${index}`"
  170. class="flex border-b divide-x divide-dividerLight border-dividerLight draggable-content group"
  171. >
  172. <span>
  173. <ButtonSecondary
  174. svg="grip-vertical"
  175. class="cursor-auto text-primary hover:text-primary"
  176. :class="{
  177. 'draggable-handle group-hover:text-secondaryLight !cursor-grab':
  178. index !== workingHeaders?.length - 1,
  179. }"
  180. tabindex="-1"
  181. />
  182. </span>
  183. <SmartAutoComplete
  184. :placeholder="`${t('count.header', { count: index + 1 })}`"
  185. :source="commonHeaders"
  186. :spellcheck="false"
  187. :value="header.key"
  188. autofocus
  189. styles="
  190. bg-transparent
  191. flex
  192. flex-1
  193. py-1
  194. px-4
  195. truncate
  196. "
  197. class="flex-1 !flex"
  198. @input="
  199. updateHeader(index, {
  200. id: header.id,
  201. key: $event,
  202. value: header.value,
  203. active: header.active,
  204. })
  205. "
  206. />
  207. <input
  208. class="flex flex-1 px-4 py-2 bg-transparent"
  209. :placeholder="`${t('count.value', { count: index + 1 })}`"
  210. :name="`value ${String(index)}`"
  211. :value="header.value"
  212. autofocus
  213. @change="
  214. updateHeader(index, {
  215. id: header.id,
  216. key: header.key,
  217. value: $event.target.value,
  218. active: header.active,
  219. })
  220. "
  221. />
  222. <span>
  223. <ButtonSecondary
  224. v-tippy="{ theme: 'tooltip' }"
  225. :title="
  226. header.hasOwnProperty('active')
  227. ? header.active
  228. ? t('action.turn_off')
  229. : t('action.turn_on')
  230. : t('action.turn_off')
  231. "
  232. :svg="
  233. header.hasOwnProperty('active')
  234. ? header.active
  235. ? 'check-circle'
  236. : 'circle'
  237. : 'check-circle'
  238. "
  239. color="green"
  240. @click.native="
  241. updateHeader(index, {
  242. id: header.id,
  243. key: header.key,
  244. value: header.value,
  245. active: !header.active,
  246. })
  247. "
  248. />
  249. </span>
  250. <span>
  251. <ButtonSecondary
  252. v-tippy="{ theme: 'tooltip' }"
  253. :title="t('action.remove')"
  254. svg="trash"
  255. color="red"
  256. @click.native="deleteHeader(index)"
  257. />
  258. </span>
  259. </div>
  260. </draggable>
  261. <div
  262. v-if="workingHeaders.length === 0"
  263. class="flex flex-col items-center justify-center p-4 text-secondaryLight"
  264. >
  265. <img
  266. :src="`/images/states/${$colorMode.value}/add_category.svg`"
  267. loading="lazy"
  268. class="inline-flex flex-col object-contain object-center w-16 h-16 my-4"
  269. :alt="`${t('empty.headers')}`"
  270. />
  271. <span class="pb-4 text-center">
  272. {{ t("empty.headers") }}
  273. </span>
  274. <ButtonSecondary
  275. :label="`${t('add.new')}`"
  276. filled
  277. svg="plus"
  278. class="mb-4"
  279. @click.native="addHeader"
  280. />
  281. </div>
  282. </div>
  283. </SmartTab>
  284. <SmartTab :id="'authorization'" :label="`${t('tab.authorization')}`">
  285. <GraphqlAuthorization />
  286. </SmartTab>
  287. </SmartTabs>
  288. <CollectionsSaveRequest
  289. mode="graphql"
  290. :show="showSaveRequestModal"
  291. @hide-modal="hideRequestModal"
  292. />
  293. </div>
  294. </template>
  295. <script setup lang="ts">
  296. import { Ref, computed, reactive, ref, watch } from "@nuxtjs/composition-api"
  297. import clone from "lodash/clone"
  298. import * as gql from "graphql"
  299. import * as E from "fp-ts/Either"
  300. import * as O from "fp-ts/Option"
  301. import * as A from "fp-ts/Array"
  302. import * as RA from "fp-ts/ReadonlyArray"
  303. import { pipe, flow } from "fp-ts/function"
  304. import {
  305. GQLHeader,
  306. makeGQLRequest,
  307. rawKeyValueEntriesToString,
  308. parseRawKeyValueEntriesE,
  309. RawKeyValueEntry,
  310. } from "@hoppscotch/data"
  311. import draggable from "vuedraggable"
  312. import isEqual from "lodash/isEqual"
  313. import cloneDeep from "lodash/cloneDeep"
  314. import { copyToClipboard } from "~/helpers/utils/clipboard"
  315. import {
  316. useNuxt,
  317. useReadonlyStream,
  318. useStream,
  319. useI18n,
  320. useToast,
  321. } from "~/helpers/utils/composables"
  322. import {
  323. gqlAuth$,
  324. gqlHeaders$,
  325. gqlQuery$,
  326. gqlResponse$,
  327. gqlURL$,
  328. gqlVariables$,
  329. setGQLAuth,
  330. setGQLHeaders,
  331. setGQLQuery,
  332. setGQLResponse,
  333. setGQLVariables,
  334. } from "~/newstore/GQLSession"
  335. import { commonHeaders } from "~/helpers/headers"
  336. import { GQLConnection } from "~/helpers/GQLConnection"
  337. import { makeGQLHistoryEntry, addGraphqlHistoryEntry } from "~/newstore/history"
  338. import { logHoppRequestRunToAnalytics } from "~/helpers/fb/analytics"
  339. import { getCurrentStrategyID } from "~/helpers/network"
  340. import { useCodemirror } from "~/helpers/editor/codemirror"
  341. import jsonLinter from "~/helpers/editor/linting/json"
  342. import { createGQLQueryLinter } from "~/helpers/editor/linting/gqlQuery"
  343. import queryCompleter from "~/helpers/editor/completion/gqlQuery"
  344. import { defineActionHandler } from "~/helpers/actions"
  345. import { getPlatformSpecialKey as getSpecialKey } from "~/helpers/platformutils"
  346. import { objRemoveKey } from "~/helpers/functional/object"
  347. type OptionTabs = "query" | "headers" | "variables" | "authorization"
  348. const selectedOptionTab = ref<OptionTabs>("query")
  349. const t = useI18n()
  350. const props = defineProps<{
  351. conn: GQLConnection
  352. }>()
  353. const toast = useToast()
  354. const nuxt = useNuxt()
  355. const url = useReadonlyStream(gqlURL$, "")
  356. const gqlQueryString = useStream(gqlQuery$, "", setGQLQuery)
  357. const variableString = useStream(gqlVariables$, "", setGQLVariables)
  358. const idTicker = ref(0)
  359. const bulkMode = ref(false)
  360. const bulkHeaders = ref("")
  361. const bulkEditor = ref<any | null>(null)
  362. const deletionToast = ref<{ goAway: (delay: number) => void } | null>(null)
  363. useCodemirror(bulkEditor, bulkHeaders, {
  364. extendedEditorConfig: {
  365. mode: "text/x-yaml",
  366. placeholder: `${t("state.bulk_mode_placeholder")}`,
  367. },
  368. linter: null,
  369. completer: null,
  370. environmentHighlights: false,
  371. })
  372. // The functional headers list (the headers actually in the system)
  373. const headers = useStream(gqlHeaders$, [], setGQLHeaders) as Ref<GQLHeader[]>
  374. const auth = useStream(
  375. gqlAuth$,
  376. { authType: "none", authActive: true },
  377. setGQLAuth
  378. )
  379. // The UI representation of the headers list (has the empty end header)
  380. const workingHeaders = ref<Array<GQLHeader & { id: number }>>([
  381. {
  382. id: idTicker.value++,
  383. key: "",
  384. value: "",
  385. active: true,
  386. },
  387. ])
  388. // Rule: Working Headers always have one empty header or the last element is always an empty header
  389. watch(workingHeaders, (headersList) => {
  390. if (
  391. headersList.length > 0 &&
  392. headersList[headersList.length - 1].key !== ""
  393. ) {
  394. workingHeaders.value.push({
  395. id: idTicker.value++,
  396. key: "",
  397. value: "",
  398. active: true,
  399. })
  400. }
  401. })
  402. // Sync logic between headers and working headers
  403. watch(
  404. headers,
  405. (newHeadersList) => {
  406. // Sync should overwrite working headers
  407. const filteredWorkingHeaders = pipe(
  408. workingHeaders.value,
  409. A.filterMap(
  410. flow(
  411. O.fromPredicate((e) => e.key !== ""),
  412. O.map(objRemoveKey("id"))
  413. )
  414. )
  415. )
  416. const filteredBulkHeaders = pipe(
  417. parseRawKeyValueEntriesE(bulkHeaders.value),
  418. E.map(
  419. flow(
  420. RA.filter((e) => e.key !== ""),
  421. RA.toArray
  422. )
  423. ),
  424. E.getOrElse(() => [] as RawKeyValueEntry[])
  425. )
  426. if (!isEqual(newHeadersList, filteredWorkingHeaders)) {
  427. workingHeaders.value = pipe(
  428. newHeadersList,
  429. A.map((x) => ({ id: idTicker.value++, ...x }))
  430. )
  431. }
  432. if (!isEqual(newHeadersList, filteredBulkHeaders)) {
  433. bulkHeaders.value = rawKeyValueEntriesToString(newHeadersList)
  434. }
  435. },
  436. { immediate: true }
  437. )
  438. watch(workingHeaders, (newWorkingHeaders) => {
  439. const fixedHeaders = pipe(
  440. newWorkingHeaders,
  441. A.filterMap(
  442. flow(
  443. O.fromPredicate((e) => e.key !== ""),
  444. O.map(objRemoveKey("id"))
  445. )
  446. )
  447. )
  448. if (!isEqual(headers.value, fixedHeaders)) {
  449. headers.value = cloneDeep(fixedHeaders)
  450. }
  451. })
  452. // Bulk Editor Syncing with Working Headers
  453. watch(bulkHeaders, (newBulkHeaders) => {
  454. const filteredBulkHeaders = pipe(
  455. parseRawKeyValueEntriesE(newBulkHeaders),
  456. E.map(
  457. flow(
  458. RA.filter((e) => e.key !== ""),
  459. RA.toArray
  460. )
  461. ),
  462. E.getOrElse(() => [] as RawKeyValueEntry[])
  463. )
  464. if (!isEqual(headers.value, filteredBulkHeaders)) {
  465. headers.value = filteredBulkHeaders
  466. }
  467. })
  468. watch(workingHeaders, (newHeadersList) => {
  469. // If we are in bulk mode, don't apply direct changes
  470. if (bulkMode.value) return
  471. try {
  472. const currentBulkHeaders = bulkHeaders.value.split("\n").map((item) => ({
  473. key: item.substring(0, item.indexOf(":")).trimLeft().replace(/^#/, ""),
  474. value: item.substring(item.indexOf(":") + 1).trimLeft(),
  475. active: !item.trim().startsWith("#"),
  476. }))
  477. const filteredHeaders = newHeadersList.filter((x) => x.key !== "")
  478. if (!isEqual(currentBulkHeaders, filteredHeaders)) {
  479. bulkHeaders.value = rawKeyValueEntriesToString(filteredHeaders)
  480. }
  481. } catch (e) {
  482. toast.error(`${t("error.something_went_wrong")}`)
  483. console.error(e)
  484. }
  485. })
  486. const addHeader = () => {
  487. workingHeaders.value.push({
  488. id: idTicker.value++,
  489. key: "",
  490. value: "",
  491. active: true,
  492. })
  493. }
  494. const updateHeader = (index: number, header: GQLHeader & { id: number }) => {
  495. workingHeaders.value = workingHeaders.value.map((h, i) =>
  496. i === index ? header : h
  497. )
  498. }
  499. const deleteHeader = (index: number) => {
  500. const headersBeforeDeletion = clone(workingHeaders.value)
  501. if (
  502. !(
  503. headersBeforeDeletion.length > 0 &&
  504. index === headersBeforeDeletion.length - 1
  505. )
  506. ) {
  507. if (deletionToast.value) {
  508. deletionToast.value.goAway(0)
  509. deletionToast.value = null
  510. }
  511. deletionToast.value = toast.success(`${t("state.deleted")}`, {
  512. action: [
  513. {
  514. text: `${t("action.undo")}`,
  515. onClick: (_, toastObject) => {
  516. workingHeaders.value = headersBeforeDeletion
  517. toastObject.goAway(0)
  518. deletionToast.value = null
  519. },
  520. },
  521. ],
  522. onComplete: () => {
  523. deletionToast.value = null
  524. },
  525. })
  526. }
  527. workingHeaders.value.splice(index, 1)
  528. }
  529. const clearContent = () => {
  530. // set headers list to the initial state
  531. workingHeaders.value = [
  532. {
  533. id: idTicker.value++,
  534. key: "",
  535. value: "",
  536. active: true,
  537. },
  538. ]
  539. bulkHeaders.value = ""
  540. }
  541. const activeGQLHeadersCount = computed(
  542. () =>
  543. headers.value.filter((x) => x.active && (x.key !== "" || x.value !== ""))
  544. .length
  545. )
  546. const variableEditor = ref<any | null>(null)
  547. useCodemirror(
  548. variableEditor,
  549. variableString,
  550. reactive({
  551. extendedEditorConfig: {
  552. mode: "application/ld+json",
  553. placeholder: `${t("request.variables")}`,
  554. },
  555. linter: computed(() =>
  556. variableString.value.length > 0 ? jsonLinter : null
  557. ),
  558. completer: null,
  559. environmentHighlights: false,
  560. })
  561. )
  562. const queryEditor = ref<any | null>(null)
  563. const schemaString = useReadonlyStream(props.conn.schema$, null)
  564. useCodemirror(queryEditor, gqlQueryString, {
  565. extendedEditorConfig: {
  566. mode: "graphql",
  567. placeholder: `${t("request.query")}`,
  568. },
  569. linter: createGQLQueryLinter(schemaString),
  570. completer: queryCompleter(schemaString),
  571. environmentHighlights: false,
  572. })
  573. const copyQueryIcon = ref("copy")
  574. const copyVariablesIcon = ref("copy")
  575. const prettifyQueryIcon = ref("wand")
  576. const prettifyVariablesIcon = ref("wand")
  577. const showSaveRequestModal = ref(false)
  578. const copyQuery = () => {
  579. copyToClipboard(gqlQueryString.value)
  580. copyQueryIcon.value = "check"
  581. toast.success(`${t("state.copied_to_clipboard")}`)
  582. setTimeout(() => (copyQueryIcon.value = "copy"), 1000)
  583. }
  584. const response = useStream(gqlResponse$, "", setGQLResponse)
  585. const runQuery = async () => {
  586. const startTime = Date.now()
  587. nuxt.value.$loading.start()
  588. response.value = "loading"
  589. try {
  590. const runURL = clone(url.value)
  591. const runHeaders = clone(headers.value)
  592. const runQuery = clone(gqlQueryString.value)
  593. const runVariables = clone(variableString.value)
  594. const runAuth = clone(auth.value)
  595. const responseText = await props.conn.runQuery(
  596. runURL,
  597. runHeaders,
  598. runQuery,
  599. runVariables,
  600. runAuth
  601. )
  602. const duration = Date.now() - startTime
  603. nuxt.value.$loading.finish()
  604. response.value = JSON.stringify(JSON.parse(responseText), null, 2)
  605. addGraphqlHistoryEntry(
  606. makeGQLHistoryEntry({
  607. request: makeGQLRequest({
  608. name: "",
  609. url: runURL,
  610. query: runQuery,
  611. headers: runHeaders,
  612. variables: runVariables,
  613. auth: runAuth,
  614. }),
  615. response: response.value,
  616. star: false,
  617. })
  618. )
  619. toast.success(`${t("state.finished_in", { duration })}`)
  620. } catch (e: any) {
  621. response.value = `${e}`
  622. nuxt.value.$loading.finish()
  623. toast.error(
  624. `${t("error.something_went_wrong")}. ${t("error.check_console_details")}`,
  625. {}
  626. )
  627. console.error(e)
  628. }
  629. logHoppRequestRunToAnalytics({
  630. platform: "graphql-query",
  631. strategy: getCurrentStrategyID(),
  632. })
  633. }
  634. const hideRequestModal = () => {
  635. showSaveRequestModal.value = false
  636. }
  637. const prettifyQuery = () => {
  638. try {
  639. gqlQueryString.value = gql.print(gql.parse(gqlQueryString.value))
  640. prettifyQueryIcon.value = "check"
  641. } catch (e) {
  642. toast.error(`${t("error.gql_prettify_invalid_query")}`)
  643. prettifyQueryIcon.value = "info"
  644. }
  645. setTimeout(() => (prettifyQueryIcon.value = "wand"), 1000)
  646. }
  647. const saveRequest = () => {
  648. showSaveRequestModal.value = true
  649. }
  650. const copyVariables = () => {
  651. copyToClipboard(variableString.value)
  652. copyVariablesIcon.value = "check"
  653. toast.success(`${t("state.copied_to_clipboard")}`)
  654. setTimeout(() => (copyVariablesIcon.value = "copy"), 1000)
  655. }
  656. const prettifyVariableString = () => {
  657. try {
  658. const jsonObj = JSON.parse(variableString.value)
  659. variableString.value = JSON.stringify(jsonObj, null, 2)
  660. prettifyVariablesIcon.value = "check"
  661. } catch (e) {
  662. console.error(e)
  663. prettifyVariablesIcon.value = "info"
  664. toast.error(`${t("error.json_prettify_invalid_body")}`)
  665. }
  666. setTimeout(() => (prettifyVariablesIcon.value = "wand"), 1000)
  667. }
  668. const clearGQLQuery = () => {
  669. gqlQueryString.value = ""
  670. }
  671. const clearGQLVariables = () => {
  672. variableString.value = ""
  673. }
  674. defineActionHandler("request.send-cancel", runQuery)
  675. defineActionHandler("request.save", saveRequest)
  676. defineActionHandler("request.reset", clearGQLQuery)
  677. </script>