@vantreeseba/drizzle-graphql 6.0.0 → 7.1.0
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/README.md +372 -10
- package/dist/README.md +372 -10
- package/dist/index.cjs +1029 -447
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +132 -2
- package/dist/index.d.ts +132 -2
- package/dist/index.js +935 -343
- package/dist/index.js.map +1 -1
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -45,15 +45,15 @@ __export(index_exports, {
|
|
|
45
45
|
extractRelationJoinColumns: () => extractRelationJoinColumns
|
|
46
46
|
});
|
|
47
47
|
module.exports = __toCommonJS(index_exports);
|
|
48
|
-
var
|
|
48
|
+
var import_drizzle_orm10 = require("drizzle-orm");
|
|
49
49
|
var import_mysql_core3 = require("drizzle-orm/mysql-core");
|
|
50
50
|
var import_pg_core3 = require("drizzle-orm/pg-core");
|
|
51
51
|
var import_sqlite_core3 = require("drizzle-orm/sqlite-core");
|
|
52
|
-
var
|
|
52
|
+
var import_graphql11 = require("graphql");
|
|
53
53
|
|
|
54
54
|
// src/util/builders/common.ts
|
|
55
|
-
var
|
|
56
|
-
var
|
|
55
|
+
var import_drizzle_orm4 = require("drizzle-orm");
|
|
56
|
+
var import_graphql5 = require("graphql");
|
|
57
57
|
|
|
58
58
|
// src/util/batch-loader/index.ts
|
|
59
59
|
var DRIZZLE_LOADERS_KEY = /* @__PURE__ */ Symbol("drizzle-graphql-loaders");
|
|
@@ -593,6 +593,124 @@ var remapFromGraphQLArrayInput = (queryInput, table) => {
|
|
|
593
593
|
return queryInput;
|
|
594
594
|
};
|
|
595
595
|
|
|
596
|
+
// src/util/builders/field-updates.ts
|
|
597
|
+
var import_drizzle_orm3 = require("drizzle-orm");
|
|
598
|
+
var import_graphql4 = require("graphql");
|
|
599
|
+
var NUMERIC_SCALARS = /* @__PURE__ */ new Set([
|
|
600
|
+
import_graphql4.GraphQLInt,
|
|
601
|
+
import_graphql4.GraphQLFloat,
|
|
602
|
+
GraphQLBigIntString,
|
|
603
|
+
GraphQLDecimalString
|
|
604
|
+
]);
|
|
605
|
+
var NON_LIST_ARRAY_COLUMNS = /* @__PURE__ */ new Set(["PgVector", "PgGeometry", "PgBytea"]);
|
|
606
|
+
var kindCache = /* @__PURE__ */ new WeakMap();
|
|
607
|
+
var fieldUpdateKind = (column, columnName, tableName) => {
|
|
608
|
+
const cached = kindCache.get(column);
|
|
609
|
+
if (cached) {
|
|
610
|
+
return cached;
|
|
611
|
+
}
|
|
612
|
+
let kind = "none";
|
|
613
|
+
if (!getColumnScalarOverride(column, true)) {
|
|
614
|
+
const { type } = drizzleColumnToGraphQLType(column, columnName, tableName, true, false, true);
|
|
615
|
+
if (NUMERIC_SCALARS.has(type)) {
|
|
616
|
+
kind = "numeric";
|
|
617
|
+
} else if (type instanceof import_graphql4.GraphQLList && !NON_LIST_ARRAY_COLUMNS.has(column.columnType)) {
|
|
618
|
+
kind = "list";
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
kindCache.set(column, kind);
|
|
622
|
+
return kind;
|
|
623
|
+
};
|
|
624
|
+
var inputCache = /* @__PURE__ */ new Map();
|
|
625
|
+
var namedFieldUpdateInput = (name, fields, description) => {
|
|
626
|
+
const cached = inputCache.get(name);
|
|
627
|
+
if (cached) {
|
|
628
|
+
return cached;
|
|
629
|
+
}
|
|
630
|
+
const input = new import_graphql4.GraphQLInputObjectType({ name, description, fields: fields() });
|
|
631
|
+
inputCache.set(name, input);
|
|
632
|
+
return input;
|
|
633
|
+
};
|
|
634
|
+
var fieldUpdateInputType = (column, columnName, tableName) => {
|
|
635
|
+
const kind = fieldUpdateKind(column, columnName, tableName);
|
|
636
|
+
if (kind === "none") {
|
|
637
|
+
return void 0;
|
|
638
|
+
}
|
|
639
|
+
const { type } = drizzleColumnToGraphQLType(column, columnName, tableName, true, false, true);
|
|
640
|
+
if (kind === "numeric") {
|
|
641
|
+
const scalar = type;
|
|
642
|
+
return namedFieldUpdateInput(
|
|
643
|
+
`${scalar.name}FieldUpdate`,
|
|
644
|
+
() => ({
|
|
645
|
+
set: { type: scalar, description: "Replace the current value with this one" },
|
|
646
|
+
increment: { type: scalar, description: "Add this to the current value (SQL `column + value`)" },
|
|
647
|
+
decrement: { type: scalar, description: "Subtract this from the current value (SQL `column - value`)" },
|
|
648
|
+
multiply: { type: scalar, description: "Multiply the current value by this (SQL `column * value`)" },
|
|
649
|
+
divide: {
|
|
650
|
+
type: scalar,
|
|
651
|
+
description: "Divide the current value by this (SQL `column / value`), rounding as the database does"
|
|
652
|
+
}
|
|
653
|
+
}),
|
|
654
|
+
`An update to a ${scalar.name} column: exactly one of these operations`
|
|
655
|
+
);
|
|
656
|
+
}
|
|
657
|
+
const list = type;
|
|
658
|
+
const element = list.ofType;
|
|
659
|
+
const elementName = element instanceof import_graphql4.GraphQLNonNull ? String(element.ofType) : String(element);
|
|
660
|
+
return namedFieldUpdateInput(
|
|
661
|
+
`${elementName}ListFieldUpdate`,
|
|
662
|
+
() => ({
|
|
663
|
+
set: { type: list, description: "Replace the current array with this one" },
|
|
664
|
+
push: { type: list, description: "Append these elements to the current array" }
|
|
665
|
+
}),
|
|
666
|
+
`An update to a ${elementName} array column: exactly one of these operations`
|
|
667
|
+
);
|
|
668
|
+
};
|
|
669
|
+
var OPERATIONS = ["set", "increment", "decrement", "multiply", "divide", "push"];
|
|
670
|
+
var singleOperation = (value, columnName) => {
|
|
671
|
+
const given = OPERATIONS.filter((operation) => value[operation] !== void 0);
|
|
672
|
+
if (given.length === 1) {
|
|
673
|
+
return [given[0], value[given[0]]];
|
|
674
|
+
}
|
|
675
|
+
throw new import_graphql4.GraphQLError(
|
|
676
|
+
given.length ? `Field '${columnName}' takes exactly one update operation, but ${given.length} were given (${given.join(", ")}).` : `Field '${columnName}' was given no update operation. Pass exactly one of ${OPERATIONS.join(", ")}.`
|
|
677
|
+
);
|
|
678
|
+
};
|
|
679
|
+
var splitFieldUpdateOperations = (values, table, tableName) => {
|
|
680
|
+
const cols = (0, import_drizzle_orm3.getColumns)(table);
|
|
681
|
+
const columns = {};
|
|
682
|
+
const expressions = {};
|
|
683
|
+
for (const [columnName, value] of Object.entries(values)) {
|
|
684
|
+
const column = cols[columnName];
|
|
685
|
+
if (!column || value === null || value === void 0) {
|
|
686
|
+
columns[columnName] = value;
|
|
687
|
+
continue;
|
|
688
|
+
}
|
|
689
|
+
const isOperations = typeof value === "object" && !Array.isArray(value) && !(value instanceof Date);
|
|
690
|
+
if (!isOperations || fieldUpdateKind(column, columnName, tableName) === "none") {
|
|
691
|
+
columns[columnName] = value;
|
|
692
|
+
continue;
|
|
693
|
+
}
|
|
694
|
+
const [operation, operand] = singleOperation(value, columnName);
|
|
695
|
+
if (operation === "set") {
|
|
696
|
+
columns[columnName] = operand;
|
|
697
|
+
continue;
|
|
698
|
+
}
|
|
699
|
+
const param = import_drizzle_orm3.sql.param(remapFromGraphQLCore(operand, column, columnName), column);
|
|
700
|
+
expressions[columnName] = operation === "increment" ? import_drizzle_orm3.sql`${column} + ${param}` : operation === "decrement" ? import_drizzle_orm3.sql`${column} - ${param}` : operation === "multiply" ? import_drizzle_orm3.sql`${column} * ${param}` : operation === "divide" ? import_drizzle_orm3.sql`${column} / ${param}` : (
|
|
701
|
+
// `push`: array concatenation, which is the only dialect-specific operation
|
|
702
|
+
// here — and arrays are a PostgreSQL column type to begin with.
|
|
703
|
+
import_drizzle_orm3.sql`${column} || ${param}`
|
|
704
|
+
);
|
|
705
|
+
}
|
|
706
|
+
return { columns, expressions };
|
|
707
|
+
};
|
|
708
|
+
var remapUpdateInput = (values, table, tableName) => {
|
|
709
|
+
const { columns, expressions } = splitFieldUpdateOperations(values, table, tableName);
|
|
710
|
+
const remapped = remapFromGraphQLSingleInput(columns, table);
|
|
711
|
+
return Object.keys(expressions).length ? { ...remapped, ...expressions } : remapped;
|
|
712
|
+
};
|
|
713
|
+
|
|
596
714
|
// src/util/builders/common.ts
|
|
597
715
|
var rqbCrashTypes = ["SQLiteBigInt", "SQLiteBlobJson", "SQLiteBlobBuffer"];
|
|
598
716
|
var resolveTypeName = (name, typeNameMapper) => {
|
|
@@ -655,9 +773,9 @@ var extractRelationJoinColumns = (relEntry, parentTable, targetTable) => {
|
|
|
655
773
|
}
|
|
656
774
|
const sourceCol = sourceColumns[0];
|
|
657
775
|
const targetCol = targetColumns[0];
|
|
658
|
-
const parentCols = (0,
|
|
776
|
+
const parentCols = (0, import_drizzle_orm4.getColumns)(parentTable);
|
|
659
777
|
const localColPropName = Object.entries(parentCols).find(([, c]) => c === sourceCol)?.[0];
|
|
660
|
-
const targetCols = (0,
|
|
778
|
+
const targetCols = (0, import_drizzle_orm4.getColumns)(targetTable);
|
|
661
779
|
const foreignColPropName = Object.entries(targetCols).find(([, c]) => c === targetCol)?.[0];
|
|
662
780
|
if (!localColPropName || !foreignColPropName) {
|
|
663
781
|
return void 0;
|
|
@@ -739,7 +857,7 @@ var collectRootMutationKeys = (selectionSet, fragments, variables, known, keys,
|
|
|
739
857
|
}
|
|
740
858
|
return true;
|
|
741
859
|
};
|
|
742
|
-
var abortedBatchError = () => new
|
|
860
|
+
var abortedBatchError = () => new import_graphql5.GraphQLError(
|
|
743
861
|
"Drizzle-GraphQL Error: Mutation was not executed because an earlier mutation in the same request failed and the shared transaction was rolled back."
|
|
744
862
|
);
|
|
745
863
|
var openSharedTx = (db, context, txCtx, stateKey, expected) => {
|
|
@@ -797,7 +915,7 @@ var openSharedTx = (db, context, txCtx, stateKey, expected) => {
|
|
|
797
915
|
}
|
|
798
916
|
timer = setTimeout(() => {
|
|
799
917
|
state.abort(
|
|
800
|
-
new
|
|
918
|
+
new import_graphql5.GraphQLError(
|
|
801
919
|
`Drizzle-GraphQL Error: Shared mutation transaction timed out after ${txCtx.timeoutMs}ms waiting for the remaining mutation fields; rolling back.`
|
|
802
920
|
)
|
|
803
921
|
);
|
|
@@ -879,27 +997,27 @@ var runMutation = async (db, context, info, txCtx, body) => {
|
|
|
879
997
|
return runOnSharedTx(state, body);
|
|
880
998
|
};
|
|
881
999
|
var batchedPaginatedRelationQuery = async (db, targetTable, foreignCol, whereCondition, orderByArg, limit, offset, pkNames, orderCtx) => {
|
|
882
|
-
const cols = (0,
|
|
1000
|
+
const cols = (0, import_drizzle_orm4.getColumns)(targetTable);
|
|
883
1001
|
const orderExprs = [
|
|
884
1002
|
...orderByArg ? extractOrderBy(targetTable, orderByArg, orderCtx) : [],
|
|
885
1003
|
...primaryKeyOrderExprs(targetTable, pkNames)
|
|
886
1004
|
];
|
|
887
|
-
const orderClause = orderExprs.length ?
|
|
1005
|
+
const orderClause = orderExprs.length ? import_drizzle_orm4.sql` order by ${import_drizzle_orm4.sql.join(orderExprs, import_drizzle_orm4.sql`, `)}` : import_drizzle_orm4.sql``;
|
|
888
1006
|
const RN = "__drizzle_graphql_rn";
|
|
889
|
-
const rowNumber =
|
|
1007
|
+
const rowNumber = import_drizzle_orm4.sql`row_number() over (partition by ${foreignCol}${orderClause})`.as(RN);
|
|
890
1008
|
const sub = db.select({ ...cols, [RN]: rowNumber }).from(targetTable).where(whereCondition).as("__paginated");
|
|
891
1009
|
const lower = offset ?? 0;
|
|
892
|
-
const windowConds = [(0,
|
|
1010
|
+
const windowConds = [(0, import_drizzle_orm4.gt)(sub[RN], lower)];
|
|
893
1011
|
if (limit != null) {
|
|
894
|
-
windowConds.push((0,
|
|
1012
|
+
windowConds.push((0, import_drizzle_orm4.lte)(sub[RN], lower + limit));
|
|
895
1013
|
}
|
|
896
|
-
const rows = await db.select().from(sub).where((0,
|
|
1014
|
+
const rows = await db.select().from(sub).where((0, import_drizzle_orm4.and)(...windowConds)).orderBy(sub[RN]);
|
|
897
1015
|
for (const row of rows) {
|
|
898
1016
|
delete row[RN];
|
|
899
1017
|
}
|
|
900
1018
|
return rows;
|
|
901
1019
|
};
|
|
902
|
-
var createRelationResolverFactory = (db, tables, filterCtx) => ({ tableName, relationName, relEntry, isOne }) => {
|
|
1020
|
+
var createRelationResolverFactory = (db, tables, nullOrdering, filterCtx, limits) => ({ tableName, relationName, relEntry, isOne }) => {
|
|
903
1021
|
const parentTable = tables[tableName];
|
|
904
1022
|
const targetTableName = relEntry.targetTableName;
|
|
905
1023
|
const targetTable = tables[targetTableName];
|
|
@@ -911,8 +1029,9 @@ var createRelationResolverFactory = (db, tables, filterCtx) => ({ tableName, rel
|
|
|
911
1029
|
return void 0;
|
|
912
1030
|
}
|
|
913
1031
|
const { localColPropName, foreignCol, foreignColPropName } = joinCols;
|
|
1032
|
+
const limitPolicy = isOne ? void 0 : limits?.(targetTableName);
|
|
914
1033
|
const targetPkNames = relEntry.targetPkNames ?? [];
|
|
915
|
-
return async (parent, args, context) => {
|
|
1034
|
+
return async (parent, args, context, info) => {
|
|
916
1035
|
if (parent[relationName] !== void 0) {
|
|
917
1036
|
return parent[relationName];
|
|
918
1037
|
}
|
|
@@ -920,21 +1039,66 @@ var createRelationResolverFactory = (db, tables, filterCtx) => ({ tableName, rel
|
|
|
920
1039
|
if (localValue == null) {
|
|
921
1040
|
return isOne ? null : [];
|
|
922
1041
|
}
|
|
923
|
-
const { where: whereArg, orderBy: orderByArg, limit, offset } = args ?? {};
|
|
1042
|
+
const { where: whereArg, orderBy: orderByArg, limit: requestedLimit, offset, after } = args ?? {};
|
|
1043
|
+
const limit = applyLimitPolicy(requestedLimit, limitPolicy, `${tableName}.${relationName}`);
|
|
1044
|
+
const distinct = (args ?? {}).distinct?.length ? (args ?? {}).distinct : void 0;
|
|
1045
|
+
const cursorSelected = !isOne && !!info && selectsCursorField(info, targetTable);
|
|
1046
|
+
let cursorEntries;
|
|
1047
|
+
if (!isOne && (after != null || cursorSelected)) {
|
|
1048
|
+
if (after != null && distinct) {
|
|
1049
|
+
throw new import_graphql5.GraphQLError("'after' cannot be combined with 'distinct'.");
|
|
1050
|
+
}
|
|
1051
|
+
if (orderByHasRelationEntry(orderByArg)) {
|
|
1052
|
+
if (after != null) {
|
|
1053
|
+
throw new import_graphql5.GraphQLError(
|
|
1054
|
+
"'after' cannot be combined with an orderBy that orders through a relation \u2014 a related row's value cannot be encoded into a cursor."
|
|
1055
|
+
);
|
|
1056
|
+
}
|
|
1057
|
+
} else if (!targetPkNames.length) {
|
|
1058
|
+
if (after != null) {
|
|
1059
|
+
throw new import_graphql5.GraphQLError(
|
|
1060
|
+
`Table ${targetTableName} has no primary key, so cursor pagination cannot be used on it.`
|
|
1061
|
+
);
|
|
1062
|
+
}
|
|
1063
|
+
} else {
|
|
1064
|
+
cursorEntries = cursorOrderingEntries(orderByArg, targetPkNames);
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
const cursorValues = after != null && cursorEntries ? decodeCursor(after, cursorEntries) : void 0;
|
|
924
1068
|
const argsKey = JSON.stringify({
|
|
925
1069
|
where: whereArg ?? null,
|
|
926
1070
|
orderBy: orderByArg ?? null,
|
|
927
1071
|
limit: limit ?? null,
|
|
928
|
-
offset: offset ?? null
|
|
1072
|
+
offset: offset ?? null,
|
|
1073
|
+
after: after ?? null,
|
|
1074
|
+
distinct: distinct ?? null,
|
|
1075
|
+
cursor: cursorEntries ? 1 : 0
|
|
929
1076
|
});
|
|
930
1077
|
const loaderKey = `${tableName}::${relationName}::${argsKey}`;
|
|
931
1078
|
const loader = getOrCreateLoader(context, loaderKey, async (parentIds) => {
|
|
932
1079
|
const executor = resolveExecutor(db, context);
|
|
933
1080
|
const uniqueIds = [...new Set(parentIds)];
|
|
934
|
-
|
|
935
|
-
(0,
|
|
936
|
-
whereArg ? extractFilters(targetTable, targetTableName, whereArg, relationFilterCtx(filterCtx, targetTableName)) : void 0
|
|
1081
|
+
let whereCondition = (0, import_drizzle_orm4.and)(
|
|
1082
|
+
(0, import_drizzle_orm4.inArray)(foreignCol, uniqueIds),
|
|
1083
|
+
whereArg ? extractFilters(targetTable, targetTableName, whereArg, relationFilterCtx(filterCtx, targetTableName)) : void 0,
|
|
1084
|
+
cursorValues ? buildCursorCondition(targetTable, cursorEntries, cursorValues, nullOrdering) : void 0
|
|
937
1085
|
);
|
|
1086
|
+
if (distinct) {
|
|
1087
|
+
const keys = await selectDistinctKeys({
|
|
1088
|
+
db: executor,
|
|
1089
|
+
table: targetTable,
|
|
1090
|
+
tableName: targetTableName,
|
|
1091
|
+
distinct,
|
|
1092
|
+
pkNames: targetPkNames,
|
|
1093
|
+
where: whereCondition,
|
|
1094
|
+
orderBy: orderByArg,
|
|
1095
|
+
partitionBy: [foreignCol]
|
|
1096
|
+
});
|
|
1097
|
+
if (!keys.length) {
|
|
1098
|
+
return parentIds.map(() => isOne ? null : []);
|
|
1099
|
+
}
|
|
1100
|
+
whereCondition = (0, import_drizzle_orm4.and)(whereCondition, primaryKeyRestriction(targetTable, targetPkNames, keys));
|
|
1101
|
+
}
|
|
938
1102
|
let rows;
|
|
939
1103
|
if (limit != null || offset != null) {
|
|
940
1104
|
rows = await batchedPaginatedRelationQuery(
|
|
@@ -950,11 +1114,15 @@ var createRelationResolverFactory = (db, tables, filterCtx) => ({ tableName, rel
|
|
|
950
1114
|
);
|
|
951
1115
|
} else {
|
|
952
1116
|
let q = executor.select().from(targetTable).where(whereCondition);
|
|
953
|
-
|
|
954
|
-
|
|
1117
|
+
const orderExprs = cursorEntries ? cursorOrderExprs(targetTable, cursorEntries) : orderByArg ? extractOrderBy(targetTable, orderByArg, relationFilterCtx(filterCtx, targetTableName)) : [];
|
|
1118
|
+
if (orderExprs.length) {
|
|
1119
|
+
q = q.orderBy(...orderExprs);
|
|
955
1120
|
}
|
|
956
1121
|
rows = await q;
|
|
957
1122
|
}
|
|
1123
|
+
if (cursorEntries) {
|
|
1124
|
+
attachRowCursors(rows, cursorEntries);
|
|
1125
|
+
}
|
|
958
1126
|
if (isOne) {
|
|
959
1127
|
const byKey = new Map(rows.map((row) => [String(row[foreignColPropName]), row]));
|
|
960
1128
|
remapToGraphQLArrayOutput(rows, targetTableName, targetTable);
|
|
@@ -980,15 +1148,47 @@ var columnDocs = (docs, column, tableName, columnName) => {
|
|
|
980
1148
|
};
|
|
981
1149
|
var inputFieldDocs = (docs, column, tableName, columnName, fieldType) => {
|
|
982
1150
|
const resolved = columnDocs(docs, column, tableName, columnName);
|
|
983
|
-
if (resolved.deprecationReason !== void 0 && fieldType instanceof
|
|
1151
|
+
if (resolved.deprecationReason !== void 0 && fieldType instanceof import_graphql5.GraphQLNonNull) {
|
|
984
1152
|
const { deprecationReason: _dropped, ...rest } = resolved;
|
|
985
1153
|
return rest;
|
|
986
1154
|
}
|
|
987
1155
|
return resolved;
|
|
988
1156
|
};
|
|
989
|
-
var
|
|
1157
|
+
var applyLimitPolicy = (limit, policy, fieldName) => {
|
|
1158
|
+
if (!policy) {
|
|
1159
|
+
return limit ?? void 0;
|
|
1160
|
+
}
|
|
1161
|
+
const { defaultLimit, maxLimit, clampToMax } = policy;
|
|
1162
|
+
if (limit == null) {
|
|
1163
|
+
const fallback = defaultLimit ?? maxLimit;
|
|
1164
|
+
if (fallback === void 0) {
|
|
1165
|
+
return void 0;
|
|
1166
|
+
}
|
|
1167
|
+
return maxLimit === void 0 ? fallback : Math.min(fallback, maxLimit);
|
|
1168
|
+
}
|
|
1169
|
+
if (maxLimit !== void 0 && limit > maxLimit) {
|
|
1170
|
+
if (clampToMax) {
|
|
1171
|
+
return maxLimit;
|
|
1172
|
+
}
|
|
1173
|
+
throw new import_graphql5.GraphQLError(`${fieldName}: 'limit' of ${limit} exceeds the maximum of ${maxLimit}.`);
|
|
1174
|
+
}
|
|
1175
|
+
return limit;
|
|
1176
|
+
};
|
|
1177
|
+
var resolveLimitPolicy = (global, table) => {
|
|
1178
|
+
const defaultLimit = table?.defaultLimit ?? global?.defaultLimit;
|
|
1179
|
+
const maxLimit = table?.maxLimit ?? global?.maxLimit;
|
|
1180
|
+
if (defaultLimit === void 0 && maxLimit === void 0) {
|
|
1181
|
+
return void 0;
|
|
1182
|
+
}
|
|
1183
|
+
return { defaultLimit, maxLimit, clampToMax: table?.clampToMax ?? global?.clampToMax ?? false };
|
|
1184
|
+
};
|
|
1185
|
+
var listFieldComplexity = (options, policy) => ({ args, childComplexity }) => {
|
|
990
1186
|
const limit = args["limit"];
|
|
991
|
-
const
|
|
1187
|
+
const requested = typeof limit === "number" && limit > 0 ? limit : void 0;
|
|
1188
|
+
let rows = requested ?? policy?.defaultLimit ?? options.defaultListSize;
|
|
1189
|
+
if (policy?.maxLimit !== void 0) {
|
|
1190
|
+
rows = Math.min(rows, policy.maxLimit);
|
|
1191
|
+
}
|
|
992
1192
|
return rows * Math.max(childComplexity, 1);
|
|
993
1193
|
};
|
|
994
1194
|
var aggregateFieldComplexity = (options) => ({ childComplexity }) => options.aggregateCost + childComplexity;
|
|
@@ -1001,7 +1201,7 @@ var relationJoinColumns = (tree, table, selectionCtx) => {
|
|
|
1001
1201
|
if (!relations) {
|
|
1002
1202
|
return [];
|
|
1003
1203
|
}
|
|
1004
|
-
const tableColumns = (0,
|
|
1204
|
+
const tableColumns = (0, import_drizzle_orm4.getColumns)(table);
|
|
1005
1205
|
const needed = [];
|
|
1006
1206
|
for (const fieldData of Object.values(tree)) {
|
|
1007
1207
|
if (tableColumns[fieldData.name]) {
|
|
@@ -1020,7 +1220,7 @@ var relationJoinColumns = (tree, table, selectionCtx) => {
|
|
|
1020
1220
|
return needed;
|
|
1021
1221
|
};
|
|
1022
1222
|
var extractSelectedColumnsFromTree = (tree, table, selectionCtx) => {
|
|
1023
|
-
const tableColumns = (0,
|
|
1223
|
+
const tableColumns = (0, import_drizzle_orm4.getColumns)(table);
|
|
1024
1224
|
const treeEntries = Object.entries(tree);
|
|
1025
1225
|
const selectedColumns = [];
|
|
1026
1226
|
for (const [_fieldName, fieldData] of treeEntries) {
|
|
@@ -1040,7 +1240,7 @@ var extractSelectedColumnsFromTree = (tree, table, selectionCtx) => {
|
|
|
1040
1240
|
return Object.fromEntries(selectedColumns);
|
|
1041
1241
|
};
|
|
1042
1242
|
var extractSelectedColumnsFromTreeSQLFormat = (tree, table, selectionCtx) => {
|
|
1043
|
-
const tableColumns = (0,
|
|
1243
|
+
const tableColumns = (0, import_drizzle_orm4.getColumns)(table);
|
|
1044
1244
|
const treeEntries = Object.entries(tree);
|
|
1045
1245
|
const selectedColumns = [];
|
|
1046
1246
|
for (const [_fieldName, fieldData] of treeEntries) {
|
|
@@ -1059,7 +1259,7 @@ var extractSelectedColumnsFromTreeSQLFormat = (tree, table, selectionCtx) => {
|
|
|
1059
1259
|
}
|
|
1060
1260
|
return Object.fromEntries(selectedColumns);
|
|
1061
1261
|
};
|
|
1062
|
-
var orderNulls = new
|
|
1262
|
+
var orderNulls = new import_graphql5.GraphQLEnumType({
|
|
1063
1263
|
name: "OrderNulls",
|
|
1064
1264
|
description: "Where NULL values sort relative to non-NULL values",
|
|
1065
1265
|
values: {
|
|
@@ -1073,12 +1273,12 @@ var orderNulls = new import_graphql4.GraphQLEnumType({
|
|
|
1073
1273
|
}
|
|
1074
1274
|
}
|
|
1075
1275
|
});
|
|
1076
|
-
var innerOrder = new
|
|
1276
|
+
var innerOrder = new import_graphql5.GraphQLInputObjectType({
|
|
1077
1277
|
name: "InnerOrder",
|
|
1078
1278
|
fields: {
|
|
1079
1279
|
direction: {
|
|
1080
|
-
type: new
|
|
1081
|
-
new
|
|
1280
|
+
type: new import_graphql5.GraphQLNonNull(
|
|
1281
|
+
new import_graphql5.GraphQLEnumType({
|
|
1082
1282
|
name: "OrderDirection",
|
|
1083
1283
|
description: "Order by direction",
|
|
1084
1284
|
values: {
|
|
@@ -1095,7 +1295,7 @@ var innerOrder = new import_graphql4.GraphQLInputObjectType({
|
|
|
1095
1295
|
)
|
|
1096
1296
|
},
|
|
1097
1297
|
priority: {
|
|
1098
|
-
type: new
|
|
1298
|
+
type: new import_graphql5.GraphQLNonNull(import_graphql5.GraphQLInt),
|
|
1099
1299
|
description: "Priority of current field"
|
|
1100
1300
|
},
|
|
1101
1301
|
nulls: {
|
|
@@ -1121,9 +1321,9 @@ var resolveGenericFilterDescriptor = (column, columnGraphQLType) => {
|
|
|
1121
1321
|
if (columnGraphQLType.type === import_graphql_scalars.GraphQLJSON) {
|
|
1122
1322
|
return { name: "JSON", kind: "json" };
|
|
1123
1323
|
}
|
|
1124
|
-
if (columnGraphQLType.type instanceof
|
|
1324
|
+
if (columnGraphQLType.type instanceof import_graphql5.GraphQLList) {
|
|
1125
1325
|
let element = columnGraphQLType.type.ofType;
|
|
1126
|
-
if (element instanceof
|
|
1326
|
+
if (element instanceof import_graphql5.GraphQLNonNull) {
|
|
1127
1327
|
element = element.ofType;
|
|
1128
1328
|
}
|
|
1129
1329
|
return { name: `${element.name}Array`, kind: "array" };
|
|
@@ -1131,10 +1331,10 @@ var resolveGenericFilterDescriptor = (column, columnGraphQLType) => {
|
|
|
1131
1331
|
if (columnGraphQLType.type === import_graphql_scalars.GraphQLUUID) {
|
|
1132
1332
|
return { name: "Id", kind: "scalar" };
|
|
1133
1333
|
}
|
|
1134
|
-
if (columnGraphQLType.type ===
|
|
1334
|
+
if (columnGraphQLType.type === import_graphql5.GraphQLBoolean) {
|
|
1135
1335
|
return { name: "Boolean", kind: "scalar" };
|
|
1136
1336
|
}
|
|
1137
|
-
if (columnGraphQLType.type instanceof
|
|
1337
|
+
if (columnGraphQLType.type instanceof import_graphql5.GraphQLEnumType) {
|
|
1138
1338
|
return { name: columnGraphQLType.type.name, kind: "scalar" };
|
|
1139
1339
|
}
|
|
1140
1340
|
if (columnGraphQLType.type === GraphQLBigIntString) {
|
|
@@ -1147,10 +1347,10 @@ var resolveGenericFilterDescriptor = (column, columnGraphQLType) => {
|
|
|
1147
1347
|
if (ct === "PgTimestamp" || ct === "PgTimestampString" || ct === "PgDate") {
|
|
1148
1348
|
return { name: "DateTime", kind: "scalar" };
|
|
1149
1349
|
}
|
|
1150
|
-
if (columnGraphQLType.type ===
|
|
1350
|
+
if (columnGraphQLType.type === import_graphql5.GraphQLInt) {
|
|
1151
1351
|
return { name: "Int", kind: "scalar" };
|
|
1152
1352
|
}
|
|
1153
|
-
if (columnGraphQLType.type ===
|
|
1353
|
+
if (columnGraphQLType.type === import_graphql5.GraphQLFloat) {
|
|
1154
1354
|
return { name: "Float", kind: "scalar" };
|
|
1155
1355
|
}
|
|
1156
1356
|
return { name: "String", kind: "scalar" };
|
|
@@ -1166,37 +1366,37 @@ var jsonFilterFields = (column, colType) => {
|
|
|
1166
1366
|
description: "Value structurally contains this JSON (Postgres `@>` / MySQL JSON_CONTAINS)"
|
|
1167
1367
|
}
|
|
1168
1368
|
} : {},
|
|
1169
|
-
isNull: { type:
|
|
1170
|
-
isNotNull: { type:
|
|
1369
|
+
isNull: { type: import_graphql5.GraphQLBoolean },
|
|
1370
|
+
isNotNull: { type: import_graphql5.GraphQLBoolean }
|
|
1171
1371
|
};
|
|
1172
1372
|
};
|
|
1173
1373
|
var IN_ARRAY_DESCRIPTION = "Matches any one of these values (SQL `IN`)";
|
|
1174
1374
|
var NOT_IN_ARRAY_DESCRIPTION = "Matches none of these values (SQL `NOT IN`)";
|
|
1175
1375
|
var arrayFilterFields = (colType, colArr) => {
|
|
1176
1376
|
let element = colType.ofType;
|
|
1177
|
-
if (element instanceof
|
|
1377
|
+
if (element instanceof import_graphql5.GraphQLNonNull) {
|
|
1178
1378
|
element = element.ofType;
|
|
1179
1379
|
}
|
|
1180
|
-
const elementList = new
|
|
1380
|
+
const elementList = new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(element));
|
|
1181
1381
|
return {
|
|
1182
1382
|
eq: { type: colType, description: "The whole array equals this array" },
|
|
1183
1383
|
ne: { type: colType, description: "The whole array differs from this array" },
|
|
1184
1384
|
has: { type: element, description: "Array contains this element" },
|
|
1185
1385
|
hasSome: { type: elementList, description: "Array contains at least one of these elements (overlap, `&&`)" },
|
|
1186
1386
|
hasEvery: { type: elementList, description: "Array contains every one of these elements (containment, `@>`)" },
|
|
1187
|
-
isEmpty: { type:
|
|
1387
|
+
isEmpty: { type: import_graphql5.GraphQLBoolean, description: "When true, matches arrays with no elements" },
|
|
1188
1388
|
inArray: { type: colArr, description: IN_ARRAY_DESCRIPTION },
|
|
1189
1389
|
notInArray: { type: colArr, description: NOT_IN_ARRAY_DESCRIPTION },
|
|
1190
|
-
isNull: { type:
|
|
1191
|
-
isNotNull: { type:
|
|
1390
|
+
isNull: { type: import_graphql5.GraphQLBoolean },
|
|
1391
|
+
isNotNull: { type: import_graphql5.GraphQLBoolean }
|
|
1192
1392
|
};
|
|
1193
1393
|
};
|
|
1194
1394
|
var FILTERS_WITHOUT_STRING_OPS = /* @__PURE__ */ new Set(["Id", "Int", "Float", "BigInt", "Decimal"]);
|
|
1195
1395
|
var BUILTIN_FILTER_SCALARS = /* @__PURE__ */ new Set([
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1396
|
+
import_graphql5.GraphQLString,
|
|
1397
|
+
import_graphql5.GraphQLInt,
|
|
1398
|
+
import_graphql5.GraphQLFloat,
|
|
1399
|
+
import_graphql5.GraphQLBoolean,
|
|
1200
1400
|
GraphQLBigIntString,
|
|
1201
1401
|
GraphQLDecimalString,
|
|
1202
1402
|
import_graphql_scalars.GraphQLUUID,
|
|
@@ -1222,9 +1422,9 @@ var generateColumnFilterValues = (column, tableName, columnName, cacheCtx) => {
|
|
|
1222
1422
|
return cached;
|
|
1223
1423
|
}
|
|
1224
1424
|
const colType = columnGraphQLType.type;
|
|
1225
|
-
const colArr = new
|
|
1425
|
+
const colArr = new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(colType));
|
|
1226
1426
|
const customOverrideFilter = inputOverride !== void 0 && !BUILTIN_FILTER_SCALARS.has(inputOverride);
|
|
1227
|
-
const underlying = (0,
|
|
1427
|
+
const underlying = (0, import_drizzle_orm4.extractExtendedColumnType)(column);
|
|
1228
1428
|
const omitStringOps = customOverrideFilter ? underlying.type !== "string" || underlying.constraint === "numeric" : FILTERS_WITHOUT_STRING_OPS.has(genericName);
|
|
1229
1429
|
const baseFields = kind === "json" ? jsonFilterFields(column, colType) : kind === "array" ? arrayFilterFields(colType, colArr) : {
|
|
1230
1430
|
eq: { type: colType, description: "Equal to" },
|
|
@@ -1234,50 +1434,50 @@ var generateColumnFilterValues = (column, tableName, columnName, cacheCtx) => {
|
|
|
1234
1434
|
gt: { type: colType, description: "Greater than" },
|
|
1235
1435
|
gte: { type: colType, description: "Greater than or equal to" },
|
|
1236
1436
|
...omitStringOps ? {} : {
|
|
1237
|
-
like: { type:
|
|
1238
|
-
notLike: { type:
|
|
1239
|
-
ilike: { type:
|
|
1240
|
-
notIlike: { type:
|
|
1437
|
+
like: { type: import_graphql5.GraphQLString },
|
|
1438
|
+
notLike: { type: import_graphql5.GraphQLString },
|
|
1439
|
+
ilike: { type: import_graphql5.GraphQLString },
|
|
1440
|
+
notIlike: { type: import_graphql5.GraphQLString },
|
|
1241
1441
|
startsWith: {
|
|
1242
|
-
type:
|
|
1442
|
+
type: import_graphql5.GraphQLString,
|
|
1243
1443
|
description: "Matches values starting with the given string. `%`, `_` and `\\` are matched literally."
|
|
1244
1444
|
},
|
|
1245
1445
|
endsWith: {
|
|
1246
|
-
type:
|
|
1446
|
+
type: import_graphql5.GraphQLString,
|
|
1247
1447
|
description: "Matches values ending with the given string. `%`, `_` and `\\` are matched literally."
|
|
1248
1448
|
},
|
|
1249
1449
|
contains: {
|
|
1250
|
-
type:
|
|
1450
|
+
type: import_graphql5.GraphQLString,
|
|
1251
1451
|
description: "Matches values containing the given string. `%`, `_` and `\\` are matched literally."
|
|
1252
1452
|
},
|
|
1253
1453
|
iStartsWith: {
|
|
1254
|
-
type:
|
|
1454
|
+
type: import_graphql5.GraphQLString,
|
|
1255
1455
|
description: "Case-insensitive `startsWith`."
|
|
1256
1456
|
},
|
|
1257
1457
|
iEndsWith: {
|
|
1258
|
-
type:
|
|
1458
|
+
type: import_graphql5.GraphQLString,
|
|
1259
1459
|
description: "Case-insensitive `endsWith`."
|
|
1260
1460
|
},
|
|
1261
1461
|
iContains: {
|
|
1262
|
-
type:
|
|
1462
|
+
type: import_graphql5.GraphQLString,
|
|
1263
1463
|
description: "Case-insensitive `contains`."
|
|
1264
1464
|
}
|
|
1265
1465
|
},
|
|
1266
1466
|
inArray: { type: colArr, description: IN_ARRAY_DESCRIPTION },
|
|
1267
1467
|
notInArray: { type: colArr, description: NOT_IN_ARRAY_DESCRIPTION },
|
|
1268
|
-
isNull: { type:
|
|
1269
|
-
isNotNull: { type:
|
|
1468
|
+
isNull: { type: import_graphql5.GraphQLBoolean, description: "When true, matches rows where the column is NULL" },
|
|
1469
|
+
isNotNull: { type: import_graphql5.GraphQLBoolean, description: "When true, matches rows where the column is not NULL" }
|
|
1270
1470
|
};
|
|
1271
|
-
const mainType = new
|
|
1471
|
+
const mainType = new import_graphql5.GraphQLInputObjectType({
|
|
1272
1472
|
name: `${genericName}Filter`,
|
|
1273
1473
|
fields: () => ({
|
|
1274
1474
|
...baseFields,
|
|
1275
1475
|
OR: {
|
|
1276
|
-
type: new
|
|
1476
|
+
type: new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(mainType)),
|
|
1277
1477
|
description: "At least one branch matches; ANDed with any sibling operators"
|
|
1278
1478
|
},
|
|
1279
1479
|
AND: {
|
|
1280
|
-
type: new
|
|
1480
|
+
type: new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(mainType)),
|
|
1281
1481
|
description: "Every branch matches"
|
|
1282
1482
|
},
|
|
1283
1483
|
NOT: {
|
|
@@ -1296,7 +1496,7 @@ var generateTableOrderCached = (table) => {
|
|
|
1296
1496
|
}
|
|
1297
1497
|
let remapped = {};
|
|
1298
1498
|
try {
|
|
1299
|
-
const columns = (0,
|
|
1499
|
+
const columns = (0, import_drizzle_orm4.getColumns)(table);
|
|
1300
1500
|
const columnEntries = Object.entries(columns);
|
|
1301
1501
|
remapped = Object.fromEntries(
|
|
1302
1502
|
columnEntries.map(([columnName, _columnDescription]) => [columnName, { type: innerOrder }])
|
|
@@ -1310,7 +1510,7 @@ var generateTableFilterValuesCached = (table, tableName, cacheCtx) => {
|
|
|
1310
1510
|
if (cacheCtx.filterFieldCache.has(table)) {
|
|
1311
1511
|
return cacheCtx.filterFieldCache.get(table);
|
|
1312
1512
|
}
|
|
1313
|
-
const columns = (0,
|
|
1513
|
+
const columns = (0, import_drizzle_orm4.getColumns)(table);
|
|
1314
1514
|
const columnEntries = Object.entries(columns);
|
|
1315
1515
|
const remapped = Object.fromEntries(
|
|
1316
1516
|
columnEntries.map(([columnName, column]) => [
|
|
@@ -1331,7 +1531,7 @@ var generateTableSelectTypeFieldsCached = (table, tableName, cacheCtx) => {
|
|
|
1331
1531
|
if (cacheCtx.selectFieldCache.has(table)) {
|
|
1332
1532
|
return cacheCtx.selectFieldCache.get(table);
|
|
1333
1533
|
}
|
|
1334
|
-
const columns = (0,
|
|
1534
|
+
const columns = (0, import_drizzle_orm4.getColumns)(table);
|
|
1335
1535
|
const columnEntries = Object.entries(columns);
|
|
1336
1536
|
const remapped = Object.fromEntries(
|
|
1337
1537
|
columnEntries.map(([columnName, column]) => [
|
|
@@ -1344,7 +1544,7 @@ var generateTableSelectTypeFieldsCached = (table, tableName, cacheCtx) => {
|
|
|
1344
1544
|
);
|
|
1345
1545
|
if (!remapped[CURSOR_FIELD_NAME]) {
|
|
1346
1546
|
remapped[CURSOR_FIELD_NAME] = {
|
|
1347
|
-
type:
|
|
1547
|
+
type: import_graphql5.GraphQLString,
|
|
1348
1548
|
description: "Opaque cursor of this row's position in the query's ordering. Pass it as `after` to resume from here. Only set on rows returned by a list query.",
|
|
1349
1549
|
resolve: rowCursorResolver
|
|
1350
1550
|
};
|
|
@@ -1365,7 +1565,7 @@ var generateRelationOrderFields = (tableName, cacheCtx, typeNameMapper, columnFi
|
|
|
1365
1565
|
}
|
|
1366
1566
|
const targetTable = tables[relEntry.targetTableName];
|
|
1367
1567
|
const relation = relEntry.relation ?? relEntry;
|
|
1368
|
-
if (!targetTable || !(0,
|
|
1568
|
+
if (!targetTable || !(0, import_drizzle_orm4.is)(relation, import_drizzle_orm4.One) || !isFilterableRelation(relation)) {
|
|
1369
1569
|
continue;
|
|
1370
1570
|
}
|
|
1371
1571
|
fields[relationName] = {
|
|
@@ -1386,7 +1586,7 @@ var generateTableOrderTypeCached = (table, tableName, typeNameMapper, cacheCtx,
|
|
|
1386
1586
|
if (cacheCtx.orderTypeCache.has(table)) {
|
|
1387
1587
|
return cacheCtx.orderTypeCache.get(table);
|
|
1388
1588
|
}
|
|
1389
|
-
const order = new
|
|
1589
|
+
const order = new import_graphql5.GraphQLInputObjectType({
|
|
1390
1590
|
name: `${resolveTypeName(tableName, typeNameMapper)}OrderBy`,
|
|
1391
1591
|
fields: () => {
|
|
1392
1592
|
const orderColumns = generateTableOrderCached(table);
|
|
@@ -1404,7 +1604,7 @@ var generateListRelationFilterCached = (targetTable, targetTableName, cacheCtx,
|
|
|
1404
1604
|
if (cached) {
|
|
1405
1605
|
return cached;
|
|
1406
1606
|
}
|
|
1407
|
-
const listFilter = new
|
|
1607
|
+
const listFilter = new import_graphql5.GraphQLInputObjectType({
|
|
1408
1608
|
name: `${resolveTypeName(targetTableName, typeNameMapper)}ListRelationFilter`,
|
|
1409
1609
|
fields: () => {
|
|
1410
1610
|
const targetFilters = generateTableFilterTypeCached(
|
|
@@ -1440,7 +1640,7 @@ var generateRelationFilterFields = (tableName, cacheCtx, typeNameMapper, columnF
|
|
|
1440
1640
|
if (!targetTable) {
|
|
1441
1641
|
continue;
|
|
1442
1642
|
}
|
|
1443
|
-
fields[relationName] = (0,
|
|
1643
|
+
fields[relationName] = (0, import_drizzle_orm4.is)(relation, import_drizzle_orm4.One) ? {
|
|
1444
1644
|
type: generateTableFilterTypeCached(
|
|
1445
1645
|
targetTable,
|
|
1446
1646
|
relEntry.targetTableName,
|
|
@@ -1474,16 +1674,16 @@ var generateTableFilterTypeCached = (table, tableName, cacheCtx, typeNameMapper,
|
|
|
1474
1674
|
...generateRelationFilterFields(tableName, cacheCtx, typeNameMapper, filterColumns, relationMap, tables)
|
|
1475
1675
|
};
|
|
1476
1676
|
};
|
|
1477
|
-
const filters = new
|
|
1677
|
+
const filters = new import_graphql5.GraphQLInputObjectType({
|
|
1478
1678
|
name: `${resolveTypeName(tableName, typeNameMapper)}Filters`,
|
|
1479
1679
|
fields: () => ({
|
|
1480
1680
|
...buildFields(),
|
|
1481
1681
|
OR: {
|
|
1482
|
-
type: new
|
|
1682
|
+
type: new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(filters)),
|
|
1483
1683
|
description: "At least one branch matches; ANDed with any sibling fields"
|
|
1484
1684
|
},
|
|
1485
1685
|
AND: {
|
|
1486
|
-
type: new
|
|
1686
|
+
type: new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(filters)),
|
|
1487
1687
|
description: "Every branch matches"
|
|
1488
1688
|
},
|
|
1489
1689
|
NOT: {
|
|
@@ -1534,7 +1734,7 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
|
|
|
1534
1734
|
}
|
|
1535
1735
|
if (isRootCall && !cacheCtx.objectTypeCache.has(tableName)) {
|
|
1536
1736
|
const typeName = resolveTypeName(tableName, typeNameMapper);
|
|
1537
|
-
const shell = new
|
|
1737
|
+
const shell = new import_graphql5.GraphQLObjectType({
|
|
1538
1738
|
name: typeName,
|
|
1539
1739
|
description: cacheCtx.docs.describeTable?.(tableName),
|
|
1540
1740
|
fields: () => ({ ...tableFields, ...container.fields })
|
|
@@ -1548,7 +1748,7 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
|
|
|
1548
1748
|
for (const [relationName, relEntry] of relationEntries) {
|
|
1549
1749
|
const { targetTableName } = relEntry;
|
|
1550
1750
|
const relation = relEntry.relation ?? relEntry;
|
|
1551
|
-
const isOne = (0,
|
|
1751
|
+
const isOne = (0, import_drizzle_orm4.is)(relation, import_drizzle_orm4.One);
|
|
1552
1752
|
const relSelectData = generateSelectFields(
|
|
1553
1753
|
tables,
|
|
1554
1754
|
targetTableName,
|
|
@@ -1576,7 +1776,7 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
|
|
|
1576
1776
|
cacheCtx.relationFieldContainers.set(targetTableName, targetContainer);
|
|
1577
1777
|
}
|
|
1578
1778
|
const capturedTargetContainer = targetContainer;
|
|
1579
|
-
relType = new
|
|
1779
|
+
relType = new import_graphql5.GraphQLObjectType({
|
|
1580
1780
|
name: resolveTypeName(targetTableName, typeNameMapper),
|
|
1581
1781
|
description: cacheCtx.docs.describeTable?.(targetTableName),
|
|
1582
1782
|
fields: () => ({ ...targetTableFields, ...capturedTargetContainer.fields })
|
|
@@ -1591,7 +1791,7 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
|
|
|
1591
1791
|
rawRelationFields.push([
|
|
1592
1792
|
relationName,
|
|
1593
1793
|
{
|
|
1594
|
-
type: isRequired ? new
|
|
1794
|
+
type: isRequired ? new import_graphql5.GraphQLNonNull(relType) : relType,
|
|
1595
1795
|
args: {
|
|
1596
1796
|
where: { type: relSelectData.filters }
|
|
1597
1797
|
},
|
|
@@ -1601,19 +1801,29 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
|
|
|
1601
1801
|
]);
|
|
1602
1802
|
continue;
|
|
1603
1803
|
}
|
|
1804
|
+
const targetDistinctEnum = cacheCtx.features.distinct ? generateDistinctEnum(tables[targetTableName], resolveTypeName(targetTableName, typeNameMapper)) : void 0;
|
|
1604
1805
|
rawRelationFields.push([
|
|
1605
1806
|
relationName,
|
|
1606
1807
|
{
|
|
1607
|
-
type: new
|
|
1808
|
+
type: new import_graphql5.GraphQLNonNull(new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(relType))),
|
|
1608
1809
|
args: {
|
|
1609
1810
|
where: { type: relSelectData.filters },
|
|
1610
1811
|
orderBy: { type: relSelectData.order },
|
|
1611
|
-
offset: { type:
|
|
1612
|
-
limit: { type:
|
|
1812
|
+
offset: { type: import_graphql5.GraphQLInt },
|
|
1813
|
+
limit: { type: import_graphql5.GraphQLInt },
|
|
1814
|
+
after: {
|
|
1815
|
+
type: import_graphql5.GraphQLString,
|
|
1816
|
+
description: "Keyset pagination: only return related rows strictly after this cursor (a row's `cursor` field from a previous page of this relation, under the same orderBy)."
|
|
1817
|
+
},
|
|
1818
|
+
...targetDistinctEnum ? { distinct: { type: new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(targetDistinctEnum)) } } : {}
|
|
1613
1819
|
},
|
|
1614
1820
|
resolve,
|
|
1615
1821
|
...relationDocs,
|
|
1616
|
-
...cacheCtx.complexity ? {
|
|
1822
|
+
...cacheCtx.complexity ? {
|
|
1823
|
+
extensions: {
|
|
1824
|
+
complexity: listFieldComplexity(cacheCtx.complexity, cacheCtx.limits?.(targetTableName))
|
|
1825
|
+
}
|
|
1826
|
+
} : {}
|
|
1617
1827
|
}
|
|
1618
1828
|
]);
|
|
1619
1829
|
const aggregateFieldName = `${relationName}Aggregate`;
|
|
@@ -1627,7 +1837,7 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
|
|
|
1627
1837
|
rawRelationFields.push([
|
|
1628
1838
|
aggregateFieldName,
|
|
1629
1839
|
{
|
|
1630
|
-
type: new
|
|
1840
|
+
type: new import_graphql5.GraphQLNonNull(relationAggregate.type),
|
|
1631
1841
|
args: {
|
|
1632
1842
|
where: { type: relSelectData.filters }
|
|
1633
1843
|
},
|
|
@@ -1679,7 +1889,7 @@ var generateTableTypes = (tableName, tables, relationMap, withReturning, relatio
|
|
|
1679
1889
|
relationAggregateFactory
|
|
1680
1890
|
);
|
|
1681
1891
|
const table = tables[tableName];
|
|
1682
|
-
const columns = (0,
|
|
1892
|
+
const columns = (0, import_drizzle_orm4.getColumns)(table);
|
|
1683
1893
|
const columnEntries = Object.entries(columns);
|
|
1684
1894
|
const relaxedColumns = nestedWrites?.relaxedColumns(tableName);
|
|
1685
1895
|
const insertFields = Object.fromEntries(
|
|
@@ -1701,30 +1911,29 @@ var generateTableTypes = (tableName, tables, relationMap, withReturning, relatio
|
|
|
1701
1911
|
const updateFields = Object.fromEntries(
|
|
1702
1912
|
columnEntries.map(([columnName, column]) => {
|
|
1703
1913
|
const converted = drizzleColumnToGraphQLType(column, columnName, tableName, true, false, true);
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
];
|
|
1914
|
+
const operations = cacheCtx.features.fieldUpdateOperations ? fieldUpdateInputType(column, columnName, tableName) : void 0;
|
|
1915
|
+
const field = operations ? { ...converted, type: operations } : converted;
|
|
1916
|
+
return [columnName, { ...field, ...inputFieldDocs(cacheCtx.docs, column, tableName, columnName, field.type) }];
|
|
1708
1917
|
})
|
|
1709
1918
|
);
|
|
1710
1919
|
const typeName = resolveTypeName(tableName, typeNameMapper);
|
|
1711
|
-
const insertInput = new
|
|
1920
|
+
const insertInput = new import_graphql5.GraphQLInputObjectType({
|
|
1712
1921
|
name: `${capitalize(insertPrefix)}${typeName}Input`,
|
|
1713
1922
|
fields: nestedWrites ? () => ({ ...insertFields, ...nestedWrites.createFields(tableName, typeName) }) : insertFields
|
|
1714
1923
|
});
|
|
1715
|
-
const updateInput = new
|
|
1924
|
+
const updateInput = new import_graphql5.GraphQLInputObjectType({
|
|
1716
1925
|
name: `${capitalize(updatePrefix)}${typeName}Input`,
|
|
1717
1926
|
fields: nestedWrites ? () => ({ ...updateFields, ...nestedWrites.updateFields(tableName, typeName) }) : updateFields
|
|
1718
1927
|
});
|
|
1719
|
-
const selectSingleOutput = cacheCtx.objectTypeCache.get(tableName) ?? new
|
|
1928
|
+
const selectSingleOutput = cacheCtx.objectTypeCache.get(tableName) ?? new import_graphql5.GraphQLObjectType({
|
|
1720
1929
|
name: resolveTypeName(tableName, typeNameMapper),
|
|
1721
1930
|
description: cacheCtx.docs.describeTable?.(tableName),
|
|
1722
1931
|
fields: { ...tableFields, ...relationFields }
|
|
1723
1932
|
});
|
|
1724
|
-
const selectArrOutput = new
|
|
1933
|
+
const selectArrOutput = new import_graphql5.GraphQLNonNull(new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(selectSingleOutput)));
|
|
1725
1934
|
const arrTableItemOutput = withReturning ? (
|
|
1726
1935
|
// ? new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(singleTableItemOutput!)))
|
|
1727
|
-
new
|
|
1936
|
+
new import_graphql5.GraphQLNonNull(new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(selectSingleOutput)))
|
|
1728
1937
|
) : void 0;
|
|
1729
1938
|
const inputs = {
|
|
1730
1939
|
insertInput,
|
|
@@ -1749,34 +1958,34 @@ var generateTableTypes = (tableName, tables, relationMap, withReturning, relatio
|
|
|
1749
1958
|
};
|
|
1750
1959
|
var orderByEntries = (orderArgs) => Object.entries(orderArgs).sort((a, b) => (b[1]?.priority ?? 0) - (a[1]?.priority ?? 0)).filter(([, config]) => config).map(([column, config]) => {
|
|
1751
1960
|
if (typeof config === "object" && config.direction === void 0) {
|
|
1752
|
-
throw new
|
|
1961
|
+
throw new import_graphql5.GraphQLError(`ORDER BY ${column}: ordering through a relation is not supported in this query`);
|
|
1753
1962
|
}
|
|
1754
1963
|
return [column, config.direction, config.nulls ?? void 0];
|
|
1755
1964
|
});
|
|
1756
1965
|
var orderExpressions = (expr, direction, nulls, dialectColumn) => {
|
|
1757
|
-
const directed = direction === "asc" ? (0,
|
|
1966
|
+
const directed = direction === "asc" ? (0, import_drizzle_orm4.asc)(expr) : (0, import_drizzle_orm4.desc)(expr);
|
|
1758
1967
|
if (!nulls) {
|
|
1759
1968
|
return [directed];
|
|
1760
1969
|
}
|
|
1761
1970
|
const isMySql = (dialectColumn.columnType ?? "").startsWith("MySql");
|
|
1762
1971
|
if (isMySql) {
|
|
1763
|
-
const nullsKey = nulls === "first" ? (0,
|
|
1972
|
+
const nullsKey = nulls === "first" ? (0, import_drizzle_orm4.desc)(import_drizzle_orm4.sql`(${expr} is null)`) : (0, import_drizzle_orm4.asc)(import_drizzle_orm4.sql`(${expr} is null)`);
|
|
1764
1973
|
return [nullsKey, directed];
|
|
1765
1974
|
}
|
|
1766
|
-
return [nulls === "first" ?
|
|
1975
|
+
return [nulls === "first" ? import_drizzle_orm4.sql`${directed} nulls first` : import_drizzle_orm4.sql`${directed} nulls last`];
|
|
1767
1976
|
};
|
|
1768
1977
|
var extendRelationOrderChain = (parentTable, relationName, relEntry, ctx, chain) => {
|
|
1769
1978
|
const targetTable = ctx.tables[relEntry.targetTableName];
|
|
1770
1979
|
const relation = relEntry.relation ?? relEntry;
|
|
1771
|
-
if (!targetTable || !(0,
|
|
1772
|
-
throw new
|
|
1980
|
+
if (!targetTable || !(0, import_drizzle_orm4.is)(relation, import_drizzle_orm4.One) || !isFilterableRelation(relation)) {
|
|
1981
|
+
throw new import_graphql5.GraphQLError(`ORDER BY ${relationName}: Relation cannot be used for ordering`);
|
|
1773
1982
|
}
|
|
1774
1983
|
ctx.aliases ??= { n: 0 };
|
|
1775
|
-
const aliasedTarget = (0,
|
|
1984
|
+
const aliasedTarget = (0, import_drizzle_orm4.aliasedTable)(targetTable, `dgql_ord_${ctx.aliases.n++}`);
|
|
1776
1985
|
const joinCondition = buildRelationJoinCondition(parentTable, relation, aliasedTarget, relationName);
|
|
1777
|
-
const relationWhere = relation.where ? (0,
|
|
1986
|
+
const relationWhere = relation.where ? (0, import_drizzle_orm4.relationsFilterToSQL)(relation.isReversed ? parentTable : aliasedTarget, relation.where) : void 0;
|
|
1778
1987
|
return {
|
|
1779
|
-
fromParts: [...chain?.fromParts ?? [], (0,
|
|
1988
|
+
fromParts: [...chain?.fromParts ?? [], (0, import_drizzle_orm4.getTableAsAliasSQL)(aliasedTarget)],
|
|
1780
1989
|
conditions: [
|
|
1781
1990
|
...chain?.conditions ?? [],
|
|
1782
1991
|
...joinCondition ? [joinCondition] : [],
|
|
@@ -1786,7 +1995,7 @@ var extendRelationOrderChain = (parentTable, relationName, relEntry, ctx, chain)
|
|
|
1786
1995
|
};
|
|
1787
1996
|
};
|
|
1788
1997
|
var collectOrderEntries = (table, tableKey, orderArgs, ctx, chain, out) => {
|
|
1789
|
-
const columns = (0,
|
|
1998
|
+
const columns = (0, import_drizzle_orm4.getColumns)(table);
|
|
1790
1999
|
const relations = ctx?.relationMap[tableKey];
|
|
1791
2000
|
for (const [key, config] of Object.entries(orderArgs)) {
|
|
1792
2001
|
if (config === null || config === void 0) {
|
|
@@ -1795,7 +2004,7 @@ var collectOrderEntries = (table, tableKey, orderArgs, ctx, chain, out) => {
|
|
|
1795
2004
|
const column = columns[key];
|
|
1796
2005
|
if (column) {
|
|
1797
2006
|
out.push({
|
|
1798
|
-
expression: chain ?
|
|
2007
|
+
expression: chain ? import_drizzle_orm4.sql`(select ${column} from ${import_drizzle_orm4.sql.join(chain.fromParts, import_drizzle_orm4.sql`, `)} where ${(0, import_drizzle_orm4.and)(...chain.conditions)})` : column,
|
|
1799
2008
|
column,
|
|
1800
2009
|
direction: config.direction,
|
|
1801
2010
|
nulls: config.nulls ?? void 0,
|
|
@@ -1805,7 +2014,7 @@ var collectOrderEntries = (table, tableKey, orderArgs, ctx, chain, out) => {
|
|
|
1805
2014
|
}
|
|
1806
2015
|
const relEntry = relations?.[key];
|
|
1807
2016
|
if (!relEntry || !ctx) {
|
|
1808
|
-
throw new
|
|
2017
|
+
throw new import_graphql5.GraphQLError(`ORDER BY ${key}: Unknown column or relation`);
|
|
1809
2018
|
}
|
|
1810
2019
|
const nextChain = extendRelationOrderChain(chain?.table ?? table, key, relEntry, ctx, chain);
|
|
1811
2020
|
collectOrderEntries(nextChain.table, relEntry.targetTableName, config, ctx, nextChain, out);
|
|
@@ -1828,34 +2037,34 @@ var safeLikeOps = {
|
|
|
1828
2037
|
};
|
|
1829
2038
|
var safeLikeCondition = (column, pattern, insensitive) => {
|
|
1830
2039
|
if (!insensitive) {
|
|
1831
|
-
return
|
|
2040
|
+
return import_drizzle_orm4.sql`${column} like ${pattern} escape ${LIKE_ESCAPE_CHAR}`;
|
|
1832
2041
|
}
|
|
1833
2042
|
const isPg = (column.columnType ?? "").startsWith("Pg");
|
|
1834
|
-
return isPg ?
|
|
2043
|
+
return isPg ? import_drizzle_orm4.sql`${column} ilike ${pattern} escape ${LIKE_ESCAPE_CHAR}` : import_drizzle_orm4.sql`lower(${column}) like ${pattern.toLowerCase()} escape ${LIKE_ESCAPE_CHAR}`;
|
|
1835
2044
|
};
|
|
1836
2045
|
var isJsonColumn2 = (column) => (column.columnType ?? "").includes("Json");
|
|
1837
2046
|
var jsonContains = (column, columnName, value) => {
|
|
1838
2047
|
const serialized = JSON.stringify(value);
|
|
1839
2048
|
switch (columnDialect(column)) {
|
|
1840
2049
|
case "pg":
|
|
1841
|
-
return column.columnType === "PgJson" ?
|
|
2050
|
+
return column.columnType === "PgJson" ? import_drizzle_orm4.sql`${column}::jsonb @> ${serialized}::jsonb` : import_drizzle_orm4.sql`${column} @> ${serialized}::jsonb`;
|
|
1842
2051
|
case "mysql":
|
|
1843
|
-
return
|
|
2052
|
+
return import_drizzle_orm4.sql`json_contains(${column}, ${serialized})`;
|
|
1844
2053
|
default:
|
|
1845
|
-
throw new
|
|
2054
|
+
throw new import_graphql5.GraphQLError(`WHERE ${columnName}: Operator 'contains' is not supported for this dialect!`);
|
|
1846
2055
|
}
|
|
1847
2056
|
};
|
|
1848
2057
|
var extractFiltersColumn = (column, columnName, operators) => {
|
|
1849
2058
|
const { OR, AND, NOT, ...restOperators } = operators;
|
|
1850
2059
|
const entries = Object.entries(restOperators);
|
|
1851
|
-
const singleValueOps = { eq:
|
|
1852
|
-
const stringValueOps = { like:
|
|
1853
|
-
const arrayValueOps = { inArray:
|
|
2060
|
+
const singleValueOps = { eq: import_drizzle_orm4.eq, ne: import_drizzle_orm4.ne, gt: import_drizzle_orm4.gt, gte: import_drizzle_orm4.gte, lt: import_drizzle_orm4.lt, lte: import_drizzle_orm4.lte };
|
|
2061
|
+
const stringValueOps = { like: import_drizzle_orm4.like, notLike: import_drizzle_orm4.notLike, ilike: import_drizzle_orm4.ilike, notIlike: import_drizzle_orm4.notIlike };
|
|
2062
|
+
const arrayValueOps = { inArray: import_drizzle_orm4.inArray, notInArray: import_drizzle_orm4.notInArray };
|
|
1854
2063
|
const arrayMembershipOps = {
|
|
1855
|
-
hasSome:
|
|
1856
|
-
hasEvery:
|
|
2064
|
+
hasSome: import_drizzle_orm4.arrayOverlaps,
|
|
2065
|
+
hasEvery: import_drizzle_orm4.arrayContains
|
|
1857
2066
|
};
|
|
1858
|
-
const nullableOps = { isNull:
|
|
2067
|
+
const nullableOps = { isNull: import_drizzle_orm4.isNull, isNotNull: import_drizzle_orm4.isNotNull };
|
|
1859
2068
|
const variants = [];
|
|
1860
2069
|
for (const [operatorName, operatorValue] of entries) {
|
|
1861
2070
|
if (operatorValue === null || operatorValue === false) {
|
|
@@ -1873,23 +2082,23 @@ var extractFiltersColumn = (column, columnName, operators) => {
|
|
|
1873
2082
|
variants.push(safeLikeCondition(column, buildPattern(operatorValue), insensitive));
|
|
1874
2083
|
} else if (operatorName in arrayValueOps) {
|
|
1875
2084
|
if (!operatorValue.length) {
|
|
1876
|
-
throw new
|
|
2085
|
+
throw new import_graphql5.GraphQLError(`WHERE ${columnName}: Unable to use operator ${operatorName} with an empty array!`);
|
|
1877
2086
|
}
|
|
1878
2087
|
const arrayValue = operatorValue.map((val) => remapFromGraphQLCore(val, column, columnName));
|
|
1879
2088
|
variants.push(arrayValueOps[operatorName](column, arrayValue));
|
|
1880
2089
|
} else if (operatorName === "has") {
|
|
1881
|
-
variants.push((0,
|
|
2090
|
+
variants.push((0, import_drizzle_orm4.arrayContains)(column, [operatorValue]));
|
|
1882
2091
|
} else if (operatorName in arrayMembershipOps) {
|
|
1883
2092
|
if (!operatorValue.length) {
|
|
1884
|
-
throw new
|
|
2093
|
+
throw new import_graphql5.GraphQLError(`WHERE ${columnName}: Unable to use operator ${operatorName} with an empty array!`);
|
|
1885
2094
|
}
|
|
1886
2095
|
variants.push(arrayMembershipOps[operatorName](column, operatorValue));
|
|
1887
2096
|
} else if (operatorName === "isEmpty") {
|
|
1888
|
-
variants.push(
|
|
2097
|
+
variants.push(import_drizzle_orm4.sql`cardinality(${column}) = 0`);
|
|
1889
2098
|
} else if (operatorName in nullableOps) {
|
|
1890
2099
|
variants.push(nullableOps[operatorName](column));
|
|
1891
2100
|
} else {
|
|
1892
|
-
throw new
|
|
2101
|
+
throw new import_graphql5.GraphQLError(`WHERE ${columnName}: Unknown operator: ${operatorName}`);
|
|
1893
2102
|
}
|
|
1894
2103
|
}
|
|
1895
2104
|
if (AND?.length) {
|
|
@@ -1903,7 +2112,7 @@ var extractFiltersColumn = (column, columnName, operators) => {
|
|
|
1903
2112
|
if (NOT) {
|
|
1904
2113
|
const extracted = extractFiltersColumn(column, columnName, NOT);
|
|
1905
2114
|
if (extracted) {
|
|
1906
|
-
variants.push((0,
|
|
2115
|
+
variants.push((0, import_drizzle_orm4.not)(extracted));
|
|
1907
2116
|
}
|
|
1908
2117
|
}
|
|
1909
2118
|
if (OR?.length) {
|
|
@@ -1915,33 +2124,33 @@ var extractFiltersColumn = (column, columnName, operators) => {
|
|
|
1915
2124
|
}
|
|
1916
2125
|
}
|
|
1917
2126
|
if (orVariants.length) {
|
|
1918
|
-
variants.push(orVariants.length > 1 ? (0,
|
|
2127
|
+
variants.push(orVariants.length > 1 ? (0, import_drizzle_orm4.or)(...orVariants) : orVariants[0]);
|
|
1919
2128
|
}
|
|
1920
2129
|
}
|
|
1921
|
-
return variants.length ? variants.length > 1 ? (0,
|
|
2130
|
+
return variants.length ? variants.length > 1 ? (0, import_drizzle_orm4.and)(...variants) : variants[0] : void 0;
|
|
1922
2131
|
};
|
|
1923
2132
|
var relationFilterCtx = (base, tableKey) => base ? { ...base, tableKey } : void 0;
|
|
1924
2133
|
var buildRelationJoinCondition = (parentTable, relation, aliasedTarget, relationName) => {
|
|
1925
2134
|
const sourceColumns = relation.sourceColumns;
|
|
1926
2135
|
const targetColumns = relation.targetColumns;
|
|
1927
2136
|
if (!sourceColumns?.length || sourceColumns.length !== targetColumns?.length) {
|
|
1928
|
-
throw new
|
|
2137
|
+
throw new import_graphql5.GraphQLError(`WHERE ${relationName}: Relation cannot be used as a filter`);
|
|
1929
2138
|
}
|
|
1930
|
-
const parentColumns = Object.values((0,
|
|
1931
|
-
const targetColumnsByName = Object.values((0,
|
|
2139
|
+
const parentColumns = Object.values((0, import_drizzle_orm4.getColumns)(parentTable));
|
|
2140
|
+
const targetColumnsByName = Object.values((0, import_drizzle_orm4.getColumns)(aliasedTarget));
|
|
1932
2141
|
const conditions = [];
|
|
1933
2142
|
for (let i = 0; i < sourceColumns.length; i++) {
|
|
1934
2143
|
const localColumn = parentColumns.find((c) => c.name === sourceColumns[i].name);
|
|
1935
2144
|
const foreignColumn = targetColumnsByName.find((c) => c.name === targetColumns[i].name);
|
|
1936
2145
|
if (!localColumn || !foreignColumn) {
|
|
1937
|
-
throw new
|
|
2146
|
+
throw new import_graphql5.GraphQLError(`WHERE ${relationName}: Relation cannot be used as a filter`);
|
|
1938
2147
|
}
|
|
1939
|
-
conditions.push((0,
|
|
2148
|
+
conditions.push((0, import_drizzle_orm4.eq)(localColumn, foreignColumn));
|
|
1940
2149
|
}
|
|
1941
|
-
return conditions.length > 1 ? (0,
|
|
2150
|
+
return conditions.length > 1 ? (0, import_drizzle_orm4.and)(...conditions) : conditions[0];
|
|
1942
2151
|
};
|
|
1943
2152
|
var resolveJunctionColumn = (aliasedThrough, junctionRef, relationName) => {
|
|
1944
|
-
const throughColumns = (0,
|
|
2153
|
+
const throughColumns = (0, import_drizzle_orm4.getColumns)(aliasedThrough);
|
|
1945
2154
|
const key = junctionRef?._?.key;
|
|
1946
2155
|
const byKey = key ? throughColumns[key] : void 0;
|
|
1947
2156
|
if (byKey) {
|
|
@@ -1950,7 +2159,7 @@ var resolveJunctionColumn = (aliasedThrough, junctionRef, relationName) => {
|
|
|
1950
2159
|
const columnName = junctionRef?._?.column?.name;
|
|
1951
2160
|
const byName = columnName ? Object.values(throughColumns).find((c) => c.name === columnName) : void 0;
|
|
1952
2161
|
if (!byName) {
|
|
1953
|
-
throw new
|
|
2162
|
+
throw new import_graphql5.GraphQLError(`WHERE ${relationName}: Relation cannot be used as a filter`);
|
|
1954
2163
|
}
|
|
1955
2164
|
return byName;
|
|
1956
2165
|
};
|
|
@@ -1959,31 +2168,31 @@ var buildThroughJoinConditions = (parentTable, relation, aliasedThrough, aliased
|
|
|
1959
2168
|
const targetColumns = relation.targetColumns;
|
|
1960
2169
|
const through = relation.through;
|
|
1961
2170
|
if (!sourceColumns?.length || !targetColumns?.length || through?.source.length !== sourceColumns.length || through.target.length !== targetColumns.length) {
|
|
1962
|
-
throw new
|
|
2171
|
+
throw new import_graphql5.GraphQLError(`WHERE ${relationName}: Relation cannot be used as a filter`);
|
|
1963
2172
|
}
|
|
1964
|
-
const parentColumns = Object.values((0,
|
|
1965
|
-
const targetTableColumns = Object.values((0,
|
|
2173
|
+
const parentColumns = Object.values((0, import_drizzle_orm4.getColumns)(parentTable));
|
|
2174
|
+
const targetTableColumns = Object.values((0, import_drizzle_orm4.getColumns)(aliasedTarget));
|
|
1966
2175
|
const correlationConditions = [];
|
|
1967
2176
|
for (let i = 0; i < sourceColumns.length; i++) {
|
|
1968
2177
|
const localColumn = parentColumns.find((c) => c.name === sourceColumns[i].name);
|
|
1969
2178
|
if (!localColumn) {
|
|
1970
|
-
throw new
|
|
2179
|
+
throw new import_graphql5.GraphQLError(`WHERE ${relationName}: Relation cannot be used as a filter`);
|
|
1971
2180
|
}
|
|
1972
|
-
correlationConditions.push((0,
|
|
2181
|
+
correlationConditions.push((0, import_drizzle_orm4.eq)(localColumn, resolveJunctionColumn(aliasedThrough, through.source[i], relationName)));
|
|
1973
2182
|
}
|
|
1974
2183
|
const junctionJoinConditions = [];
|
|
1975
2184
|
for (let i = 0; i < targetColumns.length; i++) {
|
|
1976
2185
|
const foreignColumn = targetTableColumns.find((c) => c.name === targetColumns[i].name);
|
|
1977
2186
|
if (!foreignColumn) {
|
|
1978
|
-
throw new
|
|
2187
|
+
throw new import_graphql5.GraphQLError(`WHERE ${relationName}: Relation cannot be used as a filter`);
|
|
1979
2188
|
}
|
|
1980
2189
|
junctionJoinConditions.push(
|
|
1981
|
-
(0,
|
|
2190
|
+
(0, import_drizzle_orm4.eq)(resolveJunctionColumn(aliasedThrough, through.target[i], relationName), foreignColumn)
|
|
1982
2191
|
);
|
|
1983
2192
|
}
|
|
1984
2193
|
return {
|
|
1985
|
-
correlation: correlationConditions.length > 1 ? (0,
|
|
1986
|
-
junctionJoin: junctionJoinConditions.length > 1 ? (0,
|
|
2194
|
+
correlation: correlationConditions.length > 1 ? (0, import_drizzle_orm4.and)(...correlationConditions) : correlationConditions[0],
|
|
2195
|
+
junctionJoin: junctionJoinConditions.length > 1 ? (0, import_drizzle_orm4.and)(...junctionJoinConditions) : junctionJoinConditions[0]
|
|
1987
2196
|
};
|
|
1988
2197
|
};
|
|
1989
2198
|
var buildRelationExists = (parentTable, relationName, relEntry, innerFilters, mode, ctx) => {
|
|
@@ -1991,16 +2200,16 @@ var buildRelationExists = (parentTable, relationName, relEntry, innerFilters, mo
|
|
|
1991
2200
|
const targetTable = ctx.tables[targetTableName];
|
|
1992
2201
|
const relation = relEntry.relation ?? relEntry;
|
|
1993
2202
|
if (!targetTable) {
|
|
1994
|
-
throw new
|
|
2203
|
+
throw new import_graphql5.GraphQLError(`WHERE ${relationName}: Relation cannot be used as a filter`);
|
|
1995
2204
|
}
|
|
1996
2205
|
ctx.aliases ??= { n: 0 };
|
|
1997
2206
|
const aliases = ctx.aliases;
|
|
1998
|
-
const aliasedTarget = (0,
|
|
2207
|
+
const aliasedTarget = (0, import_drizzle_orm4.aliasedTable)(targetTable, `dgql_rel_${aliases.n++}`);
|
|
1999
2208
|
const throughTable = relation.throughTable;
|
|
2000
2209
|
let fromClause;
|
|
2001
2210
|
let joinCondition;
|
|
2002
2211
|
if (throughTable) {
|
|
2003
|
-
const aliasedThrough = (0,
|
|
2212
|
+
const aliasedThrough = (0, import_drizzle_orm4.aliasedTable)(throughTable, `dgql_rel_${aliases.n++}`);
|
|
2004
2213
|
const { correlation, junctionJoin } = buildThroughJoinConditions(
|
|
2005
2214
|
parentTable,
|
|
2006
2215
|
relation,
|
|
@@ -2008,26 +2217,26 @@ var buildRelationExists = (parentTable, relationName, relEntry, innerFilters, mo
|
|
|
2008
2217
|
aliasedTarget,
|
|
2009
2218
|
relationName
|
|
2010
2219
|
);
|
|
2011
|
-
fromClause =
|
|
2220
|
+
fromClause = import_drizzle_orm4.sql`${(0, import_drizzle_orm4.getTableAsAliasSQL)(aliasedTarget)} inner join ${(0, import_drizzle_orm4.getTableAsAliasSQL)(aliasedThrough)} on ${junctionJoin}`;
|
|
2012
2221
|
joinCondition = correlation;
|
|
2013
2222
|
} else {
|
|
2014
|
-
fromClause = (0,
|
|
2223
|
+
fromClause = (0, import_drizzle_orm4.getTableAsAliasSQL)(aliasedTarget);
|
|
2015
2224
|
joinCondition = buildRelationJoinCondition(parentTable, relation, aliasedTarget, relationName);
|
|
2016
2225
|
}
|
|
2017
|
-
const relationWhere = relation.where ? (0,
|
|
2226
|
+
const relationWhere = relation.where ? (0, import_drizzle_orm4.relationsFilterToSQL)(relation.isReversed ? parentTable : aliasedTarget, relation.where) : void 0;
|
|
2018
2227
|
const inner = innerFilters ? extractFilters(aliasedTarget, targetTableName, innerFilters, { ...ctx, tableKey: targetTableName, aliases }) : void 0;
|
|
2019
2228
|
if (mode === "every") {
|
|
2020
2229
|
if (!inner) {
|
|
2021
2230
|
return void 0;
|
|
2022
2231
|
}
|
|
2023
|
-
return
|
|
2232
|
+
return import_drizzle_orm4.sql`not exists (select 1 from ${fromClause} where ${(0, import_drizzle_orm4.and)(joinCondition, relationWhere, (0, import_drizzle_orm4.not)(inner))})`;
|
|
2024
2233
|
}
|
|
2025
|
-
const condition = (0,
|
|
2026
|
-
return mode === "none" ?
|
|
2234
|
+
const condition = (0, import_drizzle_orm4.and)(joinCondition, relationWhere, inner);
|
|
2235
|
+
return mode === "none" ? import_drizzle_orm4.sql`not exists (select 1 from ${fromClause} where ${condition})` : import_drizzle_orm4.sql`exists (select 1 from ${fromClause} where ${condition})`;
|
|
2027
2236
|
};
|
|
2028
2237
|
var extractRelationFilter = (parentTable, relationName, relEntry, value, ctx) => {
|
|
2029
2238
|
const relation = relEntry.relation ?? relEntry;
|
|
2030
|
-
if ((0,
|
|
2239
|
+
if ((0, import_drizzle_orm4.is)(relation, import_drizzle_orm4.One)) {
|
|
2031
2240
|
return buildRelationExists(parentTable, relationName, relEntry, value, "some", ctx);
|
|
2032
2241
|
}
|
|
2033
2242
|
const relationMatchModes = ["some", "none", "every"];
|
|
@@ -2037,19 +2246,19 @@ var extractRelationFilter = (parentTable, relationName, relEntry, value, ctx) =>
|
|
|
2037
2246
|
continue;
|
|
2038
2247
|
}
|
|
2039
2248
|
if (!relationMatchModes.includes(mode)) {
|
|
2040
|
-
throw new
|
|
2249
|
+
throw new import_graphql5.GraphQLError(`WHERE ${relationName}: Unknown relation filter key: ${mode}`);
|
|
2041
2250
|
}
|
|
2042
2251
|
const extracted = buildRelationExists(parentTable, relationName, relEntry, inner, mode, ctx);
|
|
2043
2252
|
if (extracted) {
|
|
2044
2253
|
variants.push(extracted);
|
|
2045
2254
|
}
|
|
2046
2255
|
}
|
|
2047
|
-
return variants.length ? variants.length > 1 ? (0,
|
|
2256
|
+
return variants.length ? variants.length > 1 ? (0, import_drizzle_orm4.and)(...variants) : variants[0] : void 0;
|
|
2048
2257
|
};
|
|
2049
2258
|
var extractFilters = (table, tableName, filters, relationCtx) => {
|
|
2050
2259
|
const { OR, AND, NOT, ...fieldFilters } = filters;
|
|
2051
2260
|
const entries = Object.entries(fieldFilters);
|
|
2052
|
-
const columns = (0,
|
|
2261
|
+
const columns = (0, import_drizzle_orm4.getColumns)(table);
|
|
2053
2262
|
const relations = relationCtx?.relationMap[relationCtx.tableKey];
|
|
2054
2263
|
const variants = [];
|
|
2055
2264
|
for (const [fieldName, operators] of entries) {
|
|
@@ -2058,7 +2267,7 @@ var extractFilters = (table, tableName, filters, relationCtx) => {
|
|
|
2058
2267
|
}
|
|
2059
2268
|
const column = columns[fieldName];
|
|
2060
2269
|
if (!column && !(relations?.[fieldName] && relationCtx)) {
|
|
2061
|
-
throw new
|
|
2270
|
+
throw new import_graphql5.GraphQLError(`WHERE ${tableName}: Unknown filter key: ${fieldName}`);
|
|
2062
2271
|
}
|
|
2063
2272
|
const extracted = column ? extractFiltersColumn(column, fieldName, operators) : extractRelationFilter(table, fieldName, relations[fieldName], operators, relationCtx);
|
|
2064
2273
|
if (extracted) {
|
|
@@ -2076,7 +2285,7 @@ var extractFilters = (table, tableName, filters, relationCtx) => {
|
|
|
2076
2285
|
if (NOT) {
|
|
2077
2286
|
const extracted = extractFilters(table, tableName, NOT, relationCtx);
|
|
2078
2287
|
if (extracted) {
|
|
2079
|
-
variants.push((0,
|
|
2288
|
+
variants.push((0, import_drizzle_orm4.not)(extracted));
|
|
2080
2289
|
}
|
|
2081
2290
|
}
|
|
2082
2291
|
if (OR?.length) {
|
|
@@ -2088,12 +2297,12 @@ var extractFilters = (table, tableName, filters, relationCtx) => {
|
|
|
2088
2297
|
}
|
|
2089
2298
|
}
|
|
2090
2299
|
if (orVariants.length) {
|
|
2091
|
-
variants.push(orVariants.length > 1 ? (0,
|
|
2300
|
+
variants.push(orVariants.length > 1 ? (0, import_drizzle_orm4.or)(...orVariants) : orVariants[0]);
|
|
2092
2301
|
}
|
|
2093
2302
|
}
|
|
2094
|
-
return variants.length ? variants.length > 1 ? (0,
|
|
2303
|
+
return variants.length ? variants.length > 1 ? (0, import_drizzle_orm4.and)(...variants) : variants[0] : void 0;
|
|
2095
2304
|
};
|
|
2096
|
-
var extractRelationsParamsInner = (relationMap, tables, tableName, typeName, originField, typeNameMapper, _isInitial = false, filterCtx) => {
|
|
2305
|
+
var extractRelationsParamsInner = (relationMap, tables, tableName, typeName, originField, typeNameMapper, _isInitial = false, filterCtx, limits) => {
|
|
2097
2306
|
const relationsForTable = relationMap[tableName];
|
|
2098
2307
|
if (!relationsForTable) {
|
|
2099
2308
|
return void 0;
|
|
@@ -2122,6 +2331,10 @@ var extractRelationsParamsInner = (relationMap, tables, tableName, typeName, ori
|
|
|
2122
2331
|
if (!relFieldSelection) {
|
|
2123
2332
|
continue;
|
|
2124
2333
|
}
|
|
2334
|
+
const eagerArgs = field.args;
|
|
2335
|
+
if (!(0, import_drizzle_orm4.is)(relEntry.relation ?? relEntry, import_drizzle_orm4.One) && (eagerArgs?.after != null || !!eagerArgs?.distinct?.length || isCursorFieldSelected(relFieldSelection, tables[targetTableName]))) {
|
|
2336
|
+
continue;
|
|
2337
|
+
}
|
|
2125
2338
|
const columns = extractSelectedColumnsFromTree(relFieldSelection, tables[targetTableName], {
|
|
2126
2339
|
tableName: targetTableName,
|
|
2127
2340
|
relationMap,
|
|
@@ -2133,7 +2346,7 @@ var extractRelationsParamsInner = (relationMap, tables, tableName, typeName, ori
|
|
|
2133
2346
|
const relationField = Object.values(baseField).find((e) => e.name === relName);
|
|
2134
2347
|
const relationArgs = relationField?.args;
|
|
2135
2348
|
const offset = relationArgs?.offset ?? void 0;
|
|
2136
|
-
const limit = relationArgs?.limit ?? void 0;
|
|
2349
|
+
const limit = (0, import_drizzle_orm4.is)(relEntry.relation, import_drizzle_orm4.One) ? relationArgs?.limit ?? void 0 : applyLimitPolicy(relationArgs?.limit, limits?.(targetTableName), `${tableName}.${relName}`);
|
|
2137
2350
|
const relWhere = relationArgs?.where;
|
|
2138
2351
|
thisRecord.where = relWhere ? {
|
|
2139
2352
|
RAW: (aliasedTable2) => extractFilters(aliasedTable2, relName, relWhere, relationFilterCtx(filterCtx, targetTableName))
|
|
@@ -2151,18 +2364,29 @@ var extractRelationsParamsInner = (relationMap, tables, tableName, typeName, ori
|
|
|
2151
2364
|
relationField,
|
|
2152
2365
|
typeNameMapper,
|
|
2153
2366
|
false,
|
|
2154
|
-
filterCtx
|
|
2367
|
+
filterCtx,
|
|
2368
|
+
limits
|
|
2155
2369
|
) : void 0;
|
|
2156
2370
|
thisRecord.with = relWith;
|
|
2157
2371
|
args[relName] = thisRecord;
|
|
2158
2372
|
}
|
|
2159
2373
|
return args;
|
|
2160
2374
|
};
|
|
2161
|
-
var extractRelationsParams = (relationMap, tables, tableName, info, typeName, typeNameMapper, filterCtx) => {
|
|
2375
|
+
var extractRelationsParams = (relationMap, tables, tableName, info, typeName, typeNameMapper, filterCtx, limits) => {
|
|
2162
2376
|
if (!info) {
|
|
2163
2377
|
return void 0;
|
|
2164
2378
|
}
|
|
2165
|
-
return extractRelationsParamsInner(
|
|
2379
|
+
return extractRelationsParamsInner(
|
|
2380
|
+
relationMap,
|
|
2381
|
+
tables,
|
|
2382
|
+
tableName,
|
|
2383
|
+
typeName,
|
|
2384
|
+
info,
|
|
2385
|
+
typeNameMapper,
|
|
2386
|
+
true,
|
|
2387
|
+
filterCtx,
|
|
2388
|
+
limits
|
|
2389
|
+
);
|
|
2166
2390
|
};
|
|
2167
2391
|
var pruneNonEagerRelations = (relationMap, shouldEagerLoad) => {
|
|
2168
2392
|
const out = {};
|
|
@@ -2174,7 +2398,7 @@ var pruneNonEagerRelations = (relationMap, shouldEagerLoad) => {
|
|
|
2174
2398
|
return out;
|
|
2175
2399
|
};
|
|
2176
2400
|
var getPrimaryKeyPropNames = (table, compositePkColumnNames) => {
|
|
2177
|
-
const cols = (0,
|
|
2401
|
+
const cols = (0, import_drizzle_orm4.getColumns)(table);
|
|
2178
2402
|
const entries = Object.entries(cols);
|
|
2179
2403
|
const inlinePks = entries.filter(([, c]) => c.primary).map(([k]) => k);
|
|
2180
2404
|
if (inlinePks.length) {
|
|
@@ -2190,7 +2414,7 @@ var getPrimaryKeyPropNames = (table, compositePkColumnNames) => {
|
|
|
2190
2414
|
return [];
|
|
2191
2415
|
};
|
|
2192
2416
|
var withPrimaryKeyColumns = (columns, table, pkNames) => {
|
|
2193
|
-
const allCols = (0,
|
|
2417
|
+
const allCols = (0, import_drizzle_orm4.getColumns)(table);
|
|
2194
2418
|
for (const pk of pkNames) {
|
|
2195
2419
|
if (!(pk in columns) && allCols[pk]) {
|
|
2196
2420
|
columns[pk] = allCols[pk];
|
|
@@ -2203,8 +2427,8 @@ var getPrimaryKeyPropNamesFromConfig = (table, getTableConfig4) => {
|
|
|
2203
2427
|
return getPrimaryKeyPropNames(table, compositePkColumnNames);
|
|
2204
2428
|
};
|
|
2205
2429
|
var primaryKeyOrderExprs = (table, pkNames) => {
|
|
2206
|
-
const cols = (0,
|
|
2207
|
-
return pkNames.map((n) => cols[n]).filter(Boolean).map((col) => (0,
|
|
2430
|
+
const cols = (0, import_drizzle_orm4.getColumns)(table);
|
|
2431
|
+
return pkNames.map((n) => cols[n]).filter(Boolean).map((col) => (0, import_drizzle_orm4.asc)(col));
|
|
2208
2432
|
};
|
|
2209
2433
|
var CURSOR_FIELD_NAME = "cursor";
|
|
2210
2434
|
var ROW_CURSOR_PROP = "__drizzle_graphql_cursor";
|
|
@@ -2220,7 +2444,7 @@ var cursorOrderingEntries = (orderBy, pkNames) => {
|
|
|
2220
2444
|
return entries;
|
|
2221
2445
|
};
|
|
2222
2446
|
var cursorOrderExprs = (table, entries) => {
|
|
2223
|
-
const cols = (0,
|
|
2447
|
+
const cols = (0, import_drizzle_orm4.getColumns)(table);
|
|
2224
2448
|
return entries.flatMap(
|
|
2225
2449
|
([column, direction, nulls]) => orderExpressions(cols[column], direction, nulls ?? void 0, cols[column])
|
|
2226
2450
|
);
|
|
@@ -2257,10 +2481,10 @@ var decodeCursor = (after, entries) => {
|
|
|
2257
2481
|
try {
|
|
2258
2482
|
payload = JSON.parse(Buffer.from(after, "base64url").toString("utf8"));
|
|
2259
2483
|
} catch (_e) {
|
|
2260
|
-
throw new
|
|
2484
|
+
throw new import_graphql5.GraphQLError("Invalid cursor: unable to decode it. Pass a cursor returned by a previous page.");
|
|
2261
2485
|
}
|
|
2262
2486
|
if (!payload || typeof payload !== "object" || !Array.isArray(payload.o) || !Array.isArray(payload.v) || payload.o.length !== payload.v.length) {
|
|
2263
|
-
throw new
|
|
2487
|
+
throw new import_graphql5.GraphQLError("Invalid cursor: malformed payload. Pass a cursor returned by a previous page.");
|
|
2264
2488
|
}
|
|
2265
2489
|
const matchesOrdering = payload.o.length === entries.length && payload.o.every(
|
|
2266
2490
|
(entry, i) => Array.isArray(entry) && entry[0] === entries[i][0] && entry[1] === entries[i][1] && // The nulls override changes where NULLs sort, so it is part of the ordering identity.
|
|
@@ -2268,49 +2492,71 @@ var decodeCursor = (after, entries) => {
|
|
|
2268
2492
|
(entry[2] ?? null) === (entries[i][2] ?? null)
|
|
2269
2493
|
);
|
|
2270
2494
|
if (!matchesOrdering) {
|
|
2271
|
-
throw new
|
|
2495
|
+
throw new import_graphql5.GraphQLError(
|
|
2272
2496
|
"Invalid cursor: it was issued for a different ordering. Pass the same orderBy the cursor's page used."
|
|
2273
2497
|
);
|
|
2274
2498
|
}
|
|
2275
2499
|
return payload.v.map(decodeCursorValue);
|
|
2276
2500
|
};
|
|
2277
2501
|
var buildCursorCondition = (table, entries, values, nullOrdering) => {
|
|
2278
|
-
const cols = (0,
|
|
2502
|
+
const cols = (0, import_drizzle_orm4.getColumns)(table);
|
|
2279
2503
|
const disjuncts = [];
|
|
2280
2504
|
const equalities = [];
|
|
2281
2505
|
entries.forEach(([column, direction, nulls], i) => {
|
|
2282
2506
|
const col = cols[column];
|
|
2283
2507
|
if (!col) {
|
|
2284
|
-
throw new
|
|
2508
|
+
throw new import_graphql5.GraphQLError(`Invalid cursor: unknown column '${column}'.`);
|
|
2285
2509
|
}
|
|
2286
2510
|
const value = values[i];
|
|
2287
2511
|
const nullsSortLast = nulls != null ? nulls === "last" : direction === "asc" === (nullOrdering === "nulls-largest");
|
|
2288
2512
|
let strictlyAfter;
|
|
2289
2513
|
if (value === null || value === void 0) {
|
|
2290
|
-
strictlyAfter = nullsSortLast ? void 0 : (0,
|
|
2514
|
+
strictlyAfter = nullsSortLast ? void 0 : (0, import_drizzle_orm4.isNotNull)(col);
|
|
2291
2515
|
} else {
|
|
2292
|
-
const comparison = direction === "asc" ? (0,
|
|
2293
|
-
strictlyAfter = nullsSortLast ? (0,
|
|
2516
|
+
const comparison = direction === "asc" ? (0, import_drizzle_orm4.gt)(col, value) : (0, import_drizzle_orm4.lt)(col, value);
|
|
2517
|
+
strictlyAfter = nullsSortLast ? (0, import_drizzle_orm4.or)(comparison, (0, import_drizzle_orm4.isNull)(col)) : comparison;
|
|
2294
2518
|
}
|
|
2295
2519
|
if (strictlyAfter) {
|
|
2296
|
-
disjuncts.push(equalities.length ? (0,
|
|
2520
|
+
disjuncts.push(equalities.length ? (0, import_drizzle_orm4.and)(...equalities, strictlyAfter) : strictlyAfter);
|
|
2297
2521
|
}
|
|
2298
|
-
equalities.push(value === null || value === void 0 ? (0,
|
|
2522
|
+
equalities.push(value === null || value === void 0 ? (0, import_drizzle_orm4.isNull)(col) : (0, import_drizzle_orm4.eq)(col, value));
|
|
2299
2523
|
});
|
|
2300
2524
|
if (!disjuncts.length) {
|
|
2301
|
-
return
|
|
2525
|
+
return import_drizzle_orm4.sql`1 = 0`;
|
|
2302
2526
|
}
|
|
2303
|
-
return disjuncts.length > 1 ? (0,
|
|
2527
|
+
return disjuncts.length > 1 ? (0, import_drizzle_orm4.or)(...disjuncts) : disjuncts[0];
|
|
2304
2528
|
};
|
|
2305
2529
|
var isCursorFieldSelected = (tree, table) => {
|
|
2306
2530
|
if (!tree) {
|
|
2307
2531
|
return false;
|
|
2308
2532
|
}
|
|
2309
|
-
if ((0,
|
|
2533
|
+
if ((0, import_drizzle_orm4.getColumns)(table)[CURSOR_FIELD_NAME]) {
|
|
2310
2534
|
return false;
|
|
2311
2535
|
}
|
|
2312
2536
|
return Object.values(tree).some((field) => field.name === CURSOR_FIELD_NAME);
|
|
2313
2537
|
};
|
|
2538
|
+
var selectsCursorField = (info, table) => {
|
|
2539
|
+
if ((0, import_drizzle_orm4.getColumns)(table)[CURSOR_FIELD_NAME]) {
|
|
2540
|
+
return false;
|
|
2541
|
+
}
|
|
2542
|
+
const visited = /* @__PURE__ */ new Set();
|
|
2543
|
+
const walk = (selections) => selections.some((selection) => {
|
|
2544
|
+
if (selection.kind === "Field") {
|
|
2545
|
+
return selection.name.value === CURSOR_FIELD_NAME;
|
|
2546
|
+
}
|
|
2547
|
+
if (selection.kind === "InlineFragment") {
|
|
2548
|
+
return walk(selection.selectionSet.selections);
|
|
2549
|
+
}
|
|
2550
|
+
const name = selection.name?.value;
|
|
2551
|
+
if (!name || visited.has(name)) {
|
|
2552
|
+
return false;
|
|
2553
|
+
}
|
|
2554
|
+
visited.add(name);
|
|
2555
|
+
const fragment = info.fragments?.[name];
|
|
2556
|
+
return fragment ? walk(fragment.selectionSet.selections) : false;
|
|
2557
|
+
});
|
|
2558
|
+
return (info.fieldNodes ?? []).some((node) => !!node.selectionSet && walk(node.selectionSet.selections));
|
|
2559
|
+
};
|
|
2314
2560
|
var attachRowCursors = (rows, entries) => {
|
|
2315
2561
|
for (const row of rows) {
|
|
2316
2562
|
row[ROW_CURSOR_PROP] = encodeCursor(entries, row);
|
|
@@ -2318,7 +2564,7 @@ var attachRowCursors = (rows, entries) => {
|
|
|
2318
2564
|
};
|
|
2319
2565
|
var rowCursorResolver = (source) => source?.[ROW_CURSOR_PROP] ?? null;
|
|
2320
2566
|
var getUniqueColumnSets = (table, getTableConfig4) => {
|
|
2321
|
-
const cols = (0,
|
|
2567
|
+
const cols = (0, import_drizzle_orm4.getColumns)(table);
|
|
2322
2568
|
const propNameByColumnName = new Map(Object.entries(cols).map(([propName, col]) => [col.name, propName]));
|
|
2323
2569
|
const toPropNames = (columnNames) => {
|
|
2324
2570
|
const propNames = [];
|
|
@@ -2363,11 +2609,11 @@ var generateColumnEnum = (table, enumName, description, predicate = () => true)
|
|
|
2363
2609
|
if (cached) {
|
|
2364
2610
|
return cached;
|
|
2365
2611
|
}
|
|
2366
|
-
const columnNames = Object.entries((0,
|
|
2612
|
+
const columnNames = Object.entries((0, import_drizzle_orm4.getColumns)(table)).filter(([columnName, column]) => predicate(column, columnName)).map(([columnName]) => columnName);
|
|
2367
2613
|
if (!columnNames.length) {
|
|
2368
2614
|
return void 0;
|
|
2369
2615
|
}
|
|
2370
|
-
const enumType = new
|
|
2616
|
+
const enumType = new import_graphql5.GraphQLEnumType({
|
|
2371
2617
|
name: enumName,
|
|
2372
2618
|
description,
|
|
2373
2619
|
values: Object.fromEntries(columnNames.map((columnName) => [columnName, { value: columnName }]))
|
|
@@ -2380,7 +2626,7 @@ var generateColumnEnum = (table, enumName, description, predicate = () => true)
|
|
|
2380
2626
|
return enumType;
|
|
2381
2627
|
};
|
|
2382
2628
|
var generateDistinctEnum = (table, typeName) => generateColumnEnum(table, `${typeName}DistinctColumn`, `Columns of ${typeName} that a query can be made distinct on`);
|
|
2383
|
-
var conflictActionEnum = new
|
|
2629
|
+
var conflictActionEnum = new import_graphql5.GraphQLEnumType({
|
|
2384
2630
|
name: "ConflictAction",
|
|
2385
2631
|
description: "What an upsert does when a row with the same unique key already exists",
|
|
2386
2632
|
values: {
|
|
@@ -2405,7 +2651,7 @@ var generateOnConflictInput = (params) => {
|
|
|
2405
2651
|
description: "Whether a conflicting row is overwritten or left alone. Defaults to UPDATE."
|
|
2406
2652
|
},
|
|
2407
2653
|
update: {
|
|
2408
|
-
type: new
|
|
2654
|
+
type: new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(updateEnum)),
|
|
2409
2655
|
description: "Columns to overwrite on conflict. Defaults to every column the request supplied, minus the conflict target. Columns the request did not supply cannot be listed here \u2014 there would be no value to write."
|
|
2410
2656
|
}
|
|
2411
2657
|
};
|
|
@@ -2421,7 +2667,7 @@ var generateOnConflictInput = (params) => {
|
|
|
2421
2667
|
return void 0;
|
|
2422
2668
|
}
|
|
2423
2669
|
fields["target"] = {
|
|
2424
|
-
type: new
|
|
2670
|
+
type: new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(targetEnum)),
|
|
2425
2671
|
description: "The unique column set a conflict is detected on. Must match one of the table\u2019s unique constraints exactly. Defaults to the primary key."
|
|
2426
2672
|
};
|
|
2427
2673
|
fields["where"] = {
|
|
@@ -2429,7 +2675,7 @@ var generateOnConflictInput = (params) => {
|
|
|
2429
2675
|
description: "Only overwrite conflicting rows that match this filter. Others are left alone."
|
|
2430
2676
|
};
|
|
2431
2677
|
}
|
|
2432
|
-
return new
|
|
2678
|
+
return new import_graphql5.GraphQLInputObjectType({
|
|
2433
2679
|
name: `${typeName}OnConflict`,
|
|
2434
2680
|
description: `Conflict handling for an upsert of ${typeName}`,
|
|
2435
2681
|
fields
|
|
@@ -2437,18 +2683,18 @@ var generateOnConflictInput = (params) => {
|
|
|
2437
2683
|
};
|
|
2438
2684
|
var resolveConflictPlan = (params) => {
|
|
2439
2685
|
const { table, values, onConflict, pkNames, uniqueSets, excludedRef, withTarget, buildWhere } = params;
|
|
2440
|
-
const columns = (0,
|
|
2686
|
+
const columns = (0, import_drizzle_orm4.getColumns)(table);
|
|
2441
2687
|
let target;
|
|
2442
2688
|
if (withTarget) {
|
|
2443
2689
|
const targetNames2 = onConflict?.target?.length ? onConflict.target : [...pkNames];
|
|
2444
2690
|
if (!targetNames2.length) {
|
|
2445
|
-
throw new
|
|
2691
|
+
throw new import_graphql5.GraphQLError(
|
|
2446
2692
|
"Unable to upsert: no conflict target was given and this table has no primary key. Pass onConflict.target."
|
|
2447
2693
|
);
|
|
2448
2694
|
}
|
|
2449
2695
|
const requested = [...targetNames2].sort().join(",");
|
|
2450
2696
|
if (!uniqueSets.some((set2) => [...set2].sort().join(",") === requested)) {
|
|
2451
|
-
throw new
|
|
2697
|
+
throw new import_graphql5.GraphQLError(
|
|
2452
2698
|
`Unable to upsert: [${targetNames2.join(", ")}] is not a unique constraint on this table. Valid conflict targets: ${uniqueSets.map((set2) => `[${set2.join(", ")}]`).join(", ")}.`
|
|
2453
2699
|
);
|
|
2454
2700
|
}
|
|
@@ -2463,7 +2709,7 @@ var resolveConflictPlan = (params) => {
|
|
|
2463
2709
|
if (onConflict?.update?.length) {
|
|
2464
2710
|
const unsupplied = onConflict.update.filter((name) => !supplied.has(name));
|
|
2465
2711
|
if (unsupplied.length) {
|
|
2466
|
-
throw new
|
|
2712
|
+
throw new import_graphql5.GraphQLError(
|
|
2467
2713
|
`Unable to upsert: onConflict.update lists ${unsupplied.join(", ")}, which the values do not supply.`
|
|
2468
2714
|
);
|
|
2469
2715
|
}
|
|
@@ -2478,18 +2724,19 @@ var resolveConflictPlan = (params) => {
|
|
|
2478
2724
|
const setWhere = onConflict?.where && buildWhere ? buildWhere(onConflict.where) : void 0;
|
|
2479
2725
|
return { action: "UPDATE", target, set, setWhere };
|
|
2480
2726
|
};
|
|
2481
|
-
var excludedColumnRef = (columnName) =>
|
|
2482
|
-
var mysqlValuesColumnRef = (columnName) =>
|
|
2727
|
+
var excludedColumnRef = (columnName) => import_drizzle_orm4.sql`excluded.${import_drizzle_orm4.sql.identifier(columnName)}`;
|
|
2728
|
+
var mysqlValuesColumnRef = (columnName) => import_drizzle_orm4.sql`values(${import_drizzle_orm4.sql.identifier(columnName)})`;
|
|
2483
2729
|
var selectDistinctKeys = async (params) => {
|
|
2484
|
-
const { db, table, tableName, distinct, pkNames, where, orderBy, limit, offset } = params;
|
|
2485
|
-
const cols = (0,
|
|
2730
|
+
const { db, table, tableName, distinct, pkNames, where, orderBy, limit, offset, partitionBy } = params;
|
|
2731
|
+
const cols = (0, import_drizzle_orm4.getColumns)(table);
|
|
2486
2732
|
if (!pkNames.length) {
|
|
2487
|
-
throw new
|
|
2733
|
+
throw new import_graphql5.GraphQLError(`Table ${tableName} has no primary key, so 'distinct' cannot be applied to it.`);
|
|
2488
2734
|
}
|
|
2489
|
-
const
|
|
2490
|
-
if (!
|
|
2491
|
-
throw new
|
|
2735
|
+
const requestedCols = distinct.map((name) => cols[name]).filter(Boolean);
|
|
2736
|
+
if (!requestedCols.length) {
|
|
2737
|
+
throw new import_graphql5.GraphQLError(`No known columns were given to 'distinct' on ${tableName}.`);
|
|
2492
2738
|
}
|
|
2739
|
+
const partitionCols = [...partitionBy ?? [], ...requestedCols];
|
|
2493
2740
|
const orderEntries = orderBy ? orderByEntries(orderBy) : [];
|
|
2494
2741
|
const windowOrder = [
|
|
2495
2742
|
...orderEntries.flatMap(
|
|
@@ -2497,18 +2744,18 @@ var selectDistinctKeys = async (params) => {
|
|
|
2497
2744
|
),
|
|
2498
2745
|
...primaryKeyOrderExprs(table, pkNames)
|
|
2499
2746
|
];
|
|
2500
|
-
const rowNumber =
|
|
2747
|
+
const rowNumber = import_drizzle_orm4.sql`row_number() over (partition by ${import_drizzle_orm4.sql.join(partitionCols, import_drizzle_orm4.sql`, `)} order by ${import_drizzle_orm4.sql.join(
|
|
2501
2748
|
windowOrder,
|
|
2502
|
-
|
|
2749
|
+
import_drizzle_orm4.sql`, `
|
|
2503
2750
|
)})`.as(DISTINCT_RN);
|
|
2504
2751
|
const sub = db.select({ ...cols, [DISTINCT_RN]: rowNumber }).from(table).where(where).as("__dgql_distinct");
|
|
2505
2752
|
const outerOrder = [
|
|
2506
2753
|
...orderEntries.flatMap(
|
|
2507
2754
|
([column, direction, nulls]) => orderExpressions(sub[column], direction, nulls, cols[column])
|
|
2508
2755
|
),
|
|
2509
|
-
...pkNames.filter((name) => sub[name]).map((name) => (0,
|
|
2756
|
+
...pkNames.filter((name) => sub[name]).map((name) => (0, import_drizzle_orm4.asc)(sub[name]))
|
|
2510
2757
|
];
|
|
2511
|
-
let query = db.select(Object.fromEntries(pkNames.map((name) => [name, sub[name]]))).from(sub).where((0,
|
|
2758
|
+
let query = db.select(Object.fromEntries(pkNames.map((name) => [name, sub[name]]))).from(sub).where((0, import_drizzle_orm4.eq)(sub[DISTINCT_RN], 1)).orderBy(...outerOrder);
|
|
2512
2759
|
if (offset) {
|
|
2513
2760
|
query = query.offset(offset);
|
|
2514
2761
|
}
|
|
@@ -2518,19 +2765,28 @@ var selectDistinctKeys = async (params) => {
|
|
|
2518
2765
|
return await query;
|
|
2519
2766
|
};
|
|
2520
2767
|
var primaryKeyRestriction = (table, pkNames, keys) => {
|
|
2521
|
-
const cols = (0,
|
|
2768
|
+
const cols = (0, import_drizzle_orm4.getColumns)(table);
|
|
2522
2769
|
if (pkNames.length === 1) {
|
|
2523
2770
|
const name = pkNames[0];
|
|
2524
|
-
return (0,
|
|
2771
|
+
return (0, import_drizzle_orm4.inArray)(
|
|
2525
2772
|
cols[name],
|
|
2526
2773
|
keys.map((key) => key[name])
|
|
2527
2774
|
);
|
|
2528
2775
|
}
|
|
2529
|
-
return (0,
|
|
2776
|
+
return (0, import_drizzle_orm4.or)(...keys.map((key) => (0, import_drizzle_orm4.and)(...pkNames.map((name) => (0, import_drizzle_orm4.eq)(cols[name], key[name])))));
|
|
2530
2777
|
};
|
|
2531
2778
|
var prepareMutationRelationColumns = (params) => {
|
|
2532
2779
|
const { relationMap, tables, tableName, typeName, typeNameMapper, table, pkNames, parsedInfo } = params;
|
|
2533
|
-
const withParams = relationMap[tableName] ? extractRelationsParams(
|
|
2780
|
+
const withParams = relationMap[tableName] ? extractRelationsParams(
|
|
2781
|
+
relationMap,
|
|
2782
|
+
tables,
|
|
2783
|
+
tableName,
|
|
2784
|
+
parsedInfo,
|
|
2785
|
+
typeName,
|
|
2786
|
+
typeNameMapper,
|
|
2787
|
+
void 0,
|
|
2788
|
+
params.limits
|
|
2789
|
+
) : void 0;
|
|
2534
2790
|
const hasRelations = !!(withParams && Object.keys(withParams).length);
|
|
2535
2791
|
const baseColumns = extractSelectedColumnsFromTreeSQLFormat(parsedInfo.fieldsByTypeName[typeName], table, {
|
|
2536
2792
|
tableName,
|
|
@@ -2541,17 +2797,17 @@ var prepareMutationRelationColumns = (params) => {
|
|
|
2541
2797
|
return { columns, hasRelations, withParams };
|
|
2542
2798
|
};
|
|
2543
2799
|
var toGraphQLError = (e) => {
|
|
2544
|
-
if (e instanceof
|
|
2800
|
+
if (e instanceof import_graphql5.GraphQLError) {
|
|
2545
2801
|
return e;
|
|
2546
2802
|
}
|
|
2547
|
-
return e instanceof Error ? new
|
|
2803
|
+
return e instanceof Error ? new import_graphql5.GraphQLError(e.message, { originalError: e }) : e;
|
|
2548
2804
|
};
|
|
2549
2805
|
var defaultErrorMapper = (error) => {
|
|
2550
|
-
if (error instanceof
|
|
2806
|
+
if (error instanceof import_graphql5.GraphQLError && !error.originalError) {
|
|
2551
2807
|
return error;
|
|
2552
2808
|
}
|
|
2553
|
-
return new
|
|
2554
|
-
originalError: error instanceof
|
|
2809
|
+
return new import_graphql5.GraphQLError("Internal server error", {
|
|
2810
|
+
originalError: error instanceof import_graphql5.GraphQLError ? error.originalError ?? error : error instanceof Error ? error : null,
|
|
2555
2811
|
extensions: { code: "INTERNAL_SERVER_ERROR" }
|
|
2556
2812
|
});
|
|
2557
2813
|
};
|
|
@@ -2608,6 +2864,9 @@ var computeResolverFieldNames = (tableName, typeNameMapper, prefixes, suffixes)
|
|
|
2608
2864
|
const writeSingleSuffix = suffixes.single === "" ? "Single" : suffixes.single;
|
|
2609
2865
|
const updateSingleFieldName = `${updateFieldName}${writeSingleSuffix}`;
|
|
2610
2866
|
const deleteSingleFieldName = `${deleteFieldName}${writeSingleSuffix}`;
|
|
2867
|
+
const pluralNoun = mapped ? capitalize(mapped.plural) : capitalize(tableName);
|
|
2868
|
+
const updateCountFieldName = `${prefixes.update}${pluralNoun}Count`;
|
|
2869
|
+
const deleteCountFieldName = `${prefixes.delete}${pluralNoun}Count`;
|
|
2611
2870
|
return {
|
|
2612
2871
|
typeName,
|
|
2613
2872
|
listFieldName,
|
|
@@ -2621,13 +2880,15 @@ var computeResolverFieldNames = (tableName, typeNameMapper, prefixes, suffixes)
|
|
|
2621
2880
|
updateFieldName,
|
|
2622
2881
|
updateManyFieldName,
|
|
2623
2882
|
updateSingleFieldName,
|
|
2883
|
+
updateCountFieldName,
|
|
2624
2884
|
deleteFieldName,
|
|
2625
|
-
deleteSingleFieldName
|
|
2885
|
+
deleteSingleFieldName,
|
|
2886
|
+
deleteCountFieldName
|
|
2626
2887
|
};
|
|
2627
2888
|
};
|
|
2628
2889
|
var generateUpdateManyInput = (params) => {
|
|
2629
2890
|
const { typeName, updatePrefix, updateInput, tableFilters } = params;
|
|
2630
|
-
return new
|
|
2891
|
+
return new import_graphql5.GraphQLInputObjectType({
|
|
2631
2892
|
name: `${capitalize(updatePrefix)}${typeName}ManyInput`,
|
|
2632
2893
|
description: `One entry of a batch update of ${typeName}: the rows \`where\` matches get this entry's \`set\` applied.`,
|
|
2633
2894
|
fields: {
|
|
@@ -2636,7 +2897,7 @@ var generateUpdateManyInput = (params) => {
|
|
|
2636
2897
|
description: "Rows this entry updates. An omitted filter updates every row."
|
|
2637
2898
|
},
|
|
2638
2899
|
set: {
|
|
2639
|
-
type: new
|
|
2900
|
+
type: new import_graphql5.GraphQLNonNull(updateInput)
|
|
2640
2901
|
}
|
|
2641
2902
|
}
|
|
2642
2903
|
});
|
|
@@ -2644,29 +2905,101 @@ var generateUpdateManyInput = (params) => {
|
|
|
2644
2905
|
var extractRequiredFilters = (table, tableName, where, fieldName, relationCtx) => {
|
|
2645
2906
|
const filters = where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
2646
2907
|
if (!filters) {
|
|
2647
|
-
throw new
|
|
2908
|
+
throw new import_graphql5.GraphQLError(`${fieldName} requires a 'where' argument with at least one filter!`);
|
|
2648
2909
|
}
|
|
2649
2910
|
return filters;
|
|
2650
2911
|
};
|
|
2912
|
+
var rowsAffected = (result, fieldName) => {
|
|
2913
|
+
const asNumber = (value) => typeof value === "number" ? value : typeof value === "bigint" ? Number(value) : void 0;
|
|
2914
|
+
if (result && typeof result === "object") {
|
|
2915
|
+
for (const key of ["rowCount", "affectedRows", "rowsAffected", "changes", "count"]) {
|
|
2916
|
+
const value = asNumber(result[key]);
|
|
2917
|
+
if (value !== void 0) {
|
|
2918
|
+
return value;
|
|
2919
|
+
}
|
|
2920
|
+
}
|
|
2921
|
+
const header = Array.isArray(result) ? result[0] : void 0;
|
|
2922
|
+
const affected = header && typeof header === "object" ? asNumber(header.affectedRows) : void 0;
|
|
2923
|
+
if (affected !== void 0) {
|
|
2924
|
+
return affected;
|
|
2925
|
+
}
|
|
2926
|
+
}
|
|
2927
|
+
throw new import_graphql5.GraphQLError(`${fieldName}: the driver did not report how many rows the write affected.`);
|
|
2928
|
+
};
|
|
2651
2929
|
var assertSingleMatch = async (executor, table, filters, fieldName) => {
|
|
2652
|
-
const matched = await executor.select({ found:
|
|
2930
|
+
const matched = await executor.select({ found: import_drizzle_orm4.sql`1` }).from(table).where(filters).limit(2);
|
|
2653
2931
|
if (matched.length > 1) {
|
|
2654
|
-
throw new
|
|
2655
|
-
}
|
|
2932
|
+
throw new import_graphql5.GraphQLError(`${fieldName}: 'where' matched more than one row \u2014 nothing was written!`);
|
|
2933
|
+
}
|
|
2934
|
+
};
|
|
2935
|
+
var generateWriteCount = ({
|
|
2936
|
+
db,
|
|
2937
|
+
tableName,
|
|
2938
|
+
table,
|
|
2939
|
+
kind,
|
|
2940
|
+
setArgs,
|
|
2941
|
+
filterArgs,
|
|
2942
|
+
fieldName,
|
|
2943
|
+
requireWhere,
|
|
2944
|
+
filterCtx,
|
|
2945
|
+
txCtx,
|
|
2946
|
+
nested
|
|
2947
|
+
}) => {
|
|
2948
|
+
const queryArgs = {
|
|
2949
|
+
...setArgs ? { set: { type: new import_graphql5.GraphQLNonNull(setArgs) } } : {},
|
|
2950
|
+
where: {
|
|
2951
|
+
type: requireWhere ? new import_graphql5.GraphQLNonNull(filterArgs) : filterArgs
|
|
2952
|
+
}
|
|
2953
|
+
};
|
|
2954
|
+
return {
|
|
2955
|
+
name: fieldName,
|
|
2956
|
+
resolver: async (_source, args, context, info) => {
|
|
2957
|
+
try {
|
|
2958
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
2959
|
+
const { where, set } = args;
|
|
2960
|
+
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
2961
|
+
const filters = requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
2962
|
+
let query;
|
|
2963
|
+
if (kind === "delete") {
|
|
2964
|
+
query = executor.delete(table);
|
|
2965
|
+
} else {
|
|
2966
|
+
const entry = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
|
|
2967
|
+
if (entry && nested.hasOps(entry.ops)) {
|
|
2968
|
+
throw new import_graphql5.GraphQLError(
|
|
2969
|
+
`${fieldName} does not support nested writes \u2014 use ${fieldName.slice(0, -"Count".length)} instead.`
|
|
2970
|
+
);
|
|
2971
|
+
}
|
|
2972
|
+
const values = remapUpdateInput(entry ? entry.columns : set, table, tableName);
|
|
2973
|
+
if (!Object.keys(values).length) {
|
|
2974
|
+
throw new import_graphql5.GraphQLError("Unable to update with no values specified!");
|
|
2975
|
+
}
|
|
2976
|
+
query = executor.update(table).set(values);
|
|
2977
|
+
}
|
|
2978
|
+
if (filters) {
|
|
2979
|
+
query = query.where(filters);
|
|
2980
|
+
}
|
|
2981
|
+
return rowsAffected(await query, fieldName);
|
|
2982
|
+
});
|
|
2983
|
+
} catch (e) {
|
|
2984
|
+
throw toGraphQLError(e);
|
|
2985
|
+
}
|
|
2986
|
+
},
|
|
2987
|
+
args: queryArgs
|
|
2988
|
+
};
|
|
2656
2989
|
};
|
|
2657
2990
|
var selectArrayArgs = (orderArgs, filterArgs, distinctEnum) => ({
|
|
2658
|
-
offset: { type:
|
|
2659
|
-
limit: { type:
|
|
2991
|
+
offset: { type: import_graphql5.GraphQLInt },
|
|
2992
|
+
limit: { type: import_graphql5.GraphQLInt },
|
|
2660
2993
|
orderBy: { type: orderArgs },
|
|
2661
2994
|
where: { type: filterArgs },
|
|
2662
2995
|
after: {
|
|
2663
|
-
type:
|
|
2996
|
+
type: import_graphql5.GraphQLString,
|
|
2664
2997
|
description: "Keyset pagination: only return rows strictly after this cursor (a row's `cursor` field from a previous page, under the same orderBy)."
|
|
2665
2998
|
},
|
|
2666
|
-
...distinctEnum ? { distinct: { type: new
|
|
2999
|
+
...distinctEnum ? { distinct: { type: new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(distinctEnum)) } } : {}
|
|
2667
3000
|
});
|
|
2668
3001
|
var selectSingleArgs = (orderArgs, filterArgs) => ({
|
|
2669
|
-
offset: { type:
|
|
3002
|
+
offset: { type: import_graphql5.GraphQLInt },
|
|
2670
3003
|
orderBy: { type: orderArgs },
|
|
2671
3004
|
where: { type: filterArgs }
|
|
2672
3005
|
});
|
|
@@ -2693,17 +3026,17 @@ var runRelationalSelect = async (opts) => {
|
|
|
2693
3026
|
let cursorEntries;
|
|
2694
3027
|
if (!single && (after != null || cursorSelected)) {
|
|
2695
3028
|
if (after != null && distinct) {
|
|
2696
|
-
throw new
|
|
3029
|
+
throw new import_graphql5.GraphQLError("'after' cannot be combined with 'distinct'.");
|
|
2697
3030
|
}
|
|
2698
3031
|
if (orderByHasRelationEntry(orderBy)) {
|
|
2699
3032
|
if (after != null) {
|
|
2700
|
-
throw new
|
|
3033
|
+
throw new import_graphql5.GraphQLError(
|
|
2701
3034
|
"'after' cannot be combined with an orderBy that orders through a relation \u2014 a related row's value cannot be encoded into a cursor."
|
|
2702
3035
|
);
|
|
2703
3036
|
}
|
|
2704
3037
|
} else if (!pkNames?.length) {
|
|
2705
3038
|
if (after != null) {
|
|
2706
|
-
throw new
|
|
3039
|
+
throw new import_graphql5.GraphQLError(`Table ${tableName} has no primary key, so cursor pagination cannot be used on it.`);
|
|
2707
3040
|
}
|
|
2708
3041
|
} else {
|
|
2709
3042
|
cursorEntries = cursorOrderingEntries(orderBy, pkNames);
|
|
@@ -2747,7 +3080,7 @@ var runRelationalSelect = async (opts) => {
|
|
|
2747
3080
|
(aliasedTable2) => cursorOrderExprs(aliasedTable2, cursorEntries)
|
|
2748
3081
|
) : orderBy ? (aliasedTable2) => extractOrderBy(aliasedTable2, orderBy, relationFilterCtx(filterCtx, tableName)) : needsDefaultOrder && pkNames?.length ? (aliasedTable2) => primaryKeyOrderExprs(aliasedTable2, pkNames) : void 0,
|
|
2749
3082
|
where: distinctKeys ? { RAW: (aliasedTable2) => primaryKeyRestriction(aliasedTable2, pkNames, distinctKeys) } : where || cursorValues ? {
|
|
2750
|
-
RAW: (aliasedTable2) => (0,
|
|
3083
|
+
RAW: (aliasedTable2) => (0, import_drizzle_orm4.and)(
|
|
2751
3084
|
where ? extractFilters(aliasedTable2, tableName, where, relationFilterCtx(filterCtx, tableName)) : void 0,
|
|
2752
3085
|
cursorValues ? buildCursorCondition(
|
|
2753
3086
|
aliasedTable2,
|
|
@@ -2757,7 +3090,16 @@ var runRelationalSelect = async (opts) => {
|
|
|
2757
3090
|
) : void 0
|
|
2758
3091
|
)
|
|
2759
3092
|
} : void 0,
|
|
2760
|
-
with: relationMap[tableName] ? extractRelationsParams(
|
|
3093
|
+
with: relationMap[tableName] ? extractRelationsParams(
|
|
3094
|
+
relationMap,
|
|
3095
|
+
tables,
|
|
3096
|
+
tableName,
|
|
3097
|
+
parsedInfo,
|
|
3098
|
+
typeName,
|
|
3099
|
+
typeNameMapper,
|
|
3100
|
+
filterCtx,
|
|
3101
|
+
opts.limits
|
|
3102
|
+
) : void 0
|
|
2761
3103
|
};
|
|
2762
3104
|
if (single) {
|
|
2763
3105
|
const result2 = await queryBase.findFirst(params);
|
|
@@ -2797,23 +3139,23 @@ var eagerLoadMutationRelations = async (db, tableName, rows, pkNames, withParams
|
|
|
2797
3139
|
if (pkNames.length === 1) {
|
|
2798
3140
|
const pkName = pkNames[0];
|
|
2799
3141
|
const ids = keyableRows.map((r) => r[pkName]);
|
|
2800
|
-
whereRaw = (aliased) => (0,
|
|
3142
|
+
whereRaw = (aliased) => (0, import_drizzle_orm4.inArray)(aliased[pkName], ids);
|
|
2801
3143
|
} else {
|
|
2802
3144
|
whereRaw = (aliased) => {
|
|
2803
|
-
const lhs =
|
|
2804
|
-
pkNames.map((n) =>
|
|
2805
|
-
|
|
3145
|
+
const lhs = import_drizzle_orm4.sql.join(
|
|
3146
|
+
pkNames.map((n) => import_drizzle_orm4.sql`${aliased[n]}`),
|
|
3147
|
+
import_drizzle_orm4.sql`, `
|
|
2806
3148
|
);
|
|
2807
|
-
const tuples =
|
|
3149
|
+
const tuples = import_drizzle_orm4.sql.join(
|
|
2808
3150
|
keyableRows.map(
|
|
2809
|
-
(row) =>
|
|
2810
|
-
pkNames.map((n) =>
|
|
2811
|
-
|
|
3151
|
+
(row) => import_drizzle_orm4.sql`(${import_drizzle_orm4.sql.join(
|
|
3152
|
+
pkNames.map((n) => import_drizzle_orm4.sql`${row[n]}`),
|
|
3153
|
+
import_drizzle_orm4.sql`, `
|
|
2812
3154
|
)})`
|
|
2813
3155
|
),
|
|
2814
|
-
|
|
3156
|
+
import_drizzle_orm4.sql`, `
|
|
2815
3157
|
);
|
|
2816
|
-
return
|
|
3158
|
+
return import_drizzle_orm4.sql`(${lhs}) in (${tuples})`;
|
|
2817
3159
|
};
|
|
2818
3160
|
}
|
|
2819
3161
|
let enriched;
|
|
@@ -2844,38 +3186,38 @@ var eagerLoadMutationRelations = async (db, tableName, rows, pkNames, withParams
|
|
|
2844
3186
|
};
|
|
2845
3187
|
|
|
2846
3188
|
// src/util/builders/mysql.ts
|
|
2847
|
-
var
|
|
3189
|
+
var import_drizzle_orm6 = require("drizzle-orm");
|
|
2848
3190
|
var import_mysql_core2 = require("drizzle-orm/mysql-core");
|
|
2849
|
-
var
|
|
3191
|
+
var import_graphql7 = require("graphql");
|
|
2850
3192
|
var import_graphql_parse_resolve_info2 = require("graphql-parse-resolve-info");
|
|
2851
3193
|
|
|
2852
3194
|
// src/util/builders/aggregates.ts
|
|
2853
|
-
var
|
|
2854
|
-
var
|
|
3195
|
+
var import_drizzle_orm5 = require("drizzle-orm");
|
|
3196
|
+
var import_graphql6 = require("graphql");
|
|
2855
3197
|
var import_graphql_parse_resolve_info = require("graphql-parse-resolve-info");
|
|
2856
3198
|
var AGGREGATE_OPS = ["avg", "sum", "min", "max", "countNonNull", "countDistinct"];
|
|
2857
3199
|
var COUNT_OPS = /* @__PURE__ */ new Set(["countNonNull", "countDistinct"]);
|
|
2858
3200
|
var OP_FNS = {
|
|
2859
|
-
avg:
|
|
2860
|
-
sum:
|
|
2861
|
-
min:
|
|
2862
|
-
max:
|
|
2863
|
-
countNonNull:
|
|
2864
|
-
countDistinct:
|
|
3201
|
+
avg: import_drizzle_orm5.avg,
|
|
3202
|
+
sum: import_drizzle_orm5.sum,
|
|
3203
|
+
min: import_drizzle_orm5.min,
|
|
3204
|
+
max: import_drizzle_orm5.max,
|
|
3205
|
+
countNonNull: import_drizzle_orm5.count,
|
|
3206
|
+
countDistinct: import_drizzle_orm5.countDistinct
|
|
2865
3207
|
};
|
|
2866
3208
|
var SEP = "__";
|
|
2867
3209
|
var classifyAggregateColumns = (table, tableName) => {
|
|
2868
3210
|
const numeric = {};
|
|
2869
3211
|
const orderable = {};
|
|
2870
3212
|
const all = {};
|
|
2871
|
-
for (const [columnName, column] of Object.entries((0,
|
|
3213
|
+
for (const [columnName, column] of Object.entries((0, import_drizzle_orm5.getColumns)(table))) {
|
|
2872
3214
|
all[columnName] = column;
|
|
2873
3215
|
const converted = drizzleColumnToGraphQLType(column, columnName, tableName, true, false, false);
|
|
2874
3216
|
const gqlType = converted.type;
|
|
2875
|
-
if (gqlType instanceof
|
|
3217
|
+
if (gqlType instanceof import_graphql6.GraphQLList || gqlType instanceof import_graphql6.GraphQLObjectType) {
|
|
2876
3218
|
continue;
|
|
2877
3219
|
}
|
|
2878
|
-
const { type: dataType, constraint } = (0,
|
|
3220
|
+
const { type: dataType, constraint } = (0, import_drizzle_orm5.extractExtendedColumnType)(column);
|
|
2879
3221
|
if (dataType === "boolean" || dataType === "array" || dataType === "custom") {
|
|
2880
3222
|
continue;
|
|
2881
3223
|
}
|
|
@@ -2896,14 +3238,14 @@ var generateAggregateTypes = (table, tableName, typeName, cacheCtx) => {
|
|
|
2896
3238
|
}
|
|
2897
3239
|
const { numeric, orderable, all } = classifyAggregateColumns(table, tableName);
|
|
2898
3240
|
const fields = {
|
|
2899
|
-
count: { type: new
|
|
3241
|
+
count: { type: new import_graphql6.GraphQLNonNull(import_graphql6.GraphQLInt) }
|
|
2900
3242
|
};
|
|
2901
3243
|
if (Object.keys(numeric).length) {
|
|
2902
3244
|
for (const op of ["avg", "sum"]) {
|
|
2903
3245
|
fields[op] = {
|
|
2904
|
-
type: new
|
|
3246
|
+
type: new import_graphql6.GraphQLObjectType({
|
|
2905
3247
|
name: `${typeName}${capitalize(op)}Aggregate`,
|
|
2906
|
-
fields: Object.fromEntries(Object.keys(numeric).map((columnName) => [columnName, { type:
|
|
3248
|
+
fields: Object.fromEntries(Object.keys(numeric).map((columnName) => [columnName, { type: import_graphql6.GraphQLFloat }]))
|
|
2907
3249
|
})
|
|
2908
3250
|
};
|
|
2909
3251
|
}
|
|
@@ -2911,7 +3253,7 @@ var generateAggregateTypes = (table, tableName, typeName, cacheCtx) => {
|
|
|
2911
3253
|
if (Object.keys(orderable).length) {
|
|
2912
3254
|
for (const op of ["min", "max"]) {
|
|
2913
3255
|
fields[op] = {
|
|
2914
|
-
type: new
|
|
3256
|
+
type: new import_graphql6.GraphQLObjectType({
|
|
2915
3257
|
name: `${typeName}${capitalize(op)}Aggregate`,
|
|
2916
3258
|
fields: Object.fromEntries(
|
|
2917
3259
|
Object.entries(orderable).map(([columnName, { column, converted }]) => [
|
|
@@ -2930,15 +3272,15 @@ var generateAggregateTypes = (table, tableName, typeName, cacheCtx) => {
|
|
|
2930
3272
|
continue;
|
|
2931
3273
|
}
|
|
2932
3274
|
fields[op] = {
|
|
2933
|
-
type: new
|
|
3275
|
+
type: new import_graphql6.GraphQLObjectType({
|
|
2934
3276
|
name: `${typeName}${capitalize(op)}Aggregate`,
|
|
2935
3277
|
fields: Object.fromEntries(
|
|
2936
|
-
columnNames.map((columnName) => [columnName, { type: new
|
|
3278
|
+
columnNames.map((columnName) => [columnName, { type: new import_graphql6.GraphQLNonNull(import_graphql6.GraphQLInt) }])
|
|
2937
3279
|
)
|
|
2938
3280
|
})
|
|
2939
3281
|
};
|
|
2940
3282
|
}
|
|
2941
|
-
const aggregateType = new
|
|
3283
|
+
const aggregateType = new import_graphql6.GraphQLObjectType({
|
|
2942
3284
|
name: `${typeName}Aggregate`,
|
|
2943
3285
|
fields
|
|
2944
3286
|
});
|
|
@@ -2961,7 +3303,7 @@ var aggregateTarget = (table, tableName, typeName) => {
|
|
|
2961
3303
|
return {
|
|
2962
3304
|
tableName,
|
|
2963
3305
|
typeName,
|
|
2964
|
-
columns: (0,
|
|
3306
|
+
columns: (0, import_drizzle_orm5.getColumns)(table),
|
|
2965
3307
|
dateTimeColumns: new Set(
|
|
2966
3308
|
Object.entries(orderable).filter(([, { converted }]) => converted.typeLabel === "DateTime").map(([columnName]) => columnName)
|
|
2967
3309
|
)
|
|
@@ -2978,7 +3320,7 @@ var parseAggregateRequest = (info, target, rootTypeName = `${target.typeName}Agg
|
|
|
2978
3320
|
for (const field of Object.values(selectionTree)) {
|
|
2979
3321
|
if (field.name === "count") {
|
|
2980
3322
|
request.count = true;
|
|
2981
|
-
request.selection.count = (0,
|
|
3323
|
+
request.selection.count = (0, import_drizzle_orm5.count)();
|
|
2982
3324
|
continue;
|
|
2983
3325
|
}
|
|
2984
3326
|
if (!AGGREGATE_OPS.includes(field.name)) {
|
|
@@ -3091,8 +3433,8 @@ var createRelationAggregateFactory = (db, tables, cacheCtx, typeNameMapper, filt
|
|
|
3091
3433
|
const loader = getOrCreateLoader(context, loaderKey, async (parentIds) => {
|
|
3092
3434
|
const executor = resolveExecutor(db, context);
|
|
3093
3435
|
const uniqueIds = [...new Set(parentIds)];
|
|
3094
|
-
const whereCondition = (0,
|
|
3095
|
-
(0,
|
|
3436
|
+
const whereCondition = (0, import_drizzle_orm5.and)(
|
|
3437
|
+
(0, import_drizzle_orm5.inArray)(foreignCol, uniqueIds),
|
|
3096
3438
|
whereArg ? extractFilters(targetTable, targetTableName, whereArg, relationFilterCtx(filterCtx, targetTableName)) : void 0
|
|
3097
3439
|
);
|
|
3098
3440
|
const rows = await executor.select({ [GROUP_KEY]: foreignCol, ...request.selection }).from(targetTable).where(whereCondition).groupBy(foreignCol);
|
|
@@ -3108,15 +3450,15 @@ var createRelationAggregateFactory = (db, tables, cacheCtx, typeNameMapper, filt
|
|
|
3108
3450
|
};
|
|
3109
3451
|
};
|
|
3110
3452
|
var GROUP_COL = `group${SEP}`;
|
|
3111
|
-
var HAVING_OPS = { eq:
|
|
3453
|
+
var HAVING_OPS = { eq: import_drizzle_orm5.eq, ne: import_drizzle_orm5.ne, gt: import_drizzle_orm5.gt, gte: import_drizzle_orm5.gte, lt: import_drizzle_orm5.lt, lte: import_drizzle_orm5.lte };
|
|
3112
3454
|
var groupableColumns = (table, tableName) => {
|
|
3113
3455
|
const { orderable } = classifyAggregateColumns(table, tableName);
|
|
3114
3456
|
const groupable = { ...orderable };
|
|
3115
|
-
for (const [columnName, column] of Object.entries((0,
|
|
3457
|
+
for (const [columnName, column] of Object.entries((0, import_drizzle_orm5.getColumns)(table))) {
|
|
3116
3458
|
if (groupable[columnName]) {
|
|
3117
3459
|
continue;
|
|
3118
3460
|
}
|
|
3119
|
-
const { type: dataType } = (0,
|
|
3461
|
+
const { type: dataType } = (0, import_drizzle_orm5.extractExtendedColumnType)(column);
|
|
3120
3462
|
if (dataType !== "boolean") {
|
|
3121
3463
|
continue;
|
|
3122
3464
|
}
|
|
@@ -3136,10 +3478,10 @@ var generateGroupByEnum = (table, tableName, typeName) => {
|
|
|
3136
3478
|
(_column, columnName) => Boolean(groupable[columnName])
|
|
3137
3479
|
);
|
|
3138
3480
|
};
|
|
3139
|
-
var aggregateNumberFilter = new
|
|
3481
|
+
var aggregateNumberFilter = new import_graphql6.GraphQLInputObjectType({
|
|
3140
3482
|
name: "AggregateNumberFilter",
|
|
3141
3483
|
description: "Compares an aggregated value. Several operators in one filter are ANDed together.",
|
|
3142
|
-
fields: Object.fromEntries(Object.keys(HAVING_OPS).map((op) => [op, { type:
|
|
3484
|
+
fields: Object.fromEntries(Object.keys(HAVING_OPS).map((op) => [op, { type: import_graphql6.GraphQLFloat }]))
|
|
3143
3485
|
});
|
|
3144
3486
|
var generateHavingInput = (table, tableName, typeName) => {
|
|
3145
3487
|
const { numeric, orderable, all } = classifyAggregateColumns(table, tableName);
|
|
@@ -3160,13 +3502,13 @@ var generateHavingInput = (table, tableName, typeName) => {
|
|
|
3160
3502
|
continue;
|
|
3161
3503
|
}
|
|
3162
3504
|
fields[op] = {
|
|
3163
|
-
type: new
|
|
3505
|
+
type: new import_graphql6.GraphQLInputObjectType({
|
|
3164
3506
|
name: `${typeName}${capitalize(op)}Having`,
|
|
3165
3507
|
fields: Object.fromEntries(columnNames.map((columnName) => [columnName, { type: aggregateNumberFilter }]))
|
|
3166
3508
|
})
|
|
3167
3509
|
};
|
|
3168
3510
|
}
|
|
3169
|
-
return new
|
|
3511
|
+
return new import_graphql6.GraphQLInputObjectType({
|
|
3170
3512
|
name: `${typeName}Having`,
|
|
3171
3513
|
description: `Filters ${typeName} groups by their aggregated values`,
|
|
3172
3514
|
fields
|
|
@@ -3177,7 +3519,7 @@ var generateGroupByType = (table, tableName, typeName, cacheCtx) => {
|
|
|
3177
3519
|
if (!Object.keys(groupable).length) {
|
|
3178
3520
|
return void 0;
|
|
3179
3521
|
}
|
|
3180
|
-
const keysType = new
|
|
3522
|
+
const keysType = new import_graphql6.GraphQLObjectType({
|
|
3181
3523
|
name: `${typeName}GroupKeys`,
|
|
3182
3524
|
description: `The grouped column values of one ${typeName} group. A column the query did not group by is null.`,
|
|
3183
3525
|
fields: Object.fromEntries(
|
|
@@ -3194,9 +3536,9 @@ var generateGroupByType = (table, tableName, typeName, cacheCtx) => {
|
|
|
3194
3536
|
{ type: field.type, description: field.description ?? void 0 }
|
|
3195
3537
|
])
|
|
3196
3538
|
);
|
|
3197
|
-
return new
|
|
3539
|
+
return new import_graphql6.GraphQLObjectType({
|
|
3198
3540
|
name: `${typeName}GroupBy`,
|
|
3199
|
-
fields: { group: { type: new
|
|
3541
|
+
fields: { group: { type: new import_graphql6.GraphQLNonNull(keysType) }, ...aggregateFields }
|
|
3200
3542
|
});
|
|
3201
3543
|
};
|
|
3202
3544
|
var havingComparisons = (expression, filter) => Object.entries(filter).filter(([op, value]) => value != null && op in HAVING_OPS).map(([op, value]) => HAVING_OPS[op](expression, value));
|
|
@@ -3210,7 +3552,7 @@ var buildHavingCondition = (having, columns) => {
|
|
|
3210
3552
|
continue;
|
|
3211
3553
|
}
|
|
3212
3554
|
if (key === "count") {
|
|
3213
|
-
conditions.push(...havingComparisons((0,
|
|
3555
|
+
conditions.push(...havingComparisons((0, import_drizzle_orm5.count)(), value));
|
|
3214
3556
|
continue;
|
|
3215
3557
|
}
|
|
3216
3558
|
if (!AGGREGATE_OPS.includes(key)) {
|
|
@@ -3224,16 +3566,16 @@ var buildHavingCondition = (having, columns) => {
|
|
|
3224
3566
|
conditions.push(...havingComparisons(OP_FNS[key](column), filter));
|
|
3225
3567
|
}
|
|
3226
3568
|
}
|
|
3227
|
-
return conditions.length ? (0,
|
|
3569
|
+
return conditions.length ? (0, import_drizzle_orm5.and)(...conditions) : void 0;
|
|
3228
3570
|
};
|
|
3229
3571
|
var generateGroupBy = (db, tableName, table, typeName, fieldName, filterArgs, groupByEnum, havingInput, filterCtx) => {
|
|
3230
3572
|
const target = aggregateTarget(table, tableName, typeName);
|
|
3231
3573
|
const groupable = groupableColumns(table, tableName);
|
|
3232
|
-
const columns = (0,
|
|
3574
|
+
const columns = (0, import_drizzle_orm5.getColumns)(table);
|
|
3233
3575
|
const rootTypeName = `${typeName}GroupBy`;
|
|
3234
3576
|
const queryArgs = {
|
|
3235
3577
|
groupBy: {
|
|
3236
|
-
type: new
|
|
3578
|
+
type: new import_graphql6.GraphQLNonNull(new import_graphql6.GraphQLList(new import_graphql6.GraphQLNonNull(groupByEnum))),
|
|
3237
3579
|
description: "Columns to group by. One result row per distinct combination of their values."
|
|
3238
3580
|
},
|
|
3239
3581
|
where: { type: filterArgs, description: "Filters the rows before they are grouped." },
|
|
@@ -3245,12 +3587,12 @@ var generateGroupBy = (db, tableName, table, typeName, fieldName, filterArgs, gr
|
|
|
3245
3587
|
try {
|
|
3246
3588
|
const requestedKeys = [...new Set(args.groupBy ?? [])];
|
|
3247
3589
|
if (!requestedKeys.length) {
|
|
3248
|
-
throw new
|
|
3590
|
+
throw new import_graphql6.GraphQLError("At least one column to group by is required!");
|
|
3249
3591
|
}
|
|
3250
3592
|
const keyColumns = requestedKeys.map((columnName) => {
|
|
3251
3593
|
const groupableColumn = groupable[columnName];
|
|
3252
3594
|
if (!groupableColumn) {
|
|
3253
|
-
throw new
|
|
3595
|
+
throw new import_graphql6.GraphQLError(`Cannot group ${typeName} by ${columnName}!`);
|
|
3254
3596
|
}
|
|
3255
3597
|
return [columnName, groupableColumn.column];
|
|
3256
3598
|
});
|
|
@@ -3287,7 +3629,7 @@ var generateGroupBy = (db, tableName, table, typeName, fieldName, filterArgs, gr
|
|
|
3287
3629
|
};
|
|
3288
3630
|
|
|
3289
3631
|
// src/util/builders/mysql.ts
|
|
3290
|
-
var generateSelectArray = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, distinctEnabled = true) => {
|
|
3632
|
+
var generateSelectArray = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, distinctEnabled = true, limits) => {
|
|
3291
3633
|
const queryBase = db.query[tableName];
|
|
3292
3634
|
if (!queryBase) {
|
|
3293
3635
|
throw new Error(
|
|
@@ -3295,6 +3637,7 @@ var generateSelectArray = (db, tableName, tables, relationMap, orderArgs, filter
|
|
|
3295
3637
|
);
|
|
3296
3638
|
}
|
|
3297
3639
|
const table = tables[tableName];
|
|
3640
|
+
const limitPolicy = limits?.(tableName);
|
|
3298
3641
|
const pkNames = mysqlPrimaryKeyPropNames(table);
|
|
3299
3642
|
const queryArgs = selectArrayArgs(
|
|
3300
3643
|
orderArgs,
|
|
@@ -3317,8 +3660,10 @@ var generateSelectArray = (db, tableName, tables, relationMap, orderArgs, filter
|
|
|
3317
3660
|
typeNameMapper,
|
|
3318
3661
|
parsedInfo,
|
|
3319
3662
|
...args,
|
|
3663
|
+
limit: applyLimitPolicy(args.limit, limitPolicy, fieldName),
|
|
3320
3664
|
single: false,
|
|
3321
3665
|
filterCtx,
|
|
3666
|
+
limits,
|
|
3322
3667
|
pkNames,
|
|
3323
3668
|
db: executor,
|
|
3324
3669
|
// MySQL sorts NULLs as the smallest values (first in ASC).
|
|
@@ -3331,7 +3676,7 @@ var generateSelectArray = (db, tableName, tables, relationMap, orderArgs, filter
|
|
|
3331
3676
|
args: queryArgs
|
|
3332
3677
|
};
|
|
3333
3678
|
};
|
|
3334
|
-
var generateSelectSingle = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx) => {
|
|
3679
|
+
var generateSelectSingle = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, limits) => {
|
|
3335
3680
|
const queryBase = db.query[tableName];
|
|
3336
3681
|
if (!queryBase) {
|
|
3337
3682
|
throw new Error(
|
|
@@ -3359,6 +3704,7 @@ var generateSelectSingle = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
3359
3704
|
...args,
|
|
3360
3705
|
single: true,
|
|
3361
3706
|
filterCtx,
|
|
3707
|
+
limits,
|
|
3362
3708
|
pkNames,
|
|
3363
3709
|
db: executor
|
|
3364
3710
|
});
|
|
@@ -3372,7 +3718,7 @@ var generateSelectSingle = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
3372
3718
|
var generateInsertArray = (db, _tableName, table, baseType, fieldName, txCtx) => {
|
|
3373
3719
|
const queryArgs = {
|
|
3374
3720
|
values: {
|
|
3375
|
-
type: new
|
|
3721
|
+
type: new import_graphql7.GraphQLNonNull(new import_graphql7.GraphQLList(new import_graphql7.GraphQLNonNull(baseType)))
|
|
3376
3722
|
}
|
|
3377
3723
|
};
|
|
3378
3724
|
return {
|
|
@@ -3382,7 +3728,7 @@ var generateInsertArray = (db, _tableName, table, baseType, fieldName, txCtx) =>
|
|
|
3382
3728
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
3383
3729
|
const input = remapFromGraphQLArrayInput(args.values, table);
|
|
3384
3730
|
if (!input.length) {
|
|
3385
|
-
throw new
|
|
3731
|
+
throw new import_graphql7.GraphQLError("No values were provided!");
|
|
3386
3732
|
}
|
|
3387
3733
|
await executor.insert(table).values(input);
|
|
3388
3734
|
return { isSuccess: true };
|
|
@@ -3397,7 +3743,7 @@ var generateInsertArray = (db, _tableName, table, baseType, fieldName, txCtx) =>
|
|
|
3397
3743
|
var generateInsertSingle = (db, _tableName, table, baseType, fieldName, txCtx) => {
|
|
3398
3744
|
const queryArgs = {
|
|
3399
3745
|
values: {
|
|
3400
|
-
type: new
|
|
3746
|
+
type: new import_graphql7.GraphQLNonNull(baseType)
|
|
3401
3747
|
}
|
|
3402
3748
|
};
|
|
3403
3749
|
return {
|
|
@@ -3419,7 +3765,7 @@ var generateInsertSingle = (db, _tableName, table, baseType, fieldName, txCtx) =
|
|
|
3419
3765
|
var generateUpsert = (db, table, baseType, onConflictType, fieldName, single, txCtx) => {
|
|
3420
3766
|
const queryArgs = {
|
|
3421
3767
|
values: {
|
|
3422
|
-
type: single ? new
|
|
3768
|
+
type: single ? new import_graphql7.GraphQLNonNull(baseType) : new import_graphql7.GraphQLNonNull(new import_graphql7.GraphQLList(new import_graphql7.GraphQLNonNull(baseType)))
|
|
3423
3769
|
},
|
|
3424
3770
|
onConflict: {
|
|
3425
3771
|
type: onConflictType,
|
|
@@ -3434,7 +3780,7 @@ var generateUpsert = (db, table, baseType, onConflictType, fieldName, single, tx
|
|
|
3434
3780
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
3435
3781
|
const input = single ? [remapFromGraphQLSingleInput(args.values, table)] : remapFromGraphQLArrayInput(args.values, table);
|
|
3436
3782
|
if (!input.length) {
|
|
3437
|
-
throw new
|
|
3783
|
+
throw new import_graphql7.GraphQLError("No values were provided!");
|
|
3438
3784
|
}
|
|
3439
3785
|
const plan = resolveConflictPlan({
|
|
3440
3786
|
table,
|
|
@@ -3462,10 +3808,10 @@ var generateUpsert = (db, table, baseType, onConflictType, fieldName, single, tx
|
|
|
3462
3808
|
var generateUpdate = (db, tableName, table, setArgs, filterArgs, fieldName, single, requireWhere, filterCtx, txCtx) => {
|
|
3463
3809
|
const queryArgs = {
|
|
3464
3810
|
set: {
|
|
3465
|
-
type: new
|
|
3811
|
+
type: new import_graphql7.GraphQLNonNull(setArgs)
|
|
3466
3812
|
},
|
|
3467
3813
|
where: {
|
|
3468
|
-
type: single || requireWhere ? new
|
|
3814
|
+
type: single || requireWhere ? new import_graphql7.GraphQLNonNull(filterArgs) : filterArgs
|
|
3469
3815
|
}
|
|
3470
3816
|
};
|
|
3471
3817
|
return {
|
|
@@ -3474,9 +3820,9 @@ var generateUpdate = (db, tableName, table, setArgs, filterArgs, fieldName, sing
|
|
|
3474
3820
|
try {
|
|
3475
3821
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
3476
3822
|
const { where, set } = args;
|
|
3477
|
-
const input =
|
|
3823
|
+
const input = remapUpdateInput(set, table, tableName);
|
|
3478
3824
|
if (!Object.keys(input).length) {
|
|
3479
|
-
throw new
|
|
3825
|
+
throw new import_graphql7.GraphQLError("Unable to update with no values specified!");
|
|
3480
3826
|
}
|
|
3481
3827
|
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
3482
3828
|
const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
@@ -3500,7 +3846,7 @@ var generateUpdate = (db, tableName, table, setArgs, filterArgs, fieldName, sing
|
|
|
3500
3846
|
var generateUpdateMany = (db, tableName, table, updateManyInput, fieldName, filterCtx, txCtx) => {
|
|
3501
3847
|
const queryArgs = {
|
|
3502
3848
|
updates: {
|
|
3503
|
-
type: new
|
|
3849
|
+
type: new import_graphql7.GraphQLNonNull(new import_graphql7.GraphQLList(new import_graphql7.GraphQLNonNull(updateManyInput)))
|
|
3504
3850
|
}
|
|
3505
3851
|
};
|
|
3506
3852
|
return {
|
|
@@ -3510,12 +3856,12 @@ var generateUpdateMany = (db, tableName, table, updateManyInput, fieldName, filt
|
|
|
3510
3856
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
3511
3857
|
const { updates } = args;
|
|
3512
3858
|
if (!updates.length) {
|
|
3513
|
-
throw new
|
|
3859
|
+
throw new import_graphql7.GraphQLError("No updates were provided!");
|
|
3514
3860
|
}
|
|
3515
3861
|
const entries = updates.map(({ where, set }) => {
|
|
3516
|
-
const input =
|
|
3862
|
+
const input = remapUpdateInput(set, table, tableName);
|
|
3517
3863
|
if (!Object.keys(input).length) {
|
|
3518
|
-
throw new
|
|
3864
|
+
throw new import_graphql7.GraphQLError("Unable to update with no values specified!");
|
|
3519
3865
|
}
|
|
3520
3866
|
return {
|
|
3521
3867
|
set: input,
|
|
@@ -3543,7 +3889,7 @@ var generateUpdateMany = (db, tableName, table, updateManyInput, fieldName, filt
|
|
|
3543
3889
|
var generateDelete = (db, tableName, table, filterArgs, fieldName, single, requireWhere, filterCtx, txCtx) => {
|
|
3544
3890
|
const queryArgs = {
|
|
3545
3891
|
where: {
|
|
3546
|
-
type: single || requireWhere ? new
|
|
3892
|
+
type: single || requireWhere ? new import_graphql7.GraphQLNonNull(filterArgs) : filterArgs
|
|
3547
3893
|
}
|
|
3548
3894
|
};
|
|
3549
3895
|
return {
|
|
@@ -3573,10 +3919,10 @@ var generateDelete = (db, tableName, table, filterArgs, fieldName, single, requi
|
|
|
3573
3919
|
};
|
|
3574
3920
|
var mysqlPrimaryKeyPropNames = (table) => getPrimaryKeyPropNamesFromConfig(table, import_mysql_core2.getTableConfig);
|
|
3575
3921
|
var generateSchemaData = (db, schema, relations, options) => {
|
|
3576
|
-
const { relationsDepthLimit, prefixes, suffixes, typeNameMapper, shouldEagerLoad, features, complexity } = options;
|
|
3922
|
+
const { relationsDepthLimit, prefixes, suffixes, typeNameMapper, shouldEagerLoad, features, complexity, limits } = options;
|
|
3577
3923
|
const rawSchema = schema;
|
|
3578
3924
|
const schemaEntries = Object.entries(rawSchema);
|
|
3579
|
-
const tableEntries = schemaEntries.filter(([_key, value]) => (0,
|
|
3925
|
+
const tableEntries = schemaEntries.filter(([_key, value]) => (0, import_drizzle_orm6.is)(value, import_mysql_core2.MySqlTable));
|
|
3580
3926
|
const tables = Object.fromEntries(tableEntries);
|
|
3581
3927
|
if (!tableEntries.length) {
|
|
3582
3928
|
throw new Error(
|
|
@@ -3594,7 +3940,13 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3594
3940
|
attachTargetPrimaryKeys(namedRelations, tables, mysqlPrimaryKeyPropNames);
|
|
3595
3941
|
const eagerRelations = pruneNonEagerRelations(namedRelations, shouldEagerLoad);
|
|
3596
3942
|
const filterCtx = { tables, relationMap: namedRelations };
|
|
3597
|
-
const resolverFactory = createRelationResolverFactory(
|
|
3943
|
+
const resolverFactory = createRelationResolverFactory(
|
|
3944
|
+
db,
|
|
3945
|
+
tables,
|
|
3946
|
+
"nulls-smallest",
|
|
3947
|
+
filterCtx,
|
|
3948
|
+
limits
|
|
3949
|
+
);
|
|
3598
3950
|
const cacheCtx = {
|
|
3599
3951
|
genericFilterCache: /* @__PURE__ */ new Map(),
|
|
3600
3952
|
objectTypeCache: /* @__PURE__ */ new Map(),
|
|
@@ -3608,7 +3960,9 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3608
3960
|
listRelationFilterCache: /* @__PURE__ */ new Map(),
|
|
3609
3961
|
aggregateTypeCache: /* @__PURE__ */ new Map(),
|
|
3610
3962
|
complexity,
|
|
3611
|
-
|
|
3963
|
+
limits,
|
|
3964
|
+
docs: options.docs ?? {},
|
|
3965
|
+
features
|
|
3612
3966
|
};
|
|
3613
3967
|
const relationAggregateFactory = features.relationAggregates ? createRelationAggregateFactory(db, tables, cacheCtx, typeNameMapper, filterCtx) : void 0;
|
|
3614
3968
|
const queries = {};
|
|
@@ -3632,11 +3986,11 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3632
3986
|
)
|
|
3633
3987
|
])
|
|
3634
3988
|
);
|
|
3635
|
-
const mutationReturnType = new
|
|
3989
|
+
const mutationReturnType = new import_graphql7.GraphQLObjectType({
|
|
3636
3990
|
name: "MutationReturn",
|
|
3637
3991
|
fields: {
|
|
3638
3992
|
isSuccess: {
|
|
3639
|
-
type: new
|
|
3993
|
+
type: new import_graphql7.GraphQLNonNull(import_graphql7.GraphQLBoolean)
|
|
3640
3994
|
}
|
|
3641
3995
|
}
|
|
3642
3996
|
});
|
|
@@ -3661,8 +4015,10 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3661
4015
|
updateFieldName,
|
|
3662
4016
|
updateManyFieldName,
|
|
3663
4017
|
updateSingleFieldName,
|
|
4018
|
+
updateCountFieldName,
|
|
3664
4019
|
deleteFieldName,
|
|
3665
|
-
deleteSingleFieldName
|
|
4020
|
+
deleteSingleFieldName,
|
|
4021
|
+
deleteCountFieldName
|
|
3666
4022
|
} = computeResolverFieldNames(tableName, typeNameMapper, prefixes, suffixes);
|
|
3667
4023
|
const selectArrGenerated = generateSelectArray(
|
|
3668
4024
|
db,
|
|
@@ -3675,7 +4031,8 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3675
4031
|
typeName,
|
|
3676
4032
|
typeNameMapper,
|
|
3677
4033
|
filterCtx,
|
|
3678
|
-
features.distinct
|
|
4034
|
+
features.distinct,
|
|
4035
|
+
limits
|
|
3679
4036
|
);
|
|
3680
4037
|
const selectSingleGenerated = generateSelectSingle(
|
|
3681
4038
|
db,
|
|
@@ -3687,7 +4044,8 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3687
4044
|
singleFieldName,
|
|
3688
4045
|
typeName,
|
|
3689
4046
|
typeNameMapper,
|
|
3690
|
-
filterCtx
|
|
4047
|
+
filterCtx,
|
|
4048
|
+
limits
|
|
3691
4049
|
);
|
|
3692
4050
|
const insertArrGenerated = features.insert ? generateInsertArray(
|
|
3693
4051
|
db,
|
|
@@ -3786,6 +4144,29 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3786
4144
|
filterCtx,
|
|
3787
4145
|
mutationTxCtx
|
|
3788
4146
|
) : void 0;
|
|
4147
|
+
const updateCountGenerated = features.update && features.countMutations ? generateWriteCount({
|
|
4148
|
+
db,
|
|
4149
|
+
tableName,
|
|
4150
|
+
table: schema[tableName],
|
|
4151
|
+
kind: "update",
|
|
4152
|
+
setArgs: updateInput,
|
|
4153
|
+
filterArgs: tableFilters,
|
|
4154
|
+
fieldName: updateCountFieldName,
|
|
4155
|
+
requireWhere: features.requireWhere,
|
|
4156
|
+
filterCtx,
|
|
4157
|
+
txCtx: mutationTxCtx
|
|
4158
|
+
}) : void 0;
|
|
4159
|
+
const deleteCountGenerated = features.delete && features.countMutations ? generateWriteCount({
|
|
4160
|
+
db,
|
|
4161
|
+
tableName,
|
|
4162
|
+
table: schema[tableName],
|
|
4163
|
+
kind: "delete",
|
|
4164
|
+
filterArgs: tableFilters,
|
|
4165
|
+
fieldName: deleteCountFieldName,
|
|
4166
|
+
requireWhere: features.requireWhere,
|
|
4167
|
+
filterCtx,
|
|
4168
|
+
txCtx: mutationTxCtx
|
|
4169
|
+
}) : void 0;
|
|
3789
4170
|
const aggregateType = features.aggregates ? generateAggregateTypes(schema[tableName], tableName, typeName, cacheCtx) : void 0;
|
|
3790
4171
|
const aggregateGenerated = features.aggregates ? generateAggregate(
|
|
3791
4172
|
db,
|
|
@@ -3814,7 +4195,7 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3814
4195
|
type: selectArrOutput,
|
|
3815
4196
|
args: selectArrGenerated.args,
|
|
3816
4197
|
resolve: selectArrGenerated.resolver,
|
|
3817
|
-
...complexity ? { extensions: { complexity: listFieldComplexity(complexity) } } : {}
|
|
4198
|
+
...complexity ? { extensions: { complexity: listFieldComplexity(complexity, limits?.(tableName)) } } : {}
|
|
3818
4199
|
};
|
|
3819
4200
|
queries[selectSingleGenerated.name] = {
|
|
3820
4201
|
type: selectSingleOutput,
|
|
@@ -3823,7 +4204,7 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3823
4204
|
};
|
|
3824
4205
|
if (aggregateGenerated && aggregateType) {
|
|
3825
4206
|
queries[aggregateGenerated.name] = {
|
|
3826
|
-
type: new
|
|
4207
|
+
type: new import_graphql7.GraphQLNonNull(aggregateType),
|
|
3827
4208
|
args: aggregateGenerated.args,
|
|
3828
4209
|
resolve: aggregateGenerated.resolver,
|
|
3829
4210
|
...complexity ? { extensions: { complexity: aggregateFieldComplexity(complexity) } } : {}
|
|
@@ -3831,7 +4212,7 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3831
4212
|
}
|
|
3832
4213
|
if (groupByGenerated && groupByType) {
|
|
3833
4214
|
queries[groupByGenerated.name] = {
|
|
3834
|
-
type: new
|
|
4215
|
+
type: new import_graphql7.GraphQLNonNull(new import_graphql7.GraphQLList(new import_graphql7.GraphQLNonNull(groupByType))),
|
|
3835
4216
|
args: groupByGenerated.args,
|
|
3836
4217
|
resolve: groupByGenerated.resolver,
|
|
3837
4218
|
...complexity ? { extensions: { complexity: aggregateFieldComplexity(complexity) } } : {}
|
|
@@ -3856,6 +4237,22 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3856
4237
|
};
|
|
3857
4238
|
}
|
|
3858
4239
|
}
|
|
4240
|
+
if (updateCountGenerated) {
|
|
4241
|
+
mutations[updateCountGenerated.name] = {
|
|
4242
|
+
type: new import_graphql7.GraphQLNonNull(import_graphql7.GraphQLInt),
|
|
4243
|
+
args: updateCountGenerated.args,
|
|
4244
|
+
resolve: updateCountGenerated.resolver,
|
|
4245
|
+
description: "How many rows the update touched. The rows themselves are not read back, which is the point of this mutation."
|
|
4246
|
+
};
|
|
4247
|
+
}
|
|
4248
|
+
if (deleteCountGenerated) {
|
|
4249
|
+
mutations[deleteCountGenerated.name] = {
|
|
4250
|
+
type: new import_graphql7.GraphQLNonNull(import_graphql7.GraphQLInt),
|
|
4251
|
+
args: deleteCountGenerated.args,
|
|
4252
|
+
resolve: deleteCountGenerated.resolver,
|
|
4253
|
+
description: "How many rows the delete removed. The rows themselves are not read back, which is the point of this mutation."
|
|
4254
|
+
};
|
|
4255
|
+
}
|
|
3859
4256
|
const activeInputs = [
|
|
3860
4257
|
// The insert input types the upsert mutations too, so either feature keeps it.
|
|
3861
4258
|
...features.insert || onConflictInput ? [insertInput] : [],
|
|
@@ -3886,7 +4283,7 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3886
4283
|
for (const [tableName, tableRelations] of Object.entries(namedRelations)) {
|
|
3887
4284
|
const relResolvers = {};
|
|
3888
4285
|
for (const [relName, relEntry] of Object.entries(tableRelations)) {
|
|
3889
|
-
const isOne = (0,
|
|
4286
|
+
const isOne = (0, import_drizzle_orm6.is)(relEntry.relation ?? relEntry, import_drizzle_orm6.One);
|
|
3890
4287
|
const resolver = resolverFactory({ tableName, relationName: relName, relEntry, isOne });
|
|
3891
4288
|
if (resolver) {
|
|
3892
4289
|
relResolvers[relName] = resolver;
|
|
@@ -3900,14 +4297,14 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3900
4297
|
};
|
|
3901
4298
|
|
|
3902
4299
|
// src/util/builders/pg.ts
|
|
3903
|
-
var
|
|
4300
|
+
var import_drizzle_orm8 = require("drizzle-orm");
|
|
3904
4301
|
var import_pg_core2 = require("drizzle-orm/pg-core");
|
|
3905
|
-
var
|
|
4302
|
+
var import_graphql9 = require("graphql");
|
|
3906
4303
|
var import_graphql_parse_resolve_info3 = require("graphql-parse-resolve-info");
|
|
3907
4304
|
|
|
3908
4305
|
// src/util/builders/nested-writes.ts
|
|
3909
|
-
var
|
|
3910
|
-
var
|
|
4306
|
+
var import_drizzle_orm7 = require("drizzle-orm");
|
|
4307
|
+
var import_graphql8 = require("graphql");
|
|
3911
4308
|
var isOptionalOnInsert = (column) => !column.notNull || !!column.hasDefault || !!column.defaultFn;
|
|
3912
4309
|
var buildNestedWritePlans = (tables, relationMap, resolveUniqueSets, resolvePrimaryKeys, extractJoinColumns) => {
|
|
3913
4310
|
const uniqueCache = /* @__PURE__ */ new Map();
|
|
@@ -3951,11 +4348,11 @@ var buildNestedWritePlans = (tables, relationMap, resolveUniqueSets, resolvePrim
|
|
|
3951
4348
|
continue;
|
|
3952
4349
|
}
|
|
3953
4350
|
const { localColPropName, foreignCol, foreignColPropName } = joinColumns;
|
|
3954
|
-
const localCol = (0,
|
|
4351
|
+
const localCol = (0, import_drizzle_orm7.getColumns)(table)[localColPropName];
|
|
3955
4352
|
if (!localCol) {
|
|
3956
4353
|
continue;
|
|
3957
4354
|
}
|
|
3958
|
-
const isOne = (0,
|
|
4355
|
+
const isOne = (0, import_drizzle_orm7.is)(relation, import_drizzle_orm7.One);
|
|
3959
4356
|
const localIsPk = singleColumnPk(tableName, table) === localColPropName;
|
|
3960
4357
|
const foreignIsPk = singleColumnPk(targetTableName, targetTable) === foreignColPropName;
|
|
3961
4358
|
const localIsUnique = singleColumnUniques(tableName, table).has(localColPropName);
|
|
@@ -4007,12 +4404,12 @@ var createNestedWriteTypes = (params) => {
|
|
|
4007
4404
|
}
|
|
4008
4405
|
const omitted = plan.fkSide === "child" ? plan.foreignColPropName : void 0;
|
|
4009
4406
|
const fields = Object.fromEntries(
|
|
4010
|
-
Object.entries((0,
|
|
4407
|
+
Object.entries((0, import_drizzle_orm7.getColumns)(plan.targetTable)).filter(([columnName]) => columnName !== omitted).map(([columnName, column]) => [
|
|
4011
4408
|
columnName,
|
|
4012
4409
|
drizzleColumnToGraphQLType(column, columnName, plan.targetTableName, false, true, true)
|
|
4013
4410
|
])
|
|
4014
4411
|
);
|
|
4015
|
-
const type = new
|
|
4412
|
+
const type = new import_graphql8.GraphQLInputObjectType({
|
|
4016
4413
|
name: `${capitalize(insertPrefix)}${typeName}${capitalize(plan.relationName)}Input`,
|
|
4017
4414
|
description: omitted === void 0 ? `A new ${resolveTypeName(plan.targetTableName, typeNameMapper)} row for ${typeName}.${plan.relationName}` : `A new ${resolveTypeName(plan.targetTableName, typeNameMapper)} row for ${typeName}.${plan.relationName}. \`${omitted}\` is set from the ${typeName} row this is written with.`,
|
|
4018
4415
|
fields
|
|
@@ -4021,7 +4418,7 @@ var createNestedWriteTypes = (params) => {
|
|
|
4021
4418
|
return type;
|
|
4022
4419
|
};
|
|
4023
4420
|
const targetFilters = (plan) => cacheCtx.filterTypeCache.get(plan.targetTable);
|
|
4024
|
-
const listOf = (type) => new
|
|
4421
|
+
const listOf = (type) => new import_graphql8.GraphQLList(new import_graphql8.GraphQLNonNull(type));
|
|
4025
4422
|
const wrapperType = (tableName, typeName, plan, forUpdate) => {
|
|
4026
4423
|
const key = `${tableName}.${plan.relationName}.${forUpdate ? "update" : "create"}`;
|
|
4027
4424
|
const cached = wrapperCache.get(key);
|
|
@@ -4042,7 +4439,7 @@ var createNestedWriteTypes = (params) => {
|
|
|
4042
4439
|
}
|
|
4043
4440
|
if (forUpdate && plan.canDetach) {
|
|
4044
4441
|
fields["disconnect"] = {
|
|
4045
|
-
type:
|
|
4442
|
+
type: import_graphql8.GraphQLBoolean,
|
|
4046
4443
|
description: `Detach the currently attached ${targetTypeName} row, leaving it in place`
|
|
4047
4444
|
};
|
|
4048
4445
|
}
|
|
@@ -4065,7 +4462,7 @@ var createNestedWriteTypes = (params) => {
|
|
|
4065
4462
|
}
|
|
4066
4463
|
}
|
|
4067
4464
|
}
|
|
4068
|
-
const type = new
|
|
4465
|
+
const type = new import_graphql8.GraphQLInputObjectType({
|
|
4069
4466
|
name: `${typeName}${capitalize(plan.relationName)}Nested${forUpdate ? "Update" : "Create"}Input`,
|
|
4070
4467
|
description: `Writes through ${typeName}.${plan.relationName}`,
|
|
4071
4468
|
fields
|
|
@@ -4115,7 +4512,7 @@ var createNestedWriteRuntime = (params) => {
|
|
|
4115
4512
|
relationFilterCtx(filterCtx, plan.targetTableName)
|
|
4116
4513
|
);
|
|
4117
4514
|
if (!condition) {
|
|
4118
|
-
throw new
|
|
4515
|
+
throw new import_graphql8.GraphQLError(
|
|
4119
4516
|
`Drizzle-GraphQL Error: '${operation}' on '${plan.relationName}' needs a filter that selects rows \u2014 it was given one that matches everything.`
|
|
4120
4517
|
);
|
|
4121
4518
|
}
|
|
@@ -4124,12 +4521,12 @@ var createNestedWriteRuntime = (params) => {
|
|
|
4124
4521
|
const assertSingleOperation = (plan, op) => {
|
|
4125
4522
|
const supplied = ["create", "connect", "disconnect"].filter((key) => op[key] !== void 0 && op[key] !== null);
|
|
4126
4523
|
if (supplied.length > 1) {
|
|
4127
|
-
throw new
|
|
4524
|
+
throw new import_graphql8.GraphQLError(
|
|
4128
4525
|
`Drizzle-GraphQL Error: '${plan.relationName}' takes one of ${supplied.join(", ")} at a time \u2014 it holds a single row.`
|
|
4129
4526
|
);
|
|
4130
4527
|
}
|
|
4131
4528
|
};
|
|
4132
|
-
const detachAll = async (executor, plan, key) => executor.update(plan.targetTable).set({ [plan.foreignColPropName]: null }).where((0,
|
|
4529
|
+
const detachAll = async (executor, plan, key) => executor.update(plan.targetTable).set({ [plan.foreignColPropName]: null }).where((0, import_drizzle_orm7.eq)(plan.foreignCol, key));
|
|
4133
4530
|
return {
|
|
4134
4531
|
enabled: (tableName) => !!plans[tableName],
|
|
4135
4532
|
split: (tableName, values) => {
|
|
@@ -4154,7 +4551,7 @@ var createNestedWriteRuntime = (params) => {
|
|
|
4154
4551
|
if (!tablePlans) {
|
|
4155
4552
|
return columns;
|
|
4156
4553
|
}
|
|
4157
|
-
const allColumns = (0,
|
|
4554
|
+
const allColumns = (0, import_drizzle_orm7.getColumns)(table);
|
|
4158
4555
|
for (const relationName of Object.keys(ops)) {
|
|
4159
4556
|
const plan = tablePlans[relationName];
|
|
4160
4557
|
if (plan?.fkSide === "child" && !(plan.localColPropName in columns) && allColumns[plan.localColPropName]) {
|
|
@@ -4180,7 +4577,7 @@ var createNestedWriteRuntime = (params) => {
|
|
|
4180
4577
|
const inserted = await executor.insert(plan.targetTable).values(values).returning();
|
|
4181
4578
|
const created = inserted[0];
|
|
4182
4579
|
if (!created) {
|
|
4183
|
-
throw new
|
|
4580
|
+
throw new import_graphql8.GraphQLError(
|
|
4184
4581
|
`Drizzle-GraphQL Error: 'create' on '${relationName}' inserted no row, so there is nothing to attach.`
|
|
4185
4582
|
);
|
|
4186
4583
|
}
|
|
@@ -4188,7 +4585,7 @@ var createNestedWriteRuntime = (params) => {
|
|
|
4188
4585
|
} else if (op["connect"] !== void 0) {
|
|
4189
4586
|
const rows = await executor.select().from(plan.targetTable).where(conditionOf(plan, op["connect"], "connect"));
|
|
4190
4587
|
if (rows.length !== 1) {
|
|
4191
|
-
throw new
|
|
4588
|
+
throw new import_graphql8.GraphQLError(
|
|
4192
4589
|
`Drizzle-GraphQL Error: 'connect' on '${relationName}' matched ${rows.length} rows \u2014 it attaches a single row, so its filter must match exactly one.`
|
|
4193
4590
|
);
|
|
4194
4591
|
}
|
|
@@ -4215,7 +4612,7 @@ var createNestedWriteRuntime = (params) => {
|
|
|
4215
4612
|
for (const parentRow of parentRows) {
|
|
4216
4613
|
const key = parentRow?.[plan.localColPropName];
|
|
4217
4614
|
if (key === void 0 || key === null) {
|
|
4218
|
-
throw new
|
|
4615
|
+
throw new import_graphql8.GraphQLError(
|
|
4219
4616
|
`Drizzle-GraphQL Error: cannot write through '${relationName}': the ${tableName} row has no '${plan.localColPropName}' value to attach to.`
|
|
4220
4617
|
);
|
|
4221
4618
|
}
|
|
@@ -4232,7 +4629,7 @@ var createNestedWriteRuntime = (params) => {
|
|
|
4232
4629
|
}
|
|
4233
4630
|
} else {
|
|
4234
4631
|
for (const filter of asArray(op["disconnect"])) {
|
|
4235
|
-
await executor.update(plan.targetTable).set({ [plan.foreignColPropName]: null }).where((0,
|
|
4632
|
+
await executor.update(plan.targetTable).set({ [plan.foreignColPropName]: null }).where((0, import_drizzle_orm7.and)((0, import_drizzle_orm7.eq)(plan.foreignCol, key), conditionOf(plan, filter, "disconnect")));
|
|
4236
4633
|
}
|
|
4237
4634
|
}
|
|
4238
4635
|
}
|
|
@@ -4283,9 +4680,10 @@ var updateWithNestedOps = async (params) => {
|
|
|
4283
4680
|
};
|
|
4284
4681
|
|
|
4285
4682
|
// src/util/builders/pg.ts
|
|
4286
|
-
var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, distinctEnabled = true) => {
|
|
4683
|
+
var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, distinctEnabled = true, limits) => {
|
|
4287
4684
|
const queryBase = db.query[tableName];
|
|
4288
4685
|
const table = tables[tableName];
|
|
4686
|
+
const limitPolicy = limits?.(tableName);
|
|
4289
4687
|
const pkNames = pgPrimaryKeyPropNames(table);
|
|
4290
4688
|
const queryArgs = selectArrayArgs(
|
|
4291
4689
|
orderArgs,
|
|
@@ -4298,6 +4696,7 @@ var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
4298
4696
|
try {
|
|
4299
4697
|
const parsedInfo = (0, import_graphql_parse_resolve_info3.parseResolveInfo)(info, { deep: true });
|
|
4300
4698
|
const { executor, queryBase: requestQueryBase } = resolveQueryExecutor(db, context, tableName, queryBase);
|
|
4699
|
+
const limit = applyLimitPolicy(args.limit, limitPolicy, fieldName);
|
|
4301
4700
|
if (requestQueryBase) {
|
|
4302
4701
|
return await runRelationalSelect({
|
|
4303
4702
|
queryBase: requestQueryBase,
|
|
@@ -4309,15 +4708,17 @@ var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
4309
4708
|
typeNameMapper,
|
|
4310
4709
|
parsedInfo,
|
|
4311
4710
|
...args,
|
|
4711
|
+
limit,
|
|
4312
4712
|
single: false,
|
|
4313
4713
|
filterCtx,
|
|
4714
|
+
limits,
|
|
4314
4715
|
pkNames,
|
|
4315
4716
|
db: executor,
|
|
4316
4717
|
// PostgreSQL sorts NULLs as the largest values (last in ASC).
|
|
4317
4718
|
nullOrdering: "nulls-largest"
|
|
4318
4719
|
});
|
|
4319
4720
|
}
|
|
4320
|
-
const { offset,
|
|
4721
|
+
const { offset, orderBy, where, distinct, after } = args;
|
|
4321
4722
|
const selectedColumnsSql = extractSelectedColumnsFromTreeSQLFormat(
|
|
4322
4723
|
parsedInfo.fieldsByTypeName[typeName],
|
|
4323
4724
|
table,
|
|
@@ -4327,24 +4728,24 @@ var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
4327
4728
|
let cursorEntries;
|
|
4328
4729
|
if (after != null || cursorSelected) {
|
|
4329
4730
|
if (after != null && distinct?.length) {
|
|
4330
|
-
throw new
|
|
4731
|
+
throw new import_graphql9.GraphQLError("'after' cannot be combined with 'distinct'.");
|
|
4331
4732
|
}
|
|
4332
4733
|
if (orderByHasRelationEntry(orderBy)) {
|
|
4333
4734
|
if (after != null) {
|
|
4334
|
-
throw new
|
|
4735
|
+
throw new import_graphql9.GraphQLError(
|
|
4335
4736
|
"'after' cannot be combined with an orderBy that orders through a relation \u2014 a related row's value cannot be encoded into a cursor."
|
|
4336
4737
|
);
|
|
4337
4738
|
}
|
|
4338
4739
|
} else if (!pkNames.length) {
|
|
4339
4740
|
if (after != null) {
|
|
4340
|
-
throw new
|
|
4741
|
+
throw new import_graphql9.GraphQLError(
|
|
4341
4742
|
`Table ${tableName} has no primary key, so cursor pagination cannot be used on it.`
|
|
4342
4743
|
);
|
|
4343
4744
|
}
|
|
4344
4745
|
} else {
|
|
4345
4746
|
cursorEntries = cursorOrderingEntries(orderBy, pkNames);
|
|
4346
4747
|
if (cursorSelected) {
|
|
4347
|
-
const allColumns = (0,
|
|
4748
|
+
const allColumns = (0, import_drizzle_orm8.getColumns)(table);
|
|
4348
4749
|
for (const [column] of cursorEntries) {
|
|
4349
4750
|
selectedColumnsSql[column] ??= allColumns[column];
|
|
4350
4751
|
}
|
|
@@ -4353,7 +4754,7 @@ var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
4353
4754
|
}
|
|
4354
4755
|
const cursorCondition = after != null && cursorEntries ? buildCursorCondition(table, cursorEntries, decodeCursor(after, cursorEntries), "nulls-largest") : void 0;
|
|
4355
4756
|
const baseWhereSql = where ? extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName)) : void 0;
|
|
4356
|
-
const whereSql = cursorCondition ? (0,
|
|
4757
|
+
const whereSql = cursorCondition ? (0, import_drizzle_orm8.and)(baseWhereSql, cursorCondition) : baseWhereSql;
|
|
4357
4758
|
let distinctKeys;
|
|
4358
4759
|
if (distinct?.length) {
|
|
4359
4760
|
distinctKeys = await selectDistinctKeys({
|
|
@@ -4407,7 +4808,7 @@ var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
4407
4808
|
args: queryArgs
|
|
4408
4809
|
};
|
|
4409
4810
|
};
|
|
4410
|
-
var generateSelectSingle2 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx) => {
|
|
4811
|
+
var generateSelectSingle2 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, limits) => {
|
|
4411
4812
|
const queryBase = db.query[tableName];
|
|
4412
4813
|
const queryArgs = selectSingleArgs(orderArgs, filterArgs);
|
|
4413
4814
|
const table = tables[tableName];
|
|
@@ -4431,6 +4832,7 @@ var generateSelectSingle2 = (db, tableName, tables, relationMap, orderArgs, filt
|
|
|
4431
4832
|
...args,
|
|
4432
4833
|
single: true,
|
|
4433
4834
|
filterCtx,
|
|
4835
|
+
limits,
|
|
4434
4836
|
pkNames,
|
|
4435
4837
|
db: executor
|
|
4436
4838
|
});
|
|
@@ -4464,10 +4866,10 @@ var generateSelectSingle2 = (db, tableName, tables, relationMap, orderArgs, filt
|
|
|
4464
4866
|
};
|
|
4465
4867
|
};
|
|
4466
4868
|
var pgPrimaryKeyPropNames = (table) => getPrimaryKeyPropNamesFromConfig(table, import_pg_core2.getTableConfig);
|
|
4467
|
-
var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested) => {
|
|
4869
|
+
var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested, limits) => {
|
|
4468
4870
|
const queryArgs = {
|
|
4469
4871
|
values: {
|
|
4470
|
-
type: new
|
|
4872
|
+
type: new import_graphql9.GraphQLNonNull(new import_graphql9.GraphQLList(new import_graphql9.GraphQLNonNull(baseType)))
|
|
4471
4873
|
}
|
|
4472
4874
|
};
|
|
4473
4875
|
const pkNames = pgPrimaryKeyPropNames(table);
|
|
@@ -4477,7 +4879,7 @@ var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
4477
4879
|
try {
|
|
4478
4880
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4479
4881
|
if (!args.values.length) {
|
|
4480
|
-
throw new
|
|
4882
|
+
throw new import_graphql9.GraphQLError("No values were provided!");
|
|
4481
4883
|
}
|
|
4482
4884
|
const entries = nested?.enabled(tableName) ? args.values.map((values) => nested.split(tableName, values)) : void 0;
|
|
4483
4885
|
const nestedEntries = entries?.some((entry) => nested.hasOps(entry.ops)) ? entries : void 0;
|
|
@@ -4493,7 +4895,8 @@ var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
4493
4895
|
typeNameMapper,
|
|
4494
4896
|
table,
|
|
4495
4897
|
pkNames,
|
|
4496
|
-
parsedInfo
|
|
4898
|
+
parsedInfo,
|
|
4899
|
+
limits
|
|
4497
4900
|
});
|
|
4498
4901
|
const returning = nestedEntries ? nested.withJoinColumns(tableName, mergedOps(nestedEntries), { ...columns }, table) : columns;
|
|
4499
4902
|
const runInsert = async (target, values) => {
|
|
@@ -4521,10 +4924,10 @@ var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
4521
4924
|
args: queryArgs
|
|
4522
4925
|
};
|
|
4523
4926
|
};
|
|
4524
|
-
var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested) => {
|
|
4927
|
+
var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested, limits) => {
|
|
4525
4928
|
const queryArgs = {
|
|
4526
4929
|
values: {
|
|
4527
|
-
type: new
|
|
4930
|
+
type: new import_graphql9.GraphQLNonNull(baseType)
|
|
4528
4931
|
}
|
|
4529
4932
|
};
|
|
4530
4933
|
const pkNames = pgPrimaryKeyPropNames(table);
|
|
@@ -4547,7 +4950,8 @@ var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType
|
|
|
4547
4950
|
typeNameMapper,
|
|
4548
4951
|
table,
|
|
4549
4952
|
pkNames,
|
|
4550
|
-
parsedInfo
|
|
4953
|
+
parsedInfo,
|
|
4954
|
+
limits
|
|
4551
4955
|
});
|
|
4552
4956
|
const returning = nestedEntry ? nested.withJoinColumns(tableName, nestedEntry.ops, { ...columns }, table) : columns;
|
|
4553
4957
|
const runInsert = async (target, values) => {
|
|
@@ -4566,6 +4970,9 @@ var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType
|
|
|
4566
4970
|
write: runInsert
|
|
4567
4971
|
}) : await runInsert(executor, input);
|
|
4568
4972
|
if (!result[0]) {
|
|
4973
|
+
if (!conflictDoNothing) {
|
|
4974
|
+
throw new import_graphql9.GraphQLError(`${fieldName}: the insert returned no row.`);
|
|
4975
|
+
}
|
|
4569
4976
|
return void 0;
|
|
4570
4977
|
}
|
|
4571
4978
|
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
@@ -4578,10 +4985,10 @@ var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType
|
|
|
4578
4985
|
args: queryArgs
|
|
4579
4986
|
};
|
|
4580
4987
|
};
|
|
4581
|
-
var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx, txCtx, nested) => {
|
|
4988
|
+
var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx, txCtx, nested, limits) => {
|
|
4582
4989
|
const queryArgs = {
|
|
4583
4990
|
values: {
|
|
4584
|
-
type: single ? new
|
|
4991
|
+
type: single ? new import_graphql9.GraphQLNonNull(baseType) : new import_graphql9.GraphQLNonNull(new import_graphql9.GraphQLList(new import_graphql9.GraphQLNonNull(baseType)))
|
|
4585
4992
|
},
|
|
4586
4993
|
onConflict: {
|
|
4587
4994
|
type: onConflictType,
|
|
@@ -4596,7 +5003,7 @@ var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
4596
5003
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4597
5004
|
const supplied = single ? [args.values] : args.values;
|
|
4598
5005
|
if (!supplied.length) {
|
|
4599
|
-
throw new
|
|
5006
|
+
throw new import_graphql9.GraphQLError("No values were provided!");
|
|
4600
5007
|
}
|
|
4601
5008
|
const entries = nested?.enabled(tableName) ? supplied.map((values) => nested.split(tableName, values)) : void 0;
|
|
4602
5009
|
const nestedEntries = entries?.some((entry) => nested.hasOps(entry.ops)) ? entries : void 0;
|
|
@@ -4610,7 +5017,8 @@ var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
4610
5017
|
typeNameMapper,
|
|
4611
5018
|
table,
|
|
4612
5019
|
pkNames,
|
|
4613
|
-
parsedInfo
|
|
5020
|
+
parsedInfo,
|
|
5021
|
+
limits
|
|
4614
5022
|
});
|
|
4615
5023
|
const returning = nestedEntries ? nested.withJoinColumns(tableName, mergedOps(nestedEntries), { ...columns }, table) : columns;
|
|
4616
5024
|
const runUpsert = async (target, values) => {
|
|
@@ -4649,13 +5057,13 @@ var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
4649
5057
|
args: queryArgs
|
|
4650
5058
|
};
|
|
4651
5059
|
};
|
|
4652
|
-
var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx, txCtx, nested) => {
|
|
5060
|
+
var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx, txCtx, nested, limits) => {
|
|
4653
5061
|
const queryArgs = {
|
|
4654
5062
|
set: {
|
|
4655
|
-
type: new
|
|
5063
|
+
type: new import_graphql9.GraphQLNonNull(setArgs)
|
|
4656
5064
|
},
|
|
4657
5065
|
where: {
|
|
4658
|
-
type: single || requireWhere ? new
|
|
5066
|
+
type: single || requireWhere ? new import_graphql9.GraphQLNonNull(filterArgs) : filterArgs
|
|
4659
5067
|
}
|
|
4660
5068
|
};
|
|
4661
5069
|
const pkNames = pgPrimaryKeyPropNames(table);
|
|
@@ -4676,13 +5084,14 @@ var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
4676
5084
|
typeNameMapper,
|
|
4677
5085
|
table,
|
|
4678
5086
|
pkNames,
|
|
4679
|
-
parsedInfo
|
|
5087
|
+
parsedInfo,
|
|
5088
|
+
limits
|
|
4680
5089
|
});
|
|
4681
5090
|
const entry = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
|
|
4682
5091
|
const nestedOps = entry && nested.hasOps(entry.ops) ? entry.ops : void 0;
|
|
4683
|
-
const input =
|
|
5092
|
+
const input = remapUpdateInput(entry ? entry.columns : set, table, tableName);
|
|
4684
5093
|
if (!Object.keys(input).length && !nestedOps) {
|
|
4685
|
-
throw new
|
|
5094
|
+
throw new import_graphql9.GraphQLError("Unable to update with no values specified!");
|
|
4686
5095
|
}
|
|
4687
5096
|
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
4688
5097
|
const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
@@ -4708,7 +5117,7 @@ var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
4708
5117
|
write: runUpdate
|
|
4709
5118
|
}) : await runUpdate(executor, input);
|
|
4710
5119
|
if (single && result.length > 1) {
|
|
4711
|
-
throw new
|
|
5120
|
+
throw new import_graphql9.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
|
|
4712
5121
|
}
|
|
4713
5122
|
if (single && !result[0]) {
|
|
4714
5123
|
return void 0;
|
|
@@ -4723,10 +5132,10 @@ var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
4723
5132
|
args: queryArgs
|
|
4724
5133
|
};
|
|
4725
5134
|
};
|
|
4726
|
-
var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx, txCtx, nested) => {
|
|
5135
|
+
var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx, txCtx, nested, limits) => {
|
|
4727
5136
|
const queryArgs = {
|
|
4728
5137
|
updates: {
|
|
4729
|
-
type: new
|
|
5138
|
+
type: new import_graphql9.GraphQLNonNull(new import_graphql9.GraphQLList(new import_graphql9.GraphQLNonNull(updateManyInput)))
|
|
4730
5139
|
}
|
|
4731
5140
|
};
|
|
4732
5141
|
const pkNames = pgPrimaryKeyPropNames(table);
|
|
@@ -4737,7 +5146,7 @@ var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
4737
5146
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4738
5147
|
const { updates } = args;
|
|
4739
5148
|
if (!updates.length) {
|
|
4740
|
-
throw new
|
|
5149
|
+
throw new import_graphql9.GraphQLError("No updates were provided!");
|
|
4741
5150
|
}
|
|
4742
5151
|
const parsedInfo = (0, import_graphql_parse_resolve_info3.parseResolveInfo)(info, {
|
|
4743
5152
|
deep: true
|
|
@@ -4750,14 +5159,15 @@ var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
4750
5159
|
typeNameMapper,
|
|
4751
5160
|
table,
|
|
4752
5161
|
pkNames,
|
|
4753
|
-
parsedInfo
|
|
5162
|
+
parsedInfo,
|
|
5163
|
+
limits
|
|
4754
5164
|
});
|
|
4755
5165
|
const entries = updates.map(({ where, set }) => {
|
|
4756
5166
|
const split = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
|
|
4757
5167
|
const ops = split && nested.hasOps(split.ops) ? split.ops : void 0;
|
|
4758
|
-
const input =
|
|
5168
|
+
const input = remapUpdateInput(split ? split.columns : set, table, tableName);
|
|
4759
5169
|
if (!Object.keys(input).length && !ops) {
|
|
4760
|
-
throw new
|
|
5170
|
+
throw new import_graphql9.GraphQLError("Unable to update with no values specified!");
|
|
4761
5171
|
}
|
|
4762
5172
|
return {
|
|
4763
5173
|
set: input,
|
|
@@ -4816,7 +5226,7 @@ var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
4816
5226
|
var generateDelete2 = (db, tableName, table, filterArgs, fieldName, typeName, single, requireWhere, filterCtx, selectionCtx, txCtx) => {
|
|
4817
5227
|
const queryArgs = {
|
|
4818
5228
|
where: {
|
|
4819
|
-
type: single || requireWhere ? new
|
|
5229
|
+
type: single || requireWhere ? new import_graphql9.GraphQLNonNull(filterArgs) : filterArgs
|
|
4820
5230
|
}
|
|
4821
5231
|
};
|
|
4822
5232
|
return {
|
|
@@ -4845,7 +5255,7 @@ var generateDelete2 = (db, tableName, table, filterArgs, fieldName, typeName, si
|
|
|
4845
5255
|
query = query.returning(columns);
|
|
4846
5256
|
const result = await query;
|
|
4847
5257
|
if (single && result.length > 1) {
|
|
4848
|
-
throw new
|
|
5258
|
+
throw new import_graphql9.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
|
|
4849
5259
|
}
|
|
4850
5260
|
if (single) {
|
|
4851
5261
|
return result[0] ? remapToGraphQLSingleOutput(result[0], tableName, table) : void 0;
|
|
@@ -4868,10 +5278,11 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4868
5278
|
typeNameMapper,
|
|
4869
5279
|
shouldEagerLoad,
|
|
4870
5280
|
features,
|
|
4871
|
-
complexity
|
|
5281
|
+
complexity,
|
|
5282
|
+
limits
|
|
4872
5283
|
} = options;
|
|
4873
5284
|
const schemaEntries = Object.entries(schema);
|
|
4874
|
-
const tableEntries = schemaEntries.filter(([_key, value]) => (0,
|
|
5285
|
+
const tableEntries = schemaEntries.filter(([_key, value]) => (0, import_drizzle_orm8.is)(value, import_pg_core2.PgTable));
|
|
4875
5286
|
const tables = Object.fromEntries(tableEntries);
|
|
4876
5287
|
if (!tableEntries.length) {
|
|
4877
5288
|
throw new Error(
|
|
@@ -4884,7 +5295,13 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4884
5295
|
attachTargetPrimaryKeys(namedRelations, tables, pgPrimaryKeyPropNames);
|
|
4885
5296
|
const eagerRelations = pruneNonEagerRelations(namedRelations, shouldEagerLoad);
|
|
4886
5297
|
const filterCtx = { tables, relationMap: namedRelations };
|
|
4887
|
-
const resolverFactory = createRelationResolverFactory(
|
|
5298
|
+
const resolverFactory = createRelationResolverFactory(
|
|
5299
|
+
db,
|
|
5300
|
+
tables,
|
|
5301
|
+
"nulls-largest",
|
|
5302
|
+
filterCtx,
|
|
5303
|
+
limits
|
|
5304
|
+
);
|
|
4888
5305
|
const cacheCtx = {
|
|
4889
5306
|
genericFilterCache: /* @__PURE__ */ new Map(),
|
|
4890
5307
|
objectTypeCache: /* @__PURE__ */ new Map(),
|
|
@@ -4898,7 +5315,9 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4898
5315
|
listRelationFilterCache: /* @__PURE__ */ new Map(),
|
|
4899
5316
|
aggregateTypeCache: /* @__PURE__ */ new Map(),
|
|
4900
5317
|
complexity,
|
|
4901
|
-
|
|
5318
|
+
limits,
|
|
5319
|
+
docs: options.docs ?? {},
|
|
5320
|
+
features
|
|
4902
5321
|
};
|
|
4903
5322
|
const nestedPlans = features.nestedWrites ? buildNestedWritePlans(
|
|
4904
5323
|
tables,
|
|
@@ -4950,8 +5369,10 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4950
5369
|
updateFieldName,
|
|
4951
5370
|
updateManyFieldName,
|
|
4952
5371
|
updateSingleFieldName,
|
|
5372
|
+
updateCountFieldName,
|
|
4953
5373
|
deleteFieldName,
|
|
4954
|
-
deleteSingleFieldName
|
|
5374
|
+
deleteSingleFieldName,
|
|
5375
|
+
deleteCountFieldName
|
|
4955
5376
|
} = computeResolverFieldNames(tableName, typeNameMapper, prefixes, suffixes);
|
|
4956
5377
|
const selectArrGenerated = generateSelectArray2(
|
|
4957
5378
|
db,
|
|
@@ -4964,7 +5385,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4964
5385
|
typeName,
|
|
4965
5386
|
typeNameMapper,
|
|
4966
5387
|
filterCtx,
|
|
4967
|
-
features.distinct
|
|
5388
|
+
features.distinct,
|
|
5389
|
+
limits
|
|
4968
5390
|
);
|
|
4969
5391
|
const selectSingleGenerated = generateSelectSingle2(
|
|
4970
5392
|
db,
|
|
@@ -4976,7 +5398,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4976
5398
|
singleFieldName,
|
|
4977
5399
|
typeName,
|
|
4978
5400
|
typeNameMapper,
|
|
4979
|
-
filterCtx
|
|
5401
|
+
filterCtx,
|
|
5402
|
+
limits
|
|
4980
5403
|
);
|
|
4981
5404
|
const insertArrGenerated = features.insert ? generateInsertArray2(
|
|
4982
5405
|
db,
|
|
@@ -4990,7 +5413,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4990
5413
|
typeNameMapper,
|
|
4991
5414
|
conflictDoNothing,
|
|
4992
5415
|
mutationTxCtx,
|
|
4993
|
-
nestedRuntime
|
|
5416
|
+
nestedRuntime,
|
|
5417
|
+
limits
|
|
4994
5418
|
) : void 0;
|
|
4995
5419
|
const insertSingleGenerated = features.insert ? generateInsertSingle2(
|
|
4996
5420
|
db,
|
|
@@ -5004,7 +5428,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5004
5428
|
typeNameMapper,
|
|
5005
5429
|
conflictDoNothing,
|
|
5006
5430
|
mutationTxCtx,
|
|
5007
|
-
nestedRuntime
|
|
5431
|
+
nestedRuntime,
|
|
5432
|
+
limits
|
|
5008
5433
|
) : void 0;
|
|
5009
5434
|
const uniqueSets = features.upsert ? getUniqueColumnSets(schema[tableName], import_pg_core2.getTableConfig) : [];
|
|
5010
5435
|
const onConflictInput = features.upsert ? generateOnConflictInput({
|
|
@@ -5029,7 +5454,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5029
5454
|
typeNameMapper,
|
|
5030
5455
|
filterCtx,
|
|
5031
5456
|
mutationTxCtx,
|
|
5032
|
-
nestedRuntime
|
|
5457
|
+
nestedRuntime,
|
|
5458
|
+
limits
|
|
5033
5459
|
) : void 0;
|
|
5034
5460
|
const upsertSingleGenerated = onConflictInput ? generateUpsert2(
|
|
5035
5461
|
db,
|
|
@@ -5046,7 +5472,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5046
5472
|
typeNameMapper,
|
|
5047
5473
|
filterCtx,
|
|
5048
5474
|
mutationTxCtx,
|
|
5049
|
-
nestedRuntime
|
|
5475
|
+
nestedRuntime,
|
|
5476
|
+
limits
|
|
5050
5477
|
) : void 0;
|
|
5051
5478
|
const updateGenerated = features.update ? generateUpdate2(
|
|
5052
5479
|
db,
|
|
@@ -5063,7 +5490,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5063
5490
|
typeNameMapper,
|
|
5064
5491
|
filterCtx,
|
|
5065
5492
|
mutationTxCtx,
|
|
5066
|
-
nestedRuntime
|
|
5493
|
+
nestedRuntime,
|
|
5494
|
+
limits
|
|
5067
5495
|
) : void 0;
|
|
5068
5496
|
const updateSingleGenerated = features.update ? generateUpdate2(
|
|
5069
5497
|
db,
|
|
@@ -5080,7 +5508,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5080
5508
|
typeNameMapper,
|
|
5081
5509
|
filterCtx,
|
|
5082
5510
|
mutationTxCtx,
|
|
5083
|
-
nestedRuntime
|
|
5511
|
+
nestedRuntime,
|
|
5512
|
+
limits
|
|
5084
5513
|
) : void 0;
|
|
5085
5514
|
const updateManyInput = features.update && features.updateMany ? generateUpdateManyInput({ typeName, updatePrefix: prefixes.update, updateInput, tableFilters }) : void 0;
|
|
5086
5515
|
const updateManyGenerated = updateManyInput ? generateUpdateMany2(
|
|
@@ -5095,7 +5524,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5095
5524
|
typeNameMapper,
|
|
5096
5525
|
filterCtx,
|
|
5097
5526
|
mutationTxCtx,
|
|
5098
|
-
nestedRuntime
|
|
5527
|
+
nestedRuntime,
|
|
5528
|
+
limits
|
|
5099
5529
|
) : void 0;
|
|
5100
5530
|
const deleteGenerated = features.delete ? generateDelete2(
|
|
5101
5531
|
db,
|
|
@@ -5123,6 +5553,30 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5123
5553
|
{ tableName, relationMap: namedRelations, tables },
|
|
5124
5554
|
mutationTxCtx
|
|
5125
5555
|
) : void 0;
|
|
5556
|
+
const updateCountGenerated = features.update && features.countMutations ? generateWriteCount({
|
|
5557
|
+
db,
|
|
5558
|
+
tableName,
|
|
5559
|
+
table: schema[tableName],
|
|
5560
|
+
kind: "update",
|
|
5561
|
+
setArgs: updateInput,
|
|
5562
|
+
filterArgs: tableFilters,
|
|
5563
|
+
fieldName: updateCountFieldName,
|
|
5564
|
+
requireWhere: features.requireWhere,
|
|
5565
|
+
filterCtx,
|
|
5566
|
+
txCtx: mutationTxCtx,
|
|
5567
|
+
nested: nestedRuntime
|
|
5568
|
+
}) : void 0;
|
|
5569
|
+
const deleteCountGenerated = features.delete && features.countMutations ? generateWriteCount({
|
|
5570
|
+
db,
|
|
5571
|
+
tableName,
|
|
5572
|
+
table: schema[tableName],
|
|
5573
|
+
kind: "delete",
|
|
5574
|
+
filterArgs: tableFilters,
|
|
5575
|
+
fieldName: deleteCountFieldName,
|
|
5576
|
+
requireWhere: features.requireWhere,
|
|
5577
|
+
filterCtx,
|
|
5578
|
+
txCtx: mutationTxCtx
|
|
5579
|
+
}) : void 0;
|
|
5126
5580
|
const aggregateType = features.aggregates ? generateAggregateTypes(schema[tableName], tableName, typeName, cacheCtx) : void 0;
|
|
5127
5581
|
const aggregateGenerated = features.aggregates ? generateAggregate(
|
|
5128
5582
|
db,
|
|
@@ -5151,7 +5605,7 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5151
5605
|
type: selectArrOutput,
|
|
5152
5606
|
args: selectArrGenerated.args,
|
|
5153
5607
|
resolve: selectArrGenerated.resolver,
|
|
5154
|
-
...complexity ? { extensions: { complexity: listFieldComplexity(complexity) } } : {}
|
|
5608
|
+
...complexity ? { extensions: { complexity: listFieldComplexity(complexity, limits?.(tableName)) } } : {}
|
|
5155
5609
|
};
|
|
5156
5610
|
queries[selectSingleGenerated.name] = {
|
|
5157
5611
|
type: selectSingleOutput,
|
|
@@ -5160,7 +5614,7 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5160
5614
|
};
|
|
5161
5615
|
if (aggregateGenerated && aggregateType) {
|
|
5162
5616
|
queries[aggregateGenerated.name] = {
|
|
5163
|
-
type: new
|
|
5617
|
+
type: new import_graphql9.GraphQLNonNull(aggregateType),
|
|
5164
5618
|
args: aggregateGenerated.args,
|
|
5165
5619
|
resolve: aggregateGenerated.resolver,
|
|
5166
5620
|
...complexity ? { extensions: { complexity: aggregateFieldComplexity(complexity) } } : {}
|
|
@@ -5168,7 +5622,7 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5168
5622
|
}
|
|
5169
5623
|
if (groupByGenerated && groupByType) {
|
|
5170
5624
|
queries[groupByGenerated.name] = {
|
|
5171
|
-
type: new
|
|
5625
|
+
type: new import_graphql9.GraphQLNonNull(new import_graphql9.GraphQLList(new import_graphql9.GraphQLNonNull(groupByType))),
|
|
5172
5626
|
args: groupByGenerated.args,
|
|
5173
5627
|
resolve: groupByGenerated.resolver,
|
|
5174
5628
|
...complexity ? { extensions: { complexity: aggregateFieldComplexity(complexity) } } : {}
|
|
@@ -5183,7 +5637,9 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5183
5637
|
}
|
|
5184
5638
|
if (insertSingleGenerated) {
|
|
5185
5639
|
mutations[insertSingleGenerated.name] = {
|
|
5186
|
-
|
|
5640
|
+
// An insert either returns the row it inserted or throws — the one path to `null` is
|
|
5641
|
+
// `conflictDoNothing` swallowing the insert, so the field is nullable only there.
|
|
5642
|
+
type: conflictDoNothing ? singleTableItemOutput : new import_graphql9.GraphQLNonNull(singleTableItemOutput),
|
|
5187
5643
|
args: insertSingleGenerated.args,
|
|
5188
5644
|
resolve: insertSingleGenerated.resolver
|
|
5189
5645
|
};
|
|
@@ -5211,10 +5667,13 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5211
5667
|
}
|
|
5212
5668
|
if (updateManyGenerated) {
|
|
5213
5669
|
mutations[updateManyGenerated.name] = {
|
|
5214
|
-
|
|
5215
|
-
type: new import_graphql8.GraphQLNonNull(new import_graphql8.GraphQLList(singleTableItemOutput)),
|
|
5670
|
+
type: new import_graphql9.GraphQLNonNull(new import_graphql9.GraphQLList(singleTableItemOutput)),
|
|
5216
5671
|
args: updateManyGenerated.args,
|
|
5217
|
-
resolve: updateManyGenerated.resolver
|
|
5672
|
+
resolve: updateManyGenerated.resolver,
|
|
5673
|
+
// The nullable element is deliberate, and the reason this mutation's return type
|
|
5674
|
+
// differs from every sibling's: the result is aligned with the input, one slot per
|
|
5675
|
+
// entry, so an entry that matched nothing has to be able to say so.
|
|
5676
|
+
description: "Each entry's updated rows, in entry order. An entry whose `where` matched no rows contributes `null` in its slot; an entry that matched several contributes each of its rows."
|
|
5218
5677
|
};
|
|
5219
5678
|
}
|
|
5220
5679
|
if (updateSingleGenerated) {
|
|
@@ -5238,6 +5697,22 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5238
5697
|
resolve: deleteSingleGenerated.resolver
|
|
5239
5698
|
};
|
|
5240
5699
|
}
|
|
5700
|
+
if (updateCountGenerated) {
|
|
5701
|
+
mutations[updateCountGenerated.name] = {
|
|
5702
|
+
type: new import_graphql9.GraphQLNonNull(import_graphql9.GraphQLInt),
|
|
5703
|
+
args: updateCountGenerated.args,
|
|
5704
|
+
resolve: updateCountGenerated.resolver,
|
|
5705
|
+
description: "How many rows the update touched. The rows themselves are not read back, which is the point of this mutation."
|
|
5706
|
+
};
|
|
5707
|
+
}
|
|
5708
|
+
if (deleteCountGenerated) {
|
|
5709
|
+
mutations[deleteCountGenerated.name] = {
|
|
5710
|
+
type: new import_graphql9.GraphQLNonNull(import_graphql9.GraphQLInt),
|
|
5711
|
+
args: deleteCountGenerated.args,
|
|
5712
|
+
resolve: deleteCountGenerated.resolver,
|
|
5713
|
+
description: "How many rows the delete removed. The rows themselves are not read back, which is the point of this mutation."
|
|
5714
|
+
};
|
|
5715
|
+
}
|
|
5241
5716
|
const activeInputs = [
|
|
5242
5717
|
// The insert input types the upsert mutations too, so either feature keeps it.
|
|
5243
5718
|
...features.insert || onConflictInput ? [insertInput] : [],
|
|
@@ -5269,7 +5744,7 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5269
5744
|
for (const [tableName, tableRelations] of Object.entries(namedRelations)) {
|
|
5270
5745
|
const relResolvers = {};
|
|
5271
5746
|
for (const [relName, relEntry] of Object.entries(tableRelations)) {
|
|
5272
|
-
const isOne = (0,
|
|
5747
|
+
const isOne = (0, import_drizzle_orm8.is)(relEntry.relation ?? relEntry, import_drizzle_orm8.One);
|
|
5273
5748
|
const resolver = resolverFactory({ tableName, relationName: relName, relEntry, isOne });
|
|
5274
5749
|
if (resolver) {
|
|
5275
5750
|
relResolvers[relName] = resolver;
|
|
@@ -5283,11 +5758,11 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5283
5758
|
}
|
|
5284
5759
|
|
|
5285
5760
|
// src/util/builders/sqlite.ts
|
|
5286
|
-
var
|
|
5761
|
+
var import_drizzle_orm9 = require("drizzle-orm");
|
|
5287
5762
|
var import_sqlite_core2 = require("drizzle-orm/sqlite-core");
|
|
5288
|
-
var
|
|
5763
|
+
var import_graphql10 = require("graphql");
|
|
5289
5764
|
var import_graphql_parse_resolve_info4 = require("graphql-parse-resolve-info");
|
|
5290
|
-
var generateSelectArray3 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, distinctEnabled = true) => {
|
|
5765
|
+
var generateSelectArray3 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, distinctEnabled = true, limits) => {
|
|
5291
5766
|
const queryBase = db.query[tableName];
|
|
5292
5767
|
if (!queryBase) {
|
|
5293
5768
|
throw new Error(
|
|
@@ -5295,6 +5770,7 @@ var generateSelectArray3 = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
5295
5770
|
);
|
|
5296
5771
|
}
|
|
5297
5772
|
const table = tables[tableName];
|
|
5773
|
+
const limitPolicy = limits?.(tableName);
|
|
5298
5774
|
const pkNames = sqlitePrimaryKeyPropNames(table);
|
|
5299
5775
|
const queryArgs = selectArrayArgs(
|
|
5300
5776
|
orderArgs,
|
|
@@ -5317,8 +5793,10 @@ var generateSelectArray3 = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
5317
5793
|
typeNameMapper,
|
|
5318
5794
|
parsedInfo,
|
|
5319
5795
|
...args,
|
|
5796
|
+
limit: applyLimitPolicy(args.limit, limitPolicy, fieldName),
|
|
5320
5797
|
single: false,
|
|
5321
5798
|
filterCtx,
|
|
5799
|
+
limits,
|
|
5322
5800
|
pkNames,
|
|
5323
5801
|
db: executor,
|
|
5324
5802
|
// SQLite sorts NULLs as the smallest values (first in ASC).
|
|
@@ -5331,7 +5809,7 @@ var generateSelectArray3 = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
5331
5809
|
args: queryArgs
|
|
5332
5810
|
};
|
|
5333
5811
|
};
|
|
5334
|
-
var generateSelectSingle3 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx) => {
|
|
5812
|
+
var generateSelectSingle3 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, limits) => {
|
|
5335
5813
|
const queryBase = db.query[tableName];
|
|
5336
5814
|
if (!queryBase) {
|
|
5337
5815
|
throw new Error(
|
|
@@ -5359,6 +5837,7 @@ var generateSelectSingle3 = (db, tableName, tables, relationMap, orderArgs, filt
|
|
|
5359
5837
|
...args,
|
|
5360
5838
|
single: true,
|
|
5361
5839
|
filterCtx,
|
|
5840
|
+
limits,
|
|
5362
5841
|
pkNames,
|
|
5363
5842
|
db: executor
|
|
5364
5843
|
});
|
|
@@ -5370,10 +5849,10 @@ var generateSelectSingle3 = (db, tableName, tables, relationMap, orderArgs, filt
|
|
|
5370
5849
|
};
|
|
5371
5850
|
};
|
|
5372
5851
|
var sqlitePrimaryKeyPropNames = (table) => getPrimaryKeyPropNamesFromConfig(table, import_sqlite_core2.getTableConfig);
|
|
5373
|
-
var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested) => {
|
|
5852
|
+
var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested, limits) => {
|
|
5374
5853
|
const queryArgs = {
|
|
5375
5854
|
values: {
|
|
5376
|
-
type: new
|
|
5855
|
+
type: new import_graphql10.GraphQLNonNull(new import_graphql10.GraphQLList(new import_graphql10.GraphQLNonNull(baseType)))
|
|
5377
5856
|
}
|
|
5378
5857
|
};
|
|
5379
5858
|
const pkNames = sqlitePrimaryKeyPropNames(table);
|
|
@@ -5383,7 +5862,7 @@ var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
5383
5862
|
try {
|
|
5384
5863
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
5385
5864
|
if (!args.values.length) {
|
|
5386
|
-
throw new
|
|
5865
|
+
throw new import_graphql10.GraphQLError("No values were provided!");
|
|
5387
5866
|
}
|
|
5388
5867
|
const entries = nested?.enabled(tableName) ? args.values.map((values) => nested.split(tableName, values)) : void 0;
|
|
5389
5868
|
const nestedEntries = entries?.some((entry) => nested.hasOps(entry.ops)) ? entries : void 0;
|
|
@@ -5399,7 +5878,8 @@ var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
5399
5878
|
typeNameMapper,
|
|
5400
5879
|
table,
|
|
5401
5880
|
pkNames,
|
|
5402
|
-
parsedInfo
|
|
5881
|
+
parsedInfo,
|
|
5882
|
+
limits
|
|
5403
5883
|
});
|
|
5404
5884
|
const returning = nestedEntries ? nested.withJoinColumns(tableName, mergedOps(nestedEntries), { ...columns }, table) : columns;
|
|
5405
5885
|
const runInsert = async (target, values) => {
|
|
@@ -5427,10 +5907,10 @@ var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
5427
5907
|
args: queryArgs
|
|
5428
5908
|
};
|
|
5429
5909
|
};
|
|
5430
|
-
var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested) => {
|
|
5910
|
+
var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested, limits) => {
|
|
5431
5911
|
const queryArgs = {
|
|
5432
5912
|
values: {
|
|
5433
|
-
type: new
|
|
5913
|
+
type: new import_graphql10.GraphQLNonNull(baseType)
|
|
5434
5914
|
}
|
|
5435
5915
|
};
|
|
5436
5916
|
const pkNames = sqlitePrimaryKeyPropNames(table);
|
|
@@ -5453,7 +5933,8 @@ var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType
|
|
|
5453
5933
|
typeNameMapper,
|
|
5454
5934
|
table,
|
|
5455
5935
|
pkNames,
|
|
5456
|
-
parsedInfo
|
|
5936
|
+
parsedInfo,
|
|
5937
|
+
limits
|
|
5457
5938
|
});
|
|
5458
5939
|
const returning = nestedEntry ? nested.withJoinColumns(tableName, nestedEntry.ops, { ...columns }, table) : columns;
|
|
5459
5940
|
const runInsert = async (target, values) => {
|
|
@@ -5472,6 +5953,9 @@ var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType
|
|
|
5472
5953
|
write: runInsert
|
|
5473
5954
|
}) : await runInsert(executor, input);
|
|
5474
5955
|
if (!result[0]) {
|
|
5956
|
+
if (!conflictDoNothing) {
|
|
5957
|
+
throw new import_graphql10.GraphQLError(`${fieldName}: the insert returned no row.`);
|
|
5958
|
+
}
|
|
5475
5959
|
return void 0;
|
|
5476
5960
|
}
|
|
5477
5961
|
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
@@ -5484,10 +5968,10 @@ var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType
|
|
|
5484
5968
|
args: queryArgs
|
|
5485
5969
|
};
|
|
5486
5970
|
};
|
|
5487
|
-
var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx, txCtx, nested) => {
|
|
5971
|
+
var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx, txCtx, nested, limits) => {
|
|
5488
5972
|
const queryArgs = {
|
|
5489
5973
|
values: {
|
|
5490
|
-
type: single ? new
|
|
5974
|
+
type: single ? new import_graphql10.GraphQLNonNull(baseType) : new import_graphql10.GraphQLNonNull(new import_graphql10.GraphQLList(new import_graphql10.GraphQLNonNull(baseType)))
|
|
5491
5975
|
},
|
|
5492
5976
|
onConflict: {
|
|
5493
5977
|
type: onConflictType,
|
|
@@ -5502,7 +5986,7 @@ var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
5502
5986
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
5503
5987
|
const supplied = single ? [args.values] : args.values;
|
|
5504
5988
|
if (!supplied.length) {
|
|
5505
|
-
throw new
|
|
5989
|
+
throw new import_graphql10.GraphQLError("No values were provided!");
|
|
5506
5990
|
}
|
|
5507
5991
|
const entries = nested?.enabled(tableName) ? supplied.map((values) => nested.split(tableName, values)) : void 0;
|
|
5508
5992
|
const nestedEntries = entries?.some((entry) => nested.hasOps(entry.ops)) ? entries : void 0;
|
|
@@ -5516,7 +6000,8 @@ var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
5516
6000
|
typeNameMapper,
|
|
5517
6001
|
table,
|
|
5518
6002
|
pkNames,
|
|
5519
|
-
parsedInfo
|
|
6003
|
+
parsedInfo,
|
|
6004
|
+
limits
|
|
5520
6005
|
});
|
|
5521
6006
|
const returning = nestedEntries ? nested.withJoinColumns(tableName, mergedOps(nestedEntries), { ...columns }, table) : columns;
|
|
5522
6007
|
const runUpsert = async (target, values) => {
|
|
@@ -5555,13 +6040,13 @@ var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
5555
6040
|
args: queryArgs
|
|
5556
6041
|
};
|
|
5557
6042
|
};
|
|
5558
|
-
var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx, txCtx, nested) => {
|
|
6043
|
+
var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx, txCtx, nested, limits) => {
|
|
5559
6044
|
const queryArgs = {
|
|
5560
6045
|
set: {
|
|
5561
|
-
type: new
|
|
6046
|
+
type: new import_graphql10.GraphQLNonNull(setArgs)
|
|
5562
6047
|
},
|
|
5563
6048
|
where: {
|
|
5564
|
-
type: single || requireWhere ? new
|
|
6049
|
+
type: single || requireWhere ? new import_graphql10.GraphQLNonNull(filterArgs) : filterArgs
|
|
5565
6050
|
}
|
|
5566
6051
|
};
|
|
5567
6052
|
const pkNames = sqlitePrimaryKeyPropNames(table);
|
|
@@ -5582,13 +6067,14 @@ var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
5582
6067
|
typeNameMapper,
|
|
5583
6068
|
table,
|
|
5584
6069
|
pkNames,
|
|
5585
|
-
parsedInfo
|
|
6070
|
+
parsedInfo,
|
|
6071
|
+
limits
|
|
5586
6072
|
});
|
|
5587
6073
|
const entry = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
|
|
5588
6074
|
const nestedOps = entry && nested.hasOps(entry.ops) ? entry.ops : void 0;
|
|
5589
|
-
const input =
|
|
6075
|
+
const input = remapUpdateInput(entry ? entry.columns : set, table, tableName);
|
|
5590
6076
|
if (!Object.keys(input).length && !nestedOps) {
|
|
5591
|
-
throw new
|
|
6077
|
+
throw new import_graphql10.GraphQLError("Unable to update with no values specified!");
|
|
5592
6078
|
}
|
|
5593
6079
|
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
5594
6080
|
const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
@@ -5614,7 +6100,7 @@ var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
5614
6100
|
write: runUpdate
|
|
5615
6101
|
}) : await runUpdate(executor, input);
|
|
5616
6102
|
if (single && result.length > 1) {
|
|
5617
|
-
throw new
|
|
6103
|
+
throw new import_graphql10.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
|
|
5618
6104
|
}
|
|
5619
6105
|
if (single && !result[0]) {
|
|
5620
6106
|
return void 0;
|
|
@@ -5629,10 +6115,10 @@ var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
5629
6115
|
args: queryArgs
|
|
5630
6116
|
};
|
|
5631
6117
|
};
|
|
5632
|
-
var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx, txCtx, nested) => {
|
|
6118
|
+
var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx, txCtx, nested, limits) => {
|
|
5633
6119
|
const queryArgs = {
|
|
5634
6120
|
updates: {
|
|
5635
|
-
type: new
|
|
6121
|
+
type: new import_graphql10.GraphQLNonNull(new import_graphql10.GraphQLList(new import_graphql10.GraphQLNonNull(updateManyInput)))
|
|
5636
6122
|
}
|
|
5637
6123
|
};
|
|
5638
6124
|
const pkNames = sqlitePrimaryKeyPropNames(table);
|
|
@@ -5643,7 +6129,7 @@ var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
5643
6129
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
5644
6130
|
const { updates } = args;
|
|
5645
6131
|
if (!updates.length) {
|
|
5646
|
-
throw new
|
|
6132
|
+
throw new import_graphql10.GraphQLError("No updates were provided!");
|
|
5647
6133
|
}
|
|
5648
6134
|
const parsedInfo = (0, import_graphql_parse_resolve_info4.parseResolveInfo)(info, {
|
|
5649
6135
|
deep: true
|
|
@@ -5656,14 +6142,15 @@ var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
5656
6142
|
typeNameMapper,
|
|
5657
6143
|
table,
|
|
5658
6144
|
pkNames,
|
|
5659
|
-
parsedInfo
|
|
6145
|
+
parsedInfo,
|
|
6146
|
+
limits
|
|
5660
6147
|
});
|
|
5661
6148
|
const entries = updates.map(({ where, set }) => {
|
|
5662
6149
|
const split = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
|
|
5663
6150
|
const ops = split && nested.hasOps(split.ops) ? split.ops : void 0;
|
|
5664
|
-
const input =
|
|
6151
|
+
const input = remapUpdateInput(split ? split.columns : set, table, tableName);
|
|
5665
6152
|
if (!Object.keys(input).length && !ops) {
|
|
5666
|
-
throw new
|
|
6153
|
+
throw new import_graphql10.GraphQLError("Unable to update with no values specified!");
|
|
5667
6154
|
}
|
|
5668
6155
|
return {
|
|
5669
6156
|
set: input,
|
|
@@ -5750,7 +6237,7 @@ var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
5750
6237
|
var generateDelete3 = (db, tableName, table, filterArgs, fieldName, typeName, single, requireWhere, filterCtx, selectionCtx, txCtx) => {
|
|
5751
6238
|
const queryArgs = {
|
|
5752
6239
|
where: {
|
|
5753
|
-
type: single || requireWhere ? new
|
|
6240
|
+
type: single || requireWhere ? new import_graphql10.GraphQLNonNull(filterArgs) : filterArgs
|
|
5754
6241
|
}
|
|
5755
6242
|
};
|
|
5756
6243
|
return {
|
|
@@ -5779,7 +6266,7 @@ var generateDelete3 = (db, tableName, table, filterArgs, fieldName, typeName, si
|
|
|
5779
6266
|
query = query.returning(columns);
|
|
5780
6267
|
const result = await query;
|
|
5781
6268
|
if (single && result.length > 1) {
|
|
5782
|
-
throw new
|
|
6269
|
+
throw new import_graphql10.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
|
|
5783
6270
|
}
|
|
5784
6271
|
if (single) {
|
|
5785
6272
|
return result[0] ? remapToGraphQLSingleOutput(result[0], tableName, table) : void 0;
|
|
@@ -5802,11 +6289,12 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5802
6289
|
typeNameMapper,
|
|
5803
6290
|
shouldEagerLoad,
|
|
5804
6291
|
features,
|
|
5805
|
-
complexity
|
|
6292
|
+
complexity,
|
|
6293
|
+
limits
|
|
5806
6294
|
} = options;
|
|
5807
6295
|
const rawSchema = schema;
|
|
5808
6296
|
const schemaEntries = Object.entries(rawSchema);
|
|
5809
|
-
const tableEntries = schemaEntries.filter(([_key, value]) => (0,
|
|
6297
|
+
const tableEntries = schemaEntries.filter(([_key, value]) => (0, import_drizzle_orm9.is)(value, import_sqlite_core2.SQLiteTable));
|
|
5810
6298
|
const tables = Object.fromEntries(tableEntries);
|
|
5811
6299
|
if (!tableEntries.length) {
|
|
5812
6300
|
throw new Error(
|
|
@@ -5819,7 +6307,13 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5819
6307
|
attachTargetPrimaryKeys(namedRelations, tables, sqlitePrimaryKeyPropNames);
|
|
5820
6308
|
const eagerRelations = pruneNonEagerRelations(namedRelations, shouldEagerLoad);
|
|
5821
6309
|
const filterCtx = { tables, relationMap: namedRelations };
|
|
5822
|
-
const resolverFactory = createRelationResolverFactory(
|
|
6310
|
+
const resolverFactory = createRelationResolverFactory(
|
|
6311
|
+
db,
|
|
6312
|
+
tables,
|
|
6313
|
+
"nulls-smallest",
|
|
6314
|
+
filterCtx,
|
|
6315
|
+
limits
|
|
6316
|
+
);
|
|
5823
6317
|
const cacheCtx = {
|
|
5824
6318
|
genericFilterCache: /* @__PURE__ */ new Map(),
|
|
5825
6319
|
objectTypeCache: /* @__PURE__ */ new Map(),
|
|
@@ -5833,7 +6327,9 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5833
6327
|
listRelationFilterCache: /* @__PURE__ */ new Map(),
|
|
5834
6328
|
aggregateTypeCache: /* @__PURE__ */ new Map(),
|
|
5835
6329
|
complexity,
|
|
5836
|
-
|
|
6330
|
+
limits,
|
|
6331
|
+
docs: options.docs ?? {},
|
|
6332
|
+
features
|
|
5837
6333
|
};
|
|
5838
6334
|
if (features.nestedWrites && db.resultKind === "sync") {
|
|
5839
6335
|
throw new Error(
|
|
@@ -5895,8 +6391,10 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5895
6391
|
updateFieldName,
|
|
5896
6392
|
updateManyFieldName,
|
|
5897
6393
|
updateSingleFieldName,
|
|
6394
|
+
updateCountFieldName,
|
|
5898
6395
|
deleteFieldName,
|
|
5899
|
-
deleteSingleFieldName
|
|
6396
|
+
deleteSingleFieldName,
|
|
6397
|
+
deleteCountFieldName
|
|
5900
6398
|
} = computeResolverFieldNames(tableName, typeNameMapper, prefixes, suffixes);
|
|
5901
6399
|
const selectArrGenerated = generateSelectArray3(
|
|
5902
6400
|
db,
|
|
@@ -5909,7 +6407,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5909
6407
|
typeName,
|
|
5910
6408
|
typeNameMapper,
|
|
5911
6409
|
filterCtx,
|
|
5912
|
-
features.distinct
|
|
6410
|
+
features.distinct,
|
|
6411
|
+
limits
|
|
5913
6412
|
);
|
|
5914
6413
|
const selectSingleGenerated = generateSelectSingle3(
|
|
5915
6414
|
db,
|
|
@@ -5921,7 +6420,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5921
6420
|
singleFieldName,
|
|
5922
6421
|
typeName,
|
|
5923
6422
|
typeNameMapper,
|
|
5924
|
-
filterCtx
|
|
6423
|
+
filterCtx,
|
|
6424
|
+
limits
|
|
5925
6425
|
);
|
|
5926
6426
|
const insertArrGenerated = features.insert ? generateInsertArray3(
|
|
5927
6427
|
db,
|
|
@@ -5935,7 +6435,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5935
6435
|
typeNameMapper,
|
|
5936
6436
|
conflictDoNothing,
|
|
5937
6437
|
mutationTxCtx,
|
|
5938
|
-
nestedRuntime
|
|
6438
|
+
nestedRuntime,
|
|
6439
|
+
limits
|
|
5939
6440
|
) : void 0;
|
|
5940
6441
|
const insertSingleGenerated = features.insert ? generateInsertSingle3(
|
|
5941
6442
|
db,
|
|
@@ -5949,7 +6450,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5949
6450
|
typeNameMapper,
|
|
5950
6451
|
conflictDoNothing,
|
|
5951
6452
|
mutationTxCtx,
|
|
5952
|
-
nestedRuntime
|
|
6453
|
+
nestedRuntime,
|
|
6454
|
+
limits
|
|
5953
6455
|
) : void 0;
|
|
5954
6456
|
const uniqueSets = features.upsert ? getUniqueColumnSets(schema[tableName], import_sqlite_core2.getTableConfig) : [];
|
|
5955
6457
|
const onConflictInput = features.upsert ? generateOnConflictInput({
|
|
@@ -5974,7 +6476,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5974
6476
|
typeNameMapper,
|
|
5975
6477
|
filterCtx,
|
|
5976
6478
|
mutationTxCtx,
|
|
5977
|
-
nestedRuntime
|
|
6479
|
+
nestedRuntime,
|
|
6480
|
+
limits
|
|
5978
6481
|
) : void 0;
|
|
5979
6482
|
const upsertSingleGenerated = onConflictInput ? generateUpsert3(
|
|
5980
6483
|
db,
|
|
@@ -5991,7 +6494,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5991
6494
|
typeNameMapper,
|
|
5992
6495
|
filterCtx,
|
|
5993
6496
|
mutationTxCtx,
|
|
5994
|
-
nestedRuntime
|
|
6497
|
+
nestedRuntime,
|
|
6498
|
+
limits
|
|
5995
6499
|
) : void 0;
|
|
5996
6500
|
const updateGenerated = features.update ? generateUpdate3(
|
|
5997
6501
|
db,
|
|
@@ -6008,7 +6512,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
6008
6512
|
typeNameMapper,
|
|
6009
6513
|
filterCtx,
|
|
6010
6514
|
mutationTxCtx,
|
|
6011
|
-
nestedRuntime
|
|
6515
|
+
nestedRuntime,
|
|
6516
|
+
limits
|
|
6012
6517
|
) : void 0;
|
|
6013
6518
|
const updateSingleGenerated = features.update ? generateUpdate3(
|
|
6014
6519
|
db,
|
|
@@ -6025,7 +6530,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
6025
6530
|
typeNameMapper,
|
|
6026
6531
|
filterCtx,
|
|
6027
6532
|
mutationTxCtx,
|
|
6028
|
-
nestedRuntime
|
|
6533
|
+
nestedRuntime,
|
|
6534
|
+
limits
|
|
6029
6535
|
) : void 0;
|
|
6030
6536
|
const updateManyInput = features.update && features.updateMany ? generateUpdateManyInput({ typeName, updatePrefix: prefixes.update, updateInput, tableFilters }) : void 0;
|
|
6031
6537
|
const updateManyGenerated = updateManyInput ? generateUpdateMany3(
|
|
@@ -6040,7 +6546,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
6040
6546
|
typeNameMapper,
|
|
6041
6547
|
filterCtx,
|
|
6042
6548
|
mutationTxCtx,
|
|
6043
|
-
nestedRuntime
|
|
6549
|
+
nestedRuntime,
|
|
6550
|
+
limits
|
|
6044
6551
|
) : void 0;
|
|
6045
6552
|
const deleteGenerated = features.delete ? generateDelete3(
|
|
6046
6553
|
db,
|
|
@@ -6068,6 +6575,30 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
6068
6575
|
{ tableName, relationMap: namedRelations, tables },
|
|
6069
6576
|
mutationTxCtx
|
|
6070
6577
|
) : void 0;
|
|
6578
|
+
const updateCountGenerated = features.update && features.countMutations ? generateWriteCount({
|
|
6579
|
+
db,
|
|
6580
|
+
tableName,
|
|
6581
|
+
table: schema[tableName],
|
|
6582
|
+
kind: "update",
|
|
6583
|
+
setArgs: updateInput,
|
|
6584
|
+
filterArgs: tableFilters,
|
|
6585
|
+
fieldName: updateCountFieldName,
|
|
6586
|
+
requireWhere: features.requireWhere,
|
|
6587
|
+
filterCtx,
|
|
6588
|
+
txCtx: mutationTxCtx,
|
|
6589
|
+
nested: nestedRuntime
|
|
6590
|
+
}) : void 0;
|
|
6591
|
+
const deleteCountGenerated = features.delete && features.countMutations ? generateWriteCount({
|
|
6592
|
+
db,
|
|
6593
|
+
tableName,
|
|
6594
|
+
table: schema[tableName],
|
|
6595
|
+
kind: "delete",
|
|
6596
|
+
filterArgs: tableFilters,
|
|
6597
|
+
fieldName: deleteCountFieldName,
|
|
6598
|
+
requireWhere: features.requireWhere,
|
|
6599
|
+
filterCtx,
|
|
6600
|
+
txCtx: mutationTxCtx
|
|
6601
|
+
}) : void 0;
|
|
6071
6602
|
const aggregateType = features.aggregates ? generateAggregateTypes(schema[tableName], tableName, typeName, cacheCtx) : void 0;
|
|
6072
6603
|
const aggregateGenerated = features.aggregates ? generateAggregate(
|
|
6073
6604
|
db,
|
|
@@ -6096,7 +6627,7 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
6096
6627
|
type: selectArrOutput,
|
|
6097
6628
|
args: selectArrGenerated.args,
|
|
6098
6629
|
resolve: selectArrGenerated.resolver,
|
|
6099
|
-
...complexity ? { extensions: { complexity: listFieldComplexity(complexity) } } : {}
|
|
6630
|
+
...complexity ? { extensions: { complexity: listFieldComplexity(complexity, limits?.(tableName)) } } : {}
|
|
6100
6631
|
};
|
|
6101
6632
|
queries[selectSingleGenerated.name] = {
|
|
6102
6633
|
type: selectSingleOutput,
|
|
@@ -6105,7 +6636,7 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
6105
6636
|
};
|
|
6106
6637
|
if (aggregateGenerated && aggregateType) {
|
|
6107
6638
|
queries[aggregateGenerated.name] = {
|
|
6108
|
-
type: new
|
|
6639
|
+
type: new import_graphql10.GraphQLNonNull(aggregateType),
|
|
6109
6640
|
args: aggregateGenerated.args,
|
|
6110
6641
|
resolve: aggregateGenerated.resolver,
|
|
6111
6642
|
...complexity ? { extensions: { complexity: aggregateFieldComplexity(complexity) } } : {}
|
|
@@ -6113,7 +6644,7 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
6113
6644
|
}
|
|
6114
6645
|
if (groupByGenerated && groupByType) {
|
|
6115
6646
|
queries[groupByGenerated.name] = {
|
|
6116
|
-
type: new
|
|
6647
|
+
type: new import_graphql10.GraphQLNonNull(new import_graphql10.GraphQLList(new import_graphql10.GraphQLNonNull(groupByType))),
|
|
6117
6648
|
args: groupByGenerated.args,
|
|
6118
6649
|
resolve: groupByGenerated.resolver,
|
|
6119
6650
|
...complexity ? { extensions: { complexity: aggregateFieldComplexity(complexity) } } : {}
|
|
@@ -6128,7 +6659,9 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
6128
6659
|
}
|
|
6129
6660
|
if (insertSingleGenerated) {
|
|
6130
6661
|
mutations[insertSingleGenerated.name] = {
|
|
6131
|
-
|
|
6662
|
+
// An insert either returns the row it inserted or throws — the one path to `null` is
|
|
6663
|
+
// `conflictDoNothing` swallowing the insert, so the field is nullable only there.
|
|
6664
|
+
type: conflictDoNothing ? singleTableItemOutput : new import_graphql10.GraphQLNonNull(singleTableItemOutput),
|
|
6132
6665
|
args: insertSingleGenerated.args,
|
|
6133
6666
|
resolve: insertSingleGenerated.resolver
|
|
6134
6667
|
};
|
|
@@ -6156,10 +6689,13 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
6156
6689
|
}
|
|
6157
6690
|
if (updateManyGenerated) {
|
|
6158
6691
|
mutations[updateManyGenerated.name] = {
|
|
6159
|
-
|
|
6160
|
-
type: new import_graphql9.GraphQLNonNull(new import_graphql9.GraphQLList(singleTableItemOutput)),
|
|
6692
|
+
type: new import_graphql10.GraphQLNonNull(new import_graphql10.GraphQLList(singleTableItemOutput)),
|
|
6161
6693
|
args: updateManyGenerated.args,
|
|
6162
|
-
resolve: updateManyGenerated.resolver
|
|
6694
|
+
resolve: updateManyGenerated.resolver,
|
|
6695
|
+
// The nullable element is deliberate, and the reason this mutation's return type
|
|
6696
|
+
// differs from every sibling's: the result is aligned with the input, one slot per
|
|
6697
|
+
// entry, so an entry that matched nothing has to be able to say so.
|
|
6698
|
+
description: "Each entry's updated rows, in entry order. An entry whose `where` matched no rows contributes `null` in its slot; an entry that matched several contributes each of its rows."
|
|
6163
6699
|
};
|
|
6164
6700
|
}
|
|
6165
6701
|
if (updateSingleGenerated) {
|
|
@@ -6183,6 +6719,22 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
6183
6719
|
resolve: deleteSingleGenerated.resolver
|
|
6184
6720
|
};
|
|
6185
6721
|
}
|
|
6722
|
+
if (updateCountGenerated) {
|
|
6723
|
+
mutations[updateCountGenerated.name] = {
|
|
6724
|
+
type: new import_graphql10.GraphQLNonNull(import_graphql10.GraphQLInt),
|
|
6725
|
+
args: updateCountGenerated.args,
|
|
6726
|
+
resolve: updateCountGenerated.resolver,
|
|
6727
|
+
description: "How many rows the update touched. The rows themselves are not read back, which is the point of this mutation."
|
|
6728
|
+
};
|
|
6729
|
+
}
|
|
6730
|
+
if (deleteCountGenerated) {
|
|
6731
|
+
mutations[deleteCountGenerated.name] = {
|
|
6732
|
+
type: new import_graphql10.GraphQLNonNull(import_graphql10.GraphQLInt),
|
|
6733
|
+
args: deleteCountGenerated.args,
|
|
6734
|
+
resolve: deleteCountGenerated.resolver,
|
|
6735
|
+
description: "How many rows the delete removed. The rows themselves are not read back, which is the point of this mutation."
|
|
6736
|
+
};
|
|
6737
|
+
}
|
|
6186
6738
|
const activeInputs = [
|
|
6187
6739
|
// The insert input types the upsert mutations too, so either feature keeps it.
|
|
6188
6740
|
...features.insert || onConflictInput ? [insertInput] : [],
|
|
@@ -6214,7 +6766,7 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
6214
6766
|
for (const [tableName, tableRelations] of Object.entries(namedRelations)) {
|
|
6215
6767
|
const relResolvers = {};
|
|
6216
6768
|
for (const [relName, relEntry] of Object.entries(tableRelations)) {
|
|
6217
|
-
const isOne = (0,
|
|
6769
|
+
const isOne = (0, import_drizzle_orm9.is)(relEntry.relation ?? relEntry, import_drizzle_orm9.One);
|
|
6218
6770
|
const resolver = resolverFactory({ tableName, relationName: relName, relEntry, isOne });
|
|
6219
6771
|
if (resolver) {
|
|
6220
6772
|
relResolvers[relName] = resolver;
|
|
@@ -6260,6 +6812,8 @@ var buildSchema = (db, config) => {
|
|
|
6260
6812
|
delete: config?.features?.delete ?? true,
|
|
6261
6813
|
upsert: config?.features?.upsert ?? false,
|
|
6262
6814
|
nestedWrites: config?.features?.nestedWrites ?? false,
|
|
6815
|
+
fieldUpdateOperations: config?.features?.fieldUpdateOperations ?? false,
|
|
6816
|
+
countMutations: config?.features?.countMutations ?? false,
|
|
6263
6817
|
requireWhere: config?.features?.requireWhere ?? false
|
|
6264
6818
|
};
|
|
6265
6819
|
const complexityConfig = config?.complexity ?? true;
|
|
@@ -6269,6 +6823,33 @@ var buildSchema = (db, config) => {
|
|
|
6269
6823
|
};
|
|
6270
6824
|
const transactionsOpt = config?.transactions;
|
|
6271
6825
|
const transactions = transactionsOpt === void 0 || transactionsOpt === "none" ? void 0 : { timeoutMs: (transactionsOpt === "auto" ? void 0 : transactionsOpt.timeoutMs) ?? 3e4 };
|
|
6826
|
+
const limitsConfig = config?.limits;
|
|
6827
|
+
if (limitsConfig) {
|
|
6828
|
+
const check = (policy, where) => {
|
|
6829
|
+
for (const key of ["defaultLimit", "maxLimit"]) {
|
|
6830
|
+
const value = policy[key];
|
|
6831
|
+
if (value === void 0) {
|
|
6832
|
+
continue;
|
|
6833
|
+
}
|
|
6834
|
+
if (!Number.isInteger(value) || value < 1) {
|
|
6835
|
+
throw new Error(`Drizzle-GraphQL Error: config.limits${where}.${key} must be a positive integer.`);
|
|
6836
|
+
}
|
|
6837
|
+
}
|
|
6838
|
+
};
|
|
6839
|
+
check(limitsConfig, "");
|
|
6840
|
+
for (const [tableName, policy] of Object.entries(limitsConfig.tables ?? {})) {
|
|
6841
|
+
check(policy, `.tables.${tableName}`);
|
|
6842
|
+
}
|
|
6843
|
+
}
|
|
6844
|
+
const limitPolicyCache = /* @__PURE__ */ new Map();
|
|
6845
|
+
const limits = limitsConfig ? (tableName) => {
|
|
6846
|
+
if (limitPolicyCache.has(tableName)) {
|
|
6847
|
+
return limitPolicyCache.get(tableName);
|
|
6848
|
+
}
|
|
6849
|
+
const resolved = resolveLimitPolicy(limitsConfig, limitsConfig.tables?.[tableName]);
|
|
6850
|
+
limitPolicyCache.set(tableName, resolved);
|
|
6851
|
+
return resolved;
|
|
6852
|
+
} : void 0;
|
|
6272
6853
|
const eagerOpt = config?.eagerLoadRelations;
|
|
6273
6854
|
const shouldEagerLoad = eagerOpt === void 0 || eagerOpt === true ? () => true : eagerOpt === false ? () => false : eagerOpt;
|
|
6274
6855
|
if (!typeNameMapper && suffixes.list === suffixes.single) {
|
|
@@ -6301,6 +6882,7 @@ var buildSchema = (db, config) => {
|
|
|
6301
6882
|
mapColumnType: config?.mapColumnType,
|
|
6302
6883
|
enumNameMapper: config?.enumNameMapper,
|
|
6303
6884
|
transactions,
|
|
6885
|
+
limits,
|
|
6304
6886
|
docs: {
|
|
6305
6887
|
describeColumn: config?.describeColumn,
|
|
6306
6888
|
describeTable: config?.describeTable,
|
|
@@ -6309,11 +6891,11 @@ var buildSchema = (db, config) => {
|
|
|
6309
6891
|
}
|
|
6310
6892
|
};
|
|
6311
6893
|
let generatorOutput;
|
|
6312
|
-
if ((0,
|
|
6894
|
+
if ((0, import_drizzle_orm10.is)(db, import_mysql_core3.MySqlDatabase)) {
|
|
6313
6895
|
generatorOutput = generateSchemaData(db, schema, relations, generatorOptions);
|
|
6314
|
-
} else if ((0,
|
|
6896
|
+
} else if ((0, import_drizzle_orm10.is)(db, import_pg_core3.PgAsyncDatabase)) {
|
|
6315
6897
|
generatorOutput = generateSchemaData2(db, schema, relations, generatorOptions);
|
|
6316
|
-
} else if ((0,
|
|
6898
|
+
} else if ((0, import_drizzle_orm10.is)(db, import_sqlite_core3.BaseSQLiteDatabase)) {
|
|
6317
6899
|
generatorOutput = generateSchemaData3(db, schema, relations, generatorOptions);
|
|
6318
6900
|
} else {
|
|
6319
6901
|
throw new Error("Drizzle-GraphQL Error: Unknown database instance type");
|
|
@@ -6326,19 +6908,19 @@ var buildSchema = (db, config) => {
|
|
|
6326
6908
|
const { queries, mutations, inputs, types } = generatorOutput;
|
|
6327
6909
|
const graphQLSchemaConfig = {
|
|
6328
6910
|
types: [...Object.values(inputs), ...Object.values(types)],
|
|
6329
|
-
query: new
|
|
6911
|
+
query: new import_graphql11.GraphQLObjectType({
|
|
6330
6912
|
name: "Query",
|
|
6331
6913
|
fields: queries
|
|
6332
6914
|
})
|
|
6333
6915
|
};
|
|
6334
6916
|
if (config?.mutations !== false && Object.keys(mutations).length) {
|
|
6335
|
-
const mutation = new
|
|
6917
|
+
const mutation = new import_graphql11.GraphQLObjectType({
|
|
6336
6918
|
name: "Mutation",
|
|
6337
6919
|
fields: mutations
|
|
6338
6920
|
});
|
|
6339
6921
|
graphQLSchemaConfig.mutation = mutation;
|
|
6340
6922
|
}
|
|
6341
|
-
const outputSchema = new
|
|
6923
|
+
const outputSchema = new import_graphql11.GraphQLSchema(graphQLSchemaConfig);
|
|
6342
6924
|
return { schema: outputSchema, entities: generatorOutput };
|
|
6343
6925
|
};
|
|
6344
6926
|
// Annotate the CommonJS export names for ESM import in node:
|