Fix to ignore global rest query headers when they are not configured.

This commit is contained in:
Dean 2022-06-15 10:09:47 +01:00
parent 6edb02a22b
commit 42cd5e2c63
2 changed files with 9 additions and 5 deletions

View File

@ -9,7 +9,9 @@ export function enrichQueryFields(
parameters = {} parameters = {}
) { ) {
const enrichedQuery: { [key: string]: any } = Array.isArray(fields) ? [] : {} const enrichedQuery: { [key: string]: any } = Array.isArray(fields) ? [] : {}
if (!fields || !parameters) {
return enrichedQuery
}
// enrich the fields with dynamic parameters // enrich the fields with dynamic parameters
for (let key of Object.keys(fields)) { for (let key of Object.keys(fields)) {
if (fields[key] == null) { if (fields[key] == null) {

View File

@ -47,10 +47,12 @@ class QueryRunner {
const enrichedContext = { ...enrichedParameters, ...this.ctx } const enrichedContext = { ...enrichedParameters, ...this.ctx }
// Parse global headers // Parse global headers
if (datasource.config.defaultHeaders) {
datasource.config.defaultHeaders = enrichQueryFields( datasource.config.defaultHeaders = enrichQueryFields(
datasource.config.defaultHeaders, datasource.config.defaultHeaders,
enrichedContext enrichedContext
) )
}
let query let query
// handle SQL injections by interpolating the variables // handle SQL injections by interpolating the variables