@webiny/app 6.1.0 → 6.2.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/exports/admin.d.ts +1 -0
  2. package/exports/admin.js +1 -0
  3. package/exports/admin.js.map +1 -1
  4. package/features/eventPublisher/feature.d.ts +3 -1
  5. package/features/eventPublisher/feature.js +5 -0
  6. package/features/eventPublisher/feature.js.map +1 -1
  7. package/features/graphqlClient/BatchingGraphQLClient.d.ts +1 -3
  8. package/features/graphqlClient/BatchingGraphQLClient.js +13 -14
  9. package/features/graphqlClient/BatchingGraphQLClient.js.map +1 -1
  10. package/features/graphqlClient/FetchGraphQLClient.d.ts +0 -3
  11. package/features/graphqlClient/FetchGraphQLClient.js +4 -8
  12. package/features/graphqlClient/FetchGraphQLClient.js.map +1 -1
  13. package/features/graphqlClient/RequestValue.d.ts +1 -0
  14. package/features/graphqlClient/RequestValue.js +3 -0
  15. package/features/graphqlClient/RequestValue.js.map +1 -1
  16. package/features/graphqlClient/__tests__/GraphQLClient.test.js +20 -0
  17. package/features/graphqlClient/__tests__/GraphQLClient.test.js.map +1 -1
  18. package/features/graphqlClient/abstractions.d.ts +1 -0
  19. package/features/graphqlClient/abstractions.js.map +1 -1
  20. package/features/mainGraphQLClient/MainGraphQLClient.d.ts +11 -0
  21. package/features/mainGraphQLClient/MainGraphQLClient.js +23 -0
  22. package/features/mainGraphQLClient/MainGraphQLClient.js.map +1 -0
  23. package/features/mainGraphQLClient/abstractions.d.ts +17 -0
  24. package/features/mainGraphQLClient/abstractions.js +4 -0
  25. package/features/mainGraphQLClient/abstractions.js.map +1 -0
  26. package/features/mainGraphQLClient/feature.d.ts +3 -0
  27. package/features/mainGraphQLClient/feature.js +16 -0
  28. package/features/mainGraphQLClient/feature.js.map +1 -0
  29. package/features/mainGraphQLClient/index.d.ts +1 -0
  30. package/features/mainGraphQLClient/index.js +3 -0
  31. package/features/mainGraphQLClient/index.js.map +1 -0
  32. package/features/router/HistoryRouterGateway.d.ts +5 -3
  33. package/features/router/HistoryRouterGateway.js +49 -32
  34. package/features/router/HistoryRouterGateway.js.map +1 -1
  35. package/features/router/RouterRepository.d.ts +4 -4
  36. package/features/router/RouterRepository.js +22 -34
  37. package/features/router/RouterRepository.js.map +1 -1
  38. package/features/router/abstractions.d.ts +3 -6
  39. package/features/router/abstractions.js.map +1 -1
  40. package/features/router/index.d.ts +1 -1
  41. package/features/router/index.js.map +1 -1
  42. package/package.json +15 -15
  43. package/shared/di/useFeature.js +2 -12
  44. package/shared/di/useFeature.js.map +1 -1
@@ -1,3 +1,4 @@
1
+ export { MainGraphQLClient } from "../features/mainGraphQLClient/index.js";
1
2
  export { useFeature } from "../shared/di/useFeature.js";
2
3
  export { NetworkErrorEventHandler } from "../errors/index.js";
3
4
  export { createProviderPlugin } from "../core/createProviderPlugin.js";
package/exports/admin.js CHANGED
@@ -1,3 +1,4 @@
1
+ export { MainGraphQLClient } from "../features/mainGraphQLClient/index.js";
1
2
  export { useFeature } from "../shared/di/useFeature.js";
2
3
  export { NetworkErrorEventHandler } from "../errors/index.js";
3
4
  export { createProviderPlugin } from "../core/createProviderPlugin.js";
@@ -1 +1 @@
1
- {"version":3,"names":["useFeature","NetworkErrorEventHandler","createProviderPlugin","createProvider","Provider","Plugin"],"sources":["admin.ts"],"sourcesContent":["export { useFeature } from \"~/shared/di/useFeature.js\";\nexport { NetworkErrorEventHandler } from \"~/errors/index.js\";\nexport { createProviderPlugin } from \"~/core/createProviderPlugin.js\";\nexport { createProvider } from \"~/core/createProvider.js\";\nexport { Provider } from \"~/core/Provider.js\";\nexport { Plugin } from \"~/core/Plugin.js\";\n"],"mappings":"AAAA,SAASA,UAAU;AACnB,SAASC,wBAAwB;AACjC,SAASC,oBAAoB;AAC7B,SAASC,cAAc;AACvB,SAASC,QAAQ;AACjB,SAASC,MAAM","ignoreList":[]}
1
+ {"version":3,"names":["MainGraphQLClient","useFeature","NetworkErrorEventHandler","createProviderPlugin","createProvider","Provider","Plugin"],"sources":["admin.ts"],"sourcesContent":["export { MainGraphQLClient } from \"~/features/mainGraphQLClient/index.js\";\nexport { useFeature } from \"~/shared/di/useFeature.js\";\nexport { NetworkErrorEventHandler } from \"~/errors/index.js\";\nexport { createProviderPlugin } from \"~/core/createProviderPlugin.js\";\nexport { createProvider } from \"~/core/createProvider.js\";\nexport { Provider } from \"~/core/Provider.js\";\nexport { Plugin } from \"~/core/Plugin.js\";\n"],"mappings":"AAAA,SAASA,iBAAiB;AAC1B,SAASC,UAAU;AACnB,SAASC,wBAAwB;AACjC,SAASC,oBAAoB;AAC7B,SAASC,cAAc;AACvB,SAASC,QAAQ;AACjB,SAASC,MAAM","ignoreList":[]}
@@ -1 +1,3 @@
1
- export declare const EventPublisherFeature: import("@webiny/feature/admin").FeatureDefinition<any, []>;
1
+ export declare const EventPublisherFeature: import("@webiny/feature/admin").FeatureDefinition<{
2
+ eventPublisher: import("./abstractions.js").IEventPublisher;
3
+ }, []>;
@@ -5,6 +5,11 @@ export const EventPublisherFeature = createFeature({
5
5
  name: "EventPublisher",
6
6
  register(container) {
7
7
  container.registerInstance(EventPublisherAbstraction, new EventPublisher(container));
8
+ },
9
+ resolve(container) {
10
+ return {
11
+ eventPublisher: container.resolve(EventPublisherAbstraction)
12
+ };
8
13
  }
9
14
  });
10
15
 
@@ -1 +1 @@
1
- {"version":3,"names":["createFeature","EventPublisher","EventPublisherAbstraction","EventPublisherFeature","name","register","container","registerInstance"],"sources":["feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/admin\";\nimport { Container } from \"@webiny/di\";\nimport { EventPublisher as EventPublisherAbstraction } from \"./abstractions.js\";\nimport { EventPublisher } from \"./EventPublisher.js\";\n\nexport const EventPublisherFeature = createFeature({\n name: \"EventPublisher\",\n register(container: Container) {\n container.registerInstance(EventPublisherAbstraction, new EventPublisher(container));\n }\n});\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,uBAAuB;AAErD,SAASC,cAAc,IAAIC,yBAAyB;AACpD,SAASD,cAAc;AAEvB,OAAO,MAAME,qBAAqB,GAAGH,aAAa,CAAC;EAC/CI,IAAI,EAAE,gBAAgB;EACtBC,QAAQA,CAACC,SAAoB,EAAE;IAC3BA,SAAS,CAACC,gBAAgB,CAACL,yBAAyB,EAAE,IAAID,cAAc,CAACK,SAAS,CAAC,CAAC;EACxF;AACJ,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["createFeature","EventPublisher","EventPublisherAbstraction","EventPublisherFeature","name","register","container","registerInstance","resolve","eventPublisher"],"sources":["feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/admin\";\nimport { Container } from \"@webiny/di\";\nimport { EventPublisher as EventPublisherAbstraction } from \"./abstractions.js\";\nimport { EventPublisher } from \"./EventPublisher.js\";\n\nexport const EventPublisherFeature = createFeature({\n name: \"EventPublisher\",\n register(container: Container) {\n container.registerInstance(EventPublisherAbstraction, new EventPublisher(container));\n },\n resolve(container: Container) {\n return {\n eventPublisher: container.resolve(EventPublisherAbstraction)\n };\n }\n});\n"],"mappings":"AAAA,SAASA,aAAa,QAAQ,uBAAuB;AAErD,SAASC,cAAc,IAAIC,yBAAyB;AACpD,SAASD,cAAc;AAEvB,OAAO,MAAME,qBAAqB,GAAGH,aAAa,CAAC;EAC/CI,IAAI,EAAE,gBAAgB;EACtBC,QAAQA,CAACC,SAAoB,EAAE;IAC3BA,SAAS,CAACC,gBAAgB,CAACL,yBAAyB,EAAE,IAAID,cAAc,CAACK,SAAS,CAAC,CAAC;EACxF,CAAC;EACDE,OAAOA,CAACF,SAAoB,EAAE;IAC1B,OAAO;MACHG,cAAc,EAAEH,SAAS,CAACE,OAAO,CAACN,yBAAyB;IAC/D,CAAC;EACL;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -1,13 +1,11 @@
1
1
  import { GraphQLClient } from "./abstractions.js";
2
- import { EnvConfig } from "../../features/envConfig/index.js";
3
2
  declare class BatchingGraphQLClientImpl implements GraphQLClient.Interface {
4
- private envConfig;
5
3
  private decoratee;
6
4
  private queue;
7
5
  private batchTimeout;
8
6
  private readonly batchWindowMs;
9
7
  private readonly maxBatchSize;
10
- constructor(envConfig: EnvConfig.Interface, decoratee: GraphQLClient.Interface);
8
+ constructor(decoratee: GraphQLClient.Interface);
11
9
  execute<TVariables = any, TResult = any>(params: GraphQLClient.Request<TVariables>): Promise<TResult>;
12
10
  private flush;
13
11
  private executeBatchGroup;
@@ -1,12 +1,10 @@
1
1
  import { createDecorator } from "@webiny/di";
2
2
  import { GraphQLClient } from "./abstractions.js";
3
- import { EnvConfig } from "../envConfig/index.js";
4
3
  import { RequestValue } from "./RequestValue.js";
5
4
  class BatchingGraphQLClientImpl {
6
5
  queue = [];
7
6
  batchTimeout = null;
8
- constructor(envConfig, decoratee) {
9
- this.envConfig = envConfig;
7
+ constructor(decoratee) {
10
8
  this.decoratee = decoratee;
11
9
  // Default: 10ms window, max 10 operations per batch
12
10
  this.batchWindowMs = 10;
@@ -56,18 +54,18 @@ class BatchingGraphQLClientImpl {
56
54
  return;
57
55
  }
58
56
 
59
- // Group requests by headers (only batch requests with identical headers)
60
- const groupedByHeaders = new Map();
57
+ // Group requests by endpoint + headers (only batch requests with identical target)
58
+ const grouped = new Map();
61
59
  for (const item of batch) {
62
- const headersKey = this.serializeHeaders(item.request.headers);
63
- if (!groupedByHeaders.has(headersKey)) {
64
- groupedByHeaders.set(headersKey, []);
60
+ const groupKey = item.request.endpoint + "|" + this.serializeHeaders(item.request.headers);
61
+ if (!grouped.has(groupKey)) {
62
+ grouped.set(groupKey, []);
65
63
  }
66
- groupedByHeaders.get(headersKey).push(item);
64
+ grouped.get(groupKey).push(item);
67
65
  }
68
66
 
69
67
  // Process each group separately
70
- const batchPromises = Array.from(groupedByHeaders.entries()).map(requests => {
68
+ const batchPromises = Array.from(grouped.entries()).map(requests => {
71
69
  const group = requests[1];
72
70
  if (group.length === 1) {
73
71
  // Single request in this group - use decoratee directly
@@ -94,9 +92,10 @@ class BatchingGraphQLClientImpl {
94
92
  variables: request.variables
95
93
  };
96
94
  });
95
+ const endpoint = group[0].request.endpoint;
97
96
  const headers = group[0].request.headers;
98
97
  try {
99
- const results = await this.executeBatch(batchedOperations, headers);
98
+ const results = await this.executeBatch(endpoint, batchedOperations, headers);
100
99
  group.forEach(({
101
100
  resolve
102
101
  }, index) => {
@@ -122,10 +121,10 @@ class BatchingGraphQLClientImpl {
122
121
  }
123
122
  return JSON.stringify(sortedHeaders);
124
123
  }
125
- async executeBatch(operations, headers) {
124
+ async executeBatch(endpoint, operations, headers) {
126
125
  let response;
127
126
  try {
128
- response = await fetch(this.envConfig.get("graphqlApiUrl"), {
127
+ response = await fetch(endpoint, {
129
128
  method: "POST",
130
129
  headers: {
131
130
  "Content-Type": "application/json",
@@ -158,7 +157,7 @@ class BatchingGraphQLClientImpl {
158
157
  export const BatchingGraphQLClient = createDecorator({
159
158
  abstraction: GraphQLClient,
160
159
  decorator: BatchingGraphQLClientImpl,
161
- dependencies: [EnvConfig]
160
+ dependencies: []
162
161
  });
163
162
 
164
163
  //# sourceMappingURL=BatchingGraphQLClient.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createDecorator","GraphQLClient","EnvConfig","RequestValue","BatchingGraphQLClientImpl","queue","batchTimeout","constructor","envConfig","decoratee","batchWindowMs","maxBatchSize","execute","params","Promise","resolve","reject","push","request","from","length","flush","setTimeout","clearTimeout","batch","splice","result","error","groupedByHeaders","Map","item","headersKey","serializeHeaders","headers","has","set","get","batchPromises","Array","entries","map","requests","group","then","catch","executeBatchGroup","all","batchedOperations","query","queryAsString","operationName","variables","results","executeBatch","forEach","index","sortedKeys","Object","keys","sort","sortedHeaders","key","String","JSON","stringify","operations","response","fetch","method","body","err","Error","message","json","isArray","errors","data","BatchingGraphQLClient","abstraction","decorator","dependencies"],"sources":["BatchingGraphQLClient.ts"],"sourcesContent":["import { createDecorator } from \"@webiny/di\";\nimport { GraphQLClient } from \"./abstractions.js\";\nimport { EnvConfig } from \"~/features/envConfig/index.js\";\nimport { RequestValue } from \"~/features/graphqlClient/RequestValue.js\";\n\ninterface BatchedRequest {\n request: RequestValue;\n resolve: (value: any) => void;\n reject: (error: any) => void;\n}\n\ninterface BatchOperation {\n operationName: string | undefined;\n query: string;\n variables?: any;\n}\n\nclass BatchingGraphQLClientImpl implements GraphQLClient.Interface {\n private queue: BatchedRequest[] = [];\n private batchTimeout: NodeJS.Timeout | null = null;\n private readonly batchWindowMs: number;\n private readonly maxBatchSize: number;\n\n constructor(\n private envConfig: EnvConfig.Interface,\n private decoratee: GraphQLClient.Interface\n ) {\n // Default: 10ms window, max 10 operations per batch\n this.batchWindowMs = 10;\n this.maxBatchSize = 10;\n }\n\n async execute<TVariables = any, TResult = any>(\n params: GraphQLClient.Request<TVariables>\n ): Promise<TResult> {\n return new Promise((resolve, reject) => {\n this.queue.push({ request: RequestValue.from(params), resolve, reject });\n\n if (this.queue.length >= this.maxBatchSize) {\n this.flush();\n return;\n }\n\n if (!this.batchTimeout) {\n this.batchTimeout = setTimeout(() => {\n this.flush();\n }, this.batchWindowMs);\n }\n });\n }\n\n private async flush(): Promise<void> {\n if (this.batchTimeout) {\n clearTimeout(this.batchTimeout);\n this.batchTimeout = null;\n }\n\n if (this.queue.length === 0) {\n return;\n }\n\n const batch = this.queue.splice(0, this.queue.length);\n\n // Single request - use decoratee directly (no batching needed)\n if (batch.length === 1) {\n const { request, resolve, reject } = batch[0];\n try {\n const result = await this.decoratee.execute(request.request);\n resolve(result);\n } catch (error) {\n reject(error);\n }\n return;\n }\n\n // Group requests by headers (only batch requests with identical headers)\n const groupedByHeaders = new Map<string, BatchedRequest[]>();\n for (const item of batch) {\n const headersKey = this.serializeHeaders(item.request.headers);\n if (!groupedByHeaders.has(headersKey)) {\n groupedByHeaders.set(headersKey, []);\n }\n groupedByHeaders.get(headersKey)!.push(item);\n }\n\n // Process each group separately\n const batchPromises = Array.from(groupedByHeaders.entries()).map(requests => {\n const group = requests[1];\n\n if (group.length === 1) {\n // Single request in this group - use decoratee directly\n const { request, resolve, reject } = group[0];\n return this.decoratee.execute(request.request).then(resolve).catch(reject);\n }\n\n // Multiple requests with same headers - batch them\n return this.executeBatchGroup(group);\n });\n\n await Promise.all(batchPromises);\n }\n\n private async executeBatchGroup(group: BatchedRequest[]): Promise<void> {\n const batchedOperations = group.map(({ request }): BatchOperation => {\n return {\n query: request.queryAsString,\n operationName: request.operationName,\n variables: request.variables\n };\n });\n\n const headers = group[0].request.headers;\n\n try {\n const results = await this.executeBatch(batchedOperations, headers);\n group.forEach(({ resolve }, index) => {\n resolve(results[index]);\n });\n } catch (error) {\n group.forEach(({ reject }) => {\n reject(error);\n });\n }\n }\n\n private serializeHeaders(headers?: GraphQLClient.Headers): string {\n if (!headers) {\n return \"{}\";\n }\n // Sort keys for consistent serialization\n const sortedKeys = Object.keys(headers).sort();\n const sortedHeaders: Record<string, string> = {};\n for (const key of sortedKeys) {\n sortedHeaders[key] = String(headers[key]);\n }\n return JSON.stringify(sortedHeaders);\n }\n\n private async executeBatch(\n operations: BatchOperation[],\n headers?: GraphQLClient.Headers\n ): Promise<any[]> {\n let response: Response;\n\n try {\n response = await fetch(this.envConfig.get(\"graphqlApiUrl\"), {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...(headers || {})\n },\n body: JSON.stringify(operations)\n });\n } catch (err) {\n throw new Error(`Network error: ${(err as Error).message}`);\n }\n\n let json: any;\n try {\n json = await response.json();\n } catch {\n throw new Error(\"Failed to parse GraphQL batch response as JSON.\");\n }\n\n if (!Array.isArray(json)) {\n throw new Error(\"Expected batch response to be an array\");\n }\n\n // Map each result, handling individual errors\n return json.map((result: any, index: number) => {\n if (result.errors && result.errors.length > 0) {\n throw new Error(\n `GraphQL errors in operation ${index}: ${JSON.stringify(result.errors)}`\n );\n }\n return result.data;\n });\n }\n}\n\nexport const BatchingGraphQLClient = createDecorator({\n abstraction: GraphQLClient,\n decorator: BatchingGraphQLClientImpl,\n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iD,MAAM,CAAC,EAC1E,CAAC;MACL;MACA,OAAOjD,MAAM,CAACkD,IAAI;IACtB,CAAC,CAAC;EACN;AACJ;AAEA,OAAO,MAAMC,qBAAqB,GAAG7E,eAAe,CAAC;EACjD8E,WAAW,EAAE7E,aAAa;EAC1B8E,SAAS,EAAE3E,yBAAyB;EACpC4E,YAAY,EAAE,CAAC9E,SAAS;AAC5B,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["createDecorator","GraphQLClient","RequestValue","BatchingGraphQLClientImpl","queue","batchTimeout","constructor","decoratee","batchWindowMs","maxBatchSize","execute","params","Promise","resolve","reject","push","request","from","length","flush","setTimeout","clearTimeout","batch","splice","result","error","grouped","Map","item","groupKey","endpoint","serializeHeaders","headers","has","set","get","batchPromises","Array","entries","map","requests","group","then","catch","executeBatchGroup","all","batchedOperations","query","queryAsString","operationName","variables","results","executeBatch","forEach","index","sortedKeys","Object","keys","sort","sortedHeaders","key","String","JSON","stringify","operations","response","fetch","method","body","err","Error","message","json","isArray","errors","data","BatchingGraphQLClient","abstraction","decorator","dependencies"],"sources":["BatchingGraphQLClient.ts"],"sourcesContent":["import { createDecorator } from \"@webiny/di\";\nimport { GraphQLClient } from \"./abstractions.js\";\nimport { RequestValue } from \"~/features/graphqlClient/RequestValue.js\";\n\ninterface BatchedRequest {\n request: RequestValue;\n resolve: (value: any) => void;\n reject: (error: any) => void;\n}\n\ninterface BatchOperation {\n operationName: string | undefined;\n query: string;\n variables?: any;\n}\n\nclass BatchingGraphQLClientImpl implements GraphQLClient.Interface {\n private queue: BatchedRequest[] = [];\n private batchTimeout: NodeJS.Timeout | null = null;\n private readonly batchWindowMs: number;\n private readonly maxBatchSize: number;\n\n constructor(private decoratee: GraphQLClient.Interface) {\n // Default: 10ms window, max 10 operations per batch\n this.batchWindowMs = 10;\n this.maxBatchSize = 10;\n }\n\n async execute<TVariables = any, TResult = any>(\n params: GraphQLClient.Request<TVariables>\n ): Promise<TResult> {\n return new Promise((resolve, reject) => {\n this.queue.push({ request: RequestValue.from(params), resolve, reject });\n\n if (this.queue.length >= this.maxBatchSize) {\n this.flush();\n return;\n }\n\n if (!this.batchTimeout) {\n this.batchTimeout = setTimeout(() => {\n this.flush();\n }, this.batchWindowMs);\n }\n });\n }\n\n private async flush(): Promise<void> {\n if (this.batchTimeout) {\n clearTimeout(this.batchTimeout);\n this.batchTimeout = null;\n }\n\n if (this.queue.length === 0) {\n return;\n }\n\n const batch = this.queue.splice(0, this.queue.length);\n\n // Single request - use decoratee directly (no batching needed)\n if (batch.length === 1) {\n const { request, resolve, reject } = batch[0];\n try {\n const result = await this.decoratee.execute(request.request);\n resolve(result);\n } catch (error) {\n reject(error);\n }\n return;\n }\n\n // Group requests by endpoint + headers (only batch requests with identical target)\n const grouped = new Map<string, BatchedRequest[]>();\n for (const item of batch) {\n const groupKey =\n item.request.endpoint + \"|\" + this.serializeHeaders(item.request.headers);\n if (!grouped.has(groupKey)) {\n grouped.set(groupKey, []);\n }\n grouped.get(groupKey)!.push(item);\n }\n\n // Process each group separately\n const batchPromises = Array.from(grouped.entries()).map(requests => {\n const group = requests[1];\n\n if (group.length === 1) {\n // Single request in this group - use decoratee directly\n const { request, resolve, reject } = group[0];\n return this.decoratee.execute(request.request).then(resolve).catch(reject);\n }\n\n // Multiple requests with same headers - batch them\n return this.executeBatchGroup(group);\n });\n\n await Promise.all(batchPromises);\n }\n\n private async executeBatchGroup(group: BatchedRequest[]): Promise<void> {\n const batchedOperations = group.map(({ request }): BatchOperation => {\n return {\n query: request.queryAsString,\n operationName: request.operationName,\n variables: request.variables\n };\n });\n\n const endpoint = group[0].request.endpoint;\n const headers = group[0].request.headers;\n\n try {\n const results = await this.executeBatch(endpoint, batchedOperations, headers);\n group.forEach(({ resolve }, index) => {\n resolve(results[index]);\n });\n } catch (error) {\n group.forEach(({ reject }) => {\n reject(error);\n });\n }\n }\n\n private serializeHeaders(headers?: GraphQLClient.Headers): string {\n if (!headers) {\n return \"{}\";\n }\n // Sort keys for consistent serialization\n const sortedKeys = Object.keys(headers).sort();\n const sortedHeaders: Record<string, string> = {};\n for (const key of sortedKeys) {\n sortedHeaders[key] = String(headers[key]);\n }\n return JSON.stringify(sortedHeaders);\n }\n\n private async executeBatch(\n endpoint: string,\n operations: BatchOperation[],\n headers?: GraphQLClient.Headers\n ): Promise<any[]> {\n let response: Response;\n\n try {\n response = await fetch(endpoint, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...(headers || {})\n },\n body: JSON.stringify(operations)\n });\n } catch (err) {\n throw new Error(`Network error: ${(err as Error).message}`);\n }\n\n let json: any;\n try {\n json = await response.json();\n } catch {\n throw new Error(\"Failed to parse GraphQL batch response as JSON.\");\n }\n\n if (!Array.isArray(json)) {\n throw new Error(\"Expected batch response to be an array\");\n }\n\n // Map each result, handling individual errors\n return json.map((result: any, index: number) => {\n if (result.errors && result.errors.length > 0) {\n throw new Error(\n `GraphQL errors in operation ${index}: ${JSON.stringify(result.errors)}`\n );\n }\n return result.data;\n });\n }\n}\n\nexport const BatchingGraphQLClient = createDecorator({\n abstraction: GraphQLClient,\n decorator: BatchingGraphQLClientImpl,\n dependencies: []\n});\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,YAAY;AAC5C,SAASC,aAAa;AACtB,SAASC,YAAY;AAcrB,MAAMC,yBAAyB,CAAoC;EACvDC,KAAK,GAAqB,EAAE;EAC5BC,YAAY,GAA0B,IAAI;EAIlDC,WAAWA,CAASC,SAAkC,EAAE;IAAA,KAApCA,SAAkC,GAAlCA,SAAkC;IAClD;IACA,IAAI,CAACC,aAAa,GAAG,EAAE;IACvB,IAAI,CAACC,YAAY,GAAG,EAAE;EAC1B;EAEA,MAAMC,OAAOA,CACTC,MAAyC,EACzB;IAChB,OAAO,IAAIC,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;MACpC,IAAI,CAACV,KAAK,CAACW,IAAI,CAAC;QAAEC,OAAO,EAAEd,YAAY,CAACe,IAAI,CAAC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CAAC,CAAC;QACrB,CAAC;QACDoC,IAAI,EAAEN,IAAI,CAACC,SAAS,CAACC,UAAU;MACnC,CAAC,CAAC;IACN,CAAC,CAAC,OAAOK,GAAG,EAAE;MACV,MAAM,IAAIC,KAAK,CAAC,kBAAmBD,GAAG,CAAWE,OAAO,EAAE,CAAC;IAC/D;IAEA,IAAIC,IAAS;IACb,IAAI;MACAA,IAAI,GAAG,MAAMP,QAAQ,CAACO,IAAI,CAAC,CAAC;IAChC,CAAC,CAAC,MAAM;MACJ,MAAM,IAAIF,KAAK,CAAC,iDAAiD,CAAC;IACtE;IAEA,IAAI,CAACjC,KAAK,CAACoC,OAAO,CAACD,IAAI,CAAC,EAAE;MACtB,MAAM,IAAIF,KAAK,CAAC,wCAAwC,CAAC;IAC7D;;IAEA;IACA,OAAOE,IAAI,CAACjC,GAAG,CAAC,CAACf,MAAW,EAAE8B,KAAa,KAAK;MAC5C,IAAI9B,MAAM,CAACkD,MAAM,IAAIlD,MAAM,CAACkD,MAAM,CAACxD,MAAM,GAAG,CAAC,EAAE;QAC3C,MAAM,IAAIoD,KAAK,CACX,+BAA+BhB,KAAK,KAAKQ,IAAI,CAACC,SAAS,CAACvC,MAAM,CAACkD,MAAM,CAAC,EAC1E,CAAC;MACL;MACA,OAAOlD,MAAM,CAACmD,IAAI;IACtB,CAAC,CAAC;EACN;AACJ;AAEA,OAAO,MAAMC,qBAAqB,GAAG5E,eAAe,CAAC;EACjD6E,WAAW,EAAE5E,aAAa;EAC1B6E,SAAS,EAAE3E,yBAAyB;EACpC4E,YAAY,EAAE;AAClB,CAAC,CAAC","ignoreList":[]}
@@ -1,8 +1,5 @@
1
1
  import { GraphQLClient } from "./abstractions.js";
2
- import { EnvConfig } from "../../features/envConfig/index.js";
3
2
  declare class GraphQLClientImpl implements GraphQLClient.Interface {
4
- private readonly graphqlApiUrl;
5
- constructor(envConfig: EnvConfig.Interface);
6
3
  execute<TResult = any, TVariables = any>(params: GraphQLClient.Request<TVariables>): Promise<TResult>;
7
4
  private fetch;
8
5
  }
@@ -1,11 +1,7 @@
1
1
  import { createImplementation } from "@webiny/di";
2
2
  import { GraphQLClient } from "./abstractions.js";
3
- import { EnvConfig } from "../envConfig/index.js";
4
3
  import { RequestValue } from "./RequestValue.js";
5
4
  class GraphQLClientImpl {
6
- constructor(envConfig) {
7
- this.graphqlApiUrl = envConfig.get("graphqlApiUrl");
8
- }
9
5
  async execute(params) {
10
6
  const request = RequestValue.from(params);
11
7
  const body = JSON.stringify({
@@ -13,12 +9,12 @@ class GraphQLClientImpl {
13
9
  variables: request.variables,
14
10
  operationName: request.operationName
15
11
  });
16
- return this.fetch(body, request.headers);
12
+ return this.fetch(request.endpoint, body, request.headers);
17
13
  }
18
- async fetch(body, headers = {}) {
14
+ async fetch(endpoint, body, headers = {}) {
19
15
  let response;
20
16
  try {
21
- response = await fetch(this.graphqlApiUrl, {
17
+ response = await fetch(endpoint, {
22
18
  method: "POST",
23
19
  headers: {
24
20
  "Content-Type": "application/json",
@@ -56,7 +52,7 @@ class GraphQLClientImpl {
56
52
  export const FetchGraphQLClient = createImplementation({
57
53
  abstraction: GraphQLClient,
58
54
  implementation: GraphQLClientImpl,
59
- dependencies: [EnvConfig]
55
+ dependencies: []
60
56
  });
61
57
 
62
58
  //# sourceMappingURL=FetchGraphQLClient.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createImplementation","GraphQLClient","EnvConfig","RequestValue","GraphQLClientImpl","constructor","envConfig","graphqlApiUrl","get","execute","params","request","from","body","JSON","stringify","query","queryAsString","variables","operationName","fetch","headers","response","method","err","Error","message","json","status","code","errors","length","cause","data","FetchGraphQLClient","abstraction","implementation","dependencies"],"sources":["FetchGraphQLClient.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/di\";\nimport { GraphQLClient } from \"./abstractions.js\";\nimport { EnvConfig } from \"~/features/envConfig/index.js\";\nimport { RequestValue } from \"~/features/graphqlClient/RequestValue.js\";\n\nclass GraphQLClientImpl implements GraphQLClient.Interface {\n private readonly graphqlApiUrl: string;\n\n constructor(envConfig: EnvConfig.Interface) {\n this.graphqlApiUrl = envConfig.get(\"graphqlApiUrl\");\n }\n\n async execute<TResult = any, TVariables = any>(\n params: GraphQLClient.Request<TVariables>\n ): Promise<TResult> {\n const request = RequestValue.from(params);\n\n const body = JSON.stringify({\n query: request.queryAsString,\n variables: request.variables,\n operationName: request.operationName\n });\n\n return this.fetch<TResult>(body, request.headers);\n }\n\n private async fetch<TResult = any>(\n body: string,\n headers: GraphQLClient.Headers = {}\n ): Promise<TResult> {\n let response: Response;\n try {\n response = await fetch(this.graphqlApiUrl, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...(headers || {})\n },\n body\n });\n } catch (err) {\n throw new Error(`Network error: ${(err as Error).message}`);\n }\n let json: any;\n try {\n json = await response.json();\n } catch {\n throw new Error(\"Failed to parse GraphQL response as JSON.\");\n }\n\n // Check for generic API errors\n if (response.status !== 200) {\n throw { message: json.message, code: json.code };\n }\n\n // Check for GraphQL errors\n if (json.errors && json.errors.length > 0) {\n throw new Error(`GraphQL errors`, { cause: json.errors });\n }\n return json.data as TResult;\n }\n}\n\nexport const FetchGraphQLClient = createImplementation({\n abstraction: GraphQLClient,\n implementation: GraphQLClientImpl,\n dependencies: [EnvConfig]\n});\n"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,YAAY;AACjD,SAASC,aAAa;AACtB,SAASC,SAAS;AAClB,SAASC,YAAY;AAErB,MAAMC,iBAAiB,CAAoC;EAGvDC,WAAWA,CAACC,SAA8B,EAAE;IACxC,IAAI,CAACC,aAAa,GAAGD,SAAS,CAACE,GAAG,CAAC,eAAe,CAAC;EACvD;EAEA,MAAMC,OAAOA,CACTC,MAAyC,EACzB;IAChB,MAAMC,OAAO,GAAGR,YAAY,CAACS,IAAI,CAACF,MAAM,CAAC;IAEzC,MAAMG,IAAI,GAAGC,IAAI,CAACC,SAAS,CAAC;MACxBC,KAAK,EAAEL,OAAO,CAACM,aAAa;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AC1BmC,cAAc,EAAEhC,iBAAiB;EACjCiC,YAAY,EAAE,CAACnC,SAAS;AAC5B,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["createImplementation","GraphQLClient","RequestValue","GraphQLClientImpl","execute","params","request","from","body","JSON","stringify","query","queryAsString","variables","operationName","fetch","endpoint","headers","response","method","err","Error","message","json","status","code","errors","length","cause","data","FetchGraphQLClient","abstraction","implementation","dependencies"],"sources":["FetchGraphQLClient.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/di\";\nimport { GraphQLClient } from \"./abstractions.js\";\nimport { RequestValue } from \"~/features/graphqlClient/RequestValue.js\";\n\nclass GraphQLClientImpl implements GraphQLClient.Interface {\n async execute<TResult = any, TVariables = any>(\n params: GraphQLClient.Request<TVariables>\n ): Promise<TResult> {\n const request = RequestValue.from(params);\n\n const body = JSON.stringify({\n query: request.queryAsString,\n variables: request.variables,\n operationName: request.operationName\n });\n\n return this.fetch<TResult>(request.endpoint, body, request.headers);\n }\n\n private async fetch<TResult = any>(\n endpoint: string,\n body: string,\n headers: GraphQLClient.Headers = {}\n ): Promise<TResult> {\n let response: Response;\n try {\n response = await fetch(endpoint, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...(headers || {})\n },\n body\n });\n } catch (err) {\n throw new Error(`Network error: ${(err as Error).message}`);\n }\n let json: any;\n try {\n json = await response.json();\n } catch {\n throw new Error(\"Failed to parse GraphQL response as JSON.\");\n }\n\n // Check for generic API errors\n if (response.status !== 200) {\n throw { message: json.message, code: json.code };\n }\n\n // Check for GraphQL errors\n if (json.errors && json.errors.length > 0) {\n throw new Error(`GraphQL errors`, { cause: json.errors });\n }\n return json.data as TResult;\n }\n}\n\nexport const FetchGraphQLClient = createImplementation({\n abstraction: GraphQLClient,\n implementation: GraphQLClientImpl,\n dependencies: []\n});\n"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,YAAY;AACjD,SAASC,aAAa;AACtB,SAASC,YAAY;AAErB,MAAM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G,CAAC,EAAE;MACvC,MAAM,IAAIN,KAAK,CAAC,gBAAgB,EAAE;QAAEO,KAAK,EAAEL,IAAI,CAACG;MAAO,CAAC,CAAC;IAC7D;IACA,OAAOH,IAAI,CAACM,IAAI;EACpB;AACJ;AAEA,OAAO,MAAMC,kBAAkB,GAAG9B,oBAAoB,CAAC;EACnD+B,WAAW,EAAE9B,aAAa;EAC1B+B,cAAc,EAAE7B,iBAAiB;EACjC8B,YAAY,EAAE;AAClB,CAAC,CAAC","ignoreList":[]}
@@ -15,6 +15,7 @@ export declare class RequestValue {
15
15
  get headers(): {
16
16
  [x: string]: string | number | undefined;
17
17
  } | undefined;
18
+ get endpoint(): string;
18
19
  get operationName(): string | undefined;
19
20
  private getOperationName;
20
21
  }
@@ -30,6 +30,9 @@ export class RequestValue {
30
30
  get headers() {
31
31
  return this._request.headers;
32
32
  }
33
+ get endpoint() {
34
+ return this._request.endpoint;
35
+ }
33
36
  get operationName() {
34
37
  return this._operationName;
35
38
  }
@@ -1 +1 @@
1
- {"version":3,"names":["getOperationAST","parse","print","RequestValue","from","value","constructor","_request","query","_queryAsString","_queryAsDocumentNode","_operationName","getOperationName","request","variables","queryAsString","queryAsDocumentNode","headers","operationName","operationAST","undefined","name"],"sources":["RequestValue.ts"],"sourcesContent":["import { getOperationAST, parse, print, type DocumentNode } from \"graphql\";\nimport { GraphQLClient } from \"./abstractions.js\";\n\nexport class RequestValue {\n private readonly _operationName: string | undefined;\n private readonly _queryAsString: string;\n private readonly _queryAsDocumentNode: DocumentNode;\n private readonly _request: GraphQLClient.Request;\n\n static from(value: GraphQLClient.Request) {\n return new RequestValue(value);\n }\n\n private constructor(readonly value: GraphQLClient.Request) {\n this._request = value;\n if (typeof value.query === \"string\") {\n this._queryAsString = value.query;\n this._queryAsDocumentNode = parse(value.query);\n } else {\n this._queryAsString = print(value.query);\n this._queryAsDocumentNode = value.query;\n }\n\n this._operationName = this.getOperationName(this._queryAsDocumentNode);\n }\n\n get request() {\n return this._request;\n }\n\n get variables() {\n return this._request.variables;\n }\n\n get queryAsString() {\n return this._queryAsString;\n }\n\n get queryAsDocumentNode() {\n return this._queryAsDocumentNode;\n }\n\n get headers() {\n return this._request.headers;\n }\n\n get operationName() {\n return this._operationName;\n }\n\n private getOperationName(query: DocumentNode): string | undefined {\n const operationAST = getOperationAST(query, undefined);\n return operationAST?.name?.value;\n }\n}\n"],"mappings":"AAAA,SAASA,eAAe,EAAEC,KAAK,EAAEC,KAAK,QAA2B,SAAS;AAG1E,OAAO,MAAMC,YAAY,CAAC;EAMtB,OAAOC,IAAIA,CAACC,KAA4B,EAAE;IACtC,OAAO,IAAIF,YAAY,CAACE,KAAK,CAAC;EAClC;EAEQC,WAAWA,CAAUD,KAA4B,EAAE;IAAA,KAA9BA,KAA4B,GAA5BA,KAA4B;IACrD,IAAI,CAACE,QAAQ,GAAGF,KAAK;IACrB,IAAI,OAAOA,KAAK,CAACG,KAAK,KAAK,QAAQ,EAAE;MACjC,IAAI,CAACC,cAAc,GAAGJ,KAAK,CAACG,KAAK;MACjC,IAAI,CAACE,oBAAoB,GAAGT,KAAK,CAACI,KAAK,CAACG,KAAK,CAAC;IAClD,CAAC,MAAM;MACH,IAAI,CAACC,cAAc,GAAGP,KAAK,CAACG,KAAK,CAACG,KAAK,CAAC;MACxC,IAAI,CAACE,oBAAoB,GAAGL,KAAK,CAACG,KAAK;IAC3C;IAEA,IAAI,CAACG,cAAc,GAAG,IAAI,CAACC,gBAAgB,CAAC,IAAI,CAACF,oBAAoB,CAAC;EAC1E;EAEA,IAAIG,OAAOA,CAAA,EAAG;IACV,OAAO,IAAI,CAACN,QAAQ;EACxB;EAEA,IAAIO,SAASA,CAAA,EAAG;IACZ,OAAO,IAAI,CAACP,QAAQ,CAACO,SAAS;EAClC;EAEA,IAAIC,aAAaA,CAAA,EAAG;IAChB,OAAO,IAAI,CAACN,cAAc;EAC9B;EAEA,IAAIO,mBAAmBA,CAAA,EAAG;IACtB,OAAO,IAAI,CAACN,oBAAoB;EACpC;EAEA,IAAIO,OAAOA,CAAA,EAAG;IACV,OAAO,IAAI,CAACV,QAAQ,CAACU,OAAO;EAChC;EAEA,IAAIC,aAAaA,CAAA,EAAG;IAChB,OAAO,IAAI,CAACP,cAAc;EAC9B;EAEQC,gBAAgBA,CAACJ,KAAmB,EAAsB;IAC9D,MAAMW,YAAY,GAAGnB,eAAe,CAACQ,KAAK,EAAEY,SAAS,CAAC;IACtD,OAAOD,YAAY,EAAEE,IAAI,EAAEhB,KAAK;EACpC;AACJ","ignoreList":[]}
1
+ {"version":3,"names":["getOperationAST","parse","print","RequestValue","from","value","constructor","_request","query","_queryAsString","_queryAsDocumentNode","_operationName","getOperationName","request","variables","queryAsString","queryAsDocumentNode","headers","endpoint","operationName","operationAST","undefined","name"],"sources":["RequestValue.ts"],"sourcesContent":["import { getOperationAST, parse, print, type DocumentNode } from \"graphql\";\nimport { GraphQLClient } from \"./abstractions.js\";\n\nexport class RequestValue {\n private readonly _operationName: string | undefined;\n private readonly _queryAsString: string;\n private readonly _queryAsDocumentNode: DocumentNode;\n private readonly _request: GraphQLClient.Request;\n\n static from(value: GraphQLClient.Request) {\n return new RequestValue(value);\n }\n\n private constructor(readonly value: GraphQLClient.Request) {\n this._request = value;\n if (typeof value.query === \"string\") {\n this._queryAsString = value.query;\n this._queryAsDocumentNode = parse(value.query);\n } else {\n this._queryAsString = print(value.query);\n this._queryAsDocumentNode = value.query;\n }\n\n this._operationName = this.getOperationName(this._queryAsDocumentNode);\n }\n\n get request() {\n return this._request;\n }\n\n get variables() {\n return this._request.variables;\n }\n\n get queryAsString() {\n return this._queryAsString;\n }\n\n get queryAsDocumentNode() {\n return this._queryAsDocumentNode;\n }\n\n get headers() {\n return this._request.headers;\n }\n\n get endpoint() {\n return this._request.endpoint;\n }\n\n get operationName() {\n return this._operationName;\n }\n\n private getOperationName(query: DocumentNode): string | undefined {\n const operationAST = getOperationAST(query, undefined);\n return operationAST?.name?.value;\n }\n}\n"],"mappings":"AAA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AAgBA,CAACJ,KAAmB,EAAsB;IAC9D,MAAMY,YAAY,GAAGpB,eAAe,CAACQ,KAAK,EAAEa,SAAS,CAAC;IACtD,OAAOD,YAAY,EAAEE,IAAI,EAAEjB,KAAK;EACpC;AACJ","ignoreList":[]}
@@ -39,6 +39,7 @@ describe("GraphQLClient Feature", () => {
39
39
  });
40
40
  const client = container.resolve(GraphQLClient);
41
41
  const result = await client.execute({
42
+ endpoint: "https://api.example.com/graphql",
42
43
  query: "query GetUser { user { id name } }"
43
44
  });
44
45
  expect(result).toEqual(mockResponse.data);
@@ -64,6 +65,7 @@ describe("GraphQLClient Feature", () => {
64
65
  });
65
66
  const client = container.resolve(GraphQLClient);
66
67
  const result = await client.execute({
68
+ endpoint: "https://api.example.com/graphql",
67
69
  query: "mutation CreateUser($name: String!) { createUser(name: $name) { id name } }",
68
70
  variables: {
69
71
  name: "Jane"
@@ -85,6 +87,7 @@ describe("GraphQLClient Feature", () => {
85
87
  });
86
88
  const client = container.resolve(GraphQLClient);
87
89
  await client.execute({
90
+ endpoint: "https://api.example.com/graphql",
88
91
  query: "query GetUser { user { id } }",
89
92
  headers: {
90
93
  "x-tenant": "root",
@@ -103,6 +106,7 @@ describe("GraphQLClient Feature", () => {
103
106
  global.fetch = vi.fn().mockRejectedValue(new Error("Network failure"));
104
107
  const client = container.resolve(GraphQLClient);
105
108
  await expect(client.execute({
109
+ endpoint: "https://api.example.com/graphql",
106
110
  query: "query { user { id } }"
107
111
  })).rejects.toThrow("Network error: Network failure");
108
112
  });
@@ -119,6 +123,7 @@ describe("GraphQLClient Feature", () => {
119
123
  });
120
124
  const client = container.resolve(GraphQLClient);
121
125
  await expect(client.execute({
126
+ endpoint: "https://api.example.com/graphql",
122
127
  query: "query { user { id } }"
123
128
  })).rejects.toThrow("GraphQL errors");
124
129
  });
@@ -130,6 +135,7 @@ describe("GraphQLClient Feature", () => {
130
135
  });
131
136
  const client = container.resolve(GraphQLClient);
132
137
  await expect(client.execute({
138
+ endpoint: "https://api.example.com/graphql",
133
139
  query: "query { user { id } }"
134
140
  })).rejects.toThrow("Failed to parse GraphQL response as JSON");
135
141
  });
@@ -160,8 +166,10 @@ describe("GraphQLClient Feature", () => {
160
166
  });
161
167
  const client = container.resolve(GraphQLClient);
162
168
  const [result1, result2] = await Promise.all([client.execute({
169
+ endpoint: "https://api.example.com/graphql",
163
170
  query: "query GetUser { user { id name } }"
164
171
  }), client.execute({
172
+ endpoint: "https://api.example.com/graphql",
165
173
  query: "query GetPost { post { id title } }"
166
174
  })]);
167
175
  expect(result1).toEqual(mockResponse[0].data);
@@ -185,6 +193,7 @@ describe("GraphQLClient Feature", () => {
185
193
  });
186
194
  const client = container.resolve(GraphQLClient);
187
195
  const result = await client.execute({
196
+ endpoint: "https://api.example.com/graphql",
188
197
  query: "query GetUser { user { id name } }"
189
198
  });
190
199
  expect(result).toEqual(mockResponse.data);
@@ -214,8 +223,10 @@ describe("GraphQLClient Feature", () => {
214
223
  });
215
224
  const client = container.resolve(GraphQLClient);
216
225
  await Promise.all([client.execute({
226
+ endpoint: "https://api.example.com/graphql",
217
227
  query: "query { user { id } }"
218
228
  }), client.execute({
229
+ endpoint: "https://api.example.com/graphql",
219
230
  query: "mutation { createPost { id } }"
220
231
  })]);
221
232
  expect(global.fetch).toHaveBeenCalledTimes(1);
@@ -227,8 +238,10 @@ describe("GraphQLClient Feature", () => {
227
238
  global.fetch = vi.fn().mockRejectedValue(new Error("Network error"));
228
239
  const client = container.resolve(GraphQLClient);
229
240
  const promises = [client.execute({
241
+ endpoint: "https://api.example.com/graphql",
230
242
  query: "query { user { id } }"
231
243
  }), client.execute({
244
+ endpoint: "https://api.example.com/graphql",
232
245
  query: "query { post { id } }"
233
246
  })];
234
247
  await expect(Promise.all(promises)).rejects.toThrow("Network error");
@@ -251,8 +264,10 @@ describe("GraphQLClient Feature", () => {
251
264
  });
252
265
  const client = container.resolve(GraphQLClient);
253
266
  const promises = [client.execute({
267
+ endpoint: "https://api.example.com/graphql",
254
268
  query: "query { user { id } }"
255
269
  }), client.execute({
270
+ endpoint: "https://api.example.com/graphql",
256
271
  query: "query { post { id } }"
257
272
  })];
258
273
  await expect(Promise.all(promises)).rejects.toThrow("GraphQL errors in operation 1");
@@ -277,6 +292,7 @@ describe("GraphQLClient Feature", () => {
277
292
  });
278
293
  const client = container.resolve(GraphQLClient);
279
294
  const result = await client.execute({
295
+ endpoint: "https://api.example.com/graphql",
280
296
  query: "query { user { id } }"
281
297
  });
282
298
  expect(result).toEqual(mockResponse.data);
@@ -295,6 +311,7 @@ describe("GraphQLClient Feature", () => {
295
311
  });
296
312
  const client = container.resolve(GraphQLClient);
297
313
  await expect(client.execute({
314
+ endpoint: "https://api.example.com/graphql",
298
315
  query: "query { user { id } }"
299
316
  })).rejects.toThrow("GraphQL errors");
300
317
  expect(global.fetch).toHaveBeenCalledTimes(1);
@@ -303,6 +320,7 @@ describe("GraphQLClient Feature", () => {
303
320
  global.fetch = vi.fn().mockRejectedValue(new Error("Network error"));
304
321
  const client = container.resolve(GraphQLClient);
305
322
  await expect(client.execute({
323
+ endpoint: "https://api.example.com/graphql",
306
324
  query: "query { user { id } }"
307
325
  })).rejects.toThrow("Network error");
308
326
 
@@ -336,8 +354,10 @@ describe("GraphQLClient Feature", () => {
336
354
  });
337
355
  const client = container.resolve(GraphQLClient);
338
356
  const [result1, result2] = await Promise.all([client.execute({
357
+ endpoint: "https://api.example.com/graphql",
339
358
  query: "query { user { id } }"
340
359
  }), client.execute({
360
+ endpoint: "https://api.example.com/graphql",
341
361
  query: "query { post { id } }"
342
362
  })]);
343
363
  expect(result1).toEqual(mockResponse[0].data);
@@ -1 +1 @@
1
- {"version":3,"names":["describe","it","expect","vi","beforeEach","Container","GraphQLClient","FetchGraphQLClient","BatchingGraphQLClient","RetryGraphQLClient","EnvConfig","container","mockEnvConfig","get","fn","key","undefined","registerInstance","register","inSingletonScope","mockResponse","data","user","id","name","global","fetch","mockResolvedValue","status","json","client","resolve","result","execute","query","toEqual","toHaveBeenCalledWith","objectContaining","method","headers","createUser","variables","Authorization","mockRejectedValue","Error","rejects","toThrow","errors","message","registerDecorator","post","title","result1","result2","Promise","all","toHaveBeenCalledTimes","callBody","JSON","parse","mock","calls","body","toHaveLength","toHaveProperty","not","toBeInstanceOf","Array","createPost","promises","mockRejectedValueOnce","mockResolvedValueOnce"],"sources":["GraphQLClient.test.ts"],"sourcesContent":["import { describe, it, expect, vi, beforeEach } from \"vitest\";\nimport { Container } from \"@webiny/di\";\nimport { GraphQLClient } from \"../abstractions.js\";\nimport { FetchGraphQLClient } from \"../FetchGraphQLClient.js\";\nimport { BatchingGraphQLClient } from \"../BatchingGraphQLClient.js\";\nimport { RetryGraphQLClient } from \"../RetryGraphQLClient.js\";\nimport { EnvConfig } from \"~/features/envConfig/index.js\";\n\ndescribe(\"GraphQLClient Feature\", () => {\n let container: Container;\n let mockEnvConfig: EnvConfig.Interface;\n\n beforeEach(() => {\n container = new Container();\n\n mockEnvConfig = {\n get: vi.fn((key: string) => {\n if (key === \"graphqlApiUrl\") {\n return \"https://api.example.com/graphql\";\n }\n return undefined;\n })\n } as any;\n\n container.registerInstance(EnvConfig, mockEnvConfig);\n });\n\n describe(\"FetchGraphQLClient\", () => {\n beforeEach(() => {\n container.register(FetchGraphQLClient).inSingletonScope();\n });\n\n it(\"should execute a query successfully\", async () => {\n const mockResponse = {\n data: { user: { id: \"1\", name: \"John\" } }\n };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n const result = await client.execute({\n query: \"query GetUser { user { id name } }\"\n });\n\n expect(result).toEqual(mockResponse.data);\n expect(global.fetch).toHaveBeenCalledWith(\n \"https://api.example.com/graphql\",\n expect.objectContaining({\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" }\n })\n );\n });\n\n it(\"should execute a mutation successfully\", async () => {\n const mockResponse = {\n data: { createUser: { id: \"2\", name: \"Jane\" } }\n };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n const result = await client.execute({\n query: \"mutation CreateUser($name: String!) { createUser(name: $name) { id name } }\",\n variables: { name: \"Jane\" }\n });\n\n expect(result).toEqual(mockResponse.data);\n });\n\n it(\"should include custom headers\", async () => {\n const mockResponse = { data: { user: { id: \"1\" } } };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n await client.execute({\n query: \"query GetUser { user { id } }\",\n headers: { \"x-tenant\": \"root\", Authorization: \"Bearer token\" }\n });\n\n expect(global.fetch).toHaveBeenCalledWith(\n \"https://api.example.com/graphql\",\n expect.objectContaining({\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-tenant\": \"root\",\n Authorization: \"Bearer token\"\n }\n })\n );\n });\n\n it(\"should throw on network error\", async () => {\n global.fetch = vi.fn().mockRejectedValue(new Error(\"Network failure\"));\n\n const client = container.resolve(GraphQLClient);\n\n await expect(client.execute({ query: \"query { user { id } }\" })).rejects.toThrow(\n \"Network error: Network failure\"\n );\n });\n\n it(\"should throw on GraphQL errors\", async () => {\n const mockResponse = {\n errors: [{ message: \"User not found\" }],\n data: null\n };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n await expect(client.execute({ query: \"query { user { id } }\" })).rejects.toThrow(\n \"GraphQL errors\"\n );\n });\n\n it(\"should throw on invalid JSON response\", async () => {\n global.fetch = vi.fn().mockResolvedValue({\n json: async () => {\n throw new Error(\"Invalid JSON\");\n }\n });\n\n const client = container.resolve(GraphQLClient);\n\n await expect(client.execute({ query: \"query { user { id } }\" })).rejects.toThrow(\n \"Failed to parse GraphQL response as JSON\"\n );\n });\n });\n\n describe(\"BatchingGraphQLClient\", () => {\n beforeEach(() => {\n container.register(FetchGraphQLClient).inSingletonScope();\n container.registerDecorator(BatchingGraphQLClient);\n });\n\n it(\"should batch multiple requests within the batch window\", async () => {\n const mockResponse = [\n { data: { user: { id: \"1\", name: \"John\" } } },\n { data: { post: { id: \"2\", title: \"Hello\" } } }\n ];\n\n global.fetch = vi.fn().mockResolvedValue({\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n const [result1, result2] = await Promise.all([\n client.execute({ query: \"query GetUser { user { id name } }\" }),\n client.execute({ query: \"query GetPost { post { id title } }\" })\n ]);\n\n expect(result1).toEqual(mockResponse[0].data);\n expect(result2).toEqual(mockResponse[1].data);\n expect(global.fetch).toHaveBeenCalledTimes(1);\n\n const callBody = JSON.parse((global.fetch as any).mock.calls[0][1].body);\n expect(callBody).toHaveLength(2);\n });\n\n it(\"should execute single request without batching\", async () => {\n const mockResponse = {\n data: { user: { id: \"1\", name: \"John\" } }\n };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n const result = await client.execute({\n query: \"query GetUser { user { id name } }\"\n });\n\n expect(result).toEqual(mockResponse.data);\n\n // Should use decoratee directly for single request\n const callBody = JSON.parse((global.fetch as any).mock.calls[0][1].body);\n expect(callBody).toHaveProperty(\"query\");\n expect(callBody).not.toBeInstanceOf(Array);\n });\n\n it(\"should handle mixed queries and mutations in batch\", async () => {\n const mockResponse = [\n { data: { user: { id: \"1\" } } },\n { data: { createPost: { id: \"2\" } } }\n ];\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n await Promise.all([\n client.execute({ query: \"query { user { id } }\" }),\n client.execute({ query: \"mutation { createPost { id } }\" })\n ]);\n\n expect(global.fetch).toHaveBeenCalledTimes(1);\n const callBody = JSON.parse((global.fetch as any).mock.calls[0][1].body);\n expect(callBody[0]).toHaveProperty(\"query\");\n expect(callBody[1]).toHaveProperty(\"query\");\n });\n\n it(\"should reject all requests if batch fails\", async () => {\n global.fetch = vi.fn().mockRejectedValue(new Error(\"Network error\"));\n\n const client = container.resolve(GraphQLClient);\n\n const promises = [\n client.execute({ query: \"query { user { id } }\" }),\n client.execute({ query: \"query { post { id } }\" })\n ];\n\n await expect(Promise.all(promises)).rejects.toThrow(\"Network error\");\n });\n\n it(\"should handle GraphQL errors in batched operations\", async () => {\n const mockResponse = [\n { data: { user: { id: \"1\" } } },\n { errors: [{ message: \"Post not found\" }], data: null }\n ];\n\n global.fetch = vi.fn().mockResolvedValue({\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n const promises = [\n client.execute({ query: \"query { user { id } }\" }),\n client.execute({ query: \"query { post { id } }\" })\n ];\n\n await expect(Promise.all(promises)).rejects.toThrow(\"GraphQL errors in operation 1\");\n });\n });\n\n describe(\"RetryGraphQLClient\", () => {\n beforeEach(() => {\n container.register(FetchGraphQLClient).inSingletonScope();\n container.registerDecorator(RetryGraphQLClient);\n });\n\n it(\"should retry on network errors\", async () => {\n const mockResponse = { data: { user: { id: \"1\" } } };\n\n global.fetch = vi\n .fn()\n .mockRejectedValueOnce(new Error(\"Network timeout\"))\n .mockRejectedValueOnce(new Error(\"Network timeout\"))\n .mockResolvedValueOnce({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n const result = await client.execute({ query: \"query { user { id } }\" });\n\n expect(result).toEqual(mockResponse.data);\n expect(global.fetch).toHaveBeenCalledTimes(3);\n });\n\n it(\"should not retry on GraphQL errors\", async () => {\n const mockResponse = {\n errors: [{ message: \"Unauthorized\" }],\n data: null\n };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n await expect(client.execute({ query: \"query { user { id } }\" })).rejects.toThrow(\n \"GraphQL errors\"\n );\n\n expect(global.fetch).toHaveBeenCalledTimes(1);\n });\n\n it(\"should give up after max retries\", async () => {\n global.fetch = vi.fn().mockRejectedValue(new Error(\"Network error\"));\n\n const client = container.resolve(GraphQLClient);\n\n await expect(client.execute({ query: \"query { user { id } }\" })).rejects.toThrow(\n \"Network error\"\n );\n\n // Should try 4 times: initial + 3 retries\n expect(global.fetch).toHaveBeenCalledTimes(4);\n });\n });\n\n describe(\"Combined decorators (Retry + Batching)\", () => {\n beforeEach(() => {\n container.register(FetchGraphQLClient).inSingletonScope();\n container.registerDecorator(BatchingGraphQLClient);\n container.registerDecorator(RetryGraphQLClient);\n });\n\n it(\"should retry batched requests on failure\", async () => {\n const mockResponse = [{ data: { user: { id: \"1\" } } }, { data: { post: { id: \"2\" } } }];\n\n global.fetch = vi\n .fn()\n .mockRejectedValueOnce(new Error(\"Network error\"))\n .mockResolvedValueOnce({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n const [result1, result2] = await Promise.all([\n client.execute({ query: \"query { user { id } }\" }),\n client.execute({ query: \"query { post { id } }\" })\n ]);\n\n expect(result1).toEqual(mockResponse[0].data);\n expect(result2).toEqual(mockResponse[1].data);\n expect(global.fetch).toHaveBeenCalledTimes(2);\n });\n });\n});\n"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,EAAE,EAAEC,MAAM,EAAEC,EAAE,EAAEC,UAAU,QAAQ,QAAQ;AAC7D,SAASC,SAAS,QAAQ,YAAY;AACtC,SAASC,aAAa;AACtB,SAASC,kBAAkB;AAC3B,SAASC,qBAAqB;AAC9B,SAASC,kBAAkB;AAC3B,SAASC,SAAS;AAElBV,QAAQ,CAAC,uBAAuB,EAAE,MAAM;EACpC,IAAIW,SAAoB;EACxB,IAAIC,aAAkC;EAEtCR,UAAU,CAAC,MAAM;IACbO,SAAS,GAAG,IAAIN,SAAS,CAAC,CAAC;IAE3BO,aAAa,GAAG;MACZC,GAAG,EAAEV,EAAE,CAACW,EAAE,CAAEC,GAAW,IAAK;QACxB,IAAIA,GAAG,KAAK,eAAe,EAAE;UACzB,OAAO,iCAAiC;QAC5C;QACA,OAAOC,SAAS;MACpB,CAAC;IACL,CA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AC,CAAC;IAEFR,EAAE,CAAC,0CAA0C,EAAE,YAAY;MACvD,MAAMmB,YAAY,GAAG,CAAC;QAAEC,IAAI,EAAE;UAAEC,IAAI,EAAE;YAAEC,EAAE,EAAE;UAAI;QAAE;MAAE,CAAC,EAAE;QAAEF,IAAI,EAAE;UAAE6B,IAAI,EAAE;YAAE3B,EAAE,EAAE;UAAI;QAAE;MAAE,CAAC,CAAC;MAEvFE,MAAM,CAACC,KAAK,GAAGvB,EAAE,CACZW,EAAE,CAAC,CAAC,CACJwD,qBAAqB,CAAC,IAAI1B,KAAK,CAAC,eAAe,CAAC,CAAC,CACjD2B,qBAAqB,CAAC;QACnB3C,MAAM,EAAE,GAAG;QACXC,IAAI,EAAE,MAAAA,CAAA,KAAYT;MACtB,CAAC,CAAC;MAEN,MAAMU,MAAM,GAAGnB,SAAS,CAACoB,OAAO,CAACzB,aAAa,CAAC;MAE/C,MAAM,CAAC8C,OAAO,EAAEC,OAAO,CAAC,GAAG,MAAMC,OAAO,CAACC,GAAG,CAAC,CACzCzB,MAAM,CAACG,OAAO,CAAC;QAAEC,KAAK,EAAE;MAAwB,CAAC,CAAC,EAClDJ,MAAM,CAACG,OAAO,CAAC;QAAEC,KAAK,EAAE;MAAwB,CAAC,CAAC,CACrD,CAAC;MAEFhC,MAAM,CAACkD,OAAO,CAAC,CAACjB,OAAO,CAACf,YAAY,CAAC,CAAC,CAAC,CAACC,IAAI,CAAC;MAC7CnB,MAAM,CAACmD,OAAO,CAAC,CAAClB,OAAO,CAACf,YAAY,CAAC,CAAC,CAAC,CAACC,IAAI,CAAC;MAC7CnB,MAAM,CAACuB,MAAM,CAACC,KAAK,CAAC,CAAC8B,qBAAqB,CAAC,CAAC,CAAC;IACjD,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["describe","it","expect","vi","beforeEach","Container","GraphQLClient","FetchGraphQLClient","BatchingGraphQLClient","RetryGraphQLClient","EnvConfig","container","mockEnvConfig","get","fn","key","undefined","registerInstance","register","inSingletonScope","mockResponse","data","user","id","name","global","fetch","mockResolvedValue","status","json","client","resolve","result","execute","endpoint","query","toEqual","toHaveBeenCalledWith","objectContaining","method","headers","createUser","variables","Authorization","mockRejectedValue","Error","rejects","toThrow","errors","message","registerDecorator","post","title","result1","result2","Promise","all","toHaveBeenCalledTimes","callBody","JSON","parse","mock","calls","body","toHaveLength","toHaveProperty","not","toBeInstanceOf","Array","createPost","promises","mockRejectedValueOnce","mockResolvedValueOnce"],"sources":["GraphQLClient.test.ts"],"sourcesContent":["import { describe, it, expect, vi, beforeEach } from \"vitest\";\nimport { Container } from \"@webiny/di\";\nimport { GraphQLClient } from \"../abstractions.js\";\nimport { FetchGraphQLClient } from \"../FetchGraphQLClient.js\";\nimport { BatchingGraphQLClient } from \"../BatchingGraphQLClient.js\";\nimport { RetryGraphQLClient } from \"../RetryGraphQLClient.js\";\nimport { EnvConfig } from \"~/features/envConfig/index.js\";\n\ndescribe(\"GraphQLClient Feature\", () => {\n let container: Container;\n let mockEnvConfig: EnvConfig.Interface;\n\n beforeEach(() => {\n container = new Container();\n\n mockEnvConfig = {\n get: vi.fn((key: string) => {\n if (key === \"graphqlApiUrl\") {\n return \"https://api.example.com/graphql\";\n }\n return undefined;\n })\n } as any;\n\n container.registerInstance(EnvConfig, mockEnvConfig);\n });\n\n describe(\"FetchGraphQLClient\", () => {\n beforeEach(() => {\n container.register(FetchGraphQLClient).inSingletonScope();\n });\n\n it(\"should execute a query successfully\", async () => {\n const mockResponse = {\n data: { user: { id: \"1\", name: \"John\" } }\n };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n const result = await client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query GetUser { user { id name } }\"\n });\n\n expect(result).toEqual(mockResponse.data);\n expect(global.fetch).toHaveBeenCalledWith(\n \"https://api.example.com/graphql\",\n expect.objectContaining({\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" }\n })\n );\n });\n\n it(\"should execute a mutation successfully\", async () => {\n const mockResponse = {\n data: { createUser: { id: \"2\", name: \"Jane\" } }\n };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n const result = await client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"mutation CreateUser($name: String!) { createUser(name: $name) { id name } }\",\n variables: { name: \"Jane\" }\n });\n\n expect(result).toEqual(mockResponse.data);\n });\n\n it(\"should include custom headers\", async () => {\n const mockResponse = { data: { user: { id: \"1\" } } };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n await client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query GetUser { user { id } }\",\n headers: { \"x-tenant\": \"root\", Authorization: \"Bearer token\" }\n });\n\n expect(global.fetch).toHaveBeenCalledWith(\n \"https://api.example.com/graphql\",\n expect.objectContaining({\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-tenant\": \"root\",\n Authorization: \"Bearer token\"\n }\n })\n );\n });\n\n it(\"should throw on network error\", async () => {\n global.fetch = vi.fn().mockRejectedValue(new Error(\"Network failure\"));\n\n const client = container.resolve(GraphQLClient);\n\n await expect(\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n })\n ).rejects.toThrow(\"Network error: Network failure\");\n });\n\n it(\"should throw on GraphQL errors\", async () => {\n const mockResponse = {\n errors: [{ message: \"User not found\" }],\n data: null\n };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n await expect(\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n })\n ).rejects.toThrow(\"GraphQL errors\");\n });\n\n it(\"should throw on invalid JSON response\", async () => {\n global.fetch = vi.fn().mockResolvedValue({\n json: async () => {\n throw new Error(\"Invalid JSON\");\n }\n });\n\n const client = container.resolve(GraphQLClient);\n\n await expect(\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n })\n ).rejects.toThrow(\"Failed to parse GraphQL response as JSON\");\n });\n });\n\n describe(\"BatchingGraphQLClient\", () => {\n beforeEach(() => {\n container.register(FetchGraphQLClient).inSingletonScope();\n container.registerDecorator(BatchingGraphQLClient);\n });\n\n it(\"should batch multiple requests within the batch window\", async () => {\n const mockResponse = [\n { data: { user: { id: \"1\", name: \"John\" } } },\n { data: { post: { id: \"2\", title: \"Hello\" } } }\n ];\n\n global.fetch = vi.fn().mockResolvedValue({\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n const [result1, result2] = await Promise.all([\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query GetUser { user { id name } }\"\n }),\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query GetPost { post { id title } }\"\n })\n ]);\n\n expect(result1).toEqual(mockResponse[0].data);\n expect(result2).toEqual(mockResponse[1].data);\n expect(global.fetch).toHaveBeenCalledTimes(1);\n\n const callBody = JSON.parse((global.fetch as any).mock.calls[0][1].body);\n expect(callBody).toHaveLength(2);\n });\n\n it(\"should execute single request without batching\", async () => {\n const mockResponse = {\n data: { user: { id: \"1\", name: \"John\" } }\n };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n const result = await client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query GetUser { user { id name } }\"\n });\n\n expect(result).toEqual(mockResponse.data);\n\n // Should use decoratee directly for single request\n const callBody = JSON.parse((global.fetch as any).mock.calls[0][1].body);\n expect(callBody).toHaveProperty(\"query\");\n expect(callBody).not.toBeInstanceOf(Array);\n });\n\n it(\"should handle mixed queries and mutations in batch\", async () => {\n const mockResponse = [\n { data: { user: { id: \"1\" } } },\n { data: { createPost: { id: \"2\" } } }\n ];\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n await Promise.all([\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n }),\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"mutation { createPost { id } }\"\n })\n ]);\n\n expect(global.fetch).toHaveBeenCalledTimes(1);\n const callBody = JSON.parse((global.fetch as any).mock.calls[0][1].body);\n expect(callBody[0]).toHaveProperty(\"query\");\n expect(callBody[1]).toHaveProperty(\"query\");\n });\n\n it(\"should reject all requests if batch fails\", async () => {\n global.fetch = vi.fn().mockRejectedValue(new Error(\"Network error\"));\n\n const client = container.resolve(GraphQLClient);\n\n const promises = [\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n }),\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { post { id } }\"\n })\n ];\n\n await expect(Promise.all(promises)).rejects.toThrow(\"Network error\");\n });\n\n it(\"should handle GraphQL errors in batched operations\", async () => {\n const mockResponse = [\n { data: { user: { id: \"1\" } } },\n { errors: [{ message: \"Post not found\" }], data: null }\n ];\n\n global.fetch = vi.fn().mockResolvedValue({\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n const promises = [\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n }),\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { post { id } }\"\n })\n ];\n\n await expect(Promise.all(promises)).rejects.toThrow(\"GraphQL errors in operation 1\");\n });\n });\n\n describe(\"RetryGraphQLClient\", () => {\n beforeEach(() => {\n container.register(FetchGraphQLClient).inSingletonScope();\n container.registerDecorator(RetryGraphQLClient);\n });\n\n it(\"should retry on network errors\", async () => {\n const mockResponse = { data: { user: { id: \"1\" } } };\n\n global.fetch = vi\n .fn()\n .mockRejectedValueOnce(new Error(\"Network timeout\"))\n .mockRejectedValueOnce(new Error(\"Network timeout\"))\n .mockResolvedValueOnce({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n const result = await client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n });\n\n expect(result).toEqual(mockResponse.data);\n expect(global.fetch).toHaveBeenCalledTimes(3);\n });\n\n it(\"should not retry on GraphQL errors\", async () => {\n const mockResponse = {\n errors: [{ message: \"Unauthorized\" }],\n data: null\n };\n\n global.fetch = vi.fn().mockResolvedValue({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n await expect(\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n })\n ).rejects.toThrow(\"GraphQL errors\");\n\n expect(global.fetch).toHaveBeenCalledTimes(1);\n });\n\n it(\"should give up after max retries\", async () => {\n global.fetch = vi.fn().mockRejectedValue(new Error(\"Network error\"));\n\n const client = container.resolve(GraphQLClient);\n\n await expect(\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n })\n ).rejects.toThrow(\"Network error\");\n\n // Should try 4 times: initial + 3 retries\n expect(global.fetch).toHaveBeenCalledTimes(4);\n });\n });\n\n describe(\"Combined decorators (Retry + Batching)\", () => {\n beforeEach(() => {\n container.register(FetchGraphQLClient).inSingletonScope();\n container.registerDecorator(BatchingGraphQLClient);\n container.registerDecorator(RetryGraphQLClient);\n });\n\n it(\"should retry batched requests on failure\", async () => {\n const mockResponse = [{ data: { user: { id: \"1\" } } }, { data: { post: { id: \"2\" } } }];\n\n global.fetch = vi\n .fn()\n .mockRejectedValueOnce(new Error(\"Network error\"))\n .mockResolvedValueOnce({\n status: 200,\n json: async () => mockResponse\n });\n\n const client = container.resolve(GraphQLClient);\n\n const [result1, result2] = await Promise.all([\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { user { id } }\"\n }),\n client.execute({\n endpoint: \"https://api.example.com/graphql\",\n query: \"query { post { id } }\"\n })\n ]);\n\n expect(result1).toEqual(mockResponse[0].data);\n expect(result2).toEqual(mockResponse[1].data);\n expect(global.fetch).toHaveBeenCalledTimes(2);\n });\n });\n});\n"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,EAAE,EAAEC,MAAM,EAAEC,EAAE,EAAEC,UAAU,QAAQ,QAAQ;AAC7D,SAASC,SAAS,QAAQ,YAAY;AACtC,SAASC,aAAa;AACtB,SAASC,kBAAkB;AAC3B,SAASC,qBAAqB;AAC9B,SAASC,kBAAkB;AAC3B,SAASC,SAAS;AAElBV,QAAQ,CAAC,uBAAuB,EAAE,MAAM;EACpC,IAAIW,SAAoB;EACxB,IAAIC,aAAkC;EAEtCR,UAAU,CAAC,MAAM;IACbO,SAAS,GAAG,IAAIN,SAAS,CAAC,CAAC;IAE3BO,aAAa,GAAG;MACZC,GAAG,EAAEV,EAAE,CAACW,EAAE,CAAEC,GAAW,IAAK;QACxB,IAAIA,GAAG,KAAK,eAAe,EAAE;UACzB,OAAO,iCAAiC;QAC5C;QACA,OAAOC,SAAS;MACpB,CAAC;IACL,CAAQ;IAERL,SAAS,CAACM,gBAAgB,CAACP,SAAS,EAAEE,aAAa,CAAC;EACxD,CAAC,CAAC;EAEFZ,QAAQ,CAAC,oBAAoB,EAAE,MAAM;IACjCI,UAAU,CAAC,MAAM;MACbO,SAAS,CAACO,QAAQ,CAACX,kBAAkB,CAAC,CAACY,gBAAgB,CAAC,CAAC;IAC7D,CAAC,CAAC;IAEFlB,EAAE,CAAC,qCAAqC,EAAE,YAAY;MAClD,MAAMmB,YAAY,GAAG;QACjBC,IAAI,EAAE;UAAEC,IAAI,EAAE;YAAEC,EAAE,EAAE,GAAG;YAAEC,IAAI,EAAE;UAAO;QAAE;MAC5C,CAAC;MAEDC,MAAM,CAACC,KAAK,GAAGvB,EAAE,CAACW,EAAE,CAAC,CAAC,CAACa,iBAAiB,CAAC;QACrCC,MAAM,EAAE,GAAG;QACXC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Y;MACvD,MAAMmB,YAAY,GAAG,CAAC;QAAEC,IAAI,EAAE;UAAEC,IAAI,EAAE;YAAEC,EAAE,EAAE;UAAI;QAAE;MAAE,CAAC,EAAE;QAAEF,IAAI,EAAE;UAAE8B,IAAI,EAAE;YAAE5B,EAAE,EAAE;UAAI;QAAE;MAAE,CAAC,CAAC;MAEvFE,MAAM,CAACC,KAAK,GAAGvB,EAAE,CACZW,EAAE,CAAC,CAAC,CACJyD,qBAAqB,CAAC,IAAI1B,KAAK,CAAC,eAAe,CAAC,CAAC,CACjD2B,qBAAqB,CAAC;QACnB5C,MAAM,EAAE,GAAG;QACXC,IAAI,EAAE,MAAAA,CAAA,KAAYT;MACtB,CAAC,CAAC;MAEN,MAAMU,MAAM,GAAGnB,SAAS,CAACoB,OAAO,CAACzB,aAAa,CAAC;MAE/C,MAAM,CAAC+C,OAAO,EAAEC,OAAO,CAAC,GAAG,MAAMC,OAAO,CAACC,GAAG,CAAC,CACzC1B,MAAM,CAACG,OAAO,CAAC;QACXC,QAAQ,EAAE,iCAAiC;QAC3CC,KAAK,EAAE;MACX,CAAC,CAAC,EACFL,MAAM,CAACG,OAAO,CAAC;QACXC,QAAQ,EAAE,iCAAiC;QAC3CC,KAAK,EAAE;MACX,CAAC,CAAC,CACL,CAAC;MAEFjC,MAAM,CAACmD,OAAO,CAAC,CAACjB,OAAO,CAAChB,YAAY,CAAC,CAAC,CAAC,CAACC,IAAI,CAAC;MAC7CnB,MAAM,CAACoD,OAAO,CAAC,CAAClB,OAAO,CAAChB,YAAY,CAAC,CAAC,CAAC,CAACC,IAAI,CAAC;MAC7CnB,MAAM,CAACuB,MAAM,CAACC,KAAK,CAAC,CAAC+B,qBAAqB,CAAC,CAAC,CAAC;IACjD,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC,CAAC","ignoreList":[]}
@@ -1,6 +1,7 @@
1
1
  import type { DocumentNode } from "graphql";
2
2
  type IHeaders = Record<string, string | number | undefined>;
3
3
  type GraphQLRequest<TVariables = any> = {
4
+ endpoint: string;
4
5
  query: DocumentNode | string;
5
6
  variables?: TVariables;
6
7
  headers?: IHeaders;
@@ -1 +1 @@
1
- {"version":3,"names":["createAbstraction","GraphQLClient"],"sources":["abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/admin\";\nimport type { DocumentNode } from \"graphql\";\n\ntype IHeaders = Record<string, string | number | undefined>;\n\ntype GraphQLRequest<TVariables = any> = {\n query: DocumentNode | string;\n variables?: TVariables;\n headers?: IHeaders;\n};\n\nexport interface IGraphQLClient {\n execute<TResult = any, TVariables = any>(params: GraphQLRequest<TVariables>): Promise<TResult>;\n}\nexport const GraphQLClient = createAbstraction<IGraphQLClient>(\"GraphQLClient\");\n\nexport namespace GraphQLClient {\n export type Headers = IHeaders;\n export type Interface = IGraphQLClient;\n export type Request<TVariables = any> = GraphQLRequest<TVariables>;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,uBAAuB;AAczD,OAAO,MAAMC,aAAa,GAAGD,iBAAiB,CAAiB,eAAe,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["createAbstraction","GraphQLClient"],"sources":["abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/admin\";\nimport type { DocumentNode } from \"graphql\";\n\ntype IHeaders = Record<string, string | number | undefined>;\n\ntype GraphQLRequest<TVariables = any> = {\n endpoint: string;\n query: DocumentNode | string;\n variables?: TVariables;\n headers?: IHeaders;\n};\n\nexport interface IGraphQLClient {\n execute<TResult = any, TVariables = any>(params: GraphQLRequest<TVariables>): Promise<TResult>;\n}\nexport const GraphQLClient = createAbstraction<IGraphQLClient>(\"GraphQLClient\");\n\nexport namespace GraphQLClient {\n export type Headers = IHeaders;\n export type Interface = IGraphQLClient;\n export type Request<TVariables = any> = GraphQLRequest<TVariables>;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,uBAAuB;AAezD,OAAO,MAAMC,aAAa,GAAGD,iBAAiB,CAAiB,eAAe,CAAC","ignoreList":[]}
@@ -0,0 +1,11 @@
1
+ import { MainGraphQLClient } from "./abstractions.js";
2
+ import { GraphQLClient } from "../../features/graphqlClient/abstractions.js";
3
+ import { EnvConfig } from "../../features/envConfig/index.js";
4
+ declare class MainGraphQLClientImpl implements MainGraphQLClient.Interface {
5
+ private client;
6
+ private readonly endpoint;
7
+ constructor(envConfig: EnvConfig.Interface, client: GraphQLClient.Interface);
8
+ execute<TResult = any, TVariables = any>(params: MainGraphQLClient.Request<TVariables>): Promise<TResult>;
9
+ }
10
+ export declare const DefaultMainGraphQLClient: import("@webiny/di").Implementation<typeof MainGraphQLClientImpl>;
11
+ export {};