From ed825cf6484cc264244f281e876e4ee18b5aa039 Mon Sep 17 00:00:00 2001 From: nivedin Date: Mon, 4 Dec 2023 18:19:58 +0530 Subject: [PATCH] chore: add inherited auth and header in req runner --- .../src/components/graphql/RequestOptions.vue | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/packages/hoppscotch-common/src/components/graphql/RequestOptions.vue b/packages/hoppscotch-common/src/components/graphql/RequestOptions.vue index ff1f3f835..2d04fcc8c 100644 --- a/packages/hoppscotch-common/src/components/graphql/RequestOptions.vue +++ b/packages/hoppscotch-common/src/components/graphql/RequestOptions.vue @@ -136,10 +136,30 @@ const runQuery = async ( startPageProgress() try { const runURL = clone(url.value) - const runHeaders = clone(request.value.headers) const runQuery = clone(request.value.query) const runVariables = clone(request.value.variables) - const runAuth = clone(request.value.auth) + const runAuth = + request.value.auth.authType === "inherit" && request.value.auth.authActive + ? clone(tabs.currentActiveTab.value.document.inheritedProperties?.auth) + : clone(request.value.auth) + + const inheritedHeaders = + tabs.currentActiveTab.value.document.inheritedProperties?.headers.map( + (header) => { + if (header.inheritedHeader) { + return header.inheritedHeader + } + return [] + } + ) + + let runHeaders: HoppGQLRequest["headers"] = [] + + if (inheritedHeaders) { + runHeaders = [...inheritedHeaders, ...clone(request.value.headers)] + } else { + runHeaders = clone(request.value.headers) + } await runGQLOperation({ name: request.value.name, @@ -147,7 +167,7 @@ const runQuery = async ( headers: runHeaders, query: runQuery, variables: runVariables, - auth: runAuth, + auth: runAuth ?? { authType: "none", authActive: false }, operationName: definition?.name?.value, operationType: definition?.operation ?? "query", })