drizzle-graphql-plus 0.8.35 → 0.8.36
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 +248 -156
- package/index.cjs.map +1 -1
- package/index.d.cts +14 -2
- package/index.d.ts +14 -2
- package/index.js +255 -156
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -5,6 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __esm = (fn, res) => function __init() {
|
|
9
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
+
};
|
|
8
11
|
var __export = (target, all) => {
|
|
9
12
|
for (var name in all)
|
|
10
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -27,6 +30,158 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
30
|
));
|
|
28
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
32
|
|
|
33
|
+
// src/export-tool/utils.ts
|
|
34
|
+
var utils_exports = {};
|
|
35
|
+
__export(utils_exports, {
|
|
36
|
+
extractExportDirectives: () => extractExportDirectives,
|
|
37
|
+
getExportDirective: () => getExportDirective,
|
|
38
|
+
getVariableName: () => getVariableName,
|
|
39
|
+
hasExportVariables: () => hasExportVariables,
|
|
40
|
+
isExportVariable: () => isExportVariable,
|
|
41
|
+
processExports: () => processExports,
|
|
42
|
+
resolveExportVariables: () => resolveExportVariables
|
|
43
|
+
});
|
|
44
|
+
function isExportVariable(value) {
|
|
45
|
+
return typeof value === "string" && value.startsWith("$_") && value.length > 2;
|
|
46
|
+
}
|
|
47
|
+
function getVariableName(value) {
|
|
48
|
+
if (!isExportVariable(value)) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
return value.slice(2);
|
|
52
|
+
}
|
|
53
|
+
async function resolveExportVariables(args, exportStore, timeout, allowNull = true) {
|
|
54
|
+
if (isExportVariable(args)) {
|
|
55
|
+
const varName = getVariableName(args);
|
|
56
|
+
return await exportStore.waitFor(varName, timeout, allowNull);
|
|
57
|
+
}
|
|
58
|
+
if (Array.isArray(args)) {
|
|
59
|
+
const resolved = await Promise.all(
|
|
60
|
+
args.map(async (item) => {
|
|
61
|
+
if (isExportVariable(item)) {
|
|
62
|
+
const varName = getVariableName(item);
|
|
63
|
+
return await exportStore.waitFor(varName, timeout, allowNull);
|
|
64
|
+
} else if (typeof item === "object" && item !== null) {
|
|
65
|
+
return await resolveExportVariables(item, exportStore, timeout, allowNull);
|
|
66
|
+
}
|
|
67
|
+
return item;
|
|
68
|
+
})
|
|
69
|
+
);
|
|
70
|
+
return resolved;
|
|
71
|
+
}
|
|
72
|
+
if (typeof args === "object" && args !== null) {
|
|
73
|
+
const resolved = {};
|
|
74
|
+
for (const [key, value] of Object.entries(args)) {
|
|
75
|
+
if (isExportVariable(value)) {
|
|
76
|
+
const varName = getVariableName(value);
|
|
77
|
+
resolved[key] = await exportStore.waitFor(varName, timeout, allowNull);
|
|
78
|
+
} else if (Array.isArray(value)) {
|
|
79
|
+
resolved[key] = await resolveExportVariables(
|
|
80
|
+
value,
|
|
81
|
+
exportStore,
|
|
82
|
+
timeout,
|
|
83
|
+
allowNull
|
|
84
|
+
);
|
|
85
|
+
} else if (typeof value === "object" && value !== null) {
|
|
86
|
+
resolved[key] = await resolveExportVariables(
|
|
87
|
+
value,
|
|
88
|
+
exportStore,
|
|
89
|
+
timeout,
|
|
90
|
+
allowNull
|
|
91
|
+
);
|
|
92
|
+
} else {
|
|
93
|
+
resolved[key] = value;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return resolved;
|
|
97
|
+
}
|
|
98
|
+
return args;
|
|
99
|
+
}
|
|
100
|
+
function getExportDirective(fieldNode) {
|
|
101
|
+
const node = fieldNode;
|
|
102
|
+
if (!node || !node.directives) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
const exportDirective = node.directives.find(
|
|
106
|
+
(directive) => directive.name.value === "export"
|
|
107
|
+
);
|
|
108
|
+
if (!exportDirective) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
const asArg = exportDirective.arguments?.find(
|
|
112
|
+
(arg) => arg.name.value === "as"
|
|
113
|
+
);
|
|
114
|
+
if (!asArg || asArg.value.kind !== "StringValue") {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
return asArg.value.value;
|
|
118
|
+
}
|
|
119
|
+
function extractExportDirectives(info) {
|
|
120
|
+
const exports2 = /* @__PURE__ */ new Map();
|
|
121
|
+
const fieldNode = info.fieldNodes[0];
|
|
122
|
+
if (!fieldNode || !fieldNode.selectionSet) {
|
|
123
|
+
return exports2;
|
|
124
|
+
}
|
|
125
|
+
for (const selection of fieldNode.selectionSet.selections) {
|
|
126
|
+
if (selection.kind === "Field") {
|
|
127
|
+
const exportName = getExportDirective(selection);
|
|
128
|
+
if (exportName) {
|
|
129
|
+
const fieldName = selection.name.value;
|
|
130
|
+
exports2.set(fieldName, exportName);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return exports2;
|
|
135
|
+
}
|
|
136
|
+
function hasExportVariables(args) {
|
|
137
|
+
if (isExportVariable(args)) {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
if (Array.isArray(args)) {
|
|
141
|
+
return args.some((item) => hasExportVariables(item));
|
|
142
|
+
}
|
|
143
|
+
if (typeof args === "object" && args !== null) {
|
|
144
|
+
for (const value of Object.values(args)) {
|
|
145
|
+
if (hasExportVariables(value)) {
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
function processExports(result, selectionSet, exportStore) {
|
|
153
|
+
if (!result || !selectionSet)
|
|
154
|
+
return;
|
|
155
|
+
for (const selection of selectionSet.selections) {
|
|
156
|
+
if (selection.kind !== "Field")
|
|
157
|
+
continue;
|
|
158
|
+
const resultKey = selection.alias?.value ?? selection.name.value;
|
|
159
|
+
if (!(resultKey in result))
|
|
160
|
+
continue;
|
|
161
|
+
const value = result[resultKey];
|
|
162
|
+
const exportName = getExportDirective(selection);
|
|
163
|
+
if (exportName) {
|
|
164
|
+
exportStore.set(exportName, value);
|
|
165
|
+
}
|
|
166
|
+
if (selection.selectionSet && value !== null && value !== void 0) {
|
|
167
|
+
if (Array.isArray(value)) {
|
|
168
|
+
value.forEach((item) => {
|
|
169
|
+
if (item && typeof item === "object") {
|
|
170
|
+
processExports(item, selection.selectionSet, exportStore);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
} else if (typeof value === "object") {
|
|
174
|
+
processExports(value, selection.selectionSet, exportStore);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
var init_utils = __esm({
|
|
180
|
+
"src/export-tool/utils.ts"() {
|
|
181
|
+
"use strict";
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
|
|
30
185
|
// src/index.ts
|
|
31
186
|
var src_exports = {};
|
|
32
187
|
__export(src_exports, {
|
|
@@ -2757,127 +2912,8 @@ var buildWhereClause = (tableInfo, where) => {
|
|
|
2757
2912
|
return (0, import_drizzle_orm10.and)(...conditions);
|
|
2758
2913
|
};
|
|
2759
2914
|
|
|
2760
|
-
// src/export-tool/utils.ts
|
|
2761
|
-
function isExportVariable(value) {
|
|
2762
|
-
return typeof value === "string" && value.startsWith("$_") && value.length > 2;
|
|
2763
|
-
}
|
|
2764
|
-
function getVariableName(value) {
|
|
2765
|
-
if (!isExportVariable(value)) {
|
|
2766
|
-
return null;
|
|
2767
|
-
}
|
|
2768
|
-
return value.slice(2);
|
|
2769
|
-
}
|
|
2770
|
-
async function resolveExportVariables(args, exportStore, timeout, allowNull = true) {
|
|
2771
|
-
if (isExportVariable(args)) {
|
|
2772
|
-
const varName = getVariableName(args);
|
|
2773
|
-
return await exportStore.waitFor(varName, timeout, allowNull);
|
|
2774
|
-
}
|
|
2775
|
-
if (Array.isArray(args)) {
|
|
2776
|
-
const resolved = await Promise.all(
|
|
2777
|
-
args.map(async (item) => {
|
|
2778
|
-
if (isExportVariable(item)) {
|
|
2779
|
-
const varName = getVariableName(item);
|
|
2780
|
-
return await exportStore.waitFor(varName, timeout, allowNull);
|
|
2781
|
-
} else if (typeof item === "object" && item !== null) {
|
|
2782
|
-
return await resolveExportVariables(item, exportStore, timeout, allowNull);
|
|
2783
|
-
}
|
|
2784
|
-
return item;
|
|
2785
|
-
})
|
|
2786
|
-
);
|
|
2787
|
-
return resolved;
|
|
2788
|
-
}
|
|
2789
|
-
if (typeof args === "object" && args !== null) {
|
|
2790
|
-
const resolved = {};
|
|
2791
|
-
for (const [key, value] of Object.entries(args)) {
|
|
2792
|
-
if (isExportVariable(value)) {
|
|
2793
|
-
const varName = getVariableName(value);
|
|
2794
|
-
resolved[key] = await exportStore.waitFor(varName, timeout, allowNull);
|
|
2795
|
-
} else if (Array.isArray(value)) {
|
|
2796
|
-
resolved[key] = await resolveExportVariables(
|
|
2797
|
-
value,
|
|
2798
|
-
exportStore,
|
|
2799
|
-
timeout,
|
|
2800
|
-
allowNull
|
|
2801
|
-
);
|
|
2802
|
-
} else if (typeof value === "object" && value !== null) {
|
|
2803
|
-
resolved[key] = await resolveExportVariables(
|
|
2804
|
-
value,
|
|
2805
|
-
exportStore,
|
|
2806
|
-
timeout,
|
|
2807
|
-
allowNull
|
|
2808
|
-
);
|
|
2809
|
-
} else {
|
|
2810
|
-
resolved[key] = value;
|
|
2811
|
-
}
|
|
2812
|
-
}
|
|
2813
|
-
return resolved;
|
|
2814
|
-
}
|
|
2815
|
-
return args;
|
|
2816
|
-
}
|
|
2817
|
-
function getExportDirective(fieldNode) {
|
|
2818
|
-
const node = fieldNode;
|
|
2819
|
-
if (!node || !node.directives) {
|
|
2820
|
-
return null;
|
|
2821
|
-
}
|
|
2822
|
-
const exportDirective = node.directives.find(
|
|
2823
|
-
(directive) => directive.name.value === "export"
|
|
2824
|
-
);
|
|
2825
|
-
if (!exportDirective) {
|
|
2826
|
-
return null;
|
|
2827
|
-
}
|
|
2828
|
-
const asArg = exportDirective.arguments?.find(
|
|
2829
|
-
(arg) => arg.name.value === "as"
|
|
2830
|
-
);
|
|
2831
|
-
if (!asArg || asArg.value.kind !== "StringValue") {
|
|
2832
|
-
return null;
|
|
2833
|
-
}
|
|
2834
|
-
return asArg.value.value;
|
|
2835
|
-
}
|
|
2836
|
-
function hasExportVariables(args) {
|
|
2837
|
-
if (isExportVariable(args)) {
|
|
2838
|
-
return true;
|
|
2839
|
-
}
|
|
2840
|
-
if (Array.isArray(args)) {
|
|
2841
|
-
return args.some((item) => hasExportVariables(item));
|
|
2842
|
-
}
|
|
2843
|
-
if (typeof args === "object" && args !== null) {
|
|
2844
|
-
for (const value of Object.values(args)) {
|
|
2845
|
-
if (hasExportVariables(value)) {
|
|
2846
|
-
return true;
|
|
2847
|
-
}
|
|
2848
|
-
}
|
|
2849
|
-
}
|
|
2850
|
-
return false;
|
|
2851
|
-
}
|
|
2852
|
-
function processExports(result, selectionSet, exportStore) {
|
|
2853
|
-
if (!result || !selectionSet)
|
|
2854
|
-
return;
|
|
2855
|
-
for (const selection of selectionSet.selections) {
|
|
2856
|
-
if (selection.kind !== "Field")
|
|
2857
|
-
continue;
|
|
2858
|
-
const resultKey = selection.alias?.value ?? selection.name.value;
|
|
2859
|
-
if (!(resultKey in result))
|
|
2860
|
-
continue;
|
|
2861
|
-
const value = result[resultKey];
|
|
2862
|
-
const exportName = getExportDirective(selection);
|
|
2863
|
-
if (exportName) {
|
|
2864
|
-
exportStore.set(exportName, value);
|
|
2865
|
-
}
|
|
2866
|
-
if (selection.selectionSet && value !== null && value !== void 0) {
|
|
2867
|
-
if (Array.isArray(value)) {
|
|
2868
|
-
value.forEach((item) => {
|
|
2869
|
-
if (item && typeof item === "object") {
|
|
2870
|
-
processExports(item, selection.selectionSet, exportStore);
|
|
2871
|
-
}
|
|
2872
|
-
});
|
|
2873
|
-
} else if (typeof value === "object") {
|
|
2874
|
-
processExports(value, selection.selectionSet, exportStore);
|
|
2875
|
-
}
|
|
2876
|
-
}
|
|
2877
|
-
}
|
|
2878
|
-
}
|
|
2879
|
-
|
|
2880
2915
|
// src/buildSchemaSDL/generator/utils/selection.ts
|
|
2916
|
+
init_utils();
|
|
2881
2917
|
var buildOrderByClause = (tableInfo, orderBy) => {
|
|
2882
2918
|
if (!orderBy || Object.keys(orderBy).length === 0) {
|
|
2883
2919
|
return void 0;
|
|
@@ -3853,10 +3889,12 @@ var buildOrderByClause2 = (tableInfo, orderBy) => {
|
|
|
3853
3889
|
var import_dataloader = __toESM(require("dataloader"), 1);
|
|
3854
3890
|
var import_drizzle_orm17 = require("drizzle-orm");
|
|
3855
3891
|
var RelationDataLoader = class {
|
|
3856
|
-
constructor(queryBase, tableInfo, relations) {
|
|
3892
|
+
constructor(queryBase, tableInfo, relations, context, debugConfig) {
|
|
3857
3893
|
this.queryBase = queryBase;
|
|
3858
3894
|
this.tableInfo = tableInfo;
|
|
3859
3895
|
this.relations = relations;
|
|
3896
|
+
this.context = context;
|
|
3897
|
+
this.debugConfig = debugConfig;
|
|
3860
3898
|
}
|
|
3861
3899
|
loaders = /* @__PURE__ */ new Map();
|
|
3862
3900
|
createLoaderKey(key) {
|
|
@@ -3897,11 +3935,31 @@ var RelationDataLoader = class {
|
|
|
3897
3935
|
}
|
|
3898
3936
|
const allParentIds = groupKeys.flatMap((key) => key.parentIds);
|
|
3899
3937
|
const uniqueParentIds = Array.from(new Set(allParentIds));
|
|
3938
|
+
let resolvedWhere = firstKey.where;
|
|
3939
|
+
if (resolvedWhere && this.context?.exportStore) {
|
|
3940
|
+
const { hasExportVariables: hasExportVariables2, resolveExportVariables: resolveExportVariables2 } = await Promise.resolve().then(() => (init_utils(), utils_exports));
|
|
3941
|
+
if (hasExportVariables2(resolvedWhere)) {
|
|
3942
|
+
try {
|
|
3943
|
+
if (this.debugConfig?.exportVariables) {
|
|
3944
|
+
console.log(`\u{1F50D} DataLoader: Resolving export variables in where clause:`, resolvedWhere);
|
|
3945
|
+
}
|
|
3946
|
+
resolvedWhere = await resolveExportVariables2(resolvedWhere, this.context.exportStore);
|
|
3947
|
+
if (this.debugConfig?.exportVariables) {
|
|
3948
|
+
console.log(`\u2705 DataLoader: Successfully resolved to:`, resolvedWhere);
|
|
3949
|
+
}
|
|
3950
|
+
} catch (error) {
|
|
3951
|
+
if (this.debugConfig?.exportVariables) {
|
|
3952
|
+
console.warn(`\u274C DataLoader: Failed to resolve export variables:`, error);
|
|
3953
|
+
}
|
|
3954
|
+
}
|
|
3955
|
+
}
|
|
3956
|
+
}
|
|
3900
3957
|
const whereClause = this.buildBatchWhereClause(
|
|
3901
3958
|
uniqueParentIds,
|
|
3902
3959
|
firstKey.isReversedRelation,
|
|
3903
3960
|
firstKey.foreignKey,
|
|
3904
|
-
|
|
3961
|
+
resolvedWhere
|
|
3962
|
+
// Use resolved where clause
|
|
3905
3963
|
);
|
|
3906
3964
|
if (!whereClause) {
|
|
3907
3965
|
results.push(...groupKeys.map(() => []));
|
|
@@ -3918,9 +3976,13 @@ var RelationDataLoader = class {
|
|
|
3918
3976
|
limit: firstKey.limit,
|
|
3919
3977
|
offset: firstKey.offset
|
|
3920
3978
|
});
|
|
3921
|
-
|
|
3979
|
+
if (this.debugConfig?.dataLoader) {
|
|
3980
|
+
console.log(`DataLoader executing query for relation ${firstKey.relationName} with foreign key ${firstKey.foreignKey}`);
|
|
3981
|
+
}
|
|
3922
3982
|
const batchResults = await query;
|
|
3923
|
-
|
|
3983
|
+
if (this.debugConfig?.dataLoader) {
|
|
3984
|
+
console.log(`DataLoader got ${batchResults.length} results:`, batchResults);
|
|
3985
|
+
}
|
|
3924
3986
|
const resultsByParentId = /* @__PURE__ */ new Map();
|
|
3925
3987
|
for (const result of batchResults) {
|
|
3926
3988
|
const parentId = result[firstKey.foreignKey];
|
|
@@ -3974,18 +4036,19 @@ var RelationDataLoader = class {
|
|
|
3974
4036
|
this.loaders.clear();
|
|
3975
4037
|
}
|
|
3976
4038
|
};
|
|
3977
|
-
function getRelationLoader(context, tableName, queryBase, tableInfo, relations) {
|
|
4039
|
+
function getRelationLoader(context, tableName, queryBase, tableInfo, relations, debugConfig) {
|
|
3978
4040
|
if (!context.relationLoaders.has(tableName)) {
|
|
3979
4041
|
context.relationLoaders.set(
|
|
3980
4042
|
tableName,
|
|
3981
|
-
new RelationDataLoader(queryBase, tableInfo, relations)
|
|
4043
|
+
new RelationDataLoader(queryBase, tableInfo, relations, context, debugConfig)
|
|
4044
|
+
// Pass debug config
|
|
3982
4045
|
);
|
|
3983
4046
|
}
|
|
3984
4047
|
return context.relationLoaders.get(tableName);
|
|
3985
4048
|
}
|
|
3986
4049
|
|
|
3987
4050
|
// src/build-schema-sdl-with-dl/generator/queries/dataloader-resolvers.ts
|
|
3988
|
-
var createDataLoaderFindManyResolver = (queryBase, tableInfo, tables, relations) => {
|
|
4051
|
+
var createDataLoaderFindManyResolver = (queryBase, tableInfo, tables, relations, debugConfig) => {
|
|
3989
4052
|
return async (parent, args, context, info) => {
|
|
3990
4053
|
try {
|
|
3991
4054
|
const { where, orderBy, limit, offset } = args;
|
|
@@ -4019,7 +4082,8 @@ var createDataLoaderFindManyResolver = (queryBase, tableInfo, tables, relations)
|
|
|
4019
4082
|
tables,
|
|
4020
4083
|
relations,
|
|
4021
4084
|
allFields,
|
|
4022
|
-
context
|
|
4085
|
+
context,
|
|
4086
|
+
debugConfig
|
|
4023
4087
|
);
|
|
4024
4088
|
return enhancedResults;
|
|
4025
4089
|
} catch (e) {
|
|
@@ -4030,7 +4094,7 @@ var createDataLoaderFindManyResolver = (queryBase, tableInfo, tables, relations)
|
|
|
4030
4094
|
}
|
|
4031
4095
|
};
|
|
4032
4096
|
};
|
|
4033
|
-
var createDataLoaderFindFirstResolver = (queryBase, tableInfo, tables, relations) => {
|
|
4097
|
+
var createDataLoaderFindFirstResolver = (queryBase, tableInfo, tables, relations, debugConfig) => {
|
|
4034
4098
|
return async (parent, args, context, info) => {
|
|
4035
4099
|
try {
|
|
4036
4100
|
const { where, orderBy } = args;
|
|
@@ -4062,7 +4126,8 @@ var createDataLoaderFindFirstResolver = (queryBase, tableInfo, tables, relations
|
|
|
4062
4126
|
tables,
|
|
4063
4127
|
relations,
|
|
4064
4128
|
allFields,
|
|
4065
|
-
context
|
|
4129
|
+
context,
|
|
4130
|
+
debugConfig
|
|
4066
4131
|
);
|
|
4067
4132
|
return enhancedResult || null;
|
|
4068
4133
|
} catch (e) {
|
|
@@ -4073,7 +4138,7 @@ var createDataLoaderFindFirstResolver = (queryBase, tableInfo, tables, relations
|
|
|
4073
4138
|
}
|
|
4074
4139
|
};
|
|
4075
4140
|
};
|
|
4076
|
-
async function loadRelationsWithDataLoader(mainResults, tableInfo, tables, relations, fields, context) {
|
|
4141
|
+
async function loadRelationsWithDataLoader(mainResults, tableInfo, tables, relations, fields, context, debugConfig) {
|
|
4077
4142
|
const tableRelations = relations[tableInfo.name];
|
|
4078
4143
|
if (!tableRelations) {
|
|
4079
4144
|
return mainResults;
|
|
@@ -4124,7 +4189,9 @@ async function loadRelationsWithDataLoader(mainResults, tableInfo, tables, relat
|
|
|
4124
4189
|
let foreignKeyName;
|
|
4125
4190
|
let isReversedRelation = false;
|
|
4126
4191
|
const relationConfig = relation.config;
|
|
4127
|
-
|
|
4192
|
+
if (debugConfig?.dataLoader) {
|
|
4193
|
+
console.log(`Processing relation ${relName} for table ${tableInfo.name} -> ${targetTableName}`);
|
|
4194
|
+
}
|
|
4128
4195
|
if (relationConfig?.fields && relationConfig.fields.length > 0) {
|
|
4129
4196
|
if ((0, import_drizzle_orm18.is)(relation, import_drizzle_orm18.One)) {
|
|
4130
4197
|
const fieldColumn = relationConfig.fields[0];
|
|
@@ -4134,7 +4201,9 @@ async function loadRelationsWithDataLoader(mainResults, tableInfo, tables, relat
|
|
|
4134
4201
|
) || referenceColumn.name;
|
|
4135
4202
|
foreignKeyName = referenceKeyName;
|
|
4136
4203
|
isReversedRelation = false;
|
|
4137
|
-
|
|
4204
|
+
if (debugConfig?.dataLoader) {
|
|
4205
|
+
console.log(`One-to-one relation: foreignKey=${foreignKeyName}, isReversed=${isReversedRelation}`);
|
|
4206
|
+
}
|
|
4138
4207
|
} else {
|
|
4139
4208
|
const fieldColumn = relationConfig.fields[0];
|
|
4140
4209
|
const referenceColumn = relationConfig.references[0];
|
|
@@ -4142,12 +4211,16 @@ async function loadRelationsWithDataLoader(mainResults, tableInfo, tables, relat
|
|
|
4142
4211
|
(key) => targetTable.columns[key] === referenceColumn
|
|
4143
4212
|
) || referenceColumn.name;
|
|
4144
4213
|
isReversedRelation = false;
|
|
4145
|
-
|
|
4214
|
+
if (debugConfig?.dataLoader) {
|
|
4215
|
+
console.log(`Many-to-one relation: foreignKey=${foreignKeyName}, isReversed=${isReversedRelation}`);
|
|
4216
|
+
}
|
|
4146
4217
|
}
|
|
4147
4218
|
} else if (relationConfig?.references && relationConfig.references.length > 0) {
|
|
4148
4219
|
foreignKeyName = relationConfig.references[0].name;
|
|
4149
4220
|
isReversedRelation = true;
|
|
4150
|
-
|
|
4221
|
+
if (debugConfig?.dataLoader) {
|
|
4222
|
+
console.log(`References-only relation: foreignKey=${foreignKeyName}, isReversed=${isReversedRelation}`);
|
|
4223
|
+
}
|
|
4151
4224
|
} else {
|
|
4152
4225
|
if ((0, import_drizzle_orm18.is)(relation, import_drizzle_orm18.One)) {
|
|
4153
4226
|
let possibleForeignKeys = Object.entries(targetTable.columns).filter(([name, col]) => {
|
|
@@ -4199,7 +4272,9 @@ async function loadRelationsWithDataLoader(mainResults, tableInfo, tables, relat
|
|
|
4199
4272
|
) || fieldColumn.name;
|
|
4200
4273
|
if (tableInfo.columns[fieldKeyName]) {
|
|
4201
4274
|
actualParentIds = mainResults.map((result) => result[fieldKeyName]).filter((id) => id != null);
|
|
4202
|
-
|
|
4275
|
+
if (debugConfig?.dataLoader) {
|
|
4276
|
+
console.log(`Extracted foreign key values for many-to-one relation:`, actualParentIds);
|
|
4277
|
+
}
|
|
4203
4278
|
}
|
|
4204
4279
|
}
|
|
4205
4280
|
const targetQueryBase = context.db?.query?.[targetTableName];
|
|
@@ -4212,9 +4287,13 @@ async function loadRelationsWithDataLoader(mainResults, tableInfo, tables, relat
|
|
|
4212
4287
|
targetTableName,
|
|
4213
4288
|
targetQueryBase,
|
|
4214
4289
|
targetTable,
|
|
4215
|
-
relations[targetTableName] || {}
|
|
4290
|
+
relations[targetTableName] || {},
|
|
4291
|
+
debugConfig
|
|
4292
|
+
// Pass debug config
|
|
4216
4293
|
);
|
|
4217
|
-
|
|
4294
|
+
if (debugConfig?.dataLoader) {
|
|
4295
|
+
console.log(`Created relation loader for ${targetTableName}, calling loadRelation with parentIds:`, actualParentIds);
|
|
4296
|
+
}
|
|
4218
4297
|
const relationPromise = relationLoader.loadRelation(
|
|
4219
4298
|
relName,
|
|
4220
4299
|
actualParentIds,
|
|
@@ -4222,7 +4301,9 @@ async function loadRelationsWithDataLoader(mainResults, tableInfo, tables, relat
|
|
|
4222
4301
|
relationOptions,
|
|
4223
4302
|
isReversedRelation
|
|
4224
4303
|
).then(async (relationResults) => {
|
|
4225
|
-
|
|
4304
|
+
if (debugConfig?.dataLoader) {
|
|
4305
|
+
console.log(`Relation ${relName} loaded, got ${relationResults.length} results:`, relationResults);
|
|
4306
|
+
}
|
|
4226
4307
|
const relationMap = /* @__PURE__ */ new Map();
|
|
4227
4308
|
for (const result of relationResults) {
|
|
4228
4309
|
relationMap.set(result.parentId, result.data);
|
|
@@ -4238,7 +4319,8 @@ async function loadRelationsWithDataLoader(mainResults, tableInfo, tables, relat
|
|
|
4238
4319
|
tables,
|
|
4239
4320
|
relations,
|
|
4240
4321
|
relationFields,
|
|
4241
|
-
context
|
|
4322
|
+
context,
|
|
4323
|
+
debugConfig
|
|
4242
4324
|
);
|
|
4243
4325
|
let dataIndex = 0;
|
|
4244
4326
|
for (const result of relationResults) {
|
|
@@ -4276,7 +4358,7 @@ async function loadRelationsWithDataLoader(mainResults, tableInfo, tables, relat
|
|
|
4276
4358
|
}
|
|
4277
4359
|
|
|
4278
4360
|
// src/build-schema-sdl-with-dl/generator/queries/index.ts
|
|
4279
|
-
var generateQueries2 = (db, tables, relations) => {
|
|
4361
|
+
var generateQueries2 = (db, tables, relations, debugConfig) => {
|
|
4280
4362
|
const queries = {};
|
|
4281
4363
|
for (const [tableName, tableInfo] of Object.entries(tables)) {
|
|
4282
4364
|
const queryBase = db.query[tableName];
|
|
@@ -4289,13 +4371,15 @@ var generateQueries2 = (db, tables, relations) => {
|
|
|
4289
4371
|
queryBase,
|
|
4290
4372
|
tableInfo,
|
|
4291
4373
|
tables,
|
|
4292
|
-
relations
|
|
4374
|
+
relations,
|
|
4375
|
+
debugConfig
|
|
4293
4376
|
);
|
|
4294
4377
|
queries[`${tableName}FindFirst`] = createDataLoaderFindFirstResolver(
|
|
4295
4378
|
queryBase,
|
|
4296
4379
|
tableInfo,
|
|
4297
4380
|
tables,
|
|
4298
|
-
relations
|
|
4381
|
+
relations,
|
|
4382
|
+
debugConfig
|
|
4299
4383
|
);
|
|
4300
4384
|
}
|
|
4301
4385
|
return queries;
|
|
@@ -4303,8 +4387,8 @@ var generateQueries2 = (db, tables, relations) => {
|
|
|
4303
4387
|
|
|
4304
4388
|
// src/build-schema-sdl-with-dl/generator/mutations/resolvers.ts
|
|
4305
4389
|
var import_graphql13 = require("graphql");
|
|
4306
|
-
var createInsertManyResolver2 = (db, queryBase, tableInfo, tables, relations, primaryKeyColumn) => {
|
|
4307
|
-
const queryResolver = createDataLoaderFindManyResolver(queryBase, tableInfo, tables, relations);
|
|
4390
|
+
var createInsertManyResolver2 = (db, queryBase, tableInfo, tables, relations, primaryKeyColumn, debugConfig) => {
|
|
4391
|
+
const queryResolver = createDataLoaderFindManyResolver(queryBase, tableInfo, tables, relations, debugConfig);
|
|
4308
4392
|
return async (parent, args, context, info) => {
|
|
4309
4393
|
try {
|
|
4310
4394
|
const { values } = args;
|
|
@@ -4340,8 +4424,8 @@ var createInsertManyResolver2 = (db, queryBase, tableInfo, tables, relations, pr
|
|
|
4340
4424
|
}
|
|
4341
4425
|
};
|
|
4342
4426
|
};
|
|
4343
|
-
var createUpdateManyResolver2 = (db, queryBase, tableInfo, tables, relations, primaryKeyColumn) => {
|
|
4344
|
-
const queryResolver = createDataLoaderFindManyResolver(queryBase, tableInfo, tables, relations);
|
|
4427
|
+
var createUpdateManyResolver2 = (db, queryBase, tableInfo, tables, relations, primaryKeyColumn, debugConfig) => {
|
|
4428
|
+
const queryResolver = createDataLoaderFindManyResolver(queryBase, tableInfo, tables, relations, debugConfig);
|
|
4345
4429
|
return async (parent, args, context, info) => {
|
|
4346
4430
|
try {
|
|
4347
4431
|
const { where, set } = args;
|
|
@@ -4379,8 +4463,8 @@ var createUpdateManyResolver2 = (db, queryBase, tableInfo, tables, relations, pr
|
|
|
4379
4463
|
}
|
|
4380
4464
|
};
|
|
4381
4465
|
};
|
|
4382
|
-
var createDeleteManyResolver2 = (db, queryBase, tableInfo, tables, relations, primaryKeyColumn) => {
|
|
4383
|
-
const queryResolver = createDataLoaderFindManyResolver(queryBase, tableInfo, tables, relations);
|
|
4466
|
+
var createDeleteManyResolver2 = (db, queryBase, tableInfo, tables, relations, primaryKeyColumn, debugConfig) => {
|
|
4467
|
+
const queryResolver = createDataLoaderFindManyResolver(queryBase, tableInfo, tables, relations, debugConfig);
|
|
4384
4468
|
return async (parent, args, context, info) => {
|
|
4385
4469
|
try {
|
|
4386
4470
|
const { where } = args;
|
|
@@ -4409,7 +4493,7 @@ var createDeleteManyResolver2 = (db, queryBase, tableInfo, tables, relations, pr
|
|
|
4409
4493
|
};
|
|
4410
4494
|
|
|
4411
4495
|
// src/build-schema-sdl-with-dl/generator/mutations/index.ts
|
|
4412
|
-
var generateMutations2 = (db, tables, relations) => {
|
|
4496
|
+
var generateMutations2 = (db, tables, relations, debugConfig) => {
|
|
4413
4497
|
const mutations = {};
|
|
4414
4498
|
const deleteResultResolvers = {};
|
|
4415
4499
|
for (const [tableName, tableInfo] of Object.entries(tables)) {
|
|
@@ -4434,7 +4518,8 @@ var generateMutations2 = (db, tables, relations) => {
|
|
|
4434
4518
|
tableInfo,
|
|
4435
4519
|
tables,
|
|
4436
4520
|
relations,
|
|
4437
|
-
primaryKeyColumn
|
|
4521
|
+
primaryKeyColumn,
|
|
4522
|
+
debugConfig
|
|
4438
4523
|
);
|
|
4439
4524
|
mutations[`${tableName}UpdateMany`] = createUpdateManyResolver2(
|
|
4440
4525
|
db,
|
|
@@ -4442,7 +4527,8 @@ var generateMutations2 = (db, tables, relations) => {
|
|
|
4442
4527
|
tableInfo,
|
|
4443
4528
|
tables,
|
|
4444
4529
|
relations,
|
|
4445
|
-
primaryKeyColumn
|
|
4530
|
+
primaryKeyColumn,
|
|
4531
|
+
debugConfig
|
|
4446
4532
|
);
|
|
4447
4533
|
mutations[`${tableName}DeleteMany`] = createDeleteManyResolver2(
|
|
4448
4534
|
db,
|
|
@@ -4450,7 +4536,8 @@ var generateMutations2 = (db, tables, relations) => {
|
|
|
4450
4536
|
tableInfo,
|
|
4451
4537
|
tables,
|
|
4452
4538
|
relations,
|
|
4453
|
-
primaryKeyColumn
|
|
4539
|
+
primaryKeyColumn,
|
|
4540
|
+
debugConfig
|
|
4454
4541
|
);
|
|
4455
4542
|
deleteResultResolvers[`${capitalizedName}DeleteResult`] = {
|
|
4456
4543
|
[`${tableName}FindMany`]: (parent, args, context, info) => {
|
|
@@ -4470,7 +4557,7 @@ var exportDirectiveTypeDefs = `directive @export(as: String!) on FIELD`;
|
|
|
4470
4557
|
|
|
4471
4558
|
// src/build-schema-sdl-with-dl/index.ts
|
|
4472
4559
|
var import_schema3 = require("@graphql-tools/schema");
|
|
4473
|
-
var buildSchemaSDL2 = (db) => {
|
|
4560
|
+
var buildSchemaSDL2 = (db, config) => {
|
|
4474
4561
|
const schema = db._.fullSchema;
|
|
4475
4562
|
if (!schema) {
|
|
4476
4563
|
throw new Error(
|
|
@@ -4488,11 +4575,12 @@ var buildSchemaSDL2 = (db) => {
|
|
|
4488
4575
|
typeDefsArray.push(generateQueryTypeDefs2(tables));
|
|
4489
4576
|
typeDefsArray.push(generateMutationTypeDefs2(tables));
|
|
4490
4577
|
const typeDefs = typeDefsArray.join("\n\n");
|
|
4491
|
-
const queries = generateQueries2(db, tables, relations);
|
|
4578
|
+
const queries = generateQueries2(db, tables, relations, config?.debug);
|
|
4492
4579
|
const { mutations, deleteResultResolvers } = generateMutations2(
|
|
4493
4580
|
db,
|
|
4494
4581
|
tables,
|
|
4495
|
-
relations
|
|
4582
|
+
relations,
|
|
4583
|
+
config?.debug
|
|
4496
4584
|
);
|
|
4497
4585
|
const resolvers = {
|
|
4498
4586
|
Query: queries,
|
|
@@ -4633,6 +4721,7 @@ var ExportStore = class {
|
|
|
4633
4721
|
};
|
|
4634
4722
|
|
|
4635
4723
|
// src/export-tool/middleware.ts
|
|
4724
|
+
init_utils();
|
|
4636
4725
|
function createExportMiddleware() {
|
|
4637
4726
|
return (next) => {
|
|
4638
4727
|
return async (source, args, context, info) => {
|
|
@@ -4679,6 +4768,9 @@ function createExportMiddleware() {
|
|
|
4679
4768
|
};
|
|
4680
4769
|
}
|
|
4681
4770
|
|
|
4771
|
+
// src/export-tool/index.ts
|
|
4772
|
+
init_utils();
|
|
4773
|
+
|
|
4682
4774
|
// src/export-tool/makeScalarAcceptExports.ts
|
|
4683
4775
|
var import_graphql14 = require("graphql");
|
|
4684
4776
|
function makeScalarAcceptExports(originalScalar) {
|