From 57b8ae7842a0722b468d5d592340e8a7efd0def2 Mon Sep 17 00:00:00 2001 From: Dean Date: Wed, 15 Jun 2022 10:09:47 +0100 Subject: [PATCH] Fix to ignore global rest query headers when they are not configured. --- packages/server/src/integrations/queries/sql.ts | 4 +++- packages/server/src/threads/query.js | 10 ++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/server/src/integrations/queries/sql.ts b/packages/server/src/integrations/queries/sql.ts index cf71f2ee2a..271a414d44 100644 --- a/packages/server/src/integrations/queries/sql.ts +++ b/packages/server/src/integrations/queries/sql.ts @@ -9,7 +9,9 @@ export function enrichQueryFields( parameters = {} ) { const enrichedQuery: { [key: string]: any } = Array.isArray(fields) ? [] : {} - + if (!fields || !parameters) { + return enrichedQuery + } // enrich the fields with dynamic parameters for (let key of Object.keys(fields)) { if (fields[key] == null) { diff --git a/packages/server/src/threads/query.js b/packages/server/src/threads/query.js index b6454e758e..36f73b154d 100644 --- a/packages/server/src/threads/query.js +++ b/packages/server/src/threads/query.js @@ -47,10 +47,12 @@ class QueryRunner { const enrichedContext = { ...enrichedParameters, ...this.ctx } // Parse global headers - datasource.config.defaultHeaders = enrichQueryFields( - datasource.config.defaultHeaders, - enrichedContext - ) + if (datasource.config.defaultHeaders) { + datasource.config.defaultHeaders = enrichQueryFields( + datasource.config.defaultHeaders, + enrichedContext + ) + } let query // handle SQL injections by interpolating the variables