Skip to content

Commit

Permalink
Add extraHeaders config option (#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniFoldi authored Oct 2, 2024
1 parent c8c2597 commit 5a34ca6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion cli/src/services/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default class Document {
paths: string[];
readonly apiKey: string;
readonly apiUrl: string;
readonly extraHeaders: Record<string, string>;
readonly projectId: string | null | undefined;
readonly config: DocumentConfig;
readonly target: string;
Expand All @@ -41,6 +42,7 @@ export default class Document {
this.config = this.resolveNamePattern(documentConfig);
this.apiKey = config.apiKey;
this.apiUrl = config.apiUrl;
this.extraHeaders = config.extraHeaders || {};
this.projectId = config.project;
this.target = this.config.target;
this.paths = new Tree(this.config).list();
Expand Down Expand Up @@ -246,7 +248,7 @@ export default class Document {
}

private authorizationHeader() {
return {authorization: `Bearer ${this.apiKey}`};
return {authorization: `Bearer ${this.apiKey}`, ...this.extraHeaders};
}

private resolveNamePattern(config: DocumentConfig) {
Expand Down
3 changes: 2 additions & 1 deletion cli/src/services/project-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ export default class ProjectFetcher {
body: JSON.stringify({query, variables}),
headers: {
'Content-Type': 'application/json',
authorization: `Bearer ${config.apiKey}`
authorization: `Bearer ${config.apiKey}`,
...(config.extraHeaders ? config.extraHeaders : {})
},
method: 'POST'
});
Expand Down
1 change: 1 addition & 0 deletions cli/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {VersionConfig} from './version-config';
export interface Config {
apiUrl: string;
apiKey: string;
extraHeaders?: Record<string, string>;
project?: string | null;
version?: VersionConfig;
files: DocumentConfig[];
Expand Down

0 comments on commit 5a34ca6

Please sign in to comment.