drizzle-graphql-plus 0.8.29 → 0.8.30
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 +152 -132
- package/index.cjs.map +1 -1
- package/index.js +152 -132
- package/index.js.map +1 -1
- package/package.json +2 -2
package/index.cjs
CHANGED
|
@@ -2731,6 +2731,126 @@ var buildWhereClause = (tableInfo, where) => {
|
|
|
2731
2731
|
return (0, import_drizzle_orm10.and)(...conditions);
|
|
2732
2732
|
};
|
|
2733
2733
|
|
|
2734
|
+
// src/export-tool/utils.ts
|
|
2735
|
+
function isExportVariable(value) {
|
|
2736
|
+
return typeof value === "string" && value.startsWith("$_") && value.length > 2;
|
|
2737
|
+
}
|
|
2738
|
+
function getVariableName(value) {
|
|
2739
|
+
if (!isExportVariable(value)) {
|
|
2740
|
+
return null;
|
|
2741
|
+
}
|
|
2742
|
+
return value.slice(2);
|
|
2743
|
+
}
|
|
2744
|
+
async function resolveExportVariables(args, exportStore, timeout, allowNull = true) {
|
|
2745
|
+
if (isExportVariable(args)) {
|
|
2746
|
+
const varName = getVariableName(args);
|
|
2747
|
+
return await exportStore.waitFor(varName, timeout, allowNull);
|
|
2748
|
+
}
|
|
2749
|
+
if (Array.isArray(args)) {
|
|
2750
|
+
const resolved = await Promise.all(
|
|
2751
|
+
args.map(async (item) => {
|
|
2752
|
+
if (isExportVariable(item)) {
|
|
2753
|
+
const varName = getVariableName(item);
|
|
2754
|
+
return await exportStore.waitFor(varName, timeout, allowNull);
|
|
2755
|
+
} else if (typeof item === "object" && item !== null) {
|
|
2756
|
+
return await resolveExportVariables(item, exportStore, timeout, allowNull);
|
|
2757
|
+
}
|
|
2758
|
+
return item;
|
|
2759
|
+
})
|
|
2760
|
+
);
|
|
2761
|
+
return resolved;
|
|
2762
|
+
}
|
|
2763
|
+
if (typeof args === "object" && args !== null) {
|
|
2764
|
+
const resolved = {};
|
|
2765
|
+
for (const [key, value] of Object.entries(args)) {
|
|
2766
|
+
if (isExportVariable(value)) {
|
|
2767
|
+
const varName = getVariableName(value);
|
|
2768
|
+
resolved[key] = await exportStore.waitFor(varName, timeout, allowNull);
|
|
2769
|
+
} else if (Array.isArray(value)) {
|
|
2770
|
+
resolved[key] = await resolveExportVariables(
|
|
2771
|
+
value,
|
|
2772
|
+
exportStore,
|
|
2773
|
+
timeout,
|
|
2774
|
+
allowNull
|
|
2775
|
+
);
|
|
2776
|
+
} else if (typeof value === "object" && value !== null) {
|
|
2777
|
+
resolved[key] = await resolveExportVariables(
|
|
2778
|
+
value,
|
|
2779
|
+
exportStore,
|
|
2780
|
+
timeout,
|
|
2781
|
+
allowNull
|
|
2782
|
+
);
|
|
2783
|
+
} else {
|
|
2784
|
+
resolved[key] = value;
|
|
2785
|
+
}
|
|
2786
|
+
}
|
|
2787
|
+
return resolved;
|
|
2788
|
+
}
|
|
2789
|
+
return args;
|
|
2790
|
+
}
|
|
2791
|
+
function getExportDirective(fieldNode) {
|
|
2792
|
+
const node = fieldNode;
|
|
2793
|
+
if (!node || !node.directives) {
|
|
2794
|
+
return null;
|
|
2795
|
+
}
|
|
2796
|
+
const exportDirective = node.directives.find(
|
|
2797
|
+
(directive) => directive.name.value === "export"
|
|
2798
|
+
);
|
|
2799
|
+
if (!exportDirective) {
|
|
2800
|
+
return null;
|
|
2801
|
+
}
|
|
2802
|
+
const asArg = exportDirective.arguments?.find(
|
|
2803
|
+
(arg) => arg.name.value === "as"
|
|
2804
|
+
);
|
|
2805
|
+
if (!asArg || asArg.value.kind !== "StringValue") {
|
|
2806
|
+
return null;
|
|
2807
|
+
}
|
|
2808
|
+
return asArg.value.value;
|
|
2809
|
+
}
|
|
2810
|
+
function hasExportVariables(args) {
|
|
2811
|
+
if (isExportVariable(args)) {
|
|
2812
|
+
return true;
|
|
2813
|
+
}
|
|
2814
|
+
if (Array.isArray(args)) {
|
|
2815
|
+
return args.some((item) => hasExportVariables(item));
|
|
2816
|
+
}
|
|
2817
|
+
if (typeof args === "object" && args !== null) {
|
|
2818
|
+
for (const value of Object.values(args)) {
|
|
2819
|
+
if (hasExportVariables(value)) {
|
|
2820
|
+
return true;
|
|
2821
|
+
}
|
|
2822
|
+
}
|
|
2823
|
+
}
|
|
2824
|
+
return false;
|
|
2825
|
+
}
|
|
2826
|
+
function processExports(result, selectionSet, exportStore) {
|
|
2827
|
+
if (!result || !selectionSet)
|
|
2828
|
+
return;
|
|
2829
|
+
for (const selection of selectionSet.selections) {
|
|
2830
|
+
if (selection.kind !== "Field")
|
|
2831
|
+
continue;
|
|
2832
|
+
const resultKey = selection.alias?.value ?? selection.name.value;
|
|
2833
|
+
if (!(resultKey in result))
|
|
2834
|
+
continue;
|
|
2835
|
+
const value = result[resultKey];
|
|
2836
|
+
const exportName = getExportDirective(selection);
|
|
2837
|
+
if (exportName) {
|
|
2838
|
+
exportStore.set(exportName, value);
|
|
2839
|
+
}
|
|
2840
|
+
if (selection.selectionSet && value !== null && value !== void 0) {
|
|
2841
|
+
if (Array.isArray(value)) {
|
|
2842
|
+
value.forEach((item) => {
|
|
2843
|
+
if (item && typeof item === "object") {
|
|
2844
|
+
processExports(item, selection.selectionSet, exportStore);
|
|
2845
|
+
}
|
|
2846
|
+
});
|
|
2847
|
+
} else if (typeof value === "object") {
|
|
2848
|
+
processExports(value, selection.selectionSet, exportStore);
|
|
2849
|
+
}
|
|
2850
|
+
}
|
|
2851
|
+
}
|
|
2852
|
+
}
|
|
2853
|
+
|
|
2734
2854
|
// src/buildSchemaSDL/generator/utils/selection.ts
|
|
2735
2855
|
var buildOrderByClause = (tableInfo, orderBy) => {
|
|
2736
2856
|
if (!orderBy || Object.keys(orderBy).length === 0) {
|
|
@@ -2761,7 +2881,7 @@ var extractSelectedColumns = (fields, tableInfo) => {
|
|
|
2761
2881
|
}
|
|
2762
2882
|
return Object.keys(columns).length > 0 ? columns : {};
|
|
2763
2883
|
};
|
|
2764
|
-
var extractRelationsParams2 = (relationMap, tables, tableName, fields) => {
|
|
2884
|
+
var extractRelationsParams2 = async (relationMap, tables, tableName, fields, context) => {
|
|
2765
2885
|
const relations = relationMap[tableName];
|
|
2766
2886
|
if (!relations)
|
|
2767
2887
|
return void 0;
|
|
@@ -2787,10 +2907,15 @@ var extractRelationsParams2 = (relationMap, tables, tableName, fields) => {
|
|
|
2787
2907
|
const relationArgs = relationField.args;
|
|
2788
2908
|
if (relationArgs) {
|
|
2789
2909
|
if (relationArgs["where"]) {
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2910
|
+
let whereClause = relationArgs["where"];
|
|
2911
|
+
if (context?.exportStore && hasExportVariables(whereClause)) {
|
|
2912
|
+
try {
|
|
2913
|
+
whereClause = await resolveExportVariables(whereClause, context.exportStore);
|
|
2914
|
+
} catch (error) {
|
|
2915
|
+
console.warn(`Failed to resolve export variables in nested relation ${relName}:`, error);
|
|
2916
|
+
}
|
|
2917
|
+
}
|
|
2918
|
+
thisRecord.where = buildWhereClause(targetTable, whereClause);
|
|
2794
2919
|
}
|
|
2795
2920
|
if (relationArgs["orderBy"]) {
|
|
2796
2921
|
thisRecord.orderBy = buildOrderByClause(
|
|
@@ -2805,11 +2930,12 @@ var extractRelationsParams2 = (relationMap, tables, tableName, fields) => {
|
|
|
2805
2930
|
thisRecord.offset = relationArgs["offset"];
|
|
2806
2931
|
}
|
|
2807
2932
|
}
|
|
2808
|
-
const nestedWith = extractRelationsParams2(
|
|
2933
|
+
const nestedWith = await extractRelationsParams2(
|
|
2809
2934
|
relationMap,
|
|
2810
2935
|
tables,
|
|
2811
2936
|
targetTableName,
|
|
2812
|
-
allFields
|
|
2937
|
+
allFields,
|
|
2938
|
+
context
|
|
2813
2939
|
);
|
|
2814
2940
|
if (nestedWith) {
|
|
2815
2941
|
thisRecord.with = nestedWith;
|
|
@@ -2839,11 +2965,12 @@ var createFindManyResolver = (queryBase, tableInfo, tables, relations) => {
|
|
|
2839
2965
|
limit,
|
|
2840
2966
|
orderBy: buildOrderByClause(tableInfo, orderBy),
|
|
2841
2967
|
where: buildWhereClause(tableInfo, where),
|
|
2842
|
-
with: extractRelationsParams2(
|
|
2968
|
+
with: await extractRelationsParams2(
|
|
2843
2969
|
relations,
|
|
2844
2970
|
tables,
|
|
2845
2971
|
tableInfo.name,
|
|
2846
|
-
allFields
|
|
2972
|
+
allFields,
|
|
2973
|
+
context
|
|
2847
2974
|
)
|
|
2848
2975
|
});
|
|
2849
2976
|
return result;
|
|
@@ -2872,11 +2999,12 @@ var createFindFirstResolver = (queryBase, tableInfo, tables, relations) => {
|
|
|
2872
2999
|
columns: extractSelectedColumns(allFields, tableInfo),
|
|
2873
3000
|
orderBy: buildOrderByClause(tableInfo, orderBy),
|
|
2874
3001
|
where: buildWhereClause(tableInfo, where),
|
|
2875
|
-
with: extractRelationsParams2(
|
|
3002
|
+
with: await extractRelationsParams2(
|
|
2876
3003
|
relations,
|
|
2877
3004
|
tables,
|
|
2878
3005
|
tableInfo.name,
|
|
2879
|
-
allFields
|
|
3006
|
+
allFields,
|
|
3007
|
+
context
|
|
2880
3008
|
)
|
|
2881
3009
|
});
|
|
2882
3010
|
return result || null;
|
|
@@ -3149,8 +3277,9 @@ var ExportStore = class {
|
|
|
3149
3277
|
* Wait for a value to be available
|
|
3150
3278
|
* Returns immediately if value already exists
|
|
3151
3279
|
* Returns a Promise that resolves when value is set
|
|
3280
|
+
* If timeout occurs and allowNull is true, resolves with null instead of rejecting
|
|
3152
3281
|
*/
|
|
3153
|
-
async waitFor(name, timeout = 5e3) {
|
|
3282
|
+
async waitFor(name, timeout = 5e3, allowNull = false) {
|
|
3154
3283
|
if (this.store.has(name)) {
|
|
3155
3284
|
return this.store.get(name);
|
|
3156
3285
|
}
|
|
@@ -3165,7 +3294,11 @@ var ExportStore = class {
|
|
|
3165
3294
|
const index = callbacks.indexOf(resolve);
|
|
3166
3295
|
if (index > -1) {
|
|
3167
3296
|
callbacks.splice(index, 1);
|
|
3168
|
-
|
|
3297
|
+
if (allowNull) {
|
|
3298
|
+
resolve(null);
|
|
3299
|
+
} else {
|
|
3300
|
+
reject(new Error(`Timeout waiting for export variable "${name}"`));
|
|
3301
|
+
}
|
|
3169
3302
|
}
|
|
3170
3303
|
}
|
|
3171
3304
|
}, timeout);
|
|
@@ -3192,124 +3325,6 @@ var ExportStore = class {
|
|
|
3192
3325
|
}
|
|
3193
3326
|
};
|
|
3194
3327
|
|
|
3195
|
-
// src/export-tool/utils.ts
|
|
3196
|
-
function isExportVariable(value) {
|
|
3197
|
-
return typeof value === "string" && value.startsWith("$_") && value.length > 2;
|
|
3198
|
-
}
|
|
3199
|
-
function getVariableName(value) {
|
|
3200
|
-
if (!isExportVariable(value)) {
|
|
3201
|
-
return null;
|
|
3202
|
-
}
|
|
3203
|
-
return value.slice(2);
|
|
3204
|
-
}
|
|
3205
|
-
async function resolveExportVariables(args, exportStore, timeout) {
|
|
3206
|
-
if (isExportVariable(args)) {
|
|
3207
|
-
const varName = getVariableName(args);
|
|
3208
|
-
return await exportStore.waitFor(varName, timeout);
|
|
3209
|
-
}
|
|
3210
|
-
if (Array.isArray(args)) {
|
|
3211
|
-
const resolved = await Promise.all(
|
|
3212
|
-
args.map(async (item) => {
|
|
3213
|
-
if (isExportVariable(item)) {
|
|
3214
|
-
const varName = getVariableName(item);
|
|
3215
|
-
return await exportStore.waitFor(varName, timeout);
|
|
3216
|
-
} else if (typeof item === "object" && item !== null) {
|
|
3217
|
-
return await resolveExportVariables(item, exportStore, timeout);
|
|
3218
|
-
}
|
|
3219
|
-
return item;
|
|
3220
|
-
})
|
|
3221
|
-
);
|
|
3222
|
-
return resolved;
|
|
3223
|
-
}
|
|
3224
|
-
if (typeof args === "object" && args !== null) {
|
|
3225
|
-
const resolved = {};
|
|
3226
|
-
for (const [key, value] of Object.entries(args)) {
|
|
3227
|
-
if (isExportVariable(value)) {
|
|
3228
|
-
const varName = getVariableName(value);
|
|
3229
|
-
resolved[key] = await exportStore.waitFor(varName, timeout);
|
|
3230
|
-
} else if (Array.isArray(value)) {
|
|
3231
|
-
resolved[key] = await resolveExportVariables(
|
|
3232
|
-
value,
|
|
3233
|
-
exportStore,
|
|
3234
|
-
timeout
|
|
3235
|
-
);
|
|
3236
|
-
} else if (typeof value === "object" && value !== null) {
|
|
3237
|
-
resolved[key] = await resolveExportVariables(
|
|
3238
|
-
value,
|
|
3239
|
-
exportStore,
|
|
3240
|
-
timeout
|
|
3241
|
-
);
|
|
3242
|
-
} else {
|
|
3243
|
-
resolved[key] = value;
|
|
3244
|
-
}
|
|
3245
|
-
}
|
|
3246
|
-
return resolved;
|
|
3247
|
-
}
|
|
3248
|
-
return args;
|
|
3249
|
-
}
|
|
3250
|
-
function getExportDirective(fieldNode) {
|
|
3251
|
-
const node = fieldNode;
|
|
3252
|
-
if (!node || !node.directives) {
|
|
3253
|
-
return null;
|
|
3254
|
-
}
|
|
3255
|
-
const exportDirective = node.directives.find(
|
|
3256
|
-
(directive) => directive.name.value === "export"
|
|
3257
|
-
);
|
|
3258
|
-
if (!exportDirective) {
|
|
3259
|
-
return null;
|
|
3260
|
-
}
|
|
3261
|
-
const asArg = exportDirective.arguments?.find(
|
|
3262
|
-
(arg) => arg.name.value === "as"
|
|
3263
|
-
);
|
|
3264
|
-
if (!asArg || asArg.value.kind !== "StringValue") {
|
|
3265
|
-
return null;
|
|
3266
|
-
}
|
|
3267
|
-
return asArg.value.value;
|
|
3268
|
-
}
|
|
3269
|
-
function hasExportVariables(args) {
|
|
3270
|
-
if (isExportVariable(args)) {
|
|
3271
|
-
return true;
|
|
3272
|
-
}
|
|
3273
|
-
if (Array.isArray(args)) {
|
|
3274
|
-
return args.some((item) => hasExportVariables(item));
|
|
3275
|
-
}
|
|
3276
|
-
if (typeof args === "object" && args !== null) {
|
|
3277
|
-
for (const value of Object.values(args)) {
|
|
3278
|
-
if (hasExportVariables(value)) {
|
|
3279
|
-
return true;
|
|
3280
|
-
}
|
|
3281
|
-
}
|
|
3282
|
-
}
|
|
3283
|
-
return false;
|
|
3284
|
-
}
|
|
3285
|
-
function processExports(result, selectionSet, exportStore) {
|
|
3286
|
-
if (!result || !selectionSet)
|
|
3287
|
-
return;
|
|
3288
|
-
for (const selection of selectionSet.selections) {
|
|
3289
|
-
if (selection.kind !== "Field")
|
|
3290
|
-
continue;
|
|
3291
|
-
const resultKey = selection.alias?.value ?? selection.name.value;
|
|
3292
|
-
if (!(resultKey in result))
|
|
3293
|
-
continue;
|
|
3294
|
-
const value = result[resultKey];
|
|
3295
|
-
const exportName = getExportDirective(selection);
|
|
3296
|
-
if (exportName) {
|
|
3297
|
-
exportStore.set(exportName, value);
|
|
3298
|
-
}
|
|
3299
|
-
if (selection.selectionSet && value !== null && value !== void 0) {
|
|
3300
|
-
if (Array.isArray(value)) {
|
|
3301
|
-
value.forEach((item) => {
|
|
3302
|
-
if (item && typeof item === "object") {
|
|
3303
|
-
processExports(item, selection.selectionSet, exportStore);
|
|
3304
|
-
}
|
|
3305
|
-
});
|
|
3306
|
-
} else if (typeof value === "object") {
|
|
3307
|
-
processExports(value, selection.selectionSet, exportStore);
|
|
3308
|
-
}
|
|
3309
|
-
}
|
|
3310
|
-
}
|
|
3311
|
-
}
|
|
3312
|
-
|
|
3313
3328
|
// src/export-tool/middleware.ts
|
|
3314
3329
|
function createExportMiddleware() {
|
|
3315
3330
|
return (next) => {
|
|
@@ -3323,6 +3338,11 @@ function createExportMiddleware() {
|
|
|
3323
3338
|
try {
|
|
3324
3339
|
resolvedArgs = await resolveExportVariables(args, exportStore);
|
|
3325
3340
|
} catch (error) {
|
|
3341
|
+
if (error instanceof Error && error.message.includes("Timeout waiting for export variable")) {
|
|
3342
|
+
throw new Error(
|
|
3343
|
+
`Failed to resolve export variables in ${info.parentType.name}.${info.fieldName}: ${error.message}. Consider using a fallback value or checking if the exported field can return null.`
|
|
3344
|
+
);
|
|
3345
|
+
}
|
|
3326
3346
|
throw new Error(
|
|
3327
3347
|
`Failed to resolve export variables in ${info.parentType.name}.${info.fieldName}: ${error instanceof Error ? error.message : String(error)}`
|
|
3328
3348
|
);
|
|
@@ -3333,7 +3353,7 @@ function createExportMiddleware() {
|
|
|
3333
3353
|
if (!fieldNode)
|
|
3334
3354
|
return result;
|
|
3335
3355
|
const selfExportName = getExportDirective(fieldNode);
|
|
3336
|
-
if (selfExportName && result !== void 0
|
|
3356
|
+
if (selfExportName && result !== void 0) {
|
|
3337
3357
|
exportStore.set(selfExportName, result);
|
|
3338
3358
|
}
|
|
3339
3359
|
if (fieldNode.selectionSet && result !== void 0 && result !== null) {
|