Skip to content

Commit

Permalink
feat(#1352): add collection headers to introspection query
Browse files Browse the repository at this point in the history
  • Loading branch information
reggermont committed Jan 9, 2024
1 parent db9aeec commit 65f2858
Showing 1 changed file with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Handlebars = require('handlebars');
const { get, each } = require('lodash');
const { getIntrospectionQuery } = require('graphql');
const { setAuthHeaders } = require('./prepare-request');

Expand All @@ -15,7 +16,7 @@ const prepareGqlIntrospectionRequest = (endpoint, envVars, request, collectionRo
method: 'POST',
url: endpoint,
headers: {
...mapHeaders(request.headers),
...mapHeaders(request.headers, get(collectionRoot, 'request.headers', [])),
Accept: 'application/json',
'Content-Type': 'application/json'
},
Expand All @@ -25,10 +26,25 @@ const prepareGqlIntrospectionRequest = (endpoint, envVars, request, collectionRo
return setAuthHeaders(axiosRequest, request, collectionRoot);
};

const mapHeaders = (headers) => {
const entries = headers.filter((header) => header.enabled).map(({ name, value }) => [name, value]);
const mapHeaders = (requestHeaders, collectionHeaders) => {
const headers = {};

return Object.fromEntries(entries);
console.log(JSON.stringify(collectionHeaders, null, 4));

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;

0 comments on commit 65f2858

Please sign in to comment.