mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-07 16:44:27 +01:00
Co-authored-by: Anoop M D <anoop.md1421@gmail.com>
This commit is contained in:
parent
abeccbb182
commit
969c44023f
@ -1,3 +1,4 @@
|
|||||||
|
const { get, each } = require('lodash');
|
||||||
const { interpolate } = require('@usebruno/common');
|
const { interpolate } = require('@usebruno/common');
|
||||||
const { getIntrospectionQuery } = require('graphql');
|
const { getIntrospectionQuery } = require('graphql');
|
||||||
const { setAuthHeaders } = require('./prepare-request');
|
const { setAuthHeaders } = require('./prepare-request');
|
||||||
@ -15,7 +16,7 @@ const prepareGqlIntrospectionRequest = (endpoint, envVars, request, collectionRo
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: endpoint,
|
url: endpoint,
|
||||||
headers: {
|
headers: {
|
||||||
...mapHeaders(request.headers),
|
...mapHeaders(request.headers, get(collectionRoot, 'request.headers', [])),
|
||||||
Accept: 'application/json',
|
Accept: 'application/json',
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
@ -25,10 +26,23 @@ const prepareGqlIntrospectionRequest = (endpoint, envVars, request, collectionRo
|
|||||||
return setAuthHeaders(axiosRequest, request, collectionRoot);
|
return setAuthHeaders(axiosRequest, request, collectionRoot);
|
||||||
};
|
};
|
||||||
|
|
||||||
const mapHeaders = (headers) => {
|
const mapHeaders = (requestHeaders, collectionHeaders) => {
|
||||||
const entries = headers.filter((header) => header.enabled).map(({ name, value }) => [name, value]);
|
const headers = {};
|
||||||
|
|
||||||
return Object.fromEntries(entries);
|
each(requestHeaders, (h) => {
|
||||||
|
if (h.enabled) {
|
||||||
|
headers[h.name] = h.value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// collection headers
|
||||||
|
each(collectionHeaders, (h) => {
|
||||||
|
if (h.enabled) {
|
||||||
|
headers[h.name] = h.value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return headers;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = prepareGqlIntrospectionRequest;
|
module.exports = prepareGqlIntrospectionRequest;
|
||||||
|
Loading…
Reference in New Issue
Block a user