@@ -4,53 +4,48 @@ import { GraphHttpClient } from "./GraphHttpClient";
44import { 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+ } ;
0 commit comments