@newmo/graphql-codegen-fake-server-client 0.23.0 → 0.23.2
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.
|
@@ -106,10 +106,10 @@ export type FakeClientRegisterSequenceOptions<TVariables = Record<string, any>>
|
|
|
106
106
|
});
|
|
107
107
|
};
|
|
108
108
|
const importQueryIdentifierName = (documentName) => {
|
|
109
|
-
return `import type { ${(0, convertName_1.convertName)(documentName, config)}Query, ${(0, convertName_1.convertName)(documentName, config)}QueryVariables } from
|
|
109
|
+
return `import type { ${(0, convertName_1.convertName)(documentName, config)}Query, ${(0, convertName_1.convertName)(documentName, config)}QueryVariables } from '${config.typesFile}';`;
|
|
110
110
|
};
|
|
111
111
|
const importMutationIdentifierName = (documentName) => {
|
|
112
|
-
return `import type { ${(0, convertName_1.convertName)(documentName, config)}Mutation, ${(0, convertName_1.convertName)(documentName, config)}MutationVariables } from
|
|
112
|
+
return `import type { ${(0, convertName_1.convertName)(documentName, config)}Mutation, ${(0, convertName_1.convertName)(documentName, config)}MutationVariables } from '${config.typesFile}';`;
|
|
113
113
|
};
|
|
114
114
|
const importsSection = documents
|
|
115
115
|
.flatMap((document) => {
|
|
@@ -17,24 +17,24 @@ export type CreateFakeClientOptions = {
|
|
|
17
17
|
|
|
18
18
|
// Request queue implementation for rate limiting
|
|
19
19
|
class RequestQueue {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
#queue: Array<() => Promise<unknown>> = [];
|
|
21
|
+
#running = 0;
|
|
22
|
+
#maxConcurrent: number = 10; // Reduced default for better stability
|
|
23
|
+
#requestDelay: number = 10; // Small delay to prevent overwhelming the server
|
|
24
|
+
#lastRequestTime = 0;
|
|
25
25
|
|
|
26
26
|
async add<T>(fn: () => Promise<T>): Promise<T> {
|
|
27
27
|
return new Promise((resolve, reject) => {
|
|
28
|
-
this
|
|
28
|
+
this.#queue.push(async () => {
|
|
29
29
|
try {
|
|
30
30
|
// Apply request delay if configured
|
|
31
|
-
if (this
|
|
31
|
+
if (this.#requestDelay > 0) {
|
|
32
32
|
const now = Date.now();
|
|
33
|
-
const timeSinceLastRequest = now - this
|
|
34
|
-
if (timeSinceLastRequest < this
|
|
35
|
-
await new Promise(r => setTimeout(r, this
|
|
33
|
+
const timeSinceLastRequest = now - this.#lastRequestTime;
|
|
34
|
+
if (timeSinceLastRequest < this.#requestDelay) {
|
|
35
|
+
await new Promise(r => setTimeout(r, this.#requestDelay - timeSinceLastRequest));
|
|
36
36
|
}
|
|
37
|
-
this
|
|
37
|
+
this.#lastRequestTime = Date.now();
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
const result = await fn();
|
|
@@ -43,21 +43,21 @@ class RequestQueue {
|
|
|
43
43
|
reject(error);
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
|
-
this
|
|
46
|
+
this.#process();
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
if (this
|
|
50
|
+
async #process() {
|
|
51
|
+
if (this.#running >= this.#maxConcurrent || this.#queue.length === 0) {
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
this
|
|
56
|
-
const fn = this
|
|
55
|
+
this.#running++;
|
|
56
|
+
const fn = this.#queue.shift();
|
|
57
57
|
if (fn) {
|
|
58
58
|
await fn();
|
|
59
|
-
this
|
|
60
|
-
this
|
|
59
|
+
this.#running--;
|
|
60
|
+
this.#process();
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
}
|
|
@@ -102,7 +102,7 @@ async function fetchWithRetry(
|
|
|
102
102
|
statusText: response.statusText,
|
|
103
103
|
attempt: attempt + 1,
|
|
104
104
|
maxAttempts,
|
|
105
|
-
|
|
105
|
+
body: options.body,
|
|
106
106
|
sequenceId: (options.headers as any)?.['sequence-id'],
|
|
107
107
|
};
|
|
108
108
|
|
|
@@ -144,7 +144,7 @@ async function fetchWithRetry(
|
|
|
144
144
|
error: error instanceof Error ? error.message : String(error),
|
|
145
145
|
attempt: attempt + 1,
|
|
146
146
|
maxAttempts,
|
|
147
|
-
|
|
147
|
+
body: options.body,
|
|
148
148
|
sequenceId: (options.headers as any)?.['sequence-id'],
|
|
149
149
|
};
|
|
150
150
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@newmo/graphql-codegen-fake-server-client",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "GraphQL Codegen plugin for generating a fake server client",
|
|
6
6
|
"keywords": [
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"access": "public",
|
|
63
63
|
"registry": "https://registry.npmjs.org/"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "1b4cb773d37a6ad7197e9a8098d2fccd41047996"
|
|
66
66
|
}
|
|
@@ -177,13 +177,13 @@ export type FakeClientRegisterSequenceOptions<TVariables = Record<string, any>>
|
|
|
177
177
|
return `import type { ${convertName(
|
|
178
178
|
documentName,
|
|
179
179
|
config,
|
|
180
|
-
)}Query, ${convertName(documentName, config)}QueryVariables } from
|
|
180
|
+
)}Query, ${convertName(documentName, config)}QueryVariables } from '${config.typesFile}';`;
|
|
181
181
|
};
|
|
182
182
|
const importMutationIdentifierName = (documentName: string) => {
|
|
183
183
|
return `import type { ${convertName(documentName, config)}Mutation, ${convertName(
|
|
184
184
|
documentName,
|
|
185
185
|
config,
|
|
186
|
-
)}MutationVariables } from
|
|
186
|
+
)}MutationVariables } from '${config.typesFile}';`;
|
|
187
187
|
};
|
|
188
188
|
const importsSection = documents
|
|
189
189
|
.flatMap((document) => {
|
package/src/templates/runtime.ts
CHANGED
|
@@ -14,24 +14,24 @@ export type CreateFakeClientOptions = {
|
|
|
14
14
|
|
|
15
15
|
// Request queue implementation for rate limiting
|
|
16
16
|
class RequestQueue {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
#queue: Array<() => Promise<unknown>> = [];
|
|
18
|
+
#running = 0;
|
|
19
|
+
#maxConcurrent: number = 10; // Reduced default for better stability
|
|
20
|
+
#requestDelay: number = 10; // Small delay to prevent overwhelming the server
|
|
21
|
+
#lastRequestTime = 0;
|
|
22
22
|
|
|
23
23
|
async add<T>(fn: () => Promise<T>): Promise<T> {
|
|
24
24
|
return new Promise((resolve, reject) => {
|
|
25
|
-
this
|
|
25
|
+
this.#queue.push(async () => {
|
|
26
26
|
try {
|
|
27
27
|
// Apply request delay if configured
|
|
28
|
-
if (this
|
|
28
|
+
if (this.#requestDelay > 0) {
|
|
29
29
|
const now = Date.now();
|
|
30
|
-
const timeSinceLastRequest = now - this
|
|
31
|
-
if (timeSinceLastRequest < this
|
|
32
|
-
await new Promise(r => setTimeout(r, this
|
|
30
|
+
const timeSinceLastRequest = now - this.#lastRequestTime;
|
|
31
|
+
if (timeSinceLastRequest < this.#requestDelay) {
|
|
32
|
+
await new Promise(r => setTimeout(r, this.#requestDelay - timeSinceLastRequest));
|
|
33
33
|
}
|
|
34
|
-
this
|
|
34
|
+
this.#lastRequestTime = Date.now();
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
const result = await fn();
|
|
@@ -40,21 +40,21 @@ class RequestQueue {
|
|
|
40
40
|
reject(error);
|
|
41
41
|
}
|
|
42
42
|
});
|
|
43
|
-
this
|
|
43
|
+
this.#process();
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
if (this
|
|
47
|
+
async #process() {
|
|
48
|
+
if (this.#running >= this.#maxConcurrent || this.#queue.length === 0) {
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
this
|
|
53
|
-
const fn = this
|
|
52
|
+
this.#running++;
|
|
53
|
+
const fn = this.#queue.shift();
|
|
54
54
|
if (fn) {
|
|
55
55
|
await fn();
|
|
56
|
-
this
|
|
57
|
-
this
|
|
56
|
+
this.#running--;
|
|
57
|
+
this.#process();
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
}
|
|
@@ -99,7 +99,7 @@ async function fetchWithRetry(
|
|
|
99
99
|
statusText: response.statusText,
|
|
100
100
|
attempt: attempt + 1,
|
|
101
101
|
maxAttempts,
|
|
102
|
-
|
|
102
|
+
body: options.body,
|
|
103
103
|
sequenceId: (options.headers as any)?.['sequence-id'],
|
|
104
104
|
};
|
|
105
105
|
|
|
@@ -141,7 +141,7 @@ async function fetchWithRetry(
|
|
|
141
141
|
error: error instanceof Error ? error.message : String(error),
|
|
142
142
|
attempt: attempt + 1,
|
|
143
143
|
maxAttempts,
|
|
144
|
-
|
|
144
|
+
body: options.body,
|
|
145
145
|
sequenceId: (options.headers as any)?.['sequence-id'],
|
|
146
146
|
};
|
|
147
147
|
|