drizzle-graphql-plus 0.8.38 → 0.8.39
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.
- package/index.cjs +869 -262
- package/index.cjs.map +1 -1
- package/index.d.cts +35 -105
- package/index.d.ts +35 -105
- package/index.js +872 -254
- package/index.js.map +1 -1
- package/package.json +6 -5
package/index.cjs
CHANGED
|
@@ -30,7 +30,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
));
|
|
31
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
32
|
|
|
33
|
-
// src/export-directive/utils.ts
|
|
33
|
+
// src/export-directive[DEPRECATED]/utils.ts
|
|
34
34
|
var utils_exports = {};
|
|
35
35
|
__export(utils_exports, {
|
|
36
36
|
extractExportDirectives: () => extractExportDirectives,
|
|
@@ -39,16 +39,105 @@ __export(utils_exports, {
|
|
|
39
39
|
hasExportVariables: () => hasExportVariables,
|
|
40
40
|
isExportVariable: () => isExportVariable,
|
|
41
41
|
processExports: () => processExports,
|
|
42
|
-
|
|
42
|
+
processExportsSync: () => processExportsSync,
|
|
43
|
+
resolveExportVariables: () => resolveExportVariables,
|
|
44
|
+
resolveGraphQLVariables: () => resolveGraphQLVariables
|
|
43
45
|
});
|
|
46
|
+
async function resolveGraphQLVariables(args, graphqlVariables, info) {
|
|
47
|
+
if (Array.isArray(args)) {
|
|
48
|
+
return Promise.all(
|
|
49
|
+
args.map((item) => resolveGraphQLVariables(item, graphqlVariables, info))
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
if (typeof args === "object" && args !== null) {
|
|
53
|
+
const resolved = {};
|
|
54
|
+
for (const [key, value] of Object.entries(args)) {
|
|
55
|
+
if (Array.isArray(value) && value.length === 1 && value[0] === "") {
|
|
56
|
+
let foundUpdatedVariable = false;
|
|
57
|
+
for (const [varName, varValue] of Object.entries(graphqlVariables)) {
|
|
58
|
+
if (Array.isArray(varValue) && varValue.length > 0 && varValue[0] !== "") {
|
|
59
|
+
console.log(`\u{1F50D} Found updated variable ${varName}:`, varValue);
|
|
60
|
+
resolved[key] = varValue;
|
|
61
|
+
foundUpdatedVariable = true;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (!foundUpdatedVariable && info.parentType && (info.parentType.name === "Query" || info.parentType.name === "Mutation")) {
|
|
66
|
+
const context = info.context || {};
|
|
67
|
+
if (context.exportStore) {
|
|
68
|
+
console.log(
|
|
69
|
+
`\u{1F50D} No updated variables yet, checking for pending exports...`
|
|
70
|
+
);
|
|
71
|
+
const potentialExports = Object.keys(graphqlVariables).map(
|
|
72
|
+
(varName) => varName.startsWith("_") ? `$${varName}` : `$_${varName}`
|
|
73
|
+
);
|
|
74
|
+
console.log(
|
|
75
|
+
`\u{1F50D} Potential export names to wait for:`,
|
|
76
|
+
potentialExports
|
|
77
|
+
);
|
|
78
|
+
for (const exportName of potentialExports) {
|
|
79
|
+
try {
|
|
80
|
+
const exportedValue = await context.exportStore.waitFor(
|
|
81
|
+
exportName,
|
|
82
|
+
2e3,
|
|
83
|
+
false
|
|
84
|
+
);
|
|
85
|
+
if (exportedValue && Array.isArray(exportedValue) && exportedValue.length > 0) {
|
|
86
|
+
console.log(
|
|
87
|
+
`\u2705 Found exported value for ${exportName}:`,
|
|
88
|
+
exportedValue
|
|
89
|
+
);
|
|
90
|
+
resolved[key] = exportedValue;
|
|
91
|
+
foundUpdatedVariable = true;
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
} catch (error) {
|
|
95
|
+
console.log(
|
|
96
|
+
`\u26A0\uFE0F Export ${exportName} not available yet:`,
|
|
97
|
+
error.message
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
console.log(
|
|
103
|
+
`\u{1F6A8} No export store available in context to wait for exports`
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
}
|
|
108
|
+
if (!(key in resolved)) {
|
|
109
|
+
resolved[key] = value;
|
|
110
|
+
}
|
|
111
|
+
} else if (typeof value === "object" && value !== null) {
|
|
112
|
+
resolved[key] = await resolveGraphQLVariables(
|
|
113
|
+
value,
|
|
114
|
+
graphqlVariables,
|
|
115
|
+
info
|
|
116
|
+
);
|
|
117
|
+
} else {
|
|
118
|
+
resolved[key] = value;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return resolved;
|
|
122
|
+
}
|
|
123
|
+
return args;
|
|
124
|
+
}
|
|
44
125
|
function isExportVariable(value) {
|
|
45
|
-
|
|
126
|
+
if (typeof value !== "string") {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
return value.startsWith("$_") && value.length > 2 || value.startsWith("EXPORT_VAR:") && value.length > 11;
|
|
46
130
|
}
|
|
47
131
|
function getVariableName(value) {
|
|
48
132
|
if (!isExportVariable(value)) {
|
|
49
133
|
return null;
|
|
50
134
|
}
|
|
51
|
-
|
|
135
|
+
if (value.startsWith("$_")) {
|
|
136
|
+
return value.slice(2);
|
|
137
|
+
} else if (value.startsWith("EXPORT_VAR:")) {
|
|
138
|
+
return value.slice(11);
|
|
139
|
+
}
|
|
140
|
+
return null;
|
|
52
141
|
}
|
|
53
142
|
async function resolveExportVariables(args, exportStore, timeout = 5e3) {
|
|
54
143
|
if (isExportVariable(args)) {
|
|
@@ -61,14 +150,19 @@ async function resolveExportVariables(args, exportStore, timeout = 5e3) {
|
|
|
61
150
|
args.map(async (item) => {
|
|
62
151
|
if (isExportVariable(item)) {
|
|
63
152
|
const varName = getVariableName(item);
|
|
64
|
-
|
|
153
|
+
const resolvedValue = await exportStore.waitFor(
|
|
154
|
+
varName,
|
|
155
|
+
timeout,
|
|
156
|
+
false
|
|
157
|
+
);
|
|
158
|
+
return Array.isArray(resolvedValue) ? resolvedValue : [resolvedValue];
|
|
65
159
|
} else if (typeof item === "object" && item !== null) {
|
|
66
160
|
return await resolveExportVariables(item, exportStore, timeout);
|
|
67
161
|
}
|
|
68
162
|
return item;
|
|
69
163
|
})
|
|
70
164
|
);
|
|
71
|
-
return resolved;
|
|
165
|
+
return resolved.flat();
|
|
72
166
|
}
|
|
73
167
|
if (typeof args === "object" && args !== null) {
|
|
74
168
|
const resolved = {};
|
|
@@ -151,39 +245,140 @@ function hasExportVariables(args) {
|
|
|
151
245
|
}
|
|
152
246
|
return false;
|
|
153
247
|
}
|
|
154
|
-
function
|
|
248
|
+
async function processExportsSync(result, fieldNode, exportStore, context) {
|
|
249
|
+
if (!result || !fieldNode)
|
|
250
|
+
return;
|
|
251
|
+
const selfExportName = getExportDirective(fieldNode);
|
|
252
|
+
if (selfExportName && result !== void 0 && result !== null) {
|
|
253
|
+
if (!fieldNode.selectionSet) {
|
|
254
|
+
exportStore.set(selfExportName, result);
|
|
255
|
+
} else {
|
|
256
|
+
}
|
|
257
|
+
} else {
|
|
258
|
+
}
|
|
259
|
+
if (fieldNode.selectionSet && result !== void 0 && result !== null) {
|
|
260
|
+
if (Array.isArray(result)) {
|
|
261
|
+
result.forEach((item, index) => {
|
|
262
|
+
if (item && typeof item === "object") {
|
|
263
|
+
processExports(
|
|
264
|
+
item,
|
|
265
|
+
fieldNode.selectionSet,
|
|
266
|
+
exportStore,
|
|
267
|
+
true,
|
|
268
|
+
context
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
} else if (typeof result === "object") {
|
|
273
|
+
processExports(
|
|
274
|
+
result,
|
|
275
|
+
fieldNode.selectionSet,
|
|
276
|
+
exportStore,
|
|
277
|
+
false,
|
|
278
|
+
context
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
} else {
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
function processExports(result, selectionSet, exportStore, isArrayItem = false, context) {
|
|
155
285
|
if (!result || !selectionSet)
|
|
156
286
|
return;
|
|
157
287
|
for (const selection of selectionSet.selections) {
|
|
158
288
|
if (selection.kind !== "Field")
|
|
159
289
|
continue;
|
|
160
290
|
const resultKey = selection.alias?.value ?? selection.name.value;
|
|
161
|
-
if (!(resultKey in result))
|
|
291
|
+
if (!(resultKey in result)) {
|
|
162
292
|
continue;
|
|
293
|
+
}
|
|
163
294
|
const value = result[resultKey];
|
|
295
|
+
console.log(
|
|
296
|
+
"\u{1F527} Field value:",
|
|
297
|
+
typeof value,
|
|
298
|
+
Array.isArray(value) ? `array[${value.length}]` : "single"
|
|
299
|
+
);
|
|
164
300
|
const exportName = getExportDirective(selection);
|
|
165
301
|
if (exportName) {
|
|
166
|
-
if (
|
|
167
|
-
|
|
302
|
+
if (exportName.startsWith("$_")) {
|
|
303
|
+
const varName = exportName.slice(2);
|
|
304
|
+
const fullVarName = `_${varName}`;
|
|
305
|
+
console.log(
|
|
306
|
+
`\u{1F527} Updating GraphQL variable '${fullVarName}' with value:`,
|
|
307
|
+
value
|
|
308
|
+
);
|
|
309
|
+
if (context && context._graphqlVariables) {
|
|
310
|
+
const variableValues = context._graphqlVariables;
|
|
311
|
+
console.log(`\u{1F50D} Current variables before update:`, variableValues);
|
|
312
|
+
if (Array.isArray(variableValues[fullVarName]) && variableValues[fullVarName].length === 1 && variableValues[fullVarName][0] === "") {
|
|
313
|
+
variableValues[fullVarName] = [];
|
|
314
|
+
}
|
|
315
|
+
if (isArrayItem) {
|
|
316
|
+
if (Array.isArray(variableValues[fullVarName])) {
|
|
317
|
+
variableValues[fullVarName] = [
|
|
318
|
+
...variableValues[fullVarName],
|
|
319
|
+
value
|
|
320
|
+
];
|
|
321
|
+
} else {
|
|
322
|
+
variableValues[fullVarName] = [value];
|
|
323
|
+
}
|
|
324
|
+
} else {
|
|
325
|
+
if (Array.isArray(value)) {
|
|
326
|
+
variableValues[fullVarName] = value;
|
|
327
|
+
} else {
|
|
328
|
+
variableValues[fullVarName] = [value];
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
console.log(
|
|
332
|
+
`\u2705 Updated GraphQL variable '${fullVarName}' to:`,
|
|
333
|
+
variableValues[fullVarName]
|
|
334
|
+
);
|
|
335
|
+
} else {
|
|
336
|
+
console.log(
|
|
337
|
+
`\u26A0\uFE0F Could not access GraphQL variables to update '${fullVarName}'`
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
if (isArrayItem) {
|
|
341
|
+
exportStore.accumulate(exportName, value);
|
|
342
|
+
} else {
|
|
343
|
+
exportStore.set(exportName, value);
|
|
344
|
+
}
|
|
168
345
|
} else {
|
|
169
|
-
|
|
346
|
+
if (isArrayItem) {
|
|
347
|
+
exportStore.accumulate(exportName, value);
|
|
348
|
+
} else {
|
|
349
|
+
console.log(`\u{1F527} Setting ${exportName} with value:`, value);
|
|
350
|
+
exportStore.set(exportName, value);
|
|
351
|
+
}
|
|
170
352
|
}
|
|
353
|
+
} else {
|
|
171
354
|
}
|
|
172
355
|
if (selection.selectionSet && value !== null && value !== void 0) {
|
|
173
356
|
if (Array.isArray(value)) {
|
|
174
357
|
value.forEach((item) => {
|
|
175
358
|
if (item && typeof item === "object") {
|
|
176
|
-
processExports(
|
|
359
|
+
processExports(
|
|
360
|
+
item,
|
|
361
|
+
selection.selectionSet,
|
|
362
|
+
exportStore,
|
|
363
|
+
true,
|
|
364
|
+
context
|
|
365
|
+
);
|
|
177
366
|
}
|
|
178
367
|
});
|
|
179
368
|
} else if (typeof value === "object") {
|
|
180
|
-
processExports(
|
|
369
|
+
processExports(
|
|
370
|
+
value,
|
|
371
|
+
selection.selectionSet,
|
|
372
|
+
exportStore,
|
|
373
|
+
isArrayItem,
|
|
374
|
+
context
|
|
375
|
+
);
|
|
181
376
|
}
|
|
182
377
|
}
|
|
183
378
|
}
|
|
184
379
|
}
|
|
185
380
|
var init_utils = __esm({
|
|
186
|
-
"src/export-directive/utils.ts"() {
|
|
381
|
+
"src/export-directive[DEPRECATED]/utils.ts"() {
|
|
187
382
|
"use strict";
|
|
188
383
|
}
|
|
189
384
|
});
|
|
@@ -192,14 +387,9 @@ var init_utils = __esm({
|
|
|
192
387
|
var src_exports = {};
|
|
193
388
|
__export(src_exports, {
|
|
194
389
|
ExportStore: () => ExportStore,
|
|
195
|
-
SerialExecutor: () => SerialExecutor,
|
|
196
390
|
buildSchemaSDLWithDataLoader: () => buildSchemaSDL,
|
|
197
391
|
cleanupDataLoaderContext: () => cleanupDataLoaderContext,
|
|
198
392
|
createDataLoaderContext: () => createDataLoaderContext,
|
|
199
|
-
createExportMiddleware: () => createExportMiddleware,
|
|
200
|
-
createExportResolverMap: () => createExportResolverMap,
|
|
201
|
-
createSerialMiddleware: () => createSerialMiddleware,
|
|
202
|
-
createSerialResolverMap: () => createSerialResolverMap,
|
|
203
393
|
exportDirectiveTypeDefs: () => exportDirectiveTypeDefs,
|
|
204
394
|
makeScalarAcceptExports: () => makeScalarAcceptExports,
|
|
205
395
|
serialDirectiveTypeDefs: () => serialDirectiveTypeDefs,
|
|
@@ -207,7 +397,9 @@ __export(src_exports, {
|
|
|
207
397
|
setCustomGraphQLTypes: () => setCustomGraphQLTypes,
|
|
208
398
|
useDataLoaderCleanup: () => useDataLoaderCleanup,
|
|
209
399
|
useDataLoaderCleanupOnly: () => useDataLoaderCleanupOnly,
|
|
210
|
-
useDataLoaderContext: () => useDataLoaderContext
|
|
400
|
+
useDataLoaderContext: () => useDataLoaderContext,
|
|
401
|
+
useExportDirective: () => useExportDirective,
|
|
402
|
+
useSerialDirective: () => useSerialDirective
|
|
211
403
|
});
|
|
212
404
|
module.exports = __toCommonJS(src_exports);
|
|
213
405
|
|
|
@@ -911,8 +1103,8 @@ var RelationDataLoader = class {
|
|
|
911
1103
|
const uniqueParentIds = Array.from(new Set(allParentIds));
|
|
912
1104
|
let resolvedWhere = firstKey.where;
|
|
913
1105
|
if (resolvedWhere && this.context?.exportStore) {
|
|
914
|
-
const { hasExportVariables:
|
|
915
|
-
if (
|
|
1106
|
+
const { hasExportVariables: hasExportVariables3, resolveExportVariables: resolveExportVariables3 } = await Promise.resolve().then(() => (init_utils(), utils_exports));
|
|
1107
|
+
if (hasExportVariables3(resolvedWhere)) {
|
|
916
1108
|
try {
|
|
917
1109
|
if (this.debugConfig?.exportVariables) {
|
|
918
1110
|
console.log(
|
|
@@ -920,7 +1112,7 @@ var RelationDataLoader = class {
|
|
|
920
1112
|
resolvedWhere
|
|
921
1113
|
);
|
|
922
1114
|
}
|
|
923
|
-
resolvedWhere = await
|
|
1115
|
+
resolvedWhere = await resolveExportVariables3(
|
|
924
1116
|
resolvedWhere,
|
|
925
1117
|
this.context.exportStore
|
|
926
1118
|
);
|
|
@@ -1553,12 +1745,6 @@ var generateMutations = (db, tables, relations, debugConfig) => {
|
|
|
1553
1745
|
return { mutations, deleteResultResolvers };
|
|
1554
1746
|
};
|
|
1555
1747
|
|
|
1556
|
-
// src/export-directive/directive-definitions.ts
|
|
1557
|
-
var exportDirectiveTypeDefs = `directive @export(as: String!) on FIELD`;
|
|
1558
|
-
|
|
1559
|
-
// src/serial-directive/directive-definitions.ts
|
|
1560
|
-
var serialDirectiveTypeDefs = `directive @serial on QUERY | MUTATION | SUBSCRIPTION`;
|
|
1561
|
-
|
|
1562
1748
|
// src/build-schema-sdl-with-dl/index.ts
|
|
1563
1749
|
var import_schema2 = require("@graphql-tools/schema");
|
|
1564
1750
|
var buildSchemaSDL = (db, config) => {
|
|
@@ -1650,185 +1836,160 @@ var useDataLoaderCleanupOnly = () => ({
|
|
|
1650
1836
|
})
|
|
1651
1837
|
});
|
|
1652
1838
|
|
|
1653
|
-
// src/serial-directive/
|
|
1654
|
-
var
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
* Disable serial execution for the current operation
|
|
1665
|
-
*/
|
|
1666
|
-
disable() {
|
|
1667
|
-
this.isEnabled = false;
|
|
1668
|
-
this.executionQueue.clear();
|
|
1669
|
-
}
|
|
1670
|
-
/**
|
|
1671
|
-
* Check if serial execution is enabled
|
|
1672
|
-
*/
|
|
1673
|
-
isSerialEnabled() {
|
|
1674
|
-
return this.isEnabled;
|
|
1675
|
-
}
|
|
1676
|
-
/**
|
|
1677
|
-
* Add a resolver promise to the execution queue
|
|
1678
|
-
* @param parentPath - The path of the parent field
|
|
1679
|
-
* @param resolverPromise - The resolver promise to queue
|
|
1680
|
-
*/
|
|
1681
|
-
queueResolver(parentPath, resolverPromise) {
|
|
1682
|
-
if (!this.isEnabled) {
|
|
1683
|
-
return resolverPromise();
|
|
1684
|
-
}
|
|
1685
|
-
const queue = this.executionQueue.get(parentPath) || [];
|
|
1686
|
-
const lastPromise = queue.length > 0 ? queue[queue.length - 1] : null;
|
|
1687
|
-
const serialPromise = lastPromise ? lastPromise.then(() => resolverPromise()) : resolverPromise();
|
|
1688
|
-
queue.push(serialPromise);
|
|
1689
|
-
this.executionQueue.set(parentPath, queue);
|
|
1690
|
-
return serialPromise;
|
|
1691
|
-
}
|
|
1692
|
-
/**
|
|
1693
|
-
* Wait for all queued resolvers in a specific path to complete
|
|
1694
|
-
* @param parentPath - The path to wait for
|
|
1695
|
-
*/
|
|
1696
|
-
async waitForPath(parentPath) {
|
|
1697
|
-
const queue = this.executionQueue.get(parentPath);
|
|
1698
|
-
if (queue && queue.length > 0) {
|
|
1699
|
-
await Promise.all(queue);
|
|
1700
|
-
}
|
|
1701
|
-
}
|
|
1702
|
-
/**
|
|
1703
|
-
* Wait for all queued resolvers to complete
|
|
1704
|
-
*/
|
|
1705
|
-
async waitForAll() {
|
|
1706
|
-
const allQueues = Array.from(this.executionQueue.values());
|
|
1707
|
-
const allPromises = allQueues.flat();
|
|
1708
|
-
if (allPromises.length > 0) {
|
|
1709
|
-
await Promise.all(allPromises);
|
|
1839
|
+
// src/serial-directive-envelop-hooks/plugin.ts
|
|
1840
|
+
var import_graphql5 = require("graphql");
|
|
1841
|
+
|
|
1842
|
+
// src/serial-directive-envelop-hooks/utils.ts
|
|
1843
|
+
function hasSerialDirective(document, operationName) {
|
|
1844
|
+
const operation = document.definitions.find((def) => {
|
|
1845
|
+
if (def.kind !== "OperationDefinition")
|
|
1846
|
+
return false;
|
|
1847
|
+
const opDef = def;
|
|
1848
|
+
if (operationName) {
|
|
1849
|
+
return opDef.name?.value === operationName;
|
|
1710
1850
|
}
|
|
1711
|
-
|
|
1851
|
+
return true;
|
|
1852
|
+
});
|
|
1853
|
+
if (!operation)
|
|
1854
|
+
return false;
|
|
1855
|
+
return operation.directives?.some(
|
|
1856
|
+
(directive) => directive.name.value === "serial"
|
|
1857
|
+
) || false;
|
|
1858
|
+
}
|
|
1859
|
+
var SerialExecutor = class {
|
|
1860
|
+
queue = Promise.resolve();
|
|
1712
1861
|
/**
|
|
1713
|
-
*
|
|
1714
|
-
* @param
|
|
1862
|
+
* Add a task to the execution queue
|
|
1863
|
+
* @param task - Function that returns a promise
|
|
1864
|
+
* @returns Promise that resolves when the task completes
|
|
1715
1865
|
*/
|
|
1716
|
-
|
|
1717
|
-
this.
|
|
1866
|
+
enqueue(task) {
|
|
1867
|
+
const promise = this.queue.then(task, task);
|
|
1868
|
+
this.queue = promise.then(
|
|
1869
|
+
() => {
|
|
1870
|
+
},
|
|
1871
|
+
() => {
|
|
1872
|
+
}
|
|
1873
|
+
);
|
|
1874
|
+
return promise;
|
|
1718
1875
|
}
|
|
1719
1876
|
/**
|
|
1720
|
-
*
|
|
1877
|
+
* Reset the queue
|
|
1721
1878
|
*/
|
|
1722
|
-
|
|
1723
|
-
this.
|
|
1879
|
+
reset() {
|
|
1880
|
+
this.queue = Promise.resolve();
|
|
1724
1881
|
}
|
|
1725
1882
|
};
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
function hasSerialDirective(info) {
|
|
1729
|
-
const operation = info.operation;
|
|
1730
|
-
return operation.directives?.some(
|
|
1731
|
-
(directive) => directive.name.value === "serial"
|
|
1732
|
-
) || false;
|
|
1733
|
-
}
|
|
1734
|
-
function getFieldPath(info) {
|
|
1735
|
-
const path = [];
|
|
1736
|
-
let currentPath = info.path;
|
|
1737
|
-
while (currentPath) {
|
|
1738
|
-
if (typeof currentPath.key === "string") {
|
|
1739
|
-
path.unshift(currentPath.key);
|
|
1740
|
-
}
|
|
1741
|
-
currentPath = currentPath.prev;
|
|
1742
|
-
}
|
|
1743
|
-
return path.join(".");
|
|
1883
|
+
function createSerialExecutor() {
|
|
1884
|
+
return new SerialExecutor();
|
|
1744
1885
|
}
|
|
1745
|
-
function
|
|
1746
|
-
const path = [];
|
|
1747
|
-
let currentPath = info.path.prev;
|
|
1748
|
-
while (currentPath) {
|
|
1749
|
-
if (typeof currentPath.key === "string") {
|
|
1750
|
-
path.unshift(currentPath.key);
|
|
1751
|
-
}
|
|
1752
|
-
currentPath = currentPath.prev;
|
|
1753
|
-
}
|
|
1754
|
-
return path.join(".") || "root";
|
|
1755
|
-
}
|
|
1756
|
-
function isRootField(info) {
|
|
1757
|
-
return !info.path.prev || info.path.prev.key === void 0;
|
|
1758
|
-
}
|
|
1759
|
-
function logSerialExecution(message, info, data) {
|
|
1886
|
+
function logSerialExecution(message, data) {
|
|
1760
1887
|
if (process.env["DEBUG_SERIAL"]) {
|
|
1761
|
-
|
|
1762
|
-
const parentPath = getParentFieldPath(info);
|
|
1763
|
-
console.log(`[SERIAL] ${message}`, {
|
|
1764
|
-
field: `${info.parentType.name}.${info.fieldName}`,
|
|
1765
|
-
fieldPath,
|
|
1766
|
-
parentPath,
|
|
1767
|
-
operation: info.operation.operation,
|
|
1768
|
-
data
|
|
1769
|
-
});
|
|
1888
|
+
console.log(`[SERIAL-HOOK] ${message}`, data || "");
|
|
1770
1889
|
}
|
|
1771
1890
|
}
|
|
1772
1891
|
|
|
1773
|
-
// src/serial-directive/
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
if (shouldExecuteSerially
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
return next(source, args, context, info);
|
|
1788
|
-
}
|
|
1789
|
-
const parentPath = getParentFieldPath(info);
|
|
1790
|
-
const isRoot = isRootField(info);
|
|
1791
|
-
logSerialExecution("Queuing resolver execution", info, {
|
|
1792
|
-
parentPath,
|
|
1793
|
-
isRoot,
|
|
1794
|
-
fieldName: info.fieldName
|
|
1892
|
+
// src/serial-directive-envelop-hooks/plugin.ts
|
|
1893
|
+
var processedSchemas = /* @__PURE__ */ new WeakSet();
|
|
1894
|
+
var useSerialDirective = () => {
|
|
1895
|
+
return {
|
|
1896
|
+
onExecute({ args }) {
|
|
1897
|
+
const shouldExecuteSerially = hasSerialDirective(
|
|
1898
|
+
args.document,
|
|
1899
|
+
args.operationName || void 0
|
|
1900
|
+
);
|
|
1901
|
+
if (!shouldExecuteSerially) {
|
|
1902
|
+
return void 0;
|
|
1903
|
+
}
|
|
1904
|
+
logSerialExecution("Serial execution enabled for operation", {
|
|
1905
|
+
operationName: args.operationName
|
|
1795
1906
|
});
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
return Promise.resolve(next(source, args, context, info));
|
|
1799
|
-
};
|
|
1800
|
-
try {
|
|
1801
|
-
const result = await serialExecutor.queueResolver(
|
|
1802
|
-
parentPath,
|
|
1803
|
-
resolverPromise
|
|
1804
|
-
);
|
|
1805
|
-
logSerialExecution("Resolver execution completed", info);
|
|
1806
|
-
return result;
|
|
1807
|
-
} catch (error) {
|
|
1808
|
-
logSerialExecution("Resolver execution failed", info, { error });
|
|
1809
|
-
throw error;
|
|
1907
|
+
if (!args.contextValue) {
|
|
1908
|
+
args.contextValue = {};
|
|
1810
1909
|
}
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1910
|
+
const context = args.contextValue;
|
|
1911
|
+
if (!context.serialExecutor) {
|
|
1912
|
+
context.serialExecutor = createSerialExecutor();
|
|
1913
|
+
}
|
|
1914
|
+
const createWrappedResolver = (originalResolver) => {
|
|
1915
|
+
return (source, fieldArgs, fieldContext, info) => {
|
|
1916
|
+
const ctx = fieldContext;
|
|
1917
|
+
const serialExecutor = ctx.serialExecutor;
|
|
1918
|
+
const isRootField = !info.path.prev || info.path.prev.key === void 0;
|
|
1919
|
+
if (!isRootField || !serialExecutor) {
|
|
1920
|
+
if (originalResolver) {
|
|
1921
|
+
return originalResolver(source, fieldArgs, fieldContext, info);
|
|
1922
|
+
}
|
|
1923
|
+
const fieldName = info.fieldName;
|
|
1924
|
+
return source?.[fieldName];
|
|
1925
|
+
}
|
|
1926
|
+
logSerialExecution("Queuing root field for serial execution", {
|
|
1927
|
+
field: `${info.parentType.name}.${info.fieldName}`
|
|
1928
|
+
});
|
|
1929
|
+
return serialExecutor.enqueue(async () => {
|
|
1930
|
+
logSerialExecution("Executing root field", {
|
|
1931
|
+
field: `${info.parentType.name}.${info.fieldName}`
|
|
1932
|
+
});
|
|
1933
|
+
let result;
|
|
1934
|
+
if (originalResolver) {
|
|
1935
|
+
result = await originalResolver(source, fieldArgs, fieldContext, info);
|
|
1936
|
+
} else {
|
|
1937
|
+
const fieldName = info.fieldName;
|
|
1938
|
+
result = source?.[fieldName];
|
|
1939
|
+
}
|
|
1940
|
+
logSerialExecution("Root field execution completed", {
|
|
1941
|
+
field: `${info.parentType.name}.${info.fieldName}`
|
|
1942
|
+
});
|
|
1943
|
+
return result;
|
|
1944
|
+
});
|
|
1945
|
+
};
|
|
1946
|
+
};
|
|
1947
|
+
if (args.schema && !processedSchemas.has(args.schema)) {
|
|
1948
|
+
processedSchemas.add(args.schema);
|
|
1949
|
+
logSerialExecution("Wrapping schema resolvers for @serial support");
|
|
1950
|
+
const typeMap = args.schema.getTypeMap();
|
|
1951
|
+
for (const typeName in typeMap) {
|
|
1952
|
+
const type = typeMap[typeName];
|
|
1953
|
+
if (type instanceof import_graphql5.GraphQLObjectType && !typeName.startsWith("__")) {
|
|
1954
|
+
const fields = type.getFields();
|
|
1955
|
+
for (const fieldName in fields) {
|
|
1956
|
+
const field = fields[fieldName];
|
|
1957
|
+
if (!field) {
|
|
1958
|
+
continue;
|
|
1959
|
+
}
|
|
1960
|
+
if (field.resolve) {
|
|
1961
|
+
field.resolve = createWrappedResolver(field.resolve);
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1825
1966
|
}
|
|
1967
|
+
args.fieldResolver = createWrappedResolver(args.fieldResolver);
|
|
1968
|
+
return {
|
|
1969
|
+
onExecuteDone() {
|
|
1970
|
+
logSerialExecution("Serial execution completed", {
|
|
1971
|
+
operationName: args.operationName
|
|
1972
|
+
});
|
|
1973
|
+
}
|
|
1974
|
+
};
|
|
1826
1975
|
}
|
|
1827
|
-
}
|
|
1828
|
-
|
|
1829
|
-
|
|
1976
|
+
};
|
|
1977
|
+
};
|
|
1978
|
+
|
|
1979
|
+
// src/serial-directive-envelop-hooks/directive-definitions.ts
|
|
1980
|
+
var serialDirectiveTypeDefs = `
|
|
1981
|
+
"""
|
|
1982
|
+
Forces query fields to execute sequentially instead of in parallel.
|
|
1983
|
+
Root-level fields will execute one after another in the order they appear.
|
|
1984
|
+
Nested fields within each parent will also execute sequentially.
|
|
1985
|
+
"""
|
|
1986
|
+
directive @serial on QUERY
|
|
1987
|
+
`;
|
|
1830
1988
|
|
|
1831
|
-
// src/export-directive/
|
|
1989
|
+
// src/export-directive-envelop-hooks/plugin.ts
|
|
1990
|
+
var import_graphql7 = require("graphql");
|
|
1991
|
+
|
|
1992
|
+
// src/export-directive-envelop-hooks/ExportStore.ts
|
|
1832
1993
|
var ExportStore = class {
|
|
1833
1994
|
store = /* @__PURE__ */ new Map();
|
|
1834
1995
|
pending = /* @__PURE__ */ new Map();
|
|
@@ -1933,75 +2094,15 @@ var ExportStore = class {
|
|
|
1933
2094
|
}
|
|
1934
2095
|
};
|
|
1935
2096
|
|
|
1936
|
-
// src/export-directive/
|
|
1937
|
-
|
|
1938
|
-
function createExportMiddleware() {
|
|
1939
|
-
return (next) => {
|
|
1940
|
-
return async (source, args, context, info) => {
|
|
1941
|
-
if (!context.exportStore) {
|
|
1942
|
-
context.exportStore = new ExportStore();
|
|
1943
|
-
}
|
|
1944
|
-
const exportStore = context.exportStore;
|
|
1945
|
-
let resolvedArgs = args;
|
|
1946
|
-
if (args && typeof args === "object" && hasExportVariables(args)) {
|
|
1947
|
-
try {
|
|
1948
|
-
resolvedArgs = await resolveExportVariables(args, exportStore, 1e4);
|
|
1949
|
-
} catch (error) {
|
|
1950
|
-
throw new Error(
|
|
1951
|
-
`Export variable resolution failed in ${info.parentType.name}.${info.fieldName}: ${error instanceof Error ? error.message : String(error)}`
|
|
1952
|
-
);
|
|
1953
|
-
}
|
|
1954
|
-
}
|
|
1955
|
-
const result = await next(source, resolvedArgs, context, info);
|
|
1956
|
-
const fieldNode = info.fieldNodes[0];
|
|
1957
|
-
if (!fieldNode)
|
|
1958
|
-
return result;
|
|
1959
|
-
const selfExportName = getExportDirective(fieldNode);
|
|
1960
|
-
if (selfExportName && result !== void 0 && result !== null) {
|
|
1961
|
-
if (Array.isArray(result)) {
|
|
1962
|
-
result.forEach((value) => {
|
|
1963
|
-
if (value !== void 0 && value !== null) {
|
|
1964
|
-
exportStore.accumulate(selfExportName, value);
|
|
1965
|
-
}
|
|
1966
|
-
});
|
|
1967
|
-
} else {
|
|
1968
|
-
exportStore.set(selfExportName, result);
|
|
1969
|
-
}
|
|
1970
|
-
}
|
|
1971
|
-
if (fieldNode.selectionSet && result !== void 0 && result !== null) {
|
|
1972
|
-
if (Array.isArray(result)) {
|
|
1973
|
-
result.forEach((item) => {
|
|
1974
|
-
if (item && typeof item === "object") {
|
|
1975
|
-
processExports(item, fieldNode.selectionSet, exportStore, true);
|
|
1976
|
-
}
|
|
1977
|
-
});
|
|
1978
|
-
} else if (typeof result === "object") {
|
|
1979
|
-
processExports(result, fieldNode.selectionSet, exportStore, false);
|
|
1980
|
-
}
|
|
1981
|
-
}
|
|
1982
|
-
return result;
|
|
1983
|
-
};
|
|
1984
|
-
};
|
|
1985
|
-
}
|
|
1986
|
-
function createExportResolverMap() {
|
|
1987
|
-
return {
|
|
1988
|
-
// Apply to all resolvers (Query.*, Mutation.*, etc.)
|
|
1989
|
-
"*.*": [createExportMiddleware()]
|
|
1990
|
-
};
|
|
1991
|
-
}
|
|
1992
|
-
|
|
1993
|
-
// src/export-directive/index.ts
|
|
1994
|
-
init_utils();
|
|
1995
|
-
|
|
1996
|
-
// src/export-directive/makeScalarAcceptExports.ts
|
|
1997
|
-
var import_graphql5 = require("graphql");
|
|
2097
|
+
// src/export-directive-envelop-hooks/utils.ts
|
|
2098
|
+
var import_graphql6 = require("graphql");
|
|
1998
2099
|
function makeScalarAcceptExports(originalScalar) {
|
|
1999
2100
|
const config = originalScalar.toConfig();
|
|
2000
|
-
return new
|
|
2101
|
+
return new import_graphql6.GraphQLScalarType({
|
|
2001
2102
|
...config,
|
|
2002
2103
|
name: config.name,
|
|
2003
2104
|
// Keep original name to override it in schema
|
|
2004
|
-
description:
|
|
2105
|
+
description: config.description + " (Wrapped with makeScalarAcceptExports to accept $_ export variables)",
|
|
2005
2106
|
serialize: config.serialize,
|
|
2006
2107
|
parseValue(value) {
|
|
2007
2108
|
if (typeof value === "string" && (value.startsWith("$_") || value === "")) {
|
|
@@ -2013,18 +2114,527 @@ function makeScalarAcceptExports(originalScalar) {
|
|
|
2013
2114
|
return value;
|
|
2014
2115
|
},
|
|
2015
2116
|
parseLiteral(ast, variables) {
|
|
2016
|
-
if (ast.kind ===
|
|
2117
|
+
if (ast.kind === import_graphql6.Kind.STRING) {
|
|
2017
2118
|
if (ast.value.startsWith("$_") || ast.value === "") {
|
|
2018
2119
|
return ast.value;
|
|
2019
2120
|
}
|
|
2020
2121
|
}
|
|
2021
|
-
if (config.parseLiteral) {
|
|
2122
|
+
if (config.parseLiteral && ast) {
|
|
2022
2123
|
return config.parseLiteral(ast, variables);
|
|
2023
2124
|
}
|
|
2024
2125
|
return void 0;
|
|
2025
2126
|
}
|
|
2026
2127
|
});
|
|
2027
2128
|
}
|
|
2129
|
+
function isExportVariable2(value) {
|
|
2130
|
+
if (typeof value !== "string") {
|
|
2131
|
+
return false;
|
|
2132
|
+
}
|
|
2133
|
+
return value.startsWith("$_") && value.length > 2 || value.startsWith("EXPORT_VAR:") && value.length > 11;
|
|
2134
|
+
}
|
|
2135
|
+
function getVariableName2(value) {
|
|
2136
|
+
if (!isExportVariable2(value)) {
|
|
2137
|
+
return null;
|
|
2138
|
+
}
|
|
2139
|
+
if (value.startsWith("$_")) {
|
|
2140
|
+
return value.slice(2);
|
|
2141
|
+
} else if (value.startsWith("EXPORT_VAR:")) {
|
|
2142
|
+
return value.slice(11);
|
|
2143
|
+
}
|
|
2144
|
+
return null;
|
|
2145
|
+
}
|
|
2146
|
+
async function resolveExportVariables2(args, exportStore, timeout = 5e3) {
|
|
2147
|
+
if (isExportVariable2(args)) {
|
|
2148
|
+
const varName = getVariableName2(args);
|
|
2149
|
+
const resolvedValue = await exportStore.waitFor(varName, timeout, false);
|
|
2150
|
+
return resolvedValue;
|
|
2151
|
+
}
|
|
2152
|
+
if (Array.isArray(args)) {
|
|
2153
|
+
const resolved = await Promise.all(
|
|
2154
|
+
args.map(async (item) => {
|
|
2155
|
+
if (isExportVariable2(item)) {
|
|
2156
|
+
const varName = getVariableName2(item);
|
|
2157
|
+
const resolvedValue = await exportStore.waitFor(
|
|
2158
|
+
varName,
|
|
2159
|
+
timeout,
|
|
2160
|
+
false
|
|
2161
|
+
);
|
|
2162
|
+
return Array.isArray(resolvedValue) ? resolvedValue : [resolvedValue];
|
|
2163
|
+
} else if (typeof item === "object" && item !== null) {
|
|
2164
|
+
return await resolveExportVariables2(item, exportStore, timeout);
|
|
2165
|
+
}
|
|
2166
|
+
return item;
|
|
2167
|
+
})
|
|
2168
|
+
);
|
|
2169
|
+
return resolved.flat();
|
|
2170
|
+
}
|
|
2171
|
+
if (typeof args === "object" && args !== null) {
|
|
2172
|
+
const resolved = {};
|
|
2173
|
+
for (const [key, value] of Object.entries(args)) {
|
|
2174
|
+
if (isExportVariable2(value)) {
|
|
2175
|
+
const varName = getVariableName2(value);
|
|
2176
|
+
const resolvedValue = await exportStore.waitFor(
|
|
2177
|
+
varName,
|
|
2178
|
+
timeout,
|
|
2179
|
+
false
|
|
2180
|
+
);
|
|
2181
|
+
resolved[key] = resolvedValue;
|
|
2182
|
+
} else if (typeof value === "object" && value !== null) {
|
|
2183
|
+
resolved[key] = await resolveExportVariables2(
|
|
2184
|
+
value,
|
|
2185
|
+
exportStore,
|
|
2186
|
+
timeout
|
|
2187
|
+
);
|
|
2188
|
+
} else {
|
|
2189
|
+
resolved[key] = value;
|
|
2190
|
+
}
|
|
2191
|
+
}
|
|
2192
|
+
return resolved;
|
|
2193
|
+
}
|
|
2194
|
+
return args;
|
|
2195
|
+
}
|
|
2196
|
+
function getExportDirective2(fieldNode) {
|
|
2197
|
+
if (!fieldNode || !fieldNode.directives) {
|
|
2198
|
+
return null;
|
|
2199
|
+
}
|
|
2200
|
+
const exportDirective = fieldNode.directives.find(
|
|
2201
|
+
(directive) => directive.name.value === "export"
|
|
2202
|
+
);
|
|
2203
|
+
if (!exportDirective) {
|
|
2204
|
+
return null;
|
|
2205
|
+
}
|
|
2206
|
+
const asArg = exportDirective.arguments?.find(
|
|
2207
|
+
(arg) => arg.name.value === "as"
|
|
2208
|
+
);
|
|
2209
|
+
if (!asArg || asArg.value.kind !== "StringValue") {
|
|
2210
|
+
return null;
|
|
2211
|
+
}
|
|
2212
|
+
return asArg.value.value;
|
|
2213
|
+
}
|
|
2214
|
+
function hasExportVariables2(args) {
|
|
2215
|
+
if (isExportVariable2(args)) {
|
|
2216
|
+
return true;
|
|
2217
|
+
}
|
|
2218
|
+
if (Array.isArray(args)) {
|
|
2219
|
+
return args.some((item) => hasExportVariables2(item));
|
|
2220
|
+
}
|
|
2221
|
+
if (typeof args === "object" && args !== null) {
|
|
2222
|
+
for (const value of Object.values(args)) {
|
|
2223
|
+
if (hasExportVariables2(value)) {
|
|
2224
|
+
return true;
|
|
2225
|
+
}
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2228
|
+
return false;
|
|
2229
|
+
}
|
|
2230
|
+
function processExports2(result, selectionSet, exportStore, variables, isArrayItem = false) {
|
|
2231
|
+
if (!result || !selectionSet)
|
|
2232
|
+
return;
|
|
2233
|
+
for (const selection of selectionSet.selections) {
|
|
2234
|
+
if (selection.kind !== "Field")
|
|
2235
|
+
continue;
|
|
2236
|
+
const resultKey = selection.alias?.value ?? selection.name.value;
|
|
2237
|
+
if (!(resultKey in result)) {
|
|
2238
|
+
continue;
|
|
2239
|
+
}
|
|
2240
|
+
const value = result[resultKey];
|
|
2241
|
+
const exportName = getExportDirective2(selection);
|
|
2242
|
+
if (exportName) {
|
|
2243
|
+
logExportExecution("Found @export directive: " + exportName, {
|
|
2244
|
+
isArrayItem,
|
|
2245
|
+
value: typeof value
|
|
2246
|
+
});
|
|
2247
|
+
if (isArrayItem) {
|
|
2248
|
+
exportStore.accumulate(exportName, value);
|
|
2249
|
+
} else {
|
|
2250
|
+
exportStore.set(exportName, value);
|
|
2251
|
+
}
|
|
2252
|
+
if (variables && exportName.startsWith("$_")) {
|
|
2253
|
+
const varName = "_" + exportName.slice(2);
|
|
2254
|
+
if (isArrayItem) {
|
|
2255
|
+
if (!variables[varName]) {
|
|
2256
|
+
variables[varName] = [];
|
|
2257
|
+
}
|
|
2258
|
+
if (Array.isArray(variables[varName])) {
|
|
2259
|
+
if (!variables[varName].includes(value)) {
|
|
2260
|
+
variables[varName].push(value);
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
} else {
|
|
2264
|
+
variables[varName] = value;
|
|
2265
|
+
}
|
|
2266
|
+
logExportExecution(
|
|
2267
|
+
"Updated GraphQL variable: " + varName,
|
|
2268
|
+
variables[varName]
|
|
2269
|
+
);
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2272
|
+
if (selection.selectionSet && value !== null && value !== void 0) {
|
|
2273
|
+
if (Array.isArray(value)) {
|
|
2274
|
+
value.forEach((item) => {
|
|
2275
|
+
if (item && typeof item === "object") {
|
|
2276
|
+
processExports2(
|
|
2277
|
+
item,
|
|
2278
|
+
selection.selectionSet,
|
|
2279
|
+
exportStore,
|
|
2280
|
+
variables,
|
|
2281
|
+
true
|
|
2282
|
+
);
|
|
2283
|
+
}
|
|
2284
|
+
});
|
|
2285
|
+
} else if (typeof value === "object") {
|
|
2286
|
+
processExports2(
|
|
2287
|
+
value,
|
|
2288
|
+
selection.selectionSet,
|
|
2289
|
+
exportStore,
|
|
2290
|
+
variables,
|
|
2291
|
+
isArrayItem
|
|
2292
|
+
);
|
|
2293
|
+
}
|
|
2294
|
+
}
|
|
2295
|
+
}
|
|
2296
|
+
}
|
|
2297
|
+
async function resolveGraphQLVariables2(args, fieldNode, exportStore, timeout = 5e3) {
|
|
2298
|
+
if (!fieldNode.arguments || !args)
|
|
2299
|
+
return;
|
|
2300
|
+
logExportExecution("resolveGraphQLVariables starting", {
|
|
2301
|
+
argsKeys: Object.keys(args)
|
|
2302
|
+
});
|
|
2303
|
+
for (const arg of fieldNode.arguments) {
|
|
2304
|
+
const argName = arg.name.value;
|
|
2305
|
+
if (argName in args) {
|
|
2306
|
+
await traverseASTAndResolve(
|
|
2307
|
+
arg.value,
|
|
2308
|
+
args,
|
|
2309
|
+
argName,
|
|
2310
|
+
exportStore,
|
|
2311
|
+
timeout
|
|
2312
|
+
);
|
|
2313
|
+
} else {
|
|
2314
|
+
logExportExecution("argName not in args", argName);
|
|
2315
|
+
}
|
|
2316
|
+
}
|
|
2317
|
+
}
|
|
2318
|
+
function normalizeFilterOperators(obj) {
|
|
2319
|
+
if (!obj || typeof obj !== "object")
|
|
2320
|
+
return;
|
|
2321
|
+
if (Array.isArray(obj)) {
|
|
2322
|
+
obj.forEach((item) => normalizeFilterOperators(item));
|
|
2323
|
+
return;
|
|
2324
|
+
}
|
|
2325
|
+
for (const key of Object.keys(obj)) {
|
|
2326
|
+
const value = obj[key];
|
|
2327
|
+
if (key === "in" && value !== void 0 && !("inArray" in obj)) {
|
|
2328
|
+
obj.inArray = value;
|
|
2329
|
+
delete obj.in;
|
|
2330
|
+
} else if (value && typeof value === "object") {
|
|
2331
|
+
normalizeFilterOperators(value);
|
|
2332
|
+
}
|
|
2333
|
+
}
|
|
2334
|
+
}
|
|
2335
|
+
async function traverseASTAndResolve(node, parentObj, key, exportStore, timeout) {
|
|
2336
|
+
logExportExecution("traverseASTAndResolve", { kind: node.kind, key });
|
|
2337
|
+
if (node.kind === import_graphql6.Kind.VARIABLE) {
|
|
2338
|
+
const varName = node.name.value;
|
|
2339
|
+
const candidateNames = ["$" + varName, varName];
|
|
2340
|
+
if (varName.startsWith("_")) {
|
|
2341
|
+
candidateNames.push("$" + varName);
|
|
2342
|
+
} else {
|
|
2343
|
+
candidateNames.push("$_" + varName);
|
|
2344
|
+
}
|
|
2345
|
+
const currentValue = parentObj[key];
|
|
2346
|
+
const isDefault = currentValue === void 0 || currentValue === "" || Array.isArray(currentValue) && (currentValue.length === 0 || currentValue.length === 1 && currentValue[0] === "");
|
|
2347
|
+
logExportExecution("Checking variable", {
|
|
2348
|
+
varName,
|
|
2349
|
+
currentValue,
|
|
2350
|
+
isDefault
|
|
2351
|
+
});
|
|
2352
|
+
if (isDefault) {
|
|
2353
|
+
const exportName = "$" + varName;
|
|
2354
|
+
logExportExecution("Waiting for export variable mapping", {
|
|
2355
|
+
varName,
|
|
2356
|
+
exportName
|
|
2357
|
+
});
|
|
2358
|
+
try {
|
|
2359
|
+
const val = await exportStore.waitFor(exportName, timeout, true);
|
|
2360
|
+
if (val !== void 0) {
|
|
2361
|
+
parentObj[key] = val;
|
|
2362
|
+
logExportExecution(
|
|
2363
|
+
"Resolved variable " + varName + " to export " + exportName,
|
|
2364
|
+
val
|
|
2365
|
+
);
|
|
2366
|
+
} else {
|
|
2367
|
+
logExportExecution(
|
|
2368
|
+
"Export variable resolved to undefined (allowed)",
|
|
2369
|
+
exportName
|
|
2370
|
+
);
|
|
2371
|
+
}
|
|
2372
|
+
} catch (e) {
|
|
2373
|
+
logExportExecution(
|
|
2374
|
+
"Timeout waiting for variable " + varName + " as export " + exportName
|
|
2375
|
+
);
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
2378
|
+
} else if (node.kind === import_graphql6.Kind.OBJECT) {
|
|
2379
|
+
let obj = parentObj[key];
|
|
2380
|
+
if (!obj || typeof obj !== "object") {
|
|
2381
|
+
obj = {};
|
|
2382
|
+
parentObj[key] = obj;
|
|
2383
|
+
}
|
|
2384
|
+
for (const field of node.fields) {
|
|
2385
|
+
const fieldName = field.name.value;
|
|
2386
|
+
await traverseASTAndResolve(
|
|
2387
|
+
field.value,
|
|
2388
|
+
obj,
|
|
2389
|
+
fieldName,
|
|
2390
|
+
exportStore,
|
|
2391
|
+
timeout
|
|
2392
|
+
);
|
|
2393
|
+
}
|
|
2394
|
+
} else if (node.kind === import_graphql6.Kind.LIST) {
|
|
2395
|
+
let list = parentObj[key];
|
|
2396
|
+
if (!Array.isArray(list)) {
|
|
2397
|
+
list = new Array(node.values.length).fill(void 0);
|
|
2398
|
+
parentObj[key] = list;
|
|
2399
|
+
}
|
|
2400
|
+
const len = Math.min(list.length, node.values.length);
|
|
2401
|
+
for (let i = 0; i < len; i++) {
|
|
2402
|
+
await traverseASTAndResolve(
|
|
2403
|
+
node.values[i],
|
|
2404
|
+
list,
|
|
2405
|
+
i,
|
|
2406
|
+
exportStore,
|
|
2407
|
+
timeout
|
|
2408
|
+
);
|
|
2409
|
+
}
|
|
2410
|
+
}
|
|
2411
|
+
}
|
|
2412
|
+
function logExportExecution(message, data) {
|
|
2413
|
+
if (process.env["DEBUG_EXPORT"]) {
|
|
2414
|
+
console.log("[EXPORT-HOOK] " + message, data || "");
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
|
|
2418
|
+
// src/export-directive-envelop-hooks/plugin.ts
|
|
2419
|
+
var processedSchemas2 = /* @__PURE__ */ new WeakSet();
|
|
2420
|
+
var useExportDirective = () => {
|
|
2421
|
+
return {
|
|
2422
|
+
onExecute({ args, setExecuteFn }) {
|
|
2423
|
+
if (!args.contextValue) {
|
|
2424
|
+
args.contextValue = {};
|
|
2425
|
+
}
|
|
2426
|
+
const context = args.contextValue;
|
|
2427
|
+
if (!context.exportStore) {
|
|
2428
|
+
context.exportStore = new ExportStore();
|
|
2429
|
+
logExportExecution("Created new ExportStore in context");
|
|
2430
|
+
}
|
|
2431
|
+
const exportStore = context.exportStore;
|
|
2432
|
+
const initialVariables = args.variableValues || {};
|
|
2433
|
+
if (!context._graphqlVariables) {
|
|
2434
|
+
context._graphqlVariables = { ...initialVariables };
|
|
2435
|
+
logExportExecution(
|
|
2436
|
+
"Stored GraphQL variables reference",
|
|
2437
|
+
Object.keys(initialVariables)
|
|
2438
|
+
);
|
|
2439
|
+
}
|
|
2440
|
+
const createWrappedResolver = (originalResolver) => {
|
|
2441
|
+
return async (source, fieldArgs, fieldContext, info) => {
|
|
2442
|
+
const ctx = fieldContext;
|
|
2443
|
+
const store = ctx.exportStore;
|
|
2444
|
+
const isComments = info.fieldName === "comments" || info.fieldName === "commentFindMany";
|
|
2445
|
+
if (isComments) {
|
|
2446
|
+
logExportExecution("DEBUG Resolver Called", {
|
|
2447
|
+
fieldName: info.fieldName,
|
|
2448
|
+
args: JSON.stringify(fieldArgs),
|
|
2449
|
+
variables: JSON.stringify(ctx._graphqlVariables)
|
|
2450
|
+
});
|
|
2451
|
+
}
|
|
2452
|
+
let currentArgs = fieldArgs;
|
|
2453
|
+
if (ctx._graphqlVariables && info.parentType instanceof import_graphql7.GraphQLObjectType) {
|
|
2454
|
+
const fieldNode2 = info.fieldNodes[0];
|
|
2455
|
+
if (!fieldNode2) {
|
|
2456
|
+
if (isComments) {
|
|
2457
|
+
logExportExecution("DEBUG fieldNode NOT FOUND");
|
|
2458
|
+
}
|
|
2459
|
+
} else {
|
|
2460
|
+
const fieldName = fieldNode2.name.value;
|
|
2461
|
+
const fieldDef = info.parentType.getFields()[fieldName];
|
|
2462
|
+
if (isComments && !fieldDef) {
|
|
2463
|
+
logExportExecution("DEBUG fieldDef NOT FOUND");
|
|
2464
|
+
}
|
|
2465
|
+
if (fieldDef) {
|
|
2466
|
+
try {
|
|
2467
|
+
if (isComments) {
|
|
2468
|
+
logExportExecution("DEBUG calling getArgumentValues", {
|
|
2469
|
+
fieldNodeName: fieldNode2.name.value,
|
|
2470
|
+
fieldDefName: fieldDef.name,
|
|
2471
|
+
variablesKeys: Object.keys(
|
|
2472
|
+
ctx._graphqlVariables || {}
|
|
2473
|
+
)
|
|
2474
|
+
});
|
|
2475
|
+
}
|
|
2476
|
+
const freshArgs = (0, import_graphql7.getArgumentValues)(
|
|
2477
|
+
fieldDef,
|
|
2478
|
+
fieldNode2,
|
|
2479
|
+
ctx._graphqlVariables
|
|
2480
|
+
);
|
|
2481
|
+
if (isComments) {
|
|
2482
|
+
logExportExecution("DEBUG getArgumentValues result", {
|
|
2483
|
+
freshArgsKeys: Object.keys(freshArgs || {}),
|
|
2484
|
+
freshArgs: JSON.stringify(freshArgs)
|
|
2485
|
+
});
|
|
2486
|
+
}
|
|
2487
|
+
if (freshArgs) {
|
|
2488
|
+
currentArgs = freshArgs;
|
|
2489
|
+
}
|
|
2490
|
+
} catch (e) {
|
|
2491
|
+
logExportExecution(
|
|
2492
|
+
"Failed to re-resolve args for " + info.fieldName,
|
|
2493
|
+
e
|
|
2494
|
+
);
|
|
2495
|
+
}
|
|
2496
|
+
}
|
|
2497
|
+
}
|
|
2498
|
+
}
|
|
2499
|
+
let resolvedArgs = currentArgs;
|
|
2500
|
+
const fieldNode = info.fieldNodes[0];
|
|
2501
|
+
if (currentArgs && typeof currentArgs === "object") {
|
|
2502
|
+
if (fieldNode) {
|
|
2503
|
+
try {
|
|
2504
|
+
await resolveGraphQLVariables2(
|
|
2505
|
+
currentArgs,
|
|
2506
|
+
fieldNode,
|
|
2507
|
+
store,
|
|
2508
|
+
1e4
|
|
2509
|
+
);
|
|
2510
|
+
} catch (error) {
|
|
2511
|
+
logExportExecution("GraphQL variable resolution failed", error);
|
|
2512
|
+
}
|
|
2513
|
+
}
|
|
2514
|
+
normalizeFilterOperators(currentArgs);
|
|
2515
|
+
if (hasExportVariables2(currentArgs)) {
|
|
2516
|
+
try {
|
|
2517
|
+
resolvedArgs = await resolveExportVariables2(
|
|
2518
|
+
currentArgs,
|
|
2519
|
+
store,
|
|
2520
|
+
1e4
|
|
2521
|
+
);
|
|
2522
|
+
} catch (error) {
|
|
2523
|
+
throw new Error(
|
|
2524
|
+
"Export variable resolution failed in " + info.parentType.name + "." + info.fieldName + ": " + (error instanceof Error ? error.message : String(error))
|
|
2525
|
+
);
|
|
2526
|
+
}
|
|
2527
|
+
}
|
|
2528
|
+
}
|
|
2529
|
+
let result;
|
|
2530
|
+
if (originalResolver) {
|
|
2531
|
+
result = await originalResolver(
|
|
2532
|
+
source,
|
|
2533
|
+
resolvedArgs,
|
|
2534
|
+
fieldContext,
|
|
2535
|
+
info
|
|
2536
|
+
);
|
|
2537
|
+
} else {
|
|
2538
|
+
const fieldName = info.fieldName;
|
|
2539
|
+
result = source?.[fieldName];
|
|
2540
|
+
}
|
|
2541
|
+
if (fieldNode) {
|
|
2542
|
+
const selfExportName = getExportDirective2(fieldNode);
|
|
2543
|
+
if (selfExportName && result !== void 0 && result !== null) {
|
|
2544
|
+
if (!fieldNode.selectionSet) {
|
|
2545
|
+
logExportExecution(
|
|
2546
|
+
"Setting field-level export: " + selfExportName,
|
|
2547
|
+
{ value: result }
|
|
2548
|
+
);
|
|
2549
|
+
store.set(selfExportName, result);
|
|
2550
|
+
if (selfExportName.startsWith("$_")) {
|
|
2551
|
+
const varName = "_" + selfExportName.slice(2);
|
|
2552
|
+
if (ctx._graphqlVariables) {
|
|
2553
|
+
const currentVal = ctx._graphqlVariables[varName];
|
|
2554
|
+
if (Array.isArray(currentVal)) {
|
|
2555
|
+
if (!currentVal.includes(result) && result !== "") {
|
|
2556
|
+
currentVal.push(result);
|
|
2557
|
+
}
|
|
2558
|
+
} else {
|
|
2559
|
+
ctx._graphqlVariables[varName] = result;
|
|
2560
|
+
}
|
|
2561
|
+
logExportExecution(
|
|
2562
|
+
"Updated GraphQL variable: " + varName,
|
|
2563
|
+
ctx._graphqlVariables[varName]
|
|
2564
|
+
);
|
|
2565
|
+
}
|
|
2566
|
+
}
|
|
2567
|
+
}
|
|
2568
|
+
}
|
|
2569
|
+
if (fieldNode && fieldNode.selectionSet && result !== void 0 && result !== null) {
|
|
2570
|
+
if (Array.isArray(result)) {
|
|
2571
|
+
result.forEach((item) => {
|
|
2572
|
+
if (item && typeof item === "object") {
|
|
2573
|
+
processExports2(
|
|
2574
|
+
item,
|
|
2575
|
+
fieldNode.selectionSet,
|
|
2576
|
+
store,
|
|
2577
|
+
ctx._graphqlVariables,
|
|
2578
|
+
true
|
|
2579
|
+
);
|
|
2580
|
+
}
|
|
2581
|
+
});
|
|
2582
|
+
} else if (typeof result === "object") {
|
|
2583
|
+
processExports2(
|
|
2584
|
+
result,
|
|
2585
|
+
fieldNode.selectionSet,
|
|
2586
|
+
store,
|
|
2587
|
+
ctx._graphqlVariables,
|
|
2588
|
+
false
|
|
2589
|
+
);
|
|
2590
|
+
}
|
|
2591
|
+
}
|
|
2592
|
+
}
|
|
2593
|
+
return result;
|
|
2594
|
+
};
|
|
2595
|
+
};
|
|
2596
|
+
if (args.schema && !processedSchemas2.has(args.schema)) {
|
|
2597
|
+
processedSchemas2.add(args.schema);
|
|
2598
|
+
logExportExecution("Wrapping schema resolvers");
|
|
2599
|
+
const typeMap = args.schema.getTypeMap();
|
|
2600
|
+
for (const typeName in typeMap) {
|
|
2601
|
+
const type = typeMap[typeName];
|
|
2602
|
+
if (type instanceof import_graphql7.GraphQLObjectType && !typeName.startsWith("__")) {
|
|
2603
|
+
const fields = type.getFields();
|
|
2604
|
+
for (const fieldName in fields) {
|
|
2605
|
+
const field = fields[fieldName];
|
|
2606
|
+
if (!field) {
|
|
2607
|
+
continue;
|
|
2608
|
+
}
|
|
2609
|
+
if (field.resolve) {
|
|
2610
|
+
field.resolve = createWrappedResolver(field.resolve);
|
|
2611
|
+
}
|
|
2612
|
+
}
|
|
2613
|
+
}
|
|
2614
|
+
}
|
|
2615
|
+
}
|
|
2616
|
+
args.fieldResolver = createWrappedResolver(args.fieldResolver);
|
|
2617
|
+
return {
|
|
2618
|
+
onExecuteDone() {
|
|
2619
|
+
logExportExecution("Export execution completed", {
|
|
2620
|
+
exports: exportStore.getAll(),
|
|
2621
|
+
variables: context._graphqlVariables || {}
|
|
2622
|
+
});
|
|
2623
|
+
}
|
|
2624
|
+
};
|
|
2625
|
+
}
|
|
2626
|
+
};
|
|
2627
|
+
};
|
|
2628
|
+
|
|
2629
|
+
// src/export-directive-envelop-hooks/directive-definitions.ts
|
|
2630
|
+
var exportDirectiveTypeDefs = `
|
|
2631
|
+
"""
|
|
2632
|
+
Exports a field value for use by other fields in the same query.
|
|
2633
|
+
The exported value can be referenced using the pattern $_variableName or EXPORT_VAR:variableName.
|
|
2634
|
+
Supports accumulation when used on array items.
|
|
2635
|
+
"""
|
|
2636
|
+
directive @export(as: String!) on FIELD
|
|
2637
|
+
`;
|
|
2028
2638
|
|
|
2029
2639
|
// src/helpers.ts
|
|
2030
2640
|
var import_drizzle_orm9 = require("drizzle-orm");
|
|
@@ -2056,14 +2666,9 @@ function setCustomGraphQLTypes(table, columnTypes) {
|
|
|
2056
2666
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2057
2667
|
0 && (module.exports = {
|
|
2058
2668
|
ExportStore,
|
|
2059
|
-
SerialExecutor,
|
|
2060
2669
|
buildSchemaSDLWithDataLoader,
|
|
2061
2670
|
cleanupDataLoaderContext,
|
|
2062
2671
|
createDataLoaderContext,
|
|
2063
|
-
createExportMiddleware,
|
|
2064
|
-
createExportResolverMap,
|
|
2065
|
-
createSerialMiddleware,
|
|
2066
|
-
createSerialResolverMap,
|
|
2067
2672
|
exportDirectiveTypeDefs,
|
|
2068
2673
|
makeScalarAcceptExports,
|
|
2069
2674
|
serialDirectiveTypeDefs,
|
|
@@ -2071,6 +2676,8 @@ function setCustomGraphQLTypes(table, columnTypes) {
|
|
|
2071
2676
|
setCustomGraphQLTypes,
|
|
2072
2677
|
useDataLoaderCleanup,
|
|
2073
2678
|
useDataLoaderCleanupOnly,
|
|
2074
|
-
useDataLoaderContext
|
|
2679
|
+
useDataLoaderContext,
|
|
2680
|
+
useExportDirective,
|
|
2681
|
+
useSerialDirective
|
|
2075
2682
|
});
|
|
2076
2683
|
//# sourceMappingURL=index.cjs.map
|