From 80dbe8c8fe14850fc9af41f5da00f01887892ba1 Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Thu, 7 Nov 2024 12:28:04 +0530 Subject: [PATCH] fix: clicking on run query without connecting connects without docs polling (#4516) --- packages/hoppscotch-common/src/components.d.ts | 2 +- .../src/helpers/graphql/connection.ts | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/hoppscotch-common/src/components.d.ts b/packages/hoppscotch-common/src/components.d.ts index 5def13335..a77795471 100644 --- a/packages/hoppscotch-common/src/components.d.ts +++ b/packages/hoppscotch-common/src/components.d.ts @@ -1,10 +1,10 @@ /* eslint-disable */ -/* prettier-ignore */ // @ts-nocheck // Generated by unplugin-vue-components // Read more: https://github.com/vuejs/core/pull/3399 export {} +/* prettier-ignore */ declare module 'vue' { export interface GlobalComponents { AccessTokens: typeof import('./components/accessTokens/index.vue')['default'] diff --git a/packages/hoppscotch-common/src/helpers/graphql/connection.ts b/packages/hoppscotch-common/src/helpers/graphql/connection.ts index b41e3e734..b5666e990 100644 --- a/packages/hoppscotch-common/src/helpers/graphql/connection.ts +++ b/packages/hoppscotch-common/src/helpers/graphql/connection.ts @@ -159,7 +159,7 @@ export const graphqlTypes = computed(() => { let timeoutSubscription: any -export const connect = (url: string, headers: GQLHeader[]) => { +export const connect = async (url: string, headers: GQLHeader[]) => { if (connection.state === "CONNECTED") { throw new Error( "A connection is already running. Close it before starting another." @@ -175,7 +175,8 @@ export const connect = (url: string, headers: GQLHeader[]) => { poll() }, GQL_SCHEMA_POLL_INTERVAL) } - poll() + + await poll() } export const disconnect = () => { @@ -256,6 +257,10 @@ const getSchema = async (url: string, headers: GQLHeader[]) => { } export const runGQLOperation = async (options: RunQueryOptions) => { + if (connection.state !== "CONNECTED") { + await connect(options.url, options.headers) + } + const { url, headers, query, variables, auth, operationName, operationType } = options @@ -379,10 +384,6 @@ export const runGQLOperation = async (options: RunQueryOptions) => { operationType, } - if (connection.state !== "CONNECTED") { - connection.state = "CONNECTED" - } - addQueryToHistory(options, responseText) return responseText