Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions packages/graph/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,37 @@ type Options = (http.Client | http.ClientOptions) & {
*/
export class Client {
protected baseUrlRoot;
protected http: http.Client;
protected _http: http.Client;
protected betaHttp?: http.Client;

/**
* The underlying HTTP client, pre-configured with Graph base URL and headers.
* Use for raw Graph API requests not covered by endpoint functions.
*/
get http(): http.Client {
return this._http;
}

constructor(options?: Options) {
this.baseUrlRoot = options?.baseUrlRoot ?? defaultBaseUrlRoot;
if (!options) {
this.http = new http.Client({
this._http = new http.Client({
baseUrl: `${this.baseUrlRoot}/v1.0`,
headers: {
'Content-Type': 'application/json',
'User-Agent': `teams.ts[graph]/${__PACKAGE_VERSION__}`,
},
});
} else if ('request' in options) {
this.http = options.clone({
this._http = options.clone({
baseUrl: `${this.baseUrlRoot}/v1.0`,
headers: {
'Content-Type': 'application/json',
'User-Agent': `teams.ts[graph]/${__PACKAGE_VERSION__}`,
},
});
} else {
this.http = new http.Client({
this._http = new http.Client({
...options,
baseUrl: `${this.baseUrlRoot}/v1.0`,
headers: {
Expand Down Expand Up @@ -121,12 +129,12 @@ export class Client {

private getHttpClient(schemaVersion: SchemaVersion): http.Client {
if (schemaVersion === 'v1.0') {
return this.http;
return this._http;
}

this.betaHttp =
this.betaHttp ??
this.http.clone({
this._http.clone({
baseUrl: `${this.baseUrlRoot}/beta`,
});

Expand Down
Loading