From d2888daa8801095bf36ae41532902eeec2371bf1 Mon Sep 17 00:00:00 2001 From: anusree-bruno Date: Mon, 30 Jun 2025 13:12:35 +0530 Subject: [PATCH] add process.env variable support to GraphQL introspection --- .../bruno-electron/src/ipc/network/index.js | 11 ++++++-- .../prepare-gql-introspection-request.spec.js | 28 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/packages/bruno-electron/src/ipc/network/index.js b/packages/bruno-electron/src/ipc/network/index.js index aa70ab8c6..4237c24fa 100644 --- a/packages/bruno-electron/src/ipc/network/index.js +++ b/packages/bruno-electron/src/ipc/network/index.js @@ -333,6 +333,7 @@ const fetchGqlSchemaHandler = async (event, endpoint, environment, _request, col const runtimeVars = collection.runtimeVariables; // Precedence: runtimeVars > requestVariables > folderVars > envVars > collectionVariables > globalEnvironmentVars + const processEnvVars = getProcessEnvVars(collection.uid); const resolvedVars = merge( {}, globalEnvironmentVars, @@ -340,7 +341,14 @@ const fetchGqlSchemaHandler = async (event, endpoint, environment, _request, col envVars, folderVars, requestVariables, - runtimeVars + runtimeVars, + { + process: { + env: { + ...processEnvVars + } + } + } ); const collectionRoot = get(collection, 'root', {}); @@ -355,7 +363,6 @@ const fetchGqlSchemaHandler = async (event, endpoint, environment, _request, col } const collectionPath = collection.pathname; - const processEnvVars = getProcessEnvVars(collection.uid); const axiosInstance = await configureRequest( collection.uid, diff --git a/packages/bruno-electron/tests/network/prepare-gql-introspection-request.spec.js b/packages/bruno-electron/tests/network/prepare-gql-introspection-request.spec.js index 2eacde679..c6a043995 100644 --- a/packages/bruno-electron/tests/network/prepare-gql-introspection-request.spec.js +++ b/packages/bruno-electron/tests/network/prepare-gql-introspection-request.spec.js @@ -63,4 +63,32 @@ describe('prepareGqlIntrospectionRequest', () => { expect(result.headers['Content-Type']).toBe('application/json'); }); + it('should handle process.env variables in endpoint URL', () => { + const setup = createBasicSetup(); + setup.endpoint = 'https://{{process.env.API_HOST}}/graphql'; + const vars = { + process: { + env: { + API_HOST: 'api.example.com' + } + } + }; + + const result = prepareGqlIntrospectionRequest(setup.endpoint, vars, setup.request, setup.collectionRoot); + + expect(result.url).toBe('https://api.example.com/graphql'); + expect(result.method).toBe('POST'); + }); + + it('should handle missing process.env variables gracefully', () => { + const setup = createBasicSetup(); + setup.request.headers = [ + { name: 'X-API-Key', value: '{{process.env.MISSING_VAR}}', enabled: true } + ]; + + const result = prepareGqlIntrospectionRequest(setup.endpoint, {}, setup.request, setup.collectionRoot); + + expect(result.headers['X-API-Key']).toBe('{{process.env.MISSING_VAR}}'); + }); + }); \ No newline at end of file