drizzle-graphql-plus 0.8.10 → 0.8.12
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 +68 -9
- package/index.cjs.map +1 -1
- package/index.js +68 -9
- package/index.js.map +1 -1
- package/package.json +2 -2
package/index.cjs
CHANGED
|
@@ -278,9 +278,25 @@ var extractSelectedColumnsFromTree = (tree, table) => {
|
|
|
278
278
|
const treeEntries = Object.entries(tree);
|
|
279
279
|
const selectedColumns = [];
|
|
280
280
|
for (const [fieldName, fieldData] of treeEntries) {
|
|
281
|
-
if (
|
|
281
|
+
if (tableColumns[fieldData.name]) {
|
|
282
|
+
selectedColumns.push([fieldData.name, true]);
|
|
282
283
|
continue;
|
|
283
|
-
|
|
284
|
+
}
|
|
285
|
+
if (fieldData.fieldsByTypeName) {
|
|
286
|
+
for (const [typeName, typeFields] of Object.entries(
|
|
287
|
+
fieldData.fieldsByTypeName
|
|
288
|
+
)) {
|
|
289
|
+
if (typeName.endsWith("Fields")) {
|
|
290
|
+
for (const [subFieldName, subFieldData] of Object.entries(
|
|
291
|
+
typeFields
|
|
292
|
+
)) {
|
|
293
|
+
if (tableColumns[subFieldData.name]) {
|
|
294
|
+
selectedColumns.push([subFieldData.name, true]);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
284
300
|
}
|
|
285
301
|
if (!selectedColumns.length) {
|
|
286
302
|
const columnKeys = Object.entries(tableColumns);
|
|
@@ -296,9 +312,28 @@ var extractSelectedColumnsFromTreeSQLFormat = (tree, table) => {
|
|
|
296
312
|
const treeEntries = Object.entries(tree);
|
|
297
313
|
const selectedColumns = [];
|
|
298
314
|
for (const [fieldName, fieldData] of treeEntries) {
|
|
299
|
-
if (
|
|
315
|
+
if (tableColumns[fieldData.name]) {
|
|
316
|
+
selectedColumns.push([fieldData.name, tableColumns[fieldData.name]]);
|
|
300
317
|
continue;
|
|
301
|
-
|
|
318
|
+
}
|
|
319
|
+
if (fieldData.fieldsByTypeName) {
|
|
320
|
+
for (const [typeName, typeFields] of Object.entries(
|
|
321
|
+
fieldData.fieldsByTypeName
|
|
322
|
+
)) {
|
|
323
|
+
if (typeName.endsWith("Fields")) {
|
|
324
|
+
for (const [subFieldName, subFieldData] of Object.entries(
|
|
325
|
+
typeFields
|
|
326
|
+
)) {
|
|
327
|
+
if (tableColumns[subFieldData.name]) {
|
|
328
|
+
selectedColumns.push([
|
|
329
|
+
subFieldData.name,
|
|
330
|
+
tableColumns[subFieldData.name]
|
|
331
|
+
]);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
302
337
|
}
|
|
303
338
|
if (!selectedColumns.length) {
|
|
304
339
|
const columnKeys = Object.entries(tableColumns);
|
|
@@ -495,6 +530,24 @@ var generateTableFilterTypeCached = (table, tableName) => {
|
|
|
495
530
|
filterTypeMap.set(table, filters);
|
|
496
531
|
return filters;
|
|
497
532
|
};
|
|
533
|
+
var interfaceTypeMap = /* @__PURE__ */ new WeakMap();
|
|
534
|
+
var generateTableInterfaceTypeCached = (table, tableName) => {
|
|
535
|
+
if (interfaceTypeMap.has(table))
|
|
536
|
+
return interfaceTypeMap.get(table);
|
|
537
|
+
const tableFields = generateTableSelectTypeFieldsCached(table, tableName);
|
|
538
|
+
const interfaceType = new import_graphql3.GraphQLInterfaceType({
|
|
539
|
+
name: `${capitalize(tableName)}Fields`,
|
|
540
|
+
fields: tableFields,
|
|
541
|
+
resolveType(obj) {
|
|
542
|
+
if (obj.__typename) {
|
|
543
|
+
return obj.__typename;
|
|
544
|
+
}
|
|
545
|
+
return null;
|
|
546
|
+
}
|
|
547
|
+
});
|
|
548
|
+
interfaceTypeMap.set(table, interfaceType);
|
|
549
|
+
return interfaceType;
|
|
550
|
+
};
|
|
498
551
|
var generateSelectFields = (tables, tableName, relationMap, typeName, withOrder, relationsDepthLimit, currentDepth = 0, usedTables = /* @__PURE__ */ new Set()) => {
|
|
499
552
|
const relations = relationMap[tableName];
|
|
500
553
|
const relationEntries = relations ? Object.entries(relations) : [];
|
|
@@ -526,9 +579,15 @@ var generateSelectFields = (tables, tableName, relationMap, typeName, withOrder,
|
|
|
526
579
|
newDepth,
|
|
527
580
|
updatedUsedTables
|
|
528
581
|
);
|
|
582
|
+
const targetTable = tables[targetTableName];
|
|
583
|
+
const targetInterface = generateTableInterfaceTypeCached(
|
|
584
|
+
targetTable,
|
|
585
|
+
targetTableName
|
|
586
|
+
);
|
|
529
587
|
const relType = new import_graphql3.GraphQLObjectType({
|
|
530
588
|
name: relTypeName,
|
|
531
|
-
fields: { ...relData.tableFields, ...relData.relationFields }
|
|
589
|
+
fields: { ...relData.tableFields, ...relData.relationFields },
|
|
590
|
+
interfaces: [targetInterface]
|
|
532
591
|
});
|
|
533
592
|
if (isOne) {
|
|
534
593
|
rawRelationFields.push([
|
|
@@ -606,10 +665,10 @@ var generateTableTypes = (tableName, tables, relationMap, withReturning, relatio
|
|
|
606
665
|
name: `${stylizedName}InsertInput`,
|
|
607
666
|
fields: insertFields
|
|
608
667
|
});
|
|
609
|
-
const tableFieldsInterface =
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
668
|
+
const tableFieldsInterface = generateTableInterfaceTypeCached(
|
|
669
|
+
table,
|
|
670
|
+
tableName
|
|
671
|
+
);
|
|
613
672
|
const selectSingleOutput = new import_graphql3.GraphQLObjectType({
|
|
614
673
|
name: `${stylizedName}SelectItem`,
|
|
615
674
|
fields: { ...tableFields, ...relationFields },
|