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.js
CHANGED
|
@@ -311,9 +311,25 @@ var extractSelectedColumnsFromTree = (tree, table) => {
|
|
|
311
311
|
const treeEntries = Object.entries(tree);
|
|
312
312
|
const selectedColumns = [];
|
|
313
313
|
for (const [fieldName, fieldData] of treeEntries) {
|
|
314
|
-
if (
|
|
314
|
+
if (tableColumns[fieldData.name]) {
|
|
315
|
+
selectedColumns.push([fieldData.name, true]);
|
|
315
316
|
continue;
|
|
316
|
-
|
|
317
|
+
}
|
|
318
|
+
if (fieldData.fieldsByTypeName) {
|
|
319
|
+
for (const [typeName, typeFields] of Object.entries(
|
|
320
|
+
fieldData.fieldsByTypeName
|
|
321
|
+
)) {
|
|
322
|
+
if (typeName.endsWith("Fields")) {
|
|
323
|
+
for (const [subFieldName, subFieldData] of Object.entries(
|
|
324
|
+
typeFields
|
|
325
|
+
)) {
|
|
326
|
+
if (tableColumns[subFieldData.name]) {
|
|
327
|
+
selectedColumns.push([subFieldData.name, true]);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
317
333
|
}
|
|
318
334
|
if (!selectedColumns.length) {
|
|
319
335
|
const columnKeys = Object.entries(tableColumns);
|
|
@@ -329,9 +345,28 @@ var extractSelectedColumnsFromTreeSQLFormat = (tree, table) => {
|
|
|
329
345
|
const treeEntries = Object.entries(tree);
|
|
330
346
|
const selectedColumns = [];
|
|
331
347
|
for (const [fieldName, fieldData] of treeEntries) {
|
|
332
|
-
if (
|
|
348
|
+
if (tableColumns[fieldData.name]) {
|
|
349
|
+
selectedColumns.push([fieldData.name, tableColumns[fieldData.name]]);
|
|
333
350
|
continue;
|
|
334
|
-
|
|
351
|
+
}
|
|
352
|
+
if (fieldData.fieldsByTypeName) {
|
|
353
|
+
for (const [typeName, typeFields] of Object.entries(
|
|
354
|
+
fieldData.fieldsByTypeName
|
|
355
|
+
)) {
|
|
356
|
+
if (typeName.endsWith("Fields")) {
|
|
357
|
+
for (const [subFieldName, subFieldData] of Object.entries(
|
|
358
|
+
typeFields
|
|
359
|
+
)) {
|
|
360
|
+
if (tableColumns[subFieldData.name]) {
|
|
361
|
+
selectedColumns.push([
|
|
362
|
+
subFieldData.name,
|
|
363
|
+
tableColumns[subFieldData.name]
|
|
364
|
+
]);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
335
370
|
}
|
|
336
371
|
if (!selectedColumns.length) {
|
|
337
372
|
const columnKeys = Object.entries(tableColumns);
|
|
@@ -528,6 +563,24 @@ var generateTableFilterTypeCached = (table, tableName) => {
|
|
|
528
563
|
filterTypeMap.set(table, filters);
|
|
529
564
|
return filters;
|
|
530
565
|
};
|
|
566
|
+
var interfaceTypeMap = /* @__PURE__ */ new WeakMap();
|
|
567
|
+
var generateTableInterfaceTypeCached = (table, tableName) => {
|
|
568
|
+
if (interfaceTypeMap.has(table))
|
|
569
|
+
return interfaceTypeMap.get(table);
|
|
570
|
+
const tableFields = generateTableSelectTypeFieldsCached(table, tableName);
|
|
571
|
+
const interfaceType = new GraphQLInterfaceType({
|
|
572
|
+
name: `${capitalize(tableName)}Fields`,
|
|
573
|
+
fields: tableFields,
|
|
574
|
+
resolveType(obj) {
|
|
575
|
+
if (obj.__typename) {
|
|
576
|
+
return obj.__typename;
|
|
577
|
+
}
|
|
578
|
+
return null;
|
|
579
|
+
}
|
|
580
|
+
});
|
|
581
|
+
interfaceTypeMap.set(table, interfaceType);
|
|
582
|
+
return interfaceType;
|
|
583
|
+
};
|
|
531
584
|
var generateSelectFields = (tables, tableName, relationMap, typeName, withOrder, relationsDepthLimit, currentDepth = 0, usedTables = /* @__PURE__ */ new Set()) => {
|
|
532
585
|
const relations = relationMap[tableName];
|
|
533
586
|
const relationEntries = relations ? Object.entries(relations) : [];
|
|
@@ -559,9 +612,15 @@ var generateSelectFields = (tables, tableName, relationMap, typeName, withOrder,
|
|
|
559
612
|
newDepth,
|
|
560
613
|
updatedUsedTables
|
|
561
614
|
);
|
|
615
|
+
const targetTable = tables[targetTableName];
|
|
616
|
+
const targetInterface = generateTableInterfaceTypeCached(
|
|
617
|
+
targetTable,
|
|
618
|
+
targetTableName
|
|
619
|
+
);
|
|
562
620
|
const relType = new GraphQLObjectType2({
|
|
563
621
|
name: relTypeName,
|
|
564
|
-
fields: { ...relData.tableFields, ...relData.relationFields }
|
|
622
|
+
fields: { ...relData.tableFields, ...relData.relationFields },
|
|
623
|
+
interfaces: [targetInterface]
|
|
565
624
|
});
|
|
566
625
|
if (isOne) {
|
|
567
626
|
rawRelationFields.push([
|
|
@@ -639,10 +698,10 @@ var generateTableTypes = (tableName, tables, relationMap, withReturning, relatio
|
|
|
639
698
|
name: `${stylizedName}InsertInput`,
|
|
640
699
|
fields: insertFields
|
|
641
700
|
});
|
|
642
|
-
const tableFieldsInterface =
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
701
|
+
const tableFieldsInterface = generateTableInterfaceTypeCached(
|
|
702
|
+
table,
|
|
703
|
+
tableName
|
|
704
|
+
);
|
|
646
705
|
const selectSingleOutput = new GraphQLObjectType2({
|
|
647
706
|
name: `${stylizedName}SelectItem`,
|
|
648
707
|
fields: { ...tableFields, ...relationFields },
|