diff --git a/packages/bruno-app/src/components/RequestPane/GraphQLVariables/index.js b/packages/bruno-app/src/components/RequestPane/GraphQLVariables/index.js
index 06cf7c237e..b0ce23b442 100644
--- a/packages/bruno-app/src/components/RequestPane/GraphQLVariables/index.js
+++ b/packages/bruno-app/src/components/RequestPane/GraphQLVariables/index.js
@@ -20,14 +20,7 @@ const GraphQLVariables = ({ variables, item, collection }) => {
const onSave = () => dispatch(saveRequest(item.uid, collection.uid));
return (
-
+
);
};
diff --git a/packages/bruno-app/src/utils/network/index.js b/packages/bruno-app/src/utils/network/index.js
index 2397878b20..0fb45aeecd 100644
--- a/packages/bruno-app/src/utils/network/index.js
+++ b/packages/bruno-app/src/utils/network/index.js
@@ -58,7 +58,20 @@ export const fetchGqlSchema = async (endpoint, environment, request, collection)
return new Promise((resolve, reject) => {
const { ipcRenderer } = window;
- ipcRenderer.invoke('fetch-gql-schema', endpoint, environment, request, collection).then(resolve).catch(reject);
+ // Get current global environment and convert it from Array to Record
+ const globalEnvState = globalEnvironmentStore.getState();
+ const globalVariableList = globalEnvState.environments.get(globalEnvState.activeEnvironment)?.variables ?? [];
+ const globalVariables = globalVariableList.reduce((acc, variable) => {
+ if (variable.enabled) {
+ acc[variable.name] = variable.value;
+ }
+ return acc;
+ }, {});
+
+ ipcRenderer
+ .invoke('fetch-gql-schema', endpoint, environment, request, collection, globalVariables)
+ .then(resolve)
+ .catch(reject);
});
};
diff --git a/packages/bruno-electron/src/ipc/network/index.js b/packages/bruno-electron/src/ipc/network/index.js
index e125fbae03..af5e688f15 100644
--- a/packages/bruno-electron/src/ipc/network/index.js
+++ b/packages/bruno-electron/src/ipc/network/index.js
@@ -553,84 +553,6 @@ const registerNetworkIpc = (mainWindow) => {
});
});
- ipcMain.handle('fetch-gql-schema', async (event, endpoint, environment, _request, collection) => {
- try {
- const envVars = getEnvVars(environment);
- const collectionRoot = get(collection, 'root', {});
- const request = prepareGqlIntrospectionRequest(endpoint, envVars, _request, collectionRoot);
-
- request.timeout = preferencesUtil.getRequestTimeout();
-
- if (!preferencesUtil.shouldVerifyTls()) {
- request.httpsAgent = new https.Agent({
- rejectUnauthorized: false
- });
- }
-
- const requestUid = uuid();
- const collectionPath = collection.pathname;
- const collectionUid = collection.uid;
- const runtimeVariables = collection.runtimeVariables;
- const processEnvVars = getProcessEnvVars(collectionUid);
- const brunoConfig = getBrunoConfig(collection.uid);
- const scriptingConfig = get(brunoConfig, 'scripts', {});
-
- await runPreRequest(
- request,
- requestUid,
- envVars,
- collectionPath,
- collectionRoot,
- collectionUid,
- runtimeVariables,
- processEnvVars,
- scriptingConfig
- );
-
- interpolateVars(request, envVars, collection.runtimeVariables, processEnvVars);
- const axiosInstance = await configureRequest(
- collection.uid,
- request,
- envVars,
- collection.runtimeVariables,
- processEnvVars,
- collectionPath
- );
- const response = await axiosInstance(request);
-
- await runPostResponse(
- request,
- response,
- requestUid,
- envVars,
- collectionPath,
- collectionRoot,
- collectionUid,
- runtimeVariables,
- processEnvVars,
- scriptingConfig
- );
-
- return {
- status: response.status,
- statusText: response.statusText,
- headers: response.headers,
- data: response.data
- };
- } catch (error) {
- if (error.response) {
- return {
- status: error.response.status,
- statusText: error.response.statusText,
- headers: error.response.headers,
- data: error.response.data
- };
- }
-
- return Promise.reject(error);
- }
- });
-
// Ensure the response dir directory exists
const responseCacheDir = path.join(app.getPath('userData'), 'responseCache');
try {
diff --git a/packages/bruno-electron/src/ipc/request.ts b/packages/bruno-electron/src/ipc/request.ts
index de62e13230..8ec4c11161 100644
--- a/packages/bruno-electron/src/ipc/request.ts
+++ b/packages/bruno-electron/src/ipc/request.ts
@@ -4,8 +4,9 @@
*/
import { ipcMain, app } from 'electron';
import path from 'node:path';
-import { request as executeRequest, FolderItem, RequestItem } from '@usebruno/core';
+import { request as executeRequest, FolderItem, request, RequestItem } from '@usebruno/core';
import { CollectionSchema, EnvironmentSchema } from '@usebruno/schema';
+import { getIntrospectionQuery } from 'graphql';
const { uuid, safeStringifyJSON } = require('../utils/common');
const { cookieJar } = require('../utils/cookies');
const { getPreferences } = require('../store/preferences');
@@ -243,6 +244,96 @@ ipcMain.handle(
}
);
+ipcMain.handle(
+ 'fetch-gql-schema',
+ async (event, endpoint, environment, requestItem: RequestItem['request'], collection, globalVariables) => {
+ const webContents = event.sender;
+ const cancelToken = uuid();
+ const abortController = new AbortController();
+ cancelTokens.set(cancelToken, abortController);
+
+ const body = {
+ mode: 'json',
+ json: JSON.stringify({
+ query: getIntrospectionQuery()
+ })
+ } as const;
+
+ const headers = requestItem.headers;
+ headers.push({
+ enabled: true,
+ name: 'accept',
+ value: 'application/json'
+ });
+
+ const item: RequestItem = {
+ depth: 0,
+ draft: null,
+ filename: 'graphql-introspection',
+ name: 'graphql-introspection',
+ pathname: '',
+ seq: 0,
+ type: 'http-request',
+ uid: uuid(),
+ request: {
+ ...requestItem,
+ assertions: [],
+ tests: '',
+ script: { req: '', res: '' },
+ params: [],
+ headers,
+ url: endpoint,
+ body
+ }
+ };
+
+ const res = await executeRequest(
+ item,
+ collection,
+ globalVariables,
+ getPreferences(),
+ cookieJar,
+ responseDataDir,
+ cancelToken,
+ abortController,
+ // @ts-expect-error Defined in `vite.base.config.js`
+ BRUNO_VERSION,
+ 'standalone',
+ environment,
+ {
+ updateScriptEnvironment: (payload) => {
+ webContents.send('main:script-environment-update', payload);
+ },
+ cookieUpdated: (payload) => {
+ webContents.send('main:cookies-update', payload);
+ },
+ requestEvent: (payload) => {
+ webContents.send('main:run-request-event', payload);
+ },
+ consoleLog: (payload) => {
+ webContents.send('main:console-log', payload);
+ }
+ }
+ );
+ if (res.error) {
+ throw res.error;
+ }
+
+ cancelTokens.delete(cancelToken);
+
+ if (abortController.signal.aborted) {
+ throw new Error('Request aborted');
+ }
+
+ return {
+ status: res.response?.statusCode,
+ headers: res.response?.headers,
+ size: res.response?.size ?? 0,
+ data: res.responseBody
+ };
+ }
+);
+
ipcMain.handle('cancel-http-request', async (_event, cancelTokenUid) => {
cancelTokens.get(cancelTokenUid)?.abort();
cancelTokens.delete(cancelTokenUid);