From a3125605f3c6d42e210777d78d5828af470893ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Sch=C3=B6nefeldt?= Date: Sat, 4 Nov 2023 21:50:55 +0100 Subject: [PATCH] #884: Made sure graphql variables are only parsed after interpolation --- packages/bruno-electron/src/ipc/network/index.js | 6 ++++++ packages/bruno-electron/src/ipc/network/prepare-request.js | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/bruno-electron/src/ipc/network/index.js b/packages/bruno-electron/src/ipc/network/index.js index 7e4b7ee2..538c2114 100644 --- a/packages/bruno-electron/src/ipc/network/index.js +++ b/packages/bruno-electron/src/ipc/network/index.js @@ -284,6 +284,12 @@ const registerNetworkIpc = (mainWindow) => { // interpolate variables inside request interpolateVars(request, envVars, collectionVariables, processEnvVars); + // if this is a graphql request, parse the variables, only after interpolation + // https://github.com/usebruno/bruno/issues/884 + if (request.mode === 'graphql') { + request.data.variables = JSON.parse(request.data.variables); + } + // stringify the request url encoded params if (request.headers['content-type'] === 'application/x-www-form-urlencoded') { request.data = qs.stringify(request.data); diff --git a/packages/bruno-electron/src/ipc/network/prepare-request.js b/packages/bruno-electron/src/ipc/network/prepare-request.js index bd5f7a8d..dec98bbd 100644 --- a/packages/bruno-electron/src/ipc/network/prepare-request.js +++ b/packages/bruno-electron/src/ipc/network/prepare-request.js @@ -94,6 +94,7 @@ const prepareRequest = (request, collectionRoot) => { }); let axiosRequest = { + mode: request.body.mode, method: request.method, url: request.url, headers: headers, @@ -163,7 +164,8 @@ const prepareRequest = (request, collectionRoot) => { if (request.body.mode === 'graphql') { const graphqlQuery = { query: get(request, 'body.graphql.query'), - variables: JSON.parse(decomment(get(request, 'body.graphql.variables') || '{}')) + // https://github.com/usebruno/bruno/issues/884 - we must only parse the variables after the variable interpolation + variables: decomment(get(request, 'body.graphql.variables') || '{}') }; if (!contentTypeDefined) { axiosRequest.headers['content-type'] = 'application/json';