Skip to content

Commit 37bf7c4

Browse files
committed
Fix contructor
1 parent 93127ea commit 37bf7c4

File tree

3 files changed

+48
-53
lines changed

3 files changed

+48
-53
lines changed

src/adapter/BaseGraphRequestAdapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from "@microsoft/kiota-abstractions";
88
import { HttpClient, type ObservabilityOptions, ObservabilityOptionsImpl } from "@microsoft/kiota-http-fetchlibrary";
99
import { DefaultRequestAdapter } from "@microsoft/kiota-bundle";
10-
import { GraphHttpClient } from "../http/GraphHttpClient.js";
10+
import { createGraphClientFactory } from "../http/GraphClientFactory";
1111

1212
/**
1313
* Base request adapter for graph clients. Bootstraps telemetry and other aspects.
@@ -29,7 +29,7 @@ export class BaseGraphRequestAdapter extends DefaultRequestAdapter {
2929
authenticationProvider: AuthenticationProvider,
3030
parseNodeFactory: ParseNodeFactory = ParseNodeFactoryRegistry.defaultInstance,
3131
serializationWriterFactory: SerializationWriterFactory = SerializationWriterFactoryRegistry.defaultInstance,
32-
httpClient: HttpClient = new GraphHttpClient({
32+
httpClient: HttpClient = createGraphClientFactory({
3333
graphServiceTargetVersion,
3434
graphServiceLibraryClientVersion,
3535
}),

src/http/GraphClientFactory.ts

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,48 @@ import { GraphHttpClient } from "./GraphHttpClient";
44
import { getDefaultMiddlewares, GraphTelemetryOption } from "../middleware";
55

66
/**
7-
* Factory class for creating instances of `GraphHttpClient`.
7+
* Creates an instance of `GraphHttpClient`, with the provided middlewares and custom fetch implementation both parameters are optional.
8+
* if no middlewares are provided, the default middlewares will be used.
9+
* @param {GraphTelemetryOption} graphTelemetryOption - The telemetry options for the Graph client.
10+
* @param {(request: string, init: RequestInit) => Promise<Response>} customFetch - The custom fetch function to use for HTTP requests.
11+
* @param {BaseBearerTokenAuthenticationProvider} [authenticationProvider] - Optional authentication provider for bearer token.
12+
* @param {Middleware[]} [middlewares] - Optional array of middleware to use in the HTTP pipeline.
13+
* @returns {GraphHttpClient} - A new instance of `GraphHttpClient`.
14+
* @example
15+
* ```Typescript
16+
* // Example usage of createGraphClientFactory method with graphTelemetryOption , customFetch and middlewares parameters provided
17+
* createGraphClientFactory(graphTelemetryOption, customFetch, [middleware1, middleware2]);
18+
* ```
19+
* @example
20+
* ```Typescript
21+
* // Example usage of createGraphClientFactory method with only graphTelemetryOption and customFetch parameter provided
22+
* createGraphClientFactory(graphTelemetryOption, customFetch);
23+
* ```
24+
* @example
25+
* ```Typescript
26+
* // Example usage of createGraphClientFactory method with only graphTelemetryOption and middlewares parameter provided
27+
* createGraphClientFactory(graphTelemetryOption, undefined, [middleware1, middleware2]);
28+
* ```
29+
* @example
30+
* ```Typescript
31+
* // Example usage of createGraphClientFactory method with only graphTelemetryOption parameter provided
32+
* createGraphClientFactory(graphTelemetryOption);
33+
* ```
834
*/
9-
export class GraphClientFactory {
10-
/**
11-
* Creates an instance of `GraphHttpClient`, with the provided middlewares and custom fetch implementation both parameters are optional.
12-
* if no middlewares are provided, the default middlewares will be used.
13-
* @param {GraphTelemetryOption} graphTelemetryOption - The telemetry options for the Graph client.
14-
* @param {(request: string, init: RequestInit) => Promise<Response>} customFetch - The custom fetch function to use for HTTP requests.
15-
* @param {BaseBearerTokenAuthenticationProvider} [authenticationProvider] - Optional authentication provider for bearer token.
16-
* @param {Middleware[]} [middlewares] - Optional array of middleware to use in the HTTP pipeline.
17-
* @returns {GraphHttpClient} - A new instance of `GraphHttpClient`.
18-
* @example
19-
* ```Typescript
20-
* // Example usage of GraphClientFactory.create method with graphTelemetryOption , customFetch and middlewares parameters provided
21-
* GraphClientFactory.create(graphTelemetryOption, customFetch, [middleware1, middleware2]);
22-
* ```
23-
* @example
24-
* ```Typescript
25-
* // Example usage of GraphClientFactory.create method with only graphTelemetryOption and customFetch parameter provided
26-
* GraphClientFactory.create(graphTelemetryOption, customFetch);
27-
* ```
28-
* @example
29-
* ```Typescript
30-
* // Example usage of GraphClientFactory.create method with only graphTelemetryOption and middlewares parameter provided
31-
* GraphClientFactory.create(graphTelemetryOption, undefined, [middleware1, middleware2]);
32-
* ```
33-
* @example
34-
* ```Typescript
35-
* // Example usage of GraphClientFactory.create method with only graphTelemetryOption parameter provided
36-
* GraphClientFactory.create(graphTelemetryOption);
37-
* ```
38-
*/
39-
public static create(
40-
graphTelemetryOption: GraphTelemetryOption,
41-
customFetch: ((request: string, init: RequestInit) => Promise<Response>) | undefined,
42-
authenticationProvider?: BaseBearerTokenAuthenticationProvider,
43-
middlewares?: Middleware[],
44-
): GraphHttpClient {
45-
const middleware =
46-
middlewares ||
47-
getDefaultMiddlewares(
48-
{
49-
customFetch,
50-
graphTelemetryOption,
51-
},
52-
authenticationProvider,
53-
);
54-
return new GraphHttpClient(graphTelemetryOption, customFetch, ...middleware);
55-
}
56-
}
35+
export const createGraphClientFactory = (
36+
graphTelemetryOption: GraphTelemetryOption,
37+
customFetch?: (request: string, init: RequestInit) => Promise<Response>,
38+
authenticationProvider?: BaseBearerTokenAuthenticationProvider,
39+
middlewares?: Middleware[],
40+
): GraphHttpClient => {
41+
const middleware =
42+
middlewares ||
43+
getDefaultMiddlewares(
44+
{
45+
customFetch,
46+
graphTelemetryOption,
47+
},
48+
authenticationProvider,
49+
);
50+
return new GraphHttpClient(graphTelemetryOption, customFetch, ...middleware);
51+
};

test/http/GraphHttpClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { assert, describe, it } from "vitest";
22
import { GraphHttpClient, GraphTelemetryOption } from "../../src";
33
import { BaseBearerTokenAuthenticationProvider } from "@microsoft/kiota-abstractions";
44
import type { Middleware } from "@microsoft/kiota-http-fetchlibrary";
5-
import { GraphClientFactory } from "../../src/http/GraphClientFactory";
5+
import { createGraphClientFactory } from "../../src/http/GraphClientFactory";
66

77
const graphTelemetryOption: GraphTelemetryOption = {};
88

@@ -40,7 +40,7 @@ describe("GraphHttpClient tests", () => {
4040
assert.equal(8, count);
4141

4242
const authenticationProvider = new BaseBearerTokenAuthenticationProvider({} as any);
43-
const clientWithProvider = GraphClientFactory.create(graphTelemetryOption, undefined, authenticationProvider);
43+
const clientWithProvider = createGraphClientFactory(graphTelemetryOption, undefined, authenticationProvider);
4444
const count2 = countMiddlewares((clientWithProvider as any)["middleware"] as Middleware);
4545
assert.equal(9, count2);
4646
});

0 commit comments

Comments
 (0)