From 969c44023fbbf99f5c8a52f40b1b8a0ef950f5bf Mon Sep 17 00:00:00 2001 From: Romain Eggermont Date: Mon, 29 Jan 2024 15:53:32 +0100 Subject: [PATCH] feat(#1352): add collection headers to introspection query (#1353) Co-authored-by: Anoop M D --- .../prepare-gql-introspection-request.js | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/bruno-electron/src/ipc/network/prepare-gql-introspection-request.js b/packages/bruno-electron/src/ipc/network/prepare-gql-introspection-request.js index 1efb146c7..c137c4b33 100644 --- a/packages/bruno-electron/src/ipc/network/prepare-gql-introspection-request.js +++ b/packages/bruno-electron/src/ipc/network/prepare-gql-introspection-request.js @@ -1,3 +1,4 @@ +const { get, each } = require('lodash'); const { interpolate } = require('@usebruno/common'); const { getIntrospectionQuery } = require('graphql'); const { setAuthHeaders } = require('./prepare-request'); @@ -15,7 +16,7 @@ const prepareGqlIntrospectionRequest = (endpoint, envVars, request, collectionRo method: 'POST', url: endpoint, headers: { - ...mapHeaders(request.headers), + ...mapHeaders(request.headers, get(collectionRoot, 'request.headers', [])), Accept: 'application/json', 'Content-Type': 'application/json' }, @@ -25,10 +26,23 @@ const prepareGqlIntrospectionRequest = (endpoint, envVars, request, collectionRo return setAuthHeaders(axiosRequest, request, collectionRoot); }; -const mapHeaders = (headers) => { - const entries = headers.filter((header) => header.enabled).map(({ name, value }) => [name, value]); +const mapHeaders = (requestHeaders, collectionHeaders) => { + const headers = {}; - return Object.fromEntries(entries); + each(requestHeaders, (h) => { + if (h.enabled) { + headers[h.name] = h.value; + } + }); + + // collection headers + each(collectionHeaders, (h) => { + if (h.enabled) { + headers[h.name] = h.value; + } + }); + + return headers; }; module.exports = prepareGqlIntrospectionRequest;