mirego/accent

Extra Headers support in CLI

Opened this issue ยท 1 comments

Hi ๐Ÿ‘‹,

I'm opening this issue to ask if a new config option extraHeaders would be interesting. In our setup (behind Cloudflare Access) any programmatic access needs to provide two extra headers, provided as environment variables to the Docker container. In an effort to get rid of our mitm proxy in CI that just adds the headers to all requests, I was instead looking at a native solution.

To me it looked like the only place this needs to be added (in the CLI, since all the rest is inside the docker container that is the application behind Access) is here in project-fetcher.ts:

return await fetch(`${config.apiUrl}/graphql`, {
body: JSON.stringify({query, variables}),
headers: {
'Content-Type': 'application/json',
authorization: `Bearer ${config.apiKey}`
},
method: 'POST'
});
and a few places in document.ts - in this second case the simplest solution would be to (add it to config, pass it the Document class) and add it the the private authorizationHeader() method:
private authorizationHeader() {
return {authorization: `Bearer ${this.apiKey}`};
}
; alternatively the couple of places that call fetch() could all be modified, which one would be preferable?

In general, would this extra headers feature be something you would be interested in supporting? Happy to work on a PR implementing it.

Sure Iโ€™m open to a PR addressing thing ๐Ÿ˜ƒ