@vantreeseba/drizzle-graphql 6.0.0 → 7.0.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/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 import_drizzle_orm9 = require("drizzle-orm");
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 import_graphql10 = require("graphql");
52
+ var import_graphql11 = require("graphql");
53
53
 
54
54
  // src/util/builders/common.ts
55
- var import_drizzle_orm3 = require("drizzle-orm");
56
- var import_graphql4 = require("graphql");
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, import_drizzle_orm3.getColumns)(parentTable);
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, import_drizzle_orm3.getColumns)(targetTable);
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 import_graphql4.GraphQLError(
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 import_graphql4.GraphQLError(
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, import_drizzle_orm3.getColumns)(targetTable);
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 ? import_drizzle_orm3.sql` order by ${import_drizzle_orm3.sql.join(orderExprs, import_drizzle_orm3.sql`, `)}` : import_drizzle_orm3.sql``;
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 = import_drizzle_orm3.sql`row_number() over (partition by ${foreignCol}${orderClause})`.as(RN);
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, import_drizzle_orm3.gt)(sub[RN], lower)];
1010
+ const windowConds = [(0, import_drizzle_orm4.gt)(sub[RN], lower)];
893
1011
  if (limit != null) {
894
- windowConds.push((0, import_drizzle_orm3.lte)(sub[RN], lower + limit));
1012
+ windowConds.push((0, import_drizzle_orm4.lte)(sub[RN], lower + limit));
895
1013
  }
896
- const rows = await db.select().from(sub).where((0, import_drizzle_orm3.and)(...windowConds)).orderBy(sub[RN]);
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) => ({ tableName, relationName, relEntry, isOne }) => {
903
1021
  const parentTable = tables[tableName];
904
1022
  const targetTableName = relEntry.targetTableName;
905
1023
  const targetTable = tables[targetTableName];
@@ -912,7 +1030,7 @@ var createRelationResolverFactory = (db, tables, filterCtx) => ({ tableName, rel
912
1030
  }
913
1031
  const { localColPropName, foreignCol, foreignColPropName } = joinCols;
914
1032
  const targetPkNames = relEntry.targetPkNames ?? [];
915
- return async (parent, args, context) => {
1033
+ return async (parent, args, context, info) => {
916
1034
  if (parent[relationName] !== void 0) {
917
1035
  return parent[relationName];
918
1036
  }
@@ -920,21 +1038,65 @@ var createRelationResolverFactory = (db, tables, filterCtx) => ({ tableName, rel
920
1038
  if (localValue == null) {
921
1039
  return isOne ? null : [];
922
1040
  }
923
- const { where: whereArg, orderBy: orderByArg, limit, offset } = args ?? {};
1041
+ const { where: whereArg, orderBy: orderByArg, limit, offset, after } = args ?? {};
1042
+ const distinct = (args ?? {}).distinct?.length ? (args ?? {}).distinct : void 0;
1043
+ const cursorSelected = !isOne && !!info && selectsCursorField(info, targetTable);
1044
+ let cursorEntries;
1045
+ if (!isOne && (after != null || cursorSelected)) {
1046
+ if (after != null && distinct) {
1047
+ throw new import_graphql5.GraphQLError("'after' cannot be combined with 'distinct'.");
1048
+ }
1049
+ if (orderByHasRelationEntry(orderByArg)) {
1050
+ if (after != null) {
1051
+ throw new import_graphql5.GraphQLError(
1052
+ "'after' cannot be combined with an orderBy that orders through a relation \u2014 a related row's value cannot be encoded into a cursor."
1053
+ );
1054
+ }
1055
+ } else if (!targetPkNames.length) {
1056
+ if (after != null) {
1057
+ throw new import_graphql5.GraphQLError(
1058
+ `Table ${targetTableName} has no primary key, so cursor pagination cannot be used on it.`
1059
+ );
1060
+ }
1061
+ } else {
1062
+ cursorEntries = cursorOrderingEntries(orderByArg, targetPkNames);
1063
+ }
1064
+ }
1065
+ const cursorValues = after != null && cursorEntries ? decodeCursor(after, cursorEntries) : void 0;
924
1066
  const argsKey = JSON.stringify({
925
1067
  where: whereArg ?? null,
926
1068
  orderBy: orderByArg ?? null,
927
1069
  limit: limit ?? null,
928
- offset: offset ?? null
1070
+ offset: offset ?? null,
1071
+ after: after ?? null,
1072
+ distinct: distinct ?? null,
1073
+ cursor: cursorEntries ? 1 : 0
929
1074
  });
930
1075
  const loaderKey = `${tableName}::${relationName}::${argsKey}`;
931
1076
  const loader = getOrCreateLoader(context, loaderKey, async (parentIds) => {
932
1077
  const executor = resolveExecutor(db, context);
933
1078
  const uniqueIds = [...new Set(parentIds)];
934
- const whereCondition = (0, import_drizzle_orm3.and)(
935
- (0, import_drizzle_orm3.inArray)(foreignCol, uniqueIds),
936
- whereArg ? extractFilters(targetTable, targetTableName, whereArg, relationFilterCtx(filterCtx, targetTableName)) : void 0
1079
+ let whereCondition = (0, import_drizzle_orm4.and)(
1080
+ (0, import_drizzle_orm4.inArray)(foreignCol, uniqueIds),
1081
+ whereArg ? extractFilters(targetTable, targetTableName, whereArg, relationFilterCtx(filterCtx, targetTableName)) : void 0,
1082
+ cursorValues ? buildCursorCondition(targetTable, cursorEntries, cursorValues, nullOrdering) : void 0
937
1083
  );
1084
+ if (distinct) {
1085
+ const keys = await selectDistinctKeys({
1086
+ db: executor,
1087
+ table: targetTable,
1088
+ tableName: targetTableName,
1089
+ distinct,
1090
+ pkNames: targetPkNames,
1091
+ where: whereCondition,
1092
+ orderBy: orderByArg,
1093
+ partitionBy: [foreignCol]
1094
+ });
1095
+ if (!keys.length) {
1096
+ return parentIds.map(() => isOne ? null : []);
1097
+ }
1098
+ whereCondition = (0, import_drizzle_orm4.and)(whereCondition, primaryKeyRestriction(targetTable, targetPkNames, keys));
1099
+ }
938
1100
  let rows;
939
1101
  if (limit != null || offset != null) {
940
1102
  rows = await batchedPaginatedRelationQuery(
@@ -950,11 +1112,15 @@ var createRelationResolverFactory = (db, tables, filterCtx) => ({ tableName, rel
950
1112
  );
951
1113
  } else {
952
1114
  let q = executor.select().from(targetTable).where(whereCondition);
953
- if (orderByArg) {
954
- q = q.orderBy(...extractOrderBy(targetTable, orderByArg, relationFilterCtx(filterCtx, targetTableName)));
1115
+ const orderExprs = cursorEntries ? cursorOrderExprs(targetTable, cursorEntries) : orderByArg ? extractOrderBy(targetTable, orderByArg, relationFilterCtx(filterCtx, targetTableName)) : [];
1116
+ if (orderExprs.length) {
1117
+ q = q.orderBy(...orderExprs);
955
1118
  }
956
1119
  rows = await q;
957
1120
  }
1121
+ if (cursorEntries) {
1122
+ attachRowCursors(rows, cursorEntries);
1123
+ }
958
1124
  if (isOne) {
959
1125
  const byKey = new Map(rows.map((row) => [String(row[foreignColPropName]), row]));
960
1126
  remapToGraphQLArrayOutput(rows, targetTableName, targetTable);
@@ -980,7 +1146,7 @@ var columnDocs = (docs, column, tableName, columnName) => {
980
1146
  };
981
1147
  var inputFieldDocs = (docs, column, tableName, columnName, fieldType) => {
982
1148
  const resolved = columnDocs(docs, column, tableName, columnName);
983
- if (resolved.deprecationReason !== void 0 && fieldType instanceof import_graphql4.GraphQLNonNull) {
1149
+ if (resolved.deprecationReason !== void 0 && fieldType instanceof import_graphql5.GraphQLNonNull) {
984
1150
  const { deprecationReason: _dropped, ...rest } = resolved;
985
1151
  return rest;
986
1152
  }
@@ -1001,7 +1167,7 @@ var relationJoinColumns = (tree, table, selectionCtx) => {
1001
1167
  if (!relations) {
1002
1168
  return [];
1003
1169
  }
1004
- const tableColumns = (0, import_drizzle_orm3.getColumns)(table);
1170
+ const tableColumns = (0, import_drizzle_orm4.getColumns)(table);
1005
1171
  const needed = [];
1006
1172
  for (const fieldData of Object.values(tree)) {
1007
1173
  if (tableColumns[fieldData.name]) {
@@ -1020,7 +1186,7 @@ var relationJoinColumns = (tree, table, selectionCtx) => {
1020
1186
  return needed;
1021
1187
  };
1022
1188
  var extractSelectedColumnsFromTree = (tree, table, selectionCtx) => {
1023
- const tableColumns = (0, import_drizzle_orm3.getColumns)(table);
1189
+ const tableColumns = (0, import_drizzle_orm4.getColumns)(table);
1024
1190
  const treeEntries = Object.entries(tree);
1025
1191
  const selectedColumns = [];
1026
1192
  for (const [_fieldName, fieldData] of treeEntries) {
@@ -1040,7 +1206,7 @@ var extractSelectedColumnsFromTree = (tree, table, selectionCtx) => {
1040
1206
  return Object.fromEntries(selectedColumns);
1041
1207
  };
1042
1208
  var extractSelectedColumnsFromTreeSQLFormat = (tree, table, selectionCtx) => {
1043
- const tableColumns = (0, import_drizzle_orm3.getColumns)(table);
1209
+ const tableColumns = (0, import_drizzle_orm4.getColumns)(table);
1044
1210
  const treeEntries = Object.entries(tree);
1045
1211
  const selectedColumns = [];
1046
1212
  for (const [_fieldName, fieldData] of treeEntries) {
@@ -1059,7 +1225,7 @@ var extractSelectedColumnsFromTreeSQLFormat = (tree, table, selectionCtx) => {
1059
1225
  }
1060
1226
  return Object.fromEntries(selectedColumns);
1061
1227
  };
1062
- var orderNulls = new import_graphql4.GraphQLEnumType({
1228
+ var orderNulls = new import_graphql5.GraphQLEnumType({
1063
1229
  name: "OrderNulls",
1064
1230
  description: "Where NULL values sort relative to non-NULL values",
1065
1231
  values: {
@@ -1073,12 +1239,12 @@ var orderNulls = new import_graphql4.GraphQLEnumType({
1073
1239
  }
1074
1240
  }
1075
1241
  });
1076
- var innerOrder = new import_graphql4.GraphQLInputObjectType({
1242
+ var innerOrder = new import_graphql5.GraphQLInputObjectType({
1077
1243
  name: "InnerOrder",
1078
1244
  fields: {
1079
1245
  direction: {
1080
- type: new import_graphql4.GraphQLNonNull(
1081
- new import_graphql4.GraphQLEnumType({
1246
+ type: new import_graphql5.GraphQLNonNull(
1247
+ new import_graphql5.GraphQLEnumType({
1082
1248
  name: "OrderDirection",
1083
1249
  description: "Order by direction",
1084
1250
  values: {
@@ -1095,7 +1261,7 @@ var innerOrder = new import_graphql4.GraphQLInputObjectType({
1095
1261
  )
1096
1262
  },
1097
1263
  priority: {
1098
- type: new import_graphql4.GraphQLNonNull(import_graphql4.GraphQLInt),
1264
+ type: new import_graphql5.GraphQLNonNull(import_graphql5.GraphQLInt),
1099
1265
  description: "Priority of current field"
1100
1266
  },
1101
1267
  nulls: {
@@ -1121,9 +1287,9 @@ var resolveGenericFilterDescriptor = (column, columnGraphQLType) => {
1121
1287
  if (columnGraphQLType.type === import_graphql_scalars.GraphQLJSON) {
1122
1288
  return { name: "JSON", kind: "json" };
1123
1289
  }
1124
- if (columnGraphQLType.type instanceof import_graphql4.GraphQLList) {
1290
+ if (columnGraphQLType.type instanceof import_graphql5.GraphQLList) {
1125
1291
  let element = columnGraphQLType.type.ofType;
1126
- if (element instanceof import_graphql4.GraphQLNonNull) {
1292
+ if (element instanceof import_graphql5.GraphQLNonNull) {
1127
1293
  element = element.ofType;
1128
1294
  }
1129
1295
  return { name: `${element.name}Array`, kind: "array" };
@@ -1131,10 +1297,10 @@ var resolveGenericFilterDescriptor = (column, columnGraphQLType) => {
1131
1297
  if (columnGraphQLType.type === import_graphql_scalars.GraphQLUUID) {
1132
1298
  return { name: "Id", kind: "scalar" };
1133
1299
  }
1134
- if (columnGraphQLType.type === import_graphql4.GraphQLBoolean) {
1300
+ if (columnGraphQLType.type === import_graphql5.GraphQLBoolean) {
1135
1301
  return { name: "Boolean", kind: "scalar" };
1136
1302
  }
1137
- if (columnGraphQLType.type instanceof import_graphql4.GraphQLEnumType) {
1303
+ if (columnGraphQLType.type instanceof import_graphql5.GraphQLEnumType) {
1138
1304
  return { name: columnGraphQLType.type.name, kind: "scalar" };
1139
1305
  }
1140
1306
  if (columnGraphQLType.type === GraphQLBigIntString) {
@@ -1147,10 +1313,10 @@ var resolveGenericFilterDescriptor = (column, columnGraphQLType) => {
1147
1313
  if (ct === "PgTimestamp" || ct === "PgTimestampString" || ct === "PgDate") {
1148
1314
  return { name: "DateTime", kind: "scalar" };
1149
1315
  }
1150
- if (columnGraphQLType.type === import_graphql4.GraphQLInt) {
1316
+ if (columnGraphQLType.type === import_graphql5.GraphQLInt) {
1151
1317
  return { name: "Int", kind: "scalar" };
1152
1318
  }
1153
- if (columnGraphQLType.type === import_graphql4.GraphQLFloat) {
1319
+ if (columnGraphQLType.type === import_graphql5.GraphQLFloat) {
1154
1320
  return { name: "Float", kind: "scalar" };
1155
1321
  }
1156
1322
  return { name: "String", kind: "scalar" };
@@ -1166,37 +1332,37 @@ var jsonFilterFields = (column, colType) => {
1166
1332
  description: "Value structurally contains this JSON (Postgres `@>` / MySQL JSON_CONTAINS)"
1167
1333
  }
1168
1334
  } : {},
1169
- isNull: { type: import_graphql4.GraphQLBoolean },
1170
- isNotNull: { type: import_graphql4.GraphQLBoolean }
1335
+ isNull: { type: import_graphql5.GraphQLBoolean },
1336
+ isNotNull: { type: import_graphql5.GraphQLBoolean }
1171
1337
  };
1172
1338
  };
1173
1339
  var IN_ARRAY_DESCRIPTION = "Matches any one of these values (SQL `IN`)";
1174
1340
  var NOT_IN_ARRAY_DESCRIPTION = "Matches none of these values (SQL `NOT IN`)";
1175
1341
  var arrayFilterFields = (colType, colArr) => {
1176
1342
  let element = colType.ofType;
1177
- if (element instanceof import_graphql4.GraphQLNonNull) {
1343
+ if (element instanceof import_graphql5.GraphQLNonNull) {
1178
1344
  element = element.ofType;
1179
1345
  }
1180
- const elementList = new import_graphql4.GraphQLList(new import_graphql4.GraphQLNonNull(element));
1346
+ const elementList = new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(element));
1181
1347
  return {
1182
1348
  eq: { type: colType, description: "The whole array equals this array" },
1183
1349
  ne: { type: colType, description: "The whole array differs from this array" },
1184
1350
  has: { type: element, description: "Array contains this element" },
1185
1351
  hasSome: { type: elementList, description: "Array contains at least one of these elements (overlap, `&&`)" },
1186
1352
  hasEvery: { type: elementList, description: "Array contains every one of these elements (containment, `@>`)" },
1187
- isEmpty: { type: import_graphql4.GraphQLBoolean, description: "When true, matches arrays with no elements" },
1353
+ isEmpty: { type: import_graphql5.GraphQLBoolean, description: "When true, matches arrays with no elements" },
1188
1354
  inArray: { type: colArr, description: IN_ARRAY_DESCRIPTION },
1189
1355
  notInArray: { type: colArr, description: NOT_IN_ARRAY_DESCRIPTION },
1190
- isNull: { type: import_graphql4.GraphQLBoolean },
1191
- isNotNull: { type: import_graphql4.GraphQLBoolean }
1356
+ isNull: { type: import_graphql5.GraphQLBoolean },
1357
+ isNotNull: { type: import_graphql5.GraphQLBoolean }
1192
1358
  };
1193
1359
  };
1194
1360
  var FILTERS_WITHOUT_STRING_OPS = /* @__PURE__ */ new Set(["Id", "Int", "Float", "BigInt", "Decimal"]);
1195
1361
  var BUILTIN_FILTER_SCALARS = /* @__PURE__ */ new Set([
1196
- import_graphql4.GraphQLString,
1197
- import_graphql4.GraphQLInt,
1198
- import_graphql4.GraphQLFloat,
1199
- import_graphql4.GraphQLBoolean,
1362
+ import_graphql5.GraphQLString,
1363
+ import_graphql5.GraphQLInt,
1364
+ import_graphql5.GraphQLFloat,
1365
+ import_graphql5.GraphQLBoolean,
1200
1366
  GraphQLBigIntString,
1201
1367
  GraphQLDecimalString,
1202
1368
  import_graphql_scalars.GraphQLUUID,
@@ -1222,9 +1388,9 @@ var generateColumnFilterValues = (column, tableName, columnName, cacheCtx) => {
1222
1388
  return cached;
1223
1389
  }
1224
1390
  const colType = columnGraphQLType.type;
1225
- const colArr = new import_graphql4.GraphQLList(new import_graphql4.GraphQLNonNull(colType));
1391
+ const colArr = new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(colType));
1226
1392
  const customOverrideFilter = inputOverride !== void 0 && !BUILTIN_FILTER_SCALARS.has(inputOverride);
1227
- const underlying = (0, import_drizzle_orm3.extractExtendedColumnType)(column);
1393
+ const underlying = (0, import_drizzle_orm4.extractExtendedColumnType)(column);
1228
1394
  const omitStringOps = customOverrideFilter ? underlying.type !== "string" || underlying.constraint === "numeric" : FILTERS_WITHOUT_STRING_OPS.has(genericName);
1229
1395
  const baseFields = kind === "json" ? jsonFilterFields(column, colType) : kind === "array" ? arrayFilterFields(colType, colArr) : {
1230
1396
  eq: { type: colType, description: "Equal to" },
@@ -1234,50 +1400,50 @@ var generateColumnFilterValues = (column, tableName, columnName, cacheCtx) => {
1234
1400
  gt: { type: colType, description: "Greater than" },
1235
1401
  gte: { type: colType, description: "Greater than or equal to" },
1236
1402
  ...omitStringOps ? {} : {
1237
- like: { type: import_graphql4.GraphQLString },
1238
- notLike: { type: import_graphql4.GraphQLString },
1239
- ilike: { type: import_graphql4.GraphQLString },
1240
- notIlike: { type: import_graphql4.GraphQLString },
1403
+ like: { type: import_graphql5.GraphQLString },
1404
+ notLike: { type: import_graphql5.GraphQLString },
1405
+ ilike: { type: import_graphql5.GraphQLString },
1406
+ notIlike: { type: import_graphql5.GraphQLString },
1241
1407
  startsWith: {
1242
- type: import_graphql4.GraphQLString,
1408
+ type: import_graphql5.GraphQLString,
1243
1409
  description: "Matches values starting with the given string. `%`, `_` and `\\` are matched literally."
1244
1410
  },
1245
1411
  endsWith: {
1246
- type: import_graphql4.GraphQLString,
1412
+ type: import_graphql5.GraphQLString,
1247
1413
  description: "Matches values ending with the given string. `%`, `_` and `\\` are matched literally."
1248
1414
  },
1249
1415
  contains: {
1250
- type: import_graphql4.GraphQLString,
1416
+ type: import_graphql5.GraphQLString,
1251
1417
  description: "Matches values containing the given string. `%`, `_` and `\\` are matched literally."
1252
1418
  },
1253
1419
  iStartsWith: {
1254
- type: import_graphql4.GraphQLString,
1420
+ type: import_graphql5.GraphQLString,
1255
1421
  description: "Case-insensitive `startsWith`."
1256
1422
  },
1257
1423
  iEndsWith: {
1258
- type: import_graphql4.GraphQLString,
1424
+ type: import_graphql5.GraphQLString,
1259
1425
  description: "Case-insensitive `endsWith`."
1260
1426
  },
1261
1427
  iContains: {
1262
- type: import_graphql4.GraphQLString,
1428
+ type: import_graphql5.GraphQLString,
1263
1429
  description: "Case-insensitive `contains`."
1264
1430
  }
1265
1431
  },
1266
1432
  inArray: { type: colArr, description: IN_ARRAY_DESCRIPTION },
1267
1433
  notInArray: { type: colArr, description: NOT_IN_ARRAY_DESCRIPTION },
1268
- isNull: { type: import_graphql4.GraphQLBoolean, description: "When true, matches rows where the column is NULL" },
1269
- isNotNull: { type: import_graphql4.GraphQLBoolean, description: "When true, matches rows where the column is not NULL" }
1434
+ isNull: { type: import_graphql5.GraphQLBoolean, description: "When true, matches rows where the column is NULL" },
1435
+ isNotNull: { type: import_graphql5.GraphQLBoolean, description: "When true, matches rows where the column is not NULL" }
1270
1436
  };
1271
- const mainType = new import_graphql4.GraphQLInputObjectType({
1437
+ const mainType = new import_graphql5.GraphQLInputObjectType({
1272
1438
  name: `${genericName}Filter`,
1273
1439
  fields: () => ({
1274
1440
  ...baseFields,
1275
1441
  OR: {
1276
- type: new import_graphql4.GraphQLList(new import_graphql4.GraphQLNonNull(mainType)),
1442
+ type: new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(mainType)),
1277
1443
  description: "At least one branch matches; ANDed with any sibling operators"
1278
1444
  },
1279
1445
  AND: {
1280
- type: new import_graphql4.GraphQLList(new import_graphql4.GraphQLNonNull(mainType)),
1446
+ type: new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(mainType)),
1281
1447
  description: "Every branch matches"
1282
1448
  },
1283
1449
  NOT: {
@@ -1296,7 +1462,7 @@ var generateTableOrderCached = (table) => {
1296
1462
  }
1297
1463
  let remapped = {};
1298
1464
  try {
1299
- const columns = (0, import_drizzle_orm3.getColumns)(table);
1465
+ const columns = (0, import_drizzle_orm4.getColumns)(table);
1300
1466
  const columnEntries = Object.entries(columns);
1301
1467
  remapped = Object.fromEntries(
1302
1468
  columnEntries.map(([columnName, _columnDescription]) => [columnName, { type: innerOrder }])
@@ -1310,7 +1476,7 @@ var generateTableFilterValuesCached = (table, tableName, cacheCtx) => {
1310
1476
  if (cacheCtx.filterFieldCache.has(table)) {
1311
1477
  return cacheCtx.filterFieldCache.get(table);
1312
1478
  }
1313
- const columns = (0, import_drizzle_orm3.getColumns)(table);
1479
+ const columns = (0, import_drizzle_orm4.getColumns)(table);
1314
1480
  const columnEntries = Object.entries(columns);
1315
1481
  const remapped = Object.fromEntries(
1316
1482
  columnEntries.map(([columnName, column]) => [
@@ -1331,7 +1497,7 @@ var generateTableSelectTypeFieldsCached = (table, tableName, cacheCtx) => {
1331
1497
  if (cacheCtx.selectFieldCache.has(table)) {
1332
1498
  return cacheCtx.selectFieldCache.get(table);
1333
1499
  }
1334
- const columns = (0, import_drizzle_orm3.getColumns)(table);
1500
+ const columns = (0, import_drizzle_orm4.getColumns)(table);
1335
1501
  const columnEntries = Object.entries(columns);
1336
1502
  const remapped = Object.fromEntries(
1337
1503
  columnEntries.map(([columnName, column]) => [
@@ -1344,7 +1510,7 @@ var generateTableSelectTypeFieldsCached = (table, tableName, cacheCtx) => {
1344
1510
  );
1345
1511
  if (!remapped[CURSOR_FIELD_NAME]) {
1346
1512
  remapped[CURSOR_FIELD_NAME] = {
1347
- type: import_graphql4.GraphQLString,
1513
+ type: import_graphql5.GraphQLString,
1348
1514
  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
1515
  resolve: rowCursorResolver
1350
1516
  };
@@ -1365,7 +1531,7 @@ var generateRelationOrderFields = (tableName, cacheCtx, typeNameMapper, columnFi
1365
1531
  }
1366
1532
  const targetTable = tables[relEntry.targetTableName];
1367
1533
  const relation = relEntry.relation ?? relEntry;
1368
- if (!targetTable || !(0, import_drizzle_orm3.is)(relation, import_drizzle_orm3.One) || !isFilterableRelation(relation)) {
1534
+ if (!targetTable || !(0, import_drizzle_orm4.is)(relation, import_drizzle_orm4.One) || !isFilterableRelation(relation)) {
1369
1535
  continue;
1370
1536
  }
1371
1537
  fields[relationName] = {
@@ -1386,7 +1552,7 @@ var generateTableOrderTypeCached = (table, tableName, typeNameMapper, cacheCtx,
1386
1552
  if (cacheCtx.orderTypeCache.has(table)) {
1387
1553
  return cacheCtx.orderTypeCache.get(table);
1388
1554
  }
1389
- const order = new import_graphql4.GraphQLInputObjectType({
1555
+ const order = new import_graphql5.GraphQLInputObjectType({
1390
1556
  name: `${resolveTypeName(tableName, typeNameMapper)}OrderBy`,
1391
1557
  fields: () => {
1392
1558
  const orderColumns = generateTableOrderCached(table);
@@ -1404,7 +1570,7 @@ var generateListRelationFilterCached = (targetTable, targetTableName, cacheCtx,
1404
1570
  if (cached) {
1405
1571
  return cached;
1406
1572
  }
1407
- const listFilter = new import_graphql4.GraphQLInputObjectType({
1573
+ const listFilter = new import_graphql5.GraphQLInputObjectType({
1408
1574
  name: `${resolveTypeName(targetTableName, typeNameMapper)}ListRelationFilter`,
1409
1575
  fields: () => {
1410
1576
  const targetFilters = generateTableFilterTypeCached(
@@ -1440,7 +1606,7 @@ var generateRelationFilterFields = (tableName, cacheCtx, typeNameMapper, columnF
1440
1606
  if (!targetTable) {
1441
1607
  continue;
1442
1608
  }
1443
- fields[relationName] = (0, import_drizzle_orm3.is)(relation, import_drizzle_orm3.One) ? {
1609
+ fields[relationName] = (0, import_drizzle_orm4.is)(relation, import_drizzle_orm4.One) ? {
1444
1610
  type: generateTableFilterTypeCached(
1445
1611
  targetTable,
1446
1612
  relEntry.targetTableName,
@@ -1474,16 +1640,16 @@ var generateTableFilterTypeCached = (table, tableName, cacheCtx, typeNameMapper,
1474
1640
  ...generateRelationFilterFields(tableName, cacheCtx, typeNameMapper, filterColumns, relationMap, tables)
1475
1641
  };
1476
1642
  };
1477
- const filters = new import_graphql4.GraphQLInputObjectType({
1643
+ const filters = new import_graphql5.GraphQLInputObjectType({
1478
1644
  name: `${resolveTypeName(tableName, typeNameMapper)}Filters`,
1479
1645
  fields: () => ({
1480
1646
  ...buildFields(),
1481
1647
  OR: {
1482
- type: new import_graphql4.GraphQLList(new import_graphql4.GraphQLNonNull(filters)),
1648
+ type: new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(filters)),
1483
1649
  description: "At least one branch matches; ANDed with any sibling fields"
1484
1650
  },
1485
1651
  AND: {
1486
- type: new import_graphql4.GraphQLList(new import_graphql4.GraphQLNonNull(filters)),
1652
+ type: new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(filters)),
1487
1653
  description: "Every branch matches"
1488
1654
  },
1489
1655
  NOT: {
@@ -1534,7 +1700,7 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
1534
1700
  }
1535
1701
  if (isRootCall && !cacheCtx.objectTypeCache.has(tableName)) {
1536
1702
  const typeName = resolveTypeName(tableName, typeNameMapper);
1537
- const shell = new import_graphql4.GraphQLObjectType({
1703
+ const shell = new import_graphql5.GraphQLObjectType({
1538
1704
  name: typeName,
1539
1705
  description: cacheCtx.docs.describeTable?.(tableName),
1540
1706
  fields: () => ({ ...tableFields, ...container.fields })
@@ -1548,7 +1714,7 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
1548
1714
  for (const [relationName, relEntry] of relationEntries) {
1549
1715
  const { targetTableName } = relEntry;
1550
1716
  const relation = relEntry.relation ?? relEntry;
1551
- const isOne = (0, import_drizzle_orm3.is)(relation, import_drizzle_orm3.One);
1717
+ const isOne = (0, import_drizzle_orm4.is)(relation, import_drizzle_orm4.One);
1552
1718
  const relSelectData = generateSelectFields(
1553
1719
  tables,
1554
1720
  targetTableName,
@@ -1576,7 +1742,7 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
1576
1742
  cacheCtx.relationFieldContainers.set(targetTableName, targetContainer);
1577
1743
  }
1578
1744
  const capturedTargetContainer = targetContainer;
1579
- relType = new import_graphql4.GraphQLObjectType({
1745
+ relType = new import_graphql5.GraphQLObjectType({
1580
1746
  name: resolveTypeName(targetTableName, typeNameMapper),
1581
1747
  description: cacheCtx.docs.describeTable?.(targetTableName),
1582
1748
  fields: () => ({ ...targetTableFields, ...capturedTargetContainer.fields })
@@ -1591,7 +1757,7 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
1591
1757
  rawRelationFields.push([
1592
1758
  relationName,
1593
1759
  {
1594
- type: isRequired ? new import_graphql4.GraphQLNonNull(relType) : relType,
1760
+ type: isRequired ? new import_graphql5.GraphQLNonNull(relType) : relType,
1595
1761
  args: {
1596
1762
  where: { type: relSelectData.filters }
1597
1763
  },
@@ -1601,15 +1767,21 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
1601
1767
  ]);
1602
1768
  continue;
1603
1769
  }
1770
+ const targetDistinctEnum = cacheCtx.features.distinct ? generateDistinctEnum(tables[targetTableName], resolveTypeName(targetTableName, typeNameMapper)) : void 0;
1604
1771
  rawRelationFields.push([
1605
1772
  relationName,
1606
1773
  {
1607
- type: new import_graphql4.GraphQLNonNull(new import_graphql4.GraphQLList(new import_graphql4.GraphQLNonNull(relType))),
1774
+ type: new import_graphql5.GraphQLNonNull(new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(relType))),
1608
1775
  args: {
1609
1776
  where: { type: relSelectData.filters },
1610
1777
  orderBy: { type: relSelectData.order },
1611
- offset: { type: import_graphql4.GraphQLInt },
1612
- limit: { type: import_graphql4.GraphQLInt }
1778
+ offset: { type: import_graphql5.GraphQLInt },
1779
+ limit: { type: import_graphql5.GraphQLInt },
1780
+ after: {
1781
+ type: import_graphql5.GraphQLString,
1782
+ 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)."
1783
+ },
1784
+ ...targetDistinctEnum ? { distinct: { type: new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(targetDistinctEnum)) } } : {}
1613
1785
  },
1614
1786
  resolve,
1615
1787
  ...relationDocs,
@@ -1627,7 +1799,7 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
1627
1799
  rawRelationFields.push([
1628
1800
  aggregateFieldName,
1629
1801
  {
1630
- type: new import_graphql4.GraphQLNonNull(relationAggregate.type),
1802
+ type: new import_graphql5.GraphQLNonNull(relationAggregate.type),
1631
1803
  args: {
1632
1804
  where: { type: relSelectData.filters }
1633
1805
  },
@@ -1679,7 +1851,7 @@ var generateTableTypes = (tableName, tables, relationMap, withReturning, relatio
1679
1851
  relationAggregateFactory
1680
1852
  );
1681
1853
  const table = tables[tableName];
1682
- const columns = (0, import_drizzle_orm3.getColumns)(table);
1854
+ const columns = (0, import_drizzle_orm4.getColumns)(table);
1683
1855
  const columnEntries = Object.entries(columns);
1684
1856
  const relaxedColumns = nestedWrites?.relaxedColumns(tableName);
1685
1857
  const insertFields = Object.fromEntries(
@@ -1701,30 +1873,29 @@ var generateTableTypes = (tableName, tables, relationMap, withReturning, relatio
1701
1873
  const updateFields = Object.fromEntries(
1702
1874
  columnEntries.map(([columnName, column]) => {
1703
1875
  const converted = drizzleColumnToGraphQLType(column, columnName, tableName, true, false, true);
1704
- return [
1705
- columnName,
1706
- { ...converted, ...inputFieldDocs(cacheCtx.docs, column, tableName, columnName, converted.type) }
1707
- ];
1876
+ const operations = cacheCtx.features.fieldUpdateOperations ? fieldUpdateInputType(column, columnName, tableName) : void 0;
1877
+ const field = operations ? { ...converted, type: operations } : converted;
1878
+ return [columnName, { ...field, ...inputFieldDocs(cacheCtx.docs, column, tableName, columnName, field.type) }];
1708
1879
  })
1709
1880
  );
1710
1881
  const typeName = resolveTypeName(tableName, typeNameMapper);
1711
- const insertInput = new import_graphql4.GraphQLInputObjectType({
1882
+ const insertInput = new import_graphql5.GraphQLInputObjectType({
1712
1883
  name: `${capitalize(insertPrefix)}${typeName}Input`,
1713
1884
  fields: nestedWrites ? () => ({ ...insertFields, ...nestedWrites.createFields(tableName, typeName) }) : insertFields
1714
1885
  });
1715
- const updateInput = new import_graphql4.GraphQLInputObjectType({
1886
+ const updateInput = new import_graphql5.GraphQLInputObjectType({
1716
1887
  name: `${capitalize(updatePrefix)}${typeName}Input`,
1717
1888
  fields: nestedWrites ? () => ({ ...updateFields, ...nestedWrites.updateFields(tableName, typeName) }) : updateFields
1718
1889
  });
1719
- const selectSingleOutput = cacheCtx.objectTypeCache.get(tableName) ?? new import_graphql4.GraphQLObjectType({
1890
+ const selectSingleOutput = cacheCtx.objectTypeCache.get(tableName) ?? new import_graphql5.GraphQLObjectType({
1720
1891
  name: resolveTypeName(tableName, typeNameMapper),
1721
1892
  description: cacheCtx.docs.describeTable?.(tableName),
1722
1893
  fields: { ...tableFields, ...relationFields }
1723
1894
  });
1724
- const selectArrOutput = new import_graphql4.GraphQLNonNull(new import_graphql4.GraphQLList(new import_graphql4.GraphQLNonNull(selectSingleOutput)));
1895
+ const selectArrOutput = new import_graphql5.GraphQLNonNull(new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(selectSingleOutput)));
1725
1896
  const arrTableItemOutput = withReturning ? (
1726
1897
  // ? new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(singleTableItemOutput!)))
1727
- new import_graphql4.GraphQLNonNull(new import_graphql4.GraphQLList(new import_graphql4.GraphQLNonNull(selectSingleOutput)))
1898
+ new import_graphql5.GraphQLNonNull(new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(selectSingleOutput)))
1728
1899
  ) : void 0;
1729
1900
  const inputs = {
1730
1901
  insertInput,
@@ -1749,34 +1920,34 @@ var generateTableTypes = (tableName, tables, relationMap, withReturning, relatio
1749
1920
  };
1750
1921
  var orderByEntries = (orderArgs) => Object.entries(orderArgs).sort((a, b) => (b[1]?.priority ?? 0) - (a[1]?.priority ?? 0)).filter(([, config]) => config).map(([column, config]) => {
1751
1922
  if (typeof config === "object" && config.direction === void 0) {
1752
- throw new import_graphql4.GraphQLError(`ORDER BY ${column}: ordering through a relation is not supported in this query`);
1923
+ throw new import_graphql5.GraphQLError(`ORDER BY ${column}: ordering through a relation is not supported in this query`);
1753
1924
  }
1754
1925
  return [column, config.direction, config.nulls ?? void 0];
1755
1926
  });
1756
1927
  var orderExpressions = (expr, direction, nulls, dialectColumn) => {
1757
- const directed = direction === "asc" ? (0, import_drizzle_orm3.asc)(expr) : (0, import_drizzle_orm3.desc)(expr);
1928
+ const directed = direction === "asc" ? (0, import_drizzle_orm4.asc)(expr) : (0, import_drizzle_orm4.desc)(expr);
1758
1929
  if (!nulls) {
1759
1930
  return [directed];
1760
1931
  }
1761
1932
  const isMySql = (dialectColumn.columnType ?? "").startsWith("MySql");
1762
1933
  if (isMySql) {
1763
- const nullsKey = nulls === "first" ? (0, import_drizzle_orm3.desc)(import_drizzle_orm3.sql`(${expr} is null)`) : (0, import_drizzle_orm3.asc)(import_drizzle_orm3.sql`(${expr} is null)`);
1934
+ 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
1935
  return [nullsKey, directed];
1765
1936
  }
1766
- return [nulls === "first" ? import_drizzle_orm3.sql`${directed} nulls first` : import_drizzle_orm3.sql`${directed} nulls last`];
1937
+ return [nulls === "first" ? import_drizzle_orm4.sql`${directed} nulls first` : import_drizzle_orm4.sql`${directed} nulls last`];
1767
1938
  };
1768
1939
  var extendRelationOrderChain = (parentTable, relationName, relEntry, ctx, chain) => {
1769
1940
  const targetTable = ctx.tables[relEntry.targetTableName];
1770
1941
  const relation = relEntry.relation ?? relEntry;
1771
- if (!targetTable || !(0, import_drizzle_orm3.is)(relation, import_drizzle_orm3.One) || !isFilterableRelation(relation)) {
1772
- throw new import_graphql4.GraphQLError(`ORDER BY ${relationName}: Relation cannot be used for ordering`);
1942
+ if (!targetTable || !(0, import_drizzle_orm4.is)(relation, import_drizzle_orm4.One) || !isFilterableRelation(relation)) {
1943
+ throw new import_graphql5.GraphQLError(`ORDER BY ${relationName}: Relation cannot be used for ordering`);
1773
1944
  }
1774
1945
  ctx.aliases ??= { n: 0 };
1775
- const aliasedTarget = (0, import_drizzle_orm3.aliasedTable)(targetTable, `dgql_ord_${ctx.aliases.n++}`);
1946
+ const aliasedTarget = (0, import_drizzle_orm4.aliasedTable)(targetTable, `dgql_ord_${ctx.aliases.n++}`);
1776
1947
  const joinCondition = buildRelationJoinCondition(parentTable, relation, aliasedTarget, relationName);
1777
- const relationWhere = relation.where ? (0, import_drizzle_orm3.relationsFilterToSQL)(relation.isReversed ? parentTable : aliasedTarget, relation.where) : void 0;
1948
+ const relationWhere = relation.where ? (0, import_drizzle_orm4.relationsFilterToSQL)(relation.isReversed ? parentTable : aliasedTarget, relation.where) : void 0;
1778
1949
  return {
1779
- fromParts: [...chain?.fromParts ?? [], (0, import_drizzle_orm3.getTableAsAliasSQL)(aliasedTarget)],
1950
+ fromParts: [...chain?.fromParts ?? [], (0, import_drizzle_orm4.getTableAsAliasSQL)(aliasedTarget)],
1780
1951
  conditions: [
1781
1952
  ...chain?.conditions ?? [],
1782
1953
  ...joinCondition ? [joinCondition] : [],
@@ -1786,7 +1957,7 @@ var extendRelationOrderChain = (parentTable, relationName, relEntry, ctx, chain)
1786
1957
  };
1787
1958
  };
1788
1959
  var collectOrderEntries = (table, tableKey, orderArgs, ctx, chain, out) => {
1789
- const columns = (0, import_drizzle_orm3.getColumns)(table);
1960
+ const columns = (0, import_drizzle_orm4.getColumns)(table);
1790
1961
  const relations = ctx?.relationMap[tableKey];
1791
1962
  for (const [key, config] of Object.entries(orderArgs)) {
1792
1963
  if (config === null || config === void 0) {
@@ -1795,7 +1966,7 @@ var collectOrderEntries = (table, tableKey, orderArgs, ctx, chain, out) => {
1795
1966
  const column = columns[key];
1796
1967
  if (column) {
1797
1968
  out.push({
1798
- expression: chain ? import_drizzle_orm3.sql`(select ${column} from ${import_drizzle_orm3.sql.join(chain.fromParts, import_drizzle_orm3.sql`, `)} where ${(0, import_drizzle_orm3.and)(...chain.conditions)})` : column,
1969
+ 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
1970
  column,
1800
1971
  direction: config.direction,
1801
1972
  nulls: config.nulls ?? void 0,
@@ -1805,7 +1976,7 @@ var collectOrderEntries = (table, tableKey, orderArgs, ctx, chain, out) => {
1805
1976
  }
1806
1977
  const relEntry = relations?.[key];
1807
1978
  if (!relEntry || !ctx) {
1808
- throw new import_graphql4.GraphQLError(`ORDER BY ${key}: Unknown column or relation`);
1979
+ throw new import_graphql5.GraphQLError(`ORDER BY ${key}: Unknown column or relation`);
1809
1980
  }
1810
1981
  const nextChain = extendRelationOrderChain(chain?.table ?? table, key, relEntry, ctx, chain);
1811
1982
  collectOrderEntries(nextChain.table, relEntry.targetTableName, config, ctx, nextChain, out);
@@ -1828,34 +1999,34 @@ var safeLikeOps = {
1828
1999
  };
1829
2000
  var safeLikeCondition = (column, pattern, insensitive) => {
1830
2001
  if (!insensitive) {
1831
- return import_drizzle_orm3.sql`${column} like ${pattern} escape ${LIKE_ESCAPE_CHAR}`;
2002
+ return import_drizzle_orm4.sql`${column} like ${pattern} escape ${LIKE_ESCAPE_CHAR}`;
1832
2003
  }
1833
2004
  const isPg = (column.columnType ?? "").startsWith("Pg");
1834
- return isPg ? import_drizzle_orm3.sql`${column} ilike ${pattern} escape ${LIKE_ESCAPE_CHAR}` : import_drizzle_orm3.sql`lower(${column}) like ${pattern.toLowerCase()} escape ${LIKE_ESCAPE_CHAR}`;
2005
+ 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
2006
  };
1836
2007
  var isJsonColumn2 = (column) => (column.columnType ?? "").includes("Json");
1837
2008
  var jsonContains = (column, columnName, value) => {
1838
2009
  const serialized = JSON.stringify(value);
1839
2010
  switch (columnDialect(column)) {
1840
2011
  case "pg":
1841
- return column.columnType === "PgJson" ? import_drizzle_orm3.sql`${column}::jsonb @> ${serialized}::jsonb` : import_drizzle_orm3.sql`${column} @> ${serialized}::jsonb`;
2012
+ return column.columnType === "PgJson" ? import_drizzle_orm4.sql`${column}::jsonb @> ${serialized}::jsonb` : import_drizzle_orm4.sql`${column} @> ${serialized}::jsonb`;
1842
2013
  case "mysql":
1843
- return import_drizzle_orm3.sql`json_contains(${column}, ${serialized})`;
2014
+ return import_drizzle_orm4.sql`json_contains(${column}, ${serialized})`;
1844
2015
  default:
1845
- throw new import_graphql4.GraphQLError(`WHERE ${columnName}: Operator 'contains' is not supported for this dialect!`);
2016
+ throw new import_graphql5.GraphQLError(`WHERE ${columnName}: Operator 'contains' is not supported for this dialect!`);
1846
2017
  }
1847
2018
  };
1848
2019
  var extractFiltersColumn = (column, columnName, operators) => {
1849
2020
  const { OR, AND, NOT, ...restOperators } = operators;
1850
2021
  const entries = Object.entries(restOperators);
1851
- const singleValueOps = { eq: import_drizzle_orm3.eq, ne: import_drizzle_orm3.ne, gt: import_drizzle_orm3.gt, gte: import_drizzle_orm3.gte, lt: import_drizzle_orm3.lt, lte: import_drizzle_orm3.lte };
1852
- const stringValueOps = { like: import_drizzle_orm3.like, notLike: import_drizzle_orm3.notLike, ilike: import_drizzle_orm3.ilike, notIlike: import_drizzle_orm3.notIlike };
1853
- const arrayValueOps = { inArray: import_drizzle_orm3.inArray, notInArray: import_drizzle_orm3.notInArray };
2022
+ 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 };
2023
+ const stringValueOps = { like: import_drizzle_orm4.like, notLike: import_drizzle_orm4.notLike, ilike: import_drizzle_orm4.ilike, notIlike: import_drizzle_orm4.notIlike };
2024
+ const arrayValueOps = { inArray: import_drizzle_orm4.inArray, notInArray: import_drizzle_orm4.notInArray };
1854
2025
  const arrayMembershipOps = {
1855
- hasSome: import_drizzle_orm3.arrayOverlaps,
1856
- hasEvery: import_drizzle_orm3.arrayContains
2026
+ hasSome: import_drizzle_orm4.arrayOverlaps,
2027
+ hasEvery: import_drizzle_orm4.arrayContains
1857
2028
  };
1858
- const nullableOps = { isNull: import_drizzle_orm3.isNull, isNotNull: import_drizzle_orm3.isNotNull };
2029
+ const nullableOps = { isNull: import_drizzle_orm4.isNull, isNotNull: import_drizzle_orm4.isNotNull };
1859
2030
  const variants = [];
1860
2031
  for (const [operatorName, operatorValue] of entries) {
1861
2032
  if (operatorValue === null || operatorValue === false) {
@@ -1873,23 +2044,23 @@ var extractFiltersColumn = (column, columnName, operators) => {
1873
2044
  variants.push(safeLikeCondition(column, buildPattern(operatorValue), insensitive));
1874
2045
  } else if (operatorName in arrayValueOps) {
1875
2046
  if (!operatorValue.length) {
1876
- throw new import_graphql4.GraphQLError(`WHERE ${columnName}: Unable to use operator ${operatorName} with an empty array!`);
2047
+ throw new import_graphql5.GraphQLError(`WHERE ${columnName}: Unable to use operator ${operatorName} with an empty array!`);
1877
2048
  }
1878
2049
  const arrayValue = operatorValue.map((val) => remapFromGraphQLCore(val, column, columnName));
1879
2050
  variants.push(arrayValueOps[operatorName](column, arrayValue));
1880
2051
  } else if (operatorName === "has") {
1881
- variants.push((0, import_drizzle_orm3.arrayContains)(column, [operatorValue]));
2052
+ variants.push((0, import_drizzle_orm4.arrayContains)(column, [operatorValue]));
1882
2053
  } else if (operatorName in arrayMembershipOps) {
1883
2054
  if (!operatorValue.length) {
1884
- throw new import_graphql4.GraphQLError(`WHERE ${columnName}: Unable to use operator ${operatorName} with an empty array!`);
2055
+ throw new import_graphql5.GraphQLError(`WHERE ${columnName}: Unable to use operator ${operatorName} with an empty array!`);
1885
2056
  }
1886
2057
  variants.push(arrayMembershipOps[operatorName](column, operatorValue));
1887
2058
  } else if (operatorName === "isEmpty") {
1888
- variants.push(import_drizzle_orm3.sql`cardinality(${column}) = 0`);
2059
+ variants.push(import_drizzle_orm4.sql`cardinality(${column}) = 0`);
1889
2060
  } else if (operatorName in nullableOps) {
1890
2061
  variants.push(nullableOps[operatorName](column));
1891
2062
  } else {
1892
- throw new import_graphql4.GraphQLError(`WHERE ${columnName}: Unknown operator: ${operatorName}`);
2063
+ throw new import_graphql5.GraphQLError(`WHERE ${columnName}: Unknown operator: ${operatorName}`);
1893
2064
  }
1894
2065
  }
1895
2066
  if (AND?.length) {
@@ -1903,7 +2074,7 @@ var extractFiltersColumn = (column, columnName, operators) => {
1903
2074
  if (NOT) {
1904
2075
  const extracted = extractFiltersColumn(column, columnName, NOT);
1905
2076
  if (extracted) {
1906
- variants.push((0, import_drizzle_orm3.not)(extracted));
2077
+ variants.push((0, import_drizzle_orm4.not)(extracted));
1907
2078
  }
1908
2079
  }
1909
2080
  if (OR?.length) {
@@ -1915,33 +2086,33 @@ var extractFiltersColumn = (column, columnName, operators) => {
1915
2086
  }
1916
2087
  }
1917
2088
  if (orVariants.length) {
1918
- variants.push(orVariants.length > 1 ? (0, import_drizzle_orm3.or)(...orVariants) : orVariants[0]);
2089
+ variants.push(orVariants.length > 1 ? (0, import_drizzle_orm4.or)(...orVariants) : orVariants[0]);
1919
2090
  }
1920
2091
  }
1921
- return variants.length ? variants.length > 1 ? (0, import_drizzle_orm3.and)(...variants) : variants[0] : void 0;
2092
+ return variants.length ? variants.length > 1 ? (0, import_drizzle_orm4.and)(...variants) : variants[0] : void 0;
1922
2093
  };
1923
2094
  var relationFilterCtx = (base, tableKey) => base ? { ...base, tableKey } : void 0;
1924
2095
  var buildRelationJoinCondition = (parentTable, relation, aliasedTarget, relationName) => {
1925
2096
  const sourceColumns = relation.sourceColumns;
1926
2097
  const targetColumns = relation.targetColumns;
1927
2098
  if (!sourceColumns?.length || sourceColumns.length !== targetColumns?.length) {
1928
- throw new import_graphql4.GraphQLError(`WHERE ${relationName}: Relation cannot be used as a filter`);
2099
+ throw new import_graphql5.GraphQLError(`WHERE ${relationName}: Relation cannot be used as a filter`);
1929
2100
  }
1930
- const parentColumns = Object.values((0, import_drizzle_orm3.getColumns)(parentTable));
1931
- const targetColumnsByName = Object.values((0, import_drizzle_orm3.getColumns)(aliasedTarget));
2101
+ const parentColumns = Object.values((0, import_drizzle_orm4.getColumns)(parentTable));
2102
+ const targetColumnsByName = Object.values((0, import_drizzle_orm4.getColumns)(aliasedTarget));
1932
2103
  const conditions = [];
1933
2104
  for (let i = 0; i < sourceColumns.length; i++) {
1934
2105
  const localColumn = parentColumns.find((c) => c.name === sourceColumns[i].name);
1935
2106
  const foreignColumn = targetColumnsByName.find((c) => c.name === targetColumns[i].name);
1936
2107
  if (!localColumn || !foreignColumn) {
1937
- throw new import_graphql4.GraphQLError(`WHERE ${relationName}: Relation cannot be used as a filter`);
2108
+ throw new import_graphql5.GraphQLError(`WHERE ${relationName}: Relation cannot be used as a filter`);
1938
2109
  }
1939
- conditions.push((0, import_drizzle_orm3.eq)(localColumn, foreignColumn));
2110
+ conditions.push((0, import_drizzle_orm4.eq)(localColumn, foreignColumn));
1940
2111
  }
1941
- return conditions.length > 1 ? (0, import_drizzle_orm3.and)(...conditions) : conditions[0];
2112
+ return conditions.length > 1 ? (0, import_drizzle_orm4.and)(...conditions) : conditions[0];
1942
2113
  };
1943
2114
  var resolveJunctionColumn = (aliasedThrough, junctionRef, relationName) => {
1944
- const throughColumns = (0, import_drizzle_orm3.getColumns)(aliasedThrough);
2115
+ const throughColumns = (0, import_drizzle_orm4.getColumns)(aliasedThrough);
1945
2116
  const key = junctionRef?._?.key;
1946
2117
  const byKey = key ? throughColumns[key] : void 0;
1947
2118
  if (byKey) {
@@ -1950,7 +2121,7 @@ var resolveJunctionColumn = (aliasedThrough, junctionRef, relationName) => {
1950
2121
  const columnName = junctionRef?._?.column?.name;
1951
2122
  const byName = columnName ? Object.values(throughColumns).find((c) => c.name === columnName) : void 0;
1952
2123
  if (!byName) {
1953
- throw new import_graphql4.GraphQLError(`WHERE ${relationName}: Relation cannot be used as a filter`);
2124
+ throw new import_graphql5.GraphQLError(`WHERE ${relationName}: Relation cannot be used as a filter`);
1954
2125
  }
1955
2126
  return byName;
1956
2127
  };
@@ -1959,31 +2130,31 @@ var buildThroughJoinConditions = (parentTable, relation, aliasedThrough, aliased
1959
2130
  const targetColumns = relation.targetColumns;
1960
2131
  const through = relation.through;
1961
2132
  if (!sourceColumns?.length || !targetColumns?.length || through?.source.length !== sourceColumns.length || through.target.length !== targetColumns.length) {
1962
- throw new import_graphql4.GraphQLError(`WHERE ${relationName}: Relation cannot be used as a filter`);
2133
+ throw new import_graphql5.GraphQLError(`WHERE ${relationName}: Relation cannot be used as a filter`);
1963
2134
  }
1964
- const parentColumns = Object.values((0, import_drizzle_orm3.getColumns)(parentTable));
1965
- const targetTableColumns = Object.values((0, import_drizzle_orm3.getColumns)(aliasedTarget));
2135
+ const parentColumns = Object.values((0, import_drizzle_orm4.getColumns)(parentTable));
2136
+ const targetTableColumns = Object.values((0, import_drizzle_orm4.getColumns)(aliasedTarget));
1966
2137
  const correlationConditions = [];
1967
2138
  for (let i = 0; i < sourceColumns.length; i++) {
1968
2139
  const localColumn = parentColumns.find((c) => c.name === sourceColumns[i].name);
1969
2140
  if (!localColumn) {
1970
- throw new import_graphql4.GraphQLError(`WHERE ${relationName}: Relation cannot be used as a filter`);
2141
+ throw new import_graphql5.GraphQLError(`WHERE ${relationName}: Relation cannot be used as a filter`);
1971
2142
  }
1972
- correlationConditions.push((0, import_drizzle_orm3.eq)(localColumn, resolveJunctionColumn(aliasedThrough, through.source[i], relationName)));
2143
+ correlationConditions.push((0, import_drizzle_orm4.eq)(localColumn, resolveJunctionColumn(aliasedThrough, through.source[i], relationName)));
1973
2144
  }
1974
2145
  const junctionJoinConditions = [];
1975
2146
  for (let i = 0; i < targetColumns.length; i++) {
1976
2147
  const foreignColumn = targetTableColumns.find((c) => c.name === targetColumns[i].name);
1977
2148
  if (!foreignColumn) {
1978
- throw new import_graphql4.GraphQLError(`WHERE ${relationName}: Relation cannot be used as a filter`);
2149
+ throw new import_graphql5.GraphQLError(`WHERE ${relationName}: Relation cannot be used as a filter`);
1979
2150
  }
1980
2151
  junctionJoinConditions.push(
1981
- (0, import_drizzle_orm3.eq)(resolveJunctionColumn(aliasedThrough, through.target[i], relationName), foreignColumn)
2152
+ (0, import_drizzle_orm4.eq)(resolveJunctionColumn(aliasedThrough, through.target[i], relationName), foreignColumn)
1982
2153
  );
1983
2154
  }
1984
2155
  return {
1985
- correlation: correlationConditions.length > 1 ? (0, import_drizzle_orm3.and)(...correlationConditions) : correlationConditions[0],
1986
- junctionJoin: junctionJoinConditions.length > 1 ? (0, import_drizzle_orm3.and)(...junctionJoinConditions) : junctionJoinConditions[0]
2156
+ correlation: correlationConditions.length > 1 ? (0, import_drizzle_orm4.and)(...correlationConditions) : correlationConditions[0],
2157
+ junctionJoin: junctionJoinConditions.length > 1 ? (0, import_drizzle_orm4.and)(...junctionJoinConditions) : junctionJoinConditions[0]
1987
2158
  };
1988
2159
  };
1989
2160
  var buildRelationExists = (parentTable, relationName, relEntry, innerFilters, mode, ctx) => {
@@ -1991,16 +2162,16 @@ var buildRelationExists = (parentTable, relationName, relEntry, innerFilters, mo
1991
2162
  const targetTable = ctx.tables[targetTableName];
1992
2163
  const relation = relEntry.relation ?? relEntry;
1993
2164
  if (!targetTable) {
1994
- throw new import_graphql4.GraphQLError(`WHERE ${relationName}: Relation cannot be used as a filter`);
2165
+ throw new import_graphql5.GraphQLError(`WHERE ${relationName}: Relation cannot be used as a filter`);
1995
2166
  }
1996
2167
  ctx.aliases ??= { n: 0 };
1997
2168
  const aliases = ctx.aliases;
1998
- const aliasedTarget = (0, import_drizzle_orm3.aliasedTable)(targetTable, `dgql_rel_${aliases.n++}`);
2169
+ const aliasedTarget = (0, import_drizzle_orm4.aliasedTable)(targetTable, `dgql_rel_${aliases.n++}`);
1999
2170
  const throughTable = relation.throughTable;
2000
2171
  let fromClause;
2001
2172
  let joinCondition;
2002
2173
  if (throughTable) {
2003
- const aliasedThrough = (0, import_drizzle_orm3.aliasedTable)(throughTable, `dgql_rel_${aliases.n++}`);
2174
+ const aliasedThrough = (0, import_drizzle_orm4.aliasedTable)(throughTable, `dgql_rel_${aliases.n++}`);
2004
2175
  const { correlation, junctionJoin } = buildThroughJoinConditions(
2005
2176
  parentTable,
2006
2177
  relation,
@@ -2008,26 +2179,26 @@ var buildRelationExists = (parentTable, relationName, relEntry, innerFilters, mo
2008
2179
  aliasedTarget,
2009
2180
  relationName
2010
2181
  );
2011
- fromClause = import_drizzle_orm3.sql`${(0, import_drizzle_orm3.getTableAsAliasSQL)(aliasedTarget)} inner join ${(0, import_drizzle_orm3.getTableAsAliasSQL)(aliasedThrough)} on ${junctionJoin}`;
2182
+ fromClause = import_drizzle_orm4.sql`${(0, import_drizzle_orm4.getTableAsAliasSQL)(aliasedTarget)} inner join ${(0, import_drizzle_orm4.getTableAsAliasSQL)(aliasedThrough)} on ${junctionJoin}`;
2012
2183
  joinCondition = correlation;
2013
2184
  } else {
2014
- fromClause = (0, import_drizzle_orm3.getTableAsAliasSQL)(aliasedTarget);
2185
+ fromClause = (0, import_drizzle_orm4.getTableAsAliasSQL)(aliasedTarget);
2015
2186
  joinCondition = buildRelationJoinCondition(parentTable, relation, aliasedTarget, relationName);
2016
2187
  }
2017
- const relationWhere = relation.where ? (0, import_drizzle_orm3.relationsFilterToSQL)(relation.isReversed ? parentTable : aliasedTarget, relation.where) : void 0;
2188
+ const relationWhere = relation.where ? (0, import_drizzle_orm4.relationsFilterToSQL)(relation.isReversed ? parentTable : aliasedTarget, relation.where) : void 0;
2018
2189
  const inner = innerFilters ? extractFilters(aliasedTarget, targetTableName, innerFilters, { ...ctx, tableKey: targetTableName, aliases }) : void 0;
2019
2190
  if (mode === "every") {
2020
2191
  if (!inner) {
2021
2192
  return void 0;
2022
2193
  }
2023
- return import_drizzle_orm3.sql`not exists (select 1 from ${fromClause} where ${(0, import_drizzle_orm3.and)(joinCondition, relationWhere, (0, import_drizzle_orm3.not)(inner))})`;
2194
+ 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
2195
  }
2025
- const condition = (0, import_drizzle_orm3.and)(joinCondition, relationWhere, inner);
2026
- return mode === "none" ? import_drizzle_orm3.sql`not exists (select 1 from ${fromClause} where ${condition})` : import_drizzle_orm3.sql`exists (select 1 from ${fromClause} where ${condition})`;
2196
+ const condition = (0, import_drizzle_orm4.and)(joinCondition, relationWhere, inner);
2197
+ 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
2198
  };
2028
2199
  var extractRelationFilter = (parentTable, relationName, relEntry, value, ctx) => {
2029
2200
  const relation = relEntry.relation ?? relEntry;
2030
- if ((0, import_drizzle_orm3.is)(relation, import_drizzle_orm3.One)) {
2201
+ if ((0, import_drizzle_orm4.is)(relation, import_drizzle_orm4.One)) {
2031
2202
  return buildRelationExists(parentTable, relationName, relEntry, value, "some", ctx);
2032
2203
  }
2033
2204
  const relationMatchModes = ["some", "none", "every"];
@@ -2037,19 +2208,19 @@ var extractRelationFilter = (parentTable, relationName, relEntry, value, ctx) =>
2037
2208
  continue;
2038
2209
  }
2039
2210
  if (!relationMatchModes.includes(mode)) {
2040
- throw new import_graphql4.GraphQLError(`WHERE ${relationName}: Unknown relation filter key: ${mode}`);
2211
+ throw new import_graphql5.GraphQLError(`WHERE ${relationName}: Unknown relation filter key: ${mode}`);
2041
2212
  }
2042
2213
  const extracted = buildRelationExists(parentTable, relationName, relEntry, inner, mode, ctx);
2043
2214
  if (extracted) {
2044
2215
  variants.push(extracted);
2045
2216
  }
2046
2217
  }
2047
- return variants.length ? variants.length > 1 ? (0, import_drizzle_orm3.and)(...variants) : variants[0] : void 0;
2218
+ return variants.length ? variants.length > 1 ? (0, import_drizzle_orm4.and)(...variants) : variants[0] : void 0;
2048
2219
  };
2049
2220
  var extractFilters = (table, tableName, filters, relationCtx) => {
2050
2221
  const { OR, AND, NOT, ...fieldFilters } = filters;
2051
2222
  const entries = Object.entries(fieldFilters);
2052
- const columns = (0, import_drizzle_orm3.getColumns)(table);
2223
+ const columns = (0, import_drizzle_orm4.getColumns)(table);
2053
2224
  const relations = relationCtx?.relationMap[relationCtx.tableKey];
2054
2225
  const variants = [];
2055
2226
  for (const [fieldName, operators] of entries) {
@@ -2058,7 +2229,7 @@ var extractFilters = (table, tableName, filters, relationCtx) => {
2058
2229
  }
2059
2230
  const column = columns[fieldName];
2060
2231
  if (!column && !(relations?.[fieldName] && relationCtx)) {
2061
- throw new import_graphql4.GraphQLError(`WHERE ${tableName}: Unknown filter key: ${fieldName}`);
2232
+ throw new import_graphql5.GraphQLError(`WHERE ${tableName}: Unknown filter key: ${fieldName}`);
2062
2233
  }
2063
2234
  const extracted = column ? extractFiltersColumn(column, fieldName, operators) : extractRelationFilter(table, fieldName, relations[fieldName], operators, relationCtx);
2064
2235
  if (extracted) {
@@ -2076,7 +2247,7 @@ var extractFilters = (table, tableName, filters, relationCtx) => {
2076
2247
  if (NOT) {
2077
2248
  const extracted = extractFilters(table, tableName, NOT, relationCtx);
2078
2249
  if (extracted) {
2079
- variants.push((0, import_drizzle_orm3.not)(extracted));
2250
+ variants.push((0, import_drizzle_orm4.not)(extracted));
2080
2251
  }
2081
2252
  }
2082
2253
  if (OR?.length) {
@@ -2088,10 +2259,10 @@ var extractFilters = (table, tableName, filters, relationCtx) => {
2088
2259
  }
2089
2260
  }
2090
2261
  if (orVariants.length) {
2091
- variants.push(orVariants.length > 1 ? (0, import_drizzle_orm3.or)(...orVariants) : orVariants[0]);
2262
+ variants.push(orVariants.length > 1 ? (0, import_drizzle_orm4.or)(...orVariants) : orVariants[0]);
2092
2263
  }
2093
2264
  }
2094
- return variants.length ? variants.length > 1 ? (0, import_drizzle_orm3.and)(...variants) : variants[0] : void 0;
2265
+ return variants.length ? variants.length > 1 ? (0, import_drizzle_orm4.and)(...variants) : variants[0] : void 0;
2095
2266
  };
2096
2267
  var extractRelationsParamsInner = (relationMap, tables, tableName, typeName, originField, typeNameMapper, _isInitial = false, filterCtx) => {
2097
2268
  const relationsForTable = relationMap[tableName];
@@ -2122,6 +2293,10 @@ var extractRelationsParamsInner = (relationMap, tables, tableName, typeName, ori
2122
2293
  if (!relFieldSelection) {
2123
2294
  continue;
2124
2295
  }
2296
+ const eagerArgs = field.args;
2297
+ if (!(0, import_drizzle_orm4.is)(relEntry.relation ?? relEntry, import_drizzle_orm4.One) && (eagerArgs?.after != null || !!eagerArgs?.distinct?.length || isCursorFieldSelected(relFieldSelection, tables[targetTableName]))) {
2298
+ continue;
2299
+ }
2125
2300
  const columns = extractSelectedColumnsFromTree(relFieldSelection, tables[targetTableName], {
2126
2301
  tableName: targetTableName,
2127
2302
  relationMap,
@@ -2174,7 +2349,7 @@ var pruneNonEagerRelations = (relationMap, shouldEagerLoad) => {
2174
2349
  return out;
2175
2350
  };
2176
2351
  var getPrimaryKeyPropNames = (table, compositePkColumnNames) => {
2177
- const cols = (0, import_drizzle_orm3.getColumns)(table);
2352
+ const cols = (0, import_drizzle_orm4.getColumns)(table);
2178
2353
  const entries = Object.entries(cols);
2179
2354
  const inlinePks = entries.filter(([, c]) => c.primary).map(([k]) => k);
2180
2355
  if (inlinePks.length) {
@@ -2190,7 +2365,7 @@ var getPrimaryKeyPropNames = (table, compositePkColumnNames) => {
2190
2365
  return [];
2191
2366
  };
2192
2367
  var withPrimaryKeyColumns = (columns, table, pkNames) => {
2193
- const allCols = (0, import_drizzle_orm3.getColumns)(table);
2368
+ const allCols = (0, import_drizzle_orm4.getColumns)(table);
2194
2369
  for (const pk of pkNames) {
2195
2370
  if (!(pk in columns) && allCols[pk]) {
2196
2371
  columns[pk] = allCols[pk];
@@ -2203,8 +2378,8 @@ var getPrimaryKeyPropNamesFromConfig = (table, getTableConfig4) => {
2203
2378
  return getPrimaryKeyPropNames(table, compositePkColumnNames);
2204
2379
  };
2205
2380
  var primaryKeyOrderExprs = (table, pkNames) => {
2206
- const cols = (0, import_drizzle_orm3.getColumns)(table);
2207
- return pkNames.map((n) => cols[n]).filter(Boolean).map((col) => (0, import_drizzle_orm3.asc)(col));
2381
+ const cols = (0, import_drizzle_orm4.getColumns)(table);
2382
+ return pkNames.map((n) => cols[n]).filter(Boolean).map((col) => (0, import_drizzle_orm4.asc)(col));
2208
2383
  };
2209
2384
  var CURSOR_FIELD_NAME = "cursor";
2210
2385
  var ROW_CURSOR_PROP = "__drizzle_graphql_cursor";
@@ -2220,7 +2395,7 @@ var cursorOrderingEntries = (orderBy, pkNames) => {
2220
2395
  return entries;
2221
2396
  };
2222
2397
  var cursorOrderExprs = (table, entries) => {
2223
- const cols = (0, import_drizzle_orm3.getColumns)(table);
2398
+ const cols = (0, import_drizzle_orm4.getColumns)(table);
2224
2399
  return entries.flatMap(
2225
2400
  ([column, direction, nulls]) => orderExpressions(cols[column], direction, nulls ?? void 0, cols[column])
2226
2401
  );
@@ -2257,10 +2432,10 @@ var decodeCursor = (after, entries) => {
2257
2432
  try {
2258
2433
  payload = JSON.parse(Buffer.from(after, "base64url").toString("utf8"));
2259
2434
  } catch (_e) {
2260
- throw new import_graphql4.GraphQLError("Invalid cursor: unable to decode it. Pass a cursor returned by a previous page.");
2435
+ throw new import_graphql5.GraphQLError("Invalid cursor: unable to decode it. Pass a cursor returned by a previous page.");
2261
2436
  }
2262
2437
  if (!payload || typeof payload !== "object" || !Array.isArray(payload.o) || !Array.isArray(payload.v) || payload.o.length !== payload.v.length) {
2263
- throw new import_graphql4.GraphQLError("Invalid cursor: malformed payload. Pass a cursor returned by a previous page.");
2438
+ throw new import_graphql5.GraphQLError("Invalid cursor: malformed payload. Pass a cursor returned by a previous page.");
2264
2439
  }
2265
2440
  const matchesOrdering = payload.o.length === entries.length && payload.o.every(
2266
2441
  (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 +2443,71 @@ var decodeCursor = (after, entries) => {
2268
2443
  (entry[2] ?? null) === (entries[i][2] ?? null)
2269
2444
  );
2270
2445
  if (!matchesOrdering) {
2271
- throw new import_graphql4.GraphQLError(
2446
+ throw new import_graphql5.GraphQLError(
2272
2447
  "Invalid cursor: it was issued for a different ordering. Pass the same orderBy the cursor's page used."
2273
2448
  );
2274
2449
  }
2275
2450
  return payload.v.map(decodeCursorValue);
2276
2451
  };
2277
2452
  var buildCursorCondition = (table, entries, values, nullOrdering) => {
2278
- const cols = (0, import_drizzle_orm3.getColumns)(table);
2453
+ const cols = (0, import_drizzle_orm4.getColumns)(table);
2279
2454
  const disjuncts = [];
2280
2455
  const equalities = [];
2281
2456
  entries.forEach(([column, direction, nulls], i) => {
2282
2457
  const col = cols[column];
2283
2458
  if (!col) {
2284
- throw new import_graphql4.GraphQLError(`Invalid cursor: unknown column '${column}'.`);
2459
+ throw new import_graphql5.GraphQLError(`Invalid cursor: unknown column '${column}'.`);
2285
2460
  }
2286
2461
  const value = values[i];
2287
2462
  const nullsSortLast = nulls != null ? nulls === "last" : direction === "asc" === (nullOrdering === "nulls-largest");
2288
2463
  let strictlyAfter;
2289
2464
  if (value === null || value === void 0) {
2290
- strictlyAfter = nullsSortLast ? void 0 : (0, import_drizzle_orm3.isNotNull)(col);
2465
+ strictlyAfter = nullsSortLast ? void 0 : (0, import_drizzle_orm4.isNotNull)(col);
2291
2466
  } else {
2292
- const comparison = direction === "asc" ? (0, import_drizzle_orm3.gt)(col, value) : (0, import_drizzle_orm3.lt)(col, value);
2293
- strictlyAfter = nullsSortLast ? (0, import_drizzle_orm3.or)(comparison, (0, import_drizzle_orm3.isNull)(col)) : comparison;
2467
+ const comparison = direction === "asc" ? (0, import_drizzle_orm4.gt)(col, value) : (0, import_drizzle_orm4.lt)(col, value);
2468
+ strictlyAfter = nullsSortLast ? (0, import_drizzle_orm4.or)(comparison, (0, import_drizzle_orm4.isNull)(col)) : comparison;
2294
2469
  }
2295
2470
  if (strictlyAfter) {
2296
- disjuncts.push(equalities.length ? (0, import_drizzle_orm3.and)(...equalities, strictlyAfter) : strictlyAfter);
2471
+ disjuncts.push(equalities.length ? (0, import_drizzle_orm4.and)(...equalities, strictlyAfter) : strictlyAfter);
2297
2472
  }
2298
- equalities.push(value === null || value === void 0 ? (0, import_drizzle_orm3.isNull)(col) : (0, import_drizzle_orm3.eq)(col, value));
2473
+ equalities.push(value === null || value === void 0 ? (0, import_drizzle_orm4.isNull)(col) : (0, import_drizzle_orm4.eq)(col, value));
2299
2474
  });
2300
2475
  if (!disjuncts.length) {
2301
- return import_drizzle_orm3.sql`1 = 0`;
2476
+ return import_drizzle_orm4.sql`1 = 0`;
2302
2477
  }
2303
- return disjuncts.length > 1 ? (0, import_drizzle_orm3.or)(...disjuncts) : disjuncts[0];
2478
+ return disjuncts.length > 1 ? (0, import_drizzle_orm4.or)(...disjuncts) : disjuncts[0];
2304
2479
  };
2305
2480
  var isCursorFieldSelected = (tree, table) => {
2306
2481
  if (!tree) {
2307
2482
  return false;
2308
2483
  }
2309
- if ((0, import_drizzle_orm3.getColumns)(table)[CURSOR_FIELD_NAME]) {
2484
+ if ((0, import_drizzle_orm4.getColumns)(table)[CURSOR_FIELD_NAME]) {
2310
2485
  return false;
2311
2486
  }
2312
2487
  return Object.values(tree).some((field) => field.name === CURSOR_FIELD_NAME);
2313
2488
  };
2489
+ var selectsCursorField = (info, table) => {
2490
+ if ((0, import_drizzle_orm4.getColumns)(table)[CURSOR_FIELD_NAME]) {
2491
+ return false;
2492
+ }
2493
+ const visited = /* @__PURE__ */ new Set();
2494
+ const walk = (selections) => selections.some((selection) => {
2495
+ if (selection.kind === "Field") {
2496
+ return selection.name.value === CURSOR_FIELD_NAME;
2497
+ }
2498
+ if (selection.kind === "InlineFragment") {
2499
+ return walk(selection.selectionSet.selections);
2500
+ }
2501
+ const name = selection.name?.value;
2502
+ if (!name || visited.has(name)) {
2503
+ return false;
2504
+ }
2505
+ visited.add(name);
2506
+ const fragment = info.fragments?.[name];
2507
+ return fragment ? walk(fragment.selectionSet.selections) : false;
2508
+ });
2509
+ return (info.fieldNodes ?? []).some((node) => !!node.selectionSet && walk(node.selectionSet.selections));
2510
+ };
2314
2511
  var attachRowCursors = (rows, entries) => {
2315
2512
  for (const row of rows) {
2316
2513
  row[ROW_CURSOR_PROP] = encodeCursor(entries, row);
@@ -2318,7 +2515,7 @@ var attachRowCursors = (rows, entries) => {
2318
2515
  };
2319
2516
  var rowCursorResolver = (source) => source?.[ROW_CURSOR_PROP] ?? null;
2320
2517
  var getUniqueColumnSets = (table, getTableConfig4) => {
2321
- const cols = (0, import_drizzle_orm3.getColumns)(table);
2518
+ const cols = (0, import_drizzle_orm4.getColumns)(table);
2322
2519
  const propNameByColumnName = new Map(Object.entries(cols).map(([propName, col]) => [col.name, propName]));
2323
2520
  const toPropNames = (columnNames) => {
2324
2521
  const propNames = [];
@@ -2363,11 +2560,11 @@ var generateColumnEnum = (table, enumName, description, predicate = () => true)
2363
2560
  if (cached) {
2364
2561
  return cached;
2365
2562
  }
2366
- const columnNames = Object.entries((0, import_drizzle_orm3.getColumns)(table)).filter(([columnName, column]) => predicate(column, columnName)).map(([columnName]) => columnName);
2563
+ const columnNames = Object.entries((0, import_drizzle_orm4.getColumns)(table)).filter(([columnName, column]) => predicate(column, columnName)).map(([columnName]) => columnName);
2367
2564
  if (!columnNames.length) {
2368
2565
  return void 0;
2369
2566
  }
2370
- const enumType = new import_graphql4.GraphQLEnumType({
2567
+ const enumType = new import_graphql5.GraphQLEnumType({
2371
2568
  name: enumName,
2372
2569
  description,
2373
2570
  values: Object.fromEntries(columnNames.map((columnName) => [columnName, { value: columnName }]))
@@ -2380,7 +2577,7 @@ var generateColumnEnum = (table, enumName, description, predicate = () => true)
2380
2577
  return enumType;
2381
2578
  };
2382
2579
  var generateDistinctEnum = (table, typeName) => generateColumnEnum(table, `${typeName}DistinctColumn`, `Columns of ${typeName} that a query can be made distinct on`);
2383
- var conflictActionEnum = new import_graphql4.GraphQLEnumType({
2580
+ var conflictActionEnum = new import_graphql5.GraphQLEnumType({
2384
2581
  name: "ConflictAction",
2385
2582
  description: "What an upsert does when a row with the same unique key already exists",
2386
2583
  values: {
@@ -2405,7 +2602,7 @@ var generateOnConflictInput = (params) => {
2405
2602
  description: "Whether a conflicting row is overwritten or left alone. Defaults to UPDATE."
2406
2603
  },
2407
2604
  update: {
2408
- type: new import_graphql4.GraphQLList(new import_graphql4.GraphQLNonNull(updateEnum)),
2605
+ type: new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(updateEnum)),
2409
2606
  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
2607
  }
2411
2608
  };
@@ -2421,7 +2618,7 @@ var generateOnConflictInput = (params) => {
2421
2618
  return void 0;
2422
2619
  }
2423
2620
  fields["target"] = {
2424
- type: new import_graphql4.GraphQLList(new import_graphql4.GraphQLNonNull(targetEnum)),
2621
+ type: new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(targetEnum)),
2425
2622
  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
2623
  };
2427
2624
  fields["where"] = {
@@ -2429,7 +2626,7 @@ var generateOnConflictInput = (params) => {
2429
2626
  description: "Only overwrite conflicting rows that match this filter. Others are left alone."
2430
2627
  };
2431
2628
  }
2432
- return new import_graphql4.GraphQLInputObjectType({
2629
+ return new import_graphql5.GraphQLInputObjectType({
2433
2630
  name: `${typeName}OnConflict`,
2434
2631
  description: `Conflict handling for an upsert of ${typeName}`,
2435
2632
  fields
@@ -2437,18 +2634,18 @@ var generateOnConflictInput = (params) => {
2437
2634
  };
2438
2635
  var resolveConflictPlan = (params) => {
2439
2636
  const { table, values, onConflict, pkNames, uniqueSets, excludedRef, withTarget, buildWhere } = params;
2440
- const columns = (0, import_drizzle_orm3.getColumns)(table);
2637
+ const columns = (0, import_drizzle_orm4.getColumns)(table);
2441
2638
  let target;
2442
2639
  if (withTarget) {
2443
2640
  const targetNames2 = onConflict?.target?.length ? onConflict.target : [...pkNames];
2444
2641
  if (!targetNames2.length) {
2445
- throw new import_graphql4.GraphQLError(
2642
+ throw new import_graphql5.GraphQLError(
2446
2643
  "Unable to upsert: no conflict target was given and this table has no primary key. Pass onConflict.target."
2447
2644
  );
2448
2645
  }
2449
2646
  const requested = [...targetNames2].sort().join(",");
2450
2647
  if (!uniqueSets.some((set2) => [...set2].sort().join(",") === requested)) {
2451
- throw new import_graphql4.GraphQLError(
2648
+ throw new import_graphql5.GraphQLError(
2452
2649
  `Unable to upsert: [${targetNames2.join(", ")}] is not a unique constraint on this table. Valid conflict targets: ${uniqueSets.map((set2) => `[${set2.join(", ")}]`).join(", ")}.`
2453
2650
  );
2454
2651
  }
@@ -2463,7 +2660,7 @@ var resolveConflictPlan = (params) => {
2463
2660
  if (onConflict?.update?.length) {
2464
2661
  const unsupplied = onConflict.update.filter((name) => !supplied.has(name));
2465
2662
  if (unsupplied.length) {
2466
- throw new import_graphql4.GraphQLError(
2663
+ throw new import_graphql5.GraphQLError(
2467
2664
  `Unable to upsert: onConflict.update lists ${unsupplied.join(", ")}, which the values do not supply.`
2468
2665
  );
2469
2666
  }
@@ -2478,18 +2675,19 @@ var resolveConflictPlan = (params) => {
2478
2675
  const setWhere = onConflict?.where && buildWhere ? buildWhere(onConflict.where) : void 0;
2479
2676
  return { action: "UPDATE", target, set, setWhere };
2480
2677
  };
2481
- var excludedColumnRef = (columnName) => import_drizzle_orm3.sql`excluded.${import_drizzle_orm3.sql.identifier(columnName)}`;
2482
- var mysqlValuesColumnRef = (columnName) => import_drizzle_orm3.sql`values(${import_drizzle_orm3.sql.identifier(columnName)})`;
2678
+ var excludedColumnRef = (columnName) => import_drizzle_orm4.sql`excluded.${import_drizzle_orm4.sql.identifier(columnName)}`;
2679
+ var mysqlValuesColumnRef = (columnName) => import_drizzle_orm4.sql`values(${import_drizzle_orm4.sql.identifier(columnName)})`;
2483
2680
  var selectDistinctKeys = async (params) => {
2484
- const { db, table, tableName, distinct, pkNames, where, orderBy, limit, offset } = params;
2485
- const cols = (0, import_drizzle_orm3.getColumns)(table);
2681
+ const { db, table, tableName, distinct, pkNames, where, orderBy, limit, offset, partitionBy } = params;
2682
+ const cols = (0, import_drizzle_orm4.getColumns)(table);
2486
2683
  if (!pkNames.length) {
2487
- throw new import_graphql4.GraphQLError(`Table ${tableName} has no primary key, so 'distinct' cannot be applied to it.`);
2684
+ throw new import_graphql5.GraphQLError(`Table ${tableName} has no primary key, so 'distinct' cannot be applied to it.`);
2488
2685
  }
2489
- const partitionCols = distinct.map((name) => cols[name]).filter(Boolean);
2490
- if (!partitionCols.length) {
2491
- throw new import_graphql4.GraphQLError(`No known columns were given to 'distinct' on ${tableName}.`);
2686
+ const requestedCols = distinct.map((name) => cols[name]).filter(Boolean);
2687
+ if (!requestedCols.length) {
2688
+ throw new import_graphql5.GraphQLError(`No known columns were given to 'distinct' on ${tableName}.`);
2492
2689
  }
2690
+ const partitionCols = [...partitionBy ?? [], ...requestedCols];
2493
2691
  const orderEntries = orderBy ? orderByEntries(orderBy) : [];
2494
2692
  const windowOrder = [
2495
2693
  ...orderEntries.flatMap(
@@ -2497,18 +2695,18 @@ var selectDistinctKeys = async (params) => {
2497
2695
  ),
2498
2696
  ...primaryKeyOrderExprs(table, pkNames)
2499
2697
  ];
2500
- const rowNumber = import_drizzle_orm3.sql`row_number() over (partition by ${import_drizzle_orm3.sql.join(partitionCols, import_drizzle_orm3.sql`, `)} order by ${import_drizzle_orm3.sql.join(
2698
+ 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
2699
  windowOrder,
2502
- import_drizzle_orm3.sql`, `
2700
+ import_drizzle_orm4.sql`, `
2503
2701
  )})`.as(DISTINCT_RN);
2504
2702
  const sub = db.select({ ...cols, [DISTINCT_RN]: rowNumber }).from(table).where(where).as("__dgql_distinct");
2505
2703
  const outerOrder = [
2506
2704
  ...orderEntries.flatMap(
2507
2705
  ([column, direction, nulls]) => orderExpressions(sub[column], direction, nulls, cols[column])
2508
2706
  ),
2509
- ...pkNames.filter((name) => sub[name]).map((name) => (0, import_drizzle_orm3.asc)(sub[name]))
2707
+ ...pkNames.filter((name) => sub[name]).map((name) => (0, import_drizzle_orm4.asc)(sub[name]))
2510
2708
  ];
2511
- let query = db.select(Object.fromEntries(pkNames.map((name) => [name, sub[name]]))).from(sub).where((0, import_drizzle_orm3.eq)(sub[DISTINCT_RN], 1)).orderBy(...outerOrder);
2709
+ 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
2710
  if (offset) {
2513
2711
  query = query.offset(offset);
2514
2712
  }
@@ -2518,15 +2716,15 @@ var selectDistinctKeys = async (params) => {
2518
2716
  return await query;
2519
2717
  };
2520
2718
  var primaryKeyRestriction = (table, pkNames, keys) => {
2521
- const cols = (0, import_drizzle_orm3.getColumns)(table);
2719
+ const cols = (0, import_drizzle_orm4.getColumns)(table);
2522
2720
  if (pkNames.length === 1) {
2523
2721
  const name = pkNames[0];
2524
- return (0, import_drizzle_orm3.inArray)(
2722
+ return (0, import_drizzle_orm4.inArray)(
2525
2723
  cols[name],
2526
2724
  keys.map((key) => key[name])
2527
2725
  );
2528
2726
  }
2529
- return (0, import_drizzle_orm3.or)(...keys.map((key) => (0, import_drizzle_orm3.and)(...pkNames.map((name) => (0, import_drizzle_orm3.eq)(cols[name], key[name])))));
2727
+ 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
2728
  };
2531
2729
  var prepareMutationRelationColumns = (params) => {
2532
2730
  const { relationMap, tables, tableName, typeName, typeNameMapper, table, pkNames, parsedInfo } = params;
@@ -2541,17 +2739,17 @@ var prepareMutationRelationColumns = (params) => {
2541
2739
  return { columns, hasRelations, withParams };
2542
2740
  };
2543
2741
  var toGraphQLError = (e) => {
2544
- if (e instanceof import_graphql4.GraphQLError) {
2742
+ if (e instanceof import_graphql5.GraphQLError) {
2545
2743
  return e;
2546
2744
  }
2547
- return e instanceof Error ? new import_graphql4.GraphQLError(e.message, { originalError: e }) : e;
2745
+ return e instanceof Error ? new import_graphql5.GraphQLError(e.message, { originalError: e }) : e;
2548
2746
  };
2549
2747
  var defaultErrorMapper = (error) => {
2550
- if (error instanceof import_graphql4.GraphQLError && !error.originalError) {
2748
+ if (error instanceof import_graphql5.GraphQLError && !error.originalError) {
2551
2749
  return error;
2552
2750
  }
2553
- return new import_graphql4.GraphQLError("Internal server error", {
2554
- originalError: error instanceof import_graphql4.GraphQLError ? error.originalError ?? error : error instanceof Error ? error : null,
2751
+ return new import_graphql5.GraphQLError("Internal server error", {
2752
+ originalError: error instanceof import_graphql5.GraphQLError ? error.originalError ?? error : error instanceof Error ? error : null,
2555
2753
  extensions: { code: "INTERNAL_SERVER_ERROR" }
2556
2754
  });
2557
2755
  };
@@ -2608,6 +2806,9 @@ var computeResolverFieldNames = (tableName, typeNameMapper, prefixes, suffixes)
2608
2806
  const writeSingleSuffix = suffixes.single === "" ? "Single" : suffixes.single;
2609
2807
  const updateSingleFieldName = `${updateFieldName}${writeSingleSuffix}`;
2610
2808
  const deleteSingleFieldName = `${deleteFieldName}${writeSingleSuffix}`;
2809
+ const pluralNoun = mapped ? capitalize(mapped.plural) : capitalize(tableName);
2810
+ const updateCountFieldName = `${prefixes.update}${pluralNoun}Count`;
2811
+ const deleteCountFieldName = `${prefixes.delete}${pluralNoun}Count`;
2611
2812
  return {
2612
2813
  typeName,
2613
2814
  listFieldName,
@@ -2621,13 +2822,15 @@ var computeResolverFieldNames = (tableName, typeNameMapper, prefixes, suffixes)
2621
2822
  updateFieldName,
2622
2823
  updateManyFieldName,
2623
2824
  updateSingleFieldName,
2825
+ updateCountFieldName,
2624
2826
  deleteFieldName,
2625
- deleteSingleFieldName
2827
+ deleteSingleFieldName,
2828
+ deleteCountFieldName
2626
2829
  };
2627
2830
  };
2628
2831
  var generateUpdateManyInput = (params) => {
2629
2832
  const { typeName, updatePrefix, updateInput, tableFilters } = params;
2630
- return new import_graphql4.GraphQLInputObjectType({
2833
+ return new import_graphql5.GraphQLInputObjectType({
2631
2834
  name: `${capitalize(updatePrefix)}${typeName}ManyInput`,
2632
2835
  description: `One entry of a batch update of ${typeName}: the rows \`where\` matches get this entry's \`set\` applied.`,
2633
2836
  fields: {
@@ -2636,7 +2839,7 @@ var generateUpdateManyInput = (params) => {
2636
2839
  description: "Rows this entry updates. An omitted filter updates every row."
2637
2840
  },
2638
2841
  set: {
2639
- type: new import_graphql4.GraphQLNonNull(updateInput)
2842
+ type: new import_graphql5.GraphQLNonNull(updateInput)
2640
2843
  }
2641
2844
  }
2642
2845
  });
@@ -2644,29 +2847,101 @@ var generateUpdateManyInput = (params) => {
2644
2847
  var extractRequiredFilters = (table, tableName, where, fieldName, relationCtx) => {
2645
2848
  const filters = where ? extractFilters(table, tableName, where, relationCtx) : void 0;
2646
2849
  if (!filters) {
2647
- throw new import_graphql4.GraphQLError(`${fieldName} requires a 'where' argument with at least one filter!`);
2850
+ throw new import_graphql5.GraphQLError(`${fieldName} requires a 'where' argument with at least one filter!`);
2648
2851
  }
2649
2852
  return filters;
2650
2853
  };
2854
+ var rowsAffected = (result, fieldName) => {
2855
+ const asNumber = (value) => typeof value === "number" ? value : typeof value === "bigint" ? Number(value) : void 0;
2856
+ if (result && typeof result === "object") {
2857
+ for (const key of ["rowCount", "affectedRows", "rowsAffected", "changes", "count"]) {
2858
+ const value = asNumber(result[key]);
2859
+ if (value !== void 0) {
2860
+ return value;
2861
+ }
2862
+ }
2863
+ const header = Array.isArray(result) ? result[0] : void 0;
2864
+ const affected = header && typeof header === "object" ? asNumber(header.affectedRows) : void 0;
2865
+ if (affected !== void 0) {
2866
+ return affected;
2867
+ }
2868
+ }
2869
+ throw new import_graphql5.GraphQLError(`${fieldName}: the driver did not report how many rows the write affected.`);
2870
+ };
2651
2871
  var assertSingleMatch = async (executor, table, filters, fieldName) => {
2652
- const matched = await executor.select({ found: import_drizzle_orm3.sql`1` }).from(table).where(filters).limit(2);
2872
+ const matched = await executor.select({ found: import_drizzle_orm4.sql`1` }).from(table).where(filters).limit(2);
2653
2873
  if (matched.length > 1) {
2654
- throw new import_graphql4.GraphQLError(`${fieldName}: 'where' matched more than one row \u2014 nothing was written!`);
2655
- }
2874
+ throw new import_graphql5.GraphQLError(`${fieldName}: 'where' matched more than one row \u2014 nothing was written!`);
2875
+ }
2876
+ };
2877
+ var generateWriteCount = ({
2878
+ db,
2879
+ tableName,
2880
+ table,
2881
+ kind,
2882
+ setArgs,
2883
+ filterArgs,
2884
+ fieldName,
2885
+ requireWhere,
2886
+ filterCtx,
2887
+ txCtx,
2888
+ nested
2889
+ }) => {
2890
+ const queryArgs = {
2891
+ ...setArgs ? { set: { type: new import_graphql5.GraphQLNonNull(setArgs) } } : {},
2892
+ where: {
2893
+ type: requireWhere ? new import_graphql5.GraphQLNonNull(filterArgs) : filterArgs
2894
+ }
2895
+ };
2896
+ return {
2897
+ name: fieldName,
2898
+ resolver: async (_source, args, context, info) => {
2899
+ try {
2900
+ return await runMutation(db, context, info, txCtx, async (executor) => {
2901
+ const { where, set } = args;
2902
+ const relationCtx = relationFilterCtx(filterCtx, tableName);
2903
+ const filters = requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
2904
+ let query;
2905
+ if (kind === "delete") {
2906
+ query = executor.delete(table);
2907
+ } else {
2908
+ const entry = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
2909
+ if (entry && nested.hasOps(entry.ops)) {
2910
+ throw new import_graphql5.GraphQLError(
2911
+ `${fieldName} does not support nested writes \u2014 use ${fieldName.slice(0, -"Count".length)} instead.`
2912
+ );
2913
+ }
2914
+ const values = remapUpdateInput(entry ? entry.columns : set, table, tableName);
2915
+ if (!Object.keys(values).length) {
2916
+ throw new import_graphql5.GraphQLError("Unable to update with no values specified!");
2917
+ }
2918
+ query = executor.update(table).set(values);
2919
+ }
2920
+ if (filters) {
2921
+ query = query.where(filters);
2922
+ }
2923
+ return rowsAffected(await query, fieldName);
2924
+ });
2925
+ } catch (e) {
2926
+ throw toGraphQLError(e);
2927
+ }
2928
+ },
2929
+ args: queryArgs
2930
+ };
2656
2931
  };
2657
2932
  var selectArrayArgs = (orderArgs, filterArgs, distinctEnum) => ({
2658
- offset: { type: import_graphql4.GraphQLInt },
2659
- limit: { type: import_graphql4.GraphQLInt },
2933
+ offset: { type: import_graphql5.GraphQLInt },
2934
+ limit: { type: import_graphql5.GraphQLInt },
2660
2935
  orderBy: { type: orderArgs },
2661
2936
  where: { type: filterArgs },
2662
2937
  after: {
2663
- type: import_graphql4.GraphQLString,
2938
+ type: import_graphql5.GraphQLString,
2664
2939
  description: "Keyset pagination: only return rows strictly after this cursor (a row's `cursor` field from a previous page, under the same orderBy)."
2665
2940
  },
2666
- ...distinctEnum ? { distinct: { type: new import_graphql4.GraphQLList(new import_graphql4.GraphQLNonNull(distinctEnum)) } } : {}
2941
+ ...distinctEnum ? { distinct: { type: new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(distinctEnum)) } } : {}
2667
2942
  });
2668
2943
  var selectSingleArgs = (orderArgs, filterArgs) => ({
2669
- offset: { type: import_graphql4.GraphQLInt },
2944
+ offset: { type: import_graphql5.GraphQLInt },
2670
2945
  orderBy: { type: orderArgs },
2671
2946
  where: { type: filterArgs }
2672
2947
  });
@@ -2693,17 +2968,17 @@ var runRelationalSelect = async (opts) => {
2693
2968
  let cursorEntries;
2694
2969
  if (!single && (after != null || cursorSelected)) {
2695
2970
  if (after != null && distinct) {
2696
- throw new import_graphql4.GraphQLError("'after' cannot be combined with 'distinct'.");
2971
+ throw new import_graphql5.GraphQLError("'after' cannot be combined with 'distinct'.");
2697
2972
  }
2698
2973
  if (orderByHasRelationEntry(orderBy)) {
2699
2974
  if (after != null) {
2700
- throw new import_graphql4.GraphQLError(
2975
+ throw new import_graphql5.GraphQLError(
2701
2976
  "'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
2977
  );
2703
2978
  }
2704
2979
  } else if (!pkNames?.length) {
2705
2980
  if (after != null) {
2706
- throw new import_graphql4.GraphQLError(`Table ${tableName} has no primary key, so cursor pagination cannot be used on it.`);
2981
+ throw new import_graphql5.GraphQLError(`Table ${tableName} has no primary key, so cursor pagination cannot be used on it.`);
2707
2982
  }
2708
2983
  } else {
2709
2984
  cursorEntries = cursorOrderingEntries(orderBy, pkNames);
@@ -2747,7 +3022,7 @@ var runRelationalSelect = async (opts) => {
2747
3022
  (aliasedTable2) => cursorOrderExprs(aliasedTable2, cursorEntries)
2748
3023
  ) : orderBy ? (aliasedTable2) => extractOrderBy(aliasedTable2, orderBy, relationFilterCtx(filterCtx, tableName)) : needsDefaultOrder && pkNames?.length ? (aliasedTable2) => primaryKeyOrderExprs(aliasedTable2, pkNames) : void 0,
2749
3024
  where: distinctKeys ? { RAW: (aliasedTable2) => primaryKeyRestriction(aliasedTable2, pkNames, distinctKeys) } : where || cursorValues ? {
2750
- RAW: (aliasedTable2) => (0, import_drizzle_orm3.and)(
3025
+ RAW: (aliasedTable2) => (0, import_drizzle_orm4.and)(
2751
3026
  where ? extractFilters(aliasedTable2, tableName, where, relationFilterCtx(filterCtx, tableName)) : void 0,
2752
3027
  cursorValues ? buildCursorCondition(
2753
3028
  aliasedTable2,
@@ -2797,23 +3072,23 @@ var eagerLoadMutationRelations = async (db, tableName, rows, pkNames, withParams
2797
3072
  if (pkNames.length === 1) {
2798
3073
  const pkName = pkNames[0];
2799
3074
  const ids = keyableRows.map((r) => r[pkName]);
2800
- whereRaw = (aliased) => (0, import_drizzle_orm3.inArray)(aliased[pkName], ids);
3075
+ whereRaw = (aliased) => (0, import_drizzle_orm4.inArray)(aliased[pkName], ids);
2801
3076
  } else {
2802
3077
  whereRaw = (aliased) => {
2803
- const lhs = import_drizzle_orm3.sql.join(
2804
- pkNames.map((n) => import_drizzle_orm3.sql`${aliased[n]}`),
2805
- import_drizzle_orm3.sql`, `
3078
+ const lhs = import_drizzle_orm4.sql.join(
3079
+ pkNames.map((n) => import_drizzle_orm4.sql`${aliased[n]}`),
3080
+ import_drizzle_orm4.sql`, `
2806
3081
  );
2807
- const tuples = import_drizzle_orm3.sql.join(
3082
+ const tuples = import_drizzle_orm4.sql.join(
2808
3083
  keyableRows.map(
2809
- (row) => import_drizzle_orm3.sql`(${import_drizzle_orm3.sql.join(
2810
- pkNames.map((n) => import_drizzle_orm3.sql`${row[n]}`),
2811
- import_drizzle_orm3.sql`, `
3084
+ (row) => import_drizzle_orm4.sql`(${import_drizzle_orm4.sql.join(
3085
+ pkNames.map((n) => import_drizzle_orm4.sql`${row[n]}`),
3086
+ import_drizzle_orm4.sql`, `
2812
3087
  )})`
2813
3088
  ),
2814
- import_drizzle_orm3.sql`, `
3089
+ import_drizzle_orm4.sql`, `
2815
3090
  );
2816
- return import_drizzle_orm3.sql`(${lhs}) in (${tuples})`;
3091
+ return import_drizzle_orm4.sql`(${lhs}) in (${tuples})`;
2817
3092
  };
2818
3093
  }
2819
3094
  let enriched;
@@ -2844,38 +3119,38 @@ var eagerLoadMutationRelations = async (db, tableName, rows, pkNames, withParams
2844
3119
  };
2845
3120
 
2846
3121
  // src/util/builders/mysql.ts
2847
- var import_drizzle_orm5 = require("drizzle-orm");
3122
+ var import_drizzle_orm6 = require("drizzle-orm");
2848
3123
  var import_mysql_core2 = require("drizzle-orm/mysql-core");
2849
- var import_graphql6 = require("graphql");
3124
+ var import_graphql7 = require("graphql");
2850
3125
  var import_graphql_parse_resolve_info2 = require("graphql-parse-resolve-info");
2851
3126
 
2852
3127
  // src/util/builders/aggregates.ts
2853
- var import_drizzle_orm4 = require("drizzle-orm");
2854
- var import_graphql5 = require("graphql");
3128
+ var import_drizzle_orm5 = require("drizzle-orm");
3129
+ var import_graphql6 = require("graphql");
2855
3130
  var import_graphql_parse_resolve_info = require("graphql-parse-resolve-info");
2856
3131
  var AGGREGATE_OPS = ["avg", "sum", "min", "max", "countNonNull", "countDistinct"];
2857
3132
  var COUNT_OPS = /* @__PURE__ */ new Set(["countNonNull", "countDistinct"]);
2858
3133
  var OP_FNS = {
2859
- avg: import_drizzle_orm4.avg,
2860
- sum: import_drizzle_orm4.sum,
2861
- min: import_drizzle_orm4.min,
2862
- max: import_drizzle_orm4.max,
2863
- countNonNull: import_drizzle_orm4.count,
2864
- countDistinct: import_drizzle_orm4.countDistinct
3134
+ avg: import_drizzle_orm5.avg,
3135
+ sum: import_drizzle_orm5.sum,
3136
+ min: import_drizzle_orm5.min,
3137
+ max: import_drizzle_orm5.max,
3138
+ countNonNull: import_drizzle_orm5.count,
3139
+ countDistinct: import_drizzle_orm5.countDistinct
2865
3140
  };
2866
3141
  var SEP = "__";
2867
3142
  var classifyAggregateColumns = (table, tableName) => {
2868
3143
  const numeric = {};
2869
3144
  const orderable = {};
2870
3145
  const all = {};
2871
- for (const [columnName, column] of Object.entries((0, import_drizzle_orm4.getColumns)(table))) {
3146
+ for (const [columnName, column] of Object.entries((0, import_drizzle_orm5.getColumns)(table))) {
2872
3147
  all[columnName] = column;
2873
3148
  const converted = drizzleColumnToGraphQLType(column, columnName, tableName, true, false, false);
2874
3149
  const gqlType = converted.type;
2875
- if (gqlType instanceof import_graphql5.GraphQLList || gqlType instanceof import_graphql5.GraphQLObjectType) {
3150
+ if (gqlType instanceof import_graphql6.GraphQLList || gqlType instanceof import_graphql6.GraphQLObjectType) {
2876
3151
  continue;
2877
3152
  }
2878
- const { type: dataType, constraint } = (0, import_drizzle_orm4.extractExtendedColumnType)(column);
3153
+ const { type: dataType, constraint } = (0, import_drizzle_orm5.extractExtendedColumnType)(column);
2879
3154
  if (dataType === "boolean" || dataType === "array" || dataType === "custom") {
2880
3155
  continue;
2881
3156
  }
@@ -2896,14 +3171,14 @@ var generateAggregateTypes = (table, tableName, typeName, cacheCtx) => {
2896
3171
  }
2897
3172
  const { numeric, orderable, all } = classifyAggregateColumns(table, tableName);
2898
3173
  const fields = {
2899
- count: { type: new import_graphql5.GraphQLNonNull(import_graphql5.GraphQLInt) }
3174
+ count: { type: new import_graphql6.GraphQLNonNull(import_graphql6.GraphQLInt) }
2900
3175
  };
2901
3176
  if (Object.keys(numeric).length) {
2902
3177
  for (const op of ["avg", "sum"]) {
2903
3178
  fields[op] = {
2904
- type: new import_graphql5.GraphQLObjectType({
3179
+ type: new import_graphql6.GraphQLObjectType({
2905
3180
  name: `${typeName}${capitalize(op)}Aggregate`,
2906
- fields: Object.fromEntries(Object.keys(numeric).map((columnName) => [columnName, { type: import_graphql5.GraphQLFloat }]))
3181
+ fields: Object.fromEntries(Object.keys(numeric).map((columnName) => [columnName, { type: import_graphql6.GraphQLFloat }]))
2907
3182
  })
2908
3183
  };
2909
3184
  }
@@ -2911,7 +3186,7 @@ var generateAggregateTypes = (table, tableName, typeName, cacheCtx) => {
2911
3186
  if (Object.keys(orderable).length) {
2912
3187
  for (const op of ["min", "max"]) {
2913
3188
  fields[op] = {
2914
- type: new import_graphql5.GraphQLObjectType({
3189
+ type: new import_graphql6.GraphQLObjectType({
2915
3190
  name: `${typeName}${capitalize(op)}Aggregate`,
2916
3191
  fields: Object.fromEntries(
2917
3192
  Object.entries(orderable).map(([columnName, { column, converted }]) => [
@@ -2930,15 +3205,15 @@ var generateAggregateTypes = (table, tableName, typeName, cacheCtx) => {
2930
3205
  continue;
2931
3206
  }
2932
3207
  fields[op] = {
2933
- type: new import_graphql5.GraphQLObjectType({
3208
+ type: new import_graphql6.GraphQLObjectType({
2934
3209
  name: `${typeName}${capitalize(op)}Aggregate`,
2935
3210
  fields: Object.fromEntries(
2936
- columnNames.map((columnName) => [columnName, { type: new import_graphql5.GraphQLNonNull(import_graphql5.GraphQLInt) }])
3211
+ columnNames.map((columnName) => [columnName, { type: new import_graphql6.GraphQLNonNull(import_graphql6.GraphQLInt) }])
2937
3212
  )
2938
3213
  })
2939
3214
  };
2940
3215
  }
2941
- const aggregateType = new import_graphql5.GraphQLObjectType({
3216
+ const aggregateType = new import_graphql6.GraphQLObjectType({
2942
3217
  name: `${typeName}Aggregate`,
2943
3218
  fields
2944
3219
  });
@@ -2961,7 +3236,7 @@ var aggregateTarget = (table, tableName, typeName) => {
2961
3236
  return {
2962
3237
  tableName,
2963
3238
  typeName,
2964
- columns: (0, import_drizzle_orm4.getColumns)(table),
3239
+ columns: (0, import_drizzle_orm5.getColumns)(table),
2965
3240
  dateTimeColumns: new Set(
2966
3241
  Object.entries(orderable).filter(([, { converted }]) => converted.typeLabel === "DateTime").map(([columnName]) => columnName)
2967
3242
  )
@@ -2978,7 +3253,7 @@ var parseAggregateRequest = (info, target, rootTypeName = `${target.typeName}Agg
2978
3253
  for (const field of Object.values(selectionTree)) {
2979
3254
  if (field.name === "count") {
2980
3255
  request.count = true;
2981
- request.selection.count = (0, import_drizzle_orm4.count)();
3256
+ request.selection.count = (0, import_drizzle_orm5.count)();
2982
3257
  continue;
2983
3258
  }
2984
3259
  if (!AGGREGATE_OPS.includes(field.name)) {
@@ -3091,8 +3366,8 @@ var createRelationAggregateFactory = (db, tables, cacheCtx, typeNameMapper, filt
3091
3366
  const loader = getOrCreateLoader(context, loaderKey, async (parentIds) => {
3092
3367
  const executor = resolveExecutor(db, context);
3093
3368
  const uniqueIds = [...new Set(parentIds)];
3094
- const whereCondition = (0, import_drizzle_orm4.and)(
3095
- (0, import_drizzle_orm4.inArray)(foreignCol, uniqueIds),
3369
+ const whereCondition = (0, import_drizzle_orm5.and)(
3370
+ (0, import_drizzle_orm5.inArray)(foreignCol, uniqueIds),
3096
3371
  whereArg ? extractFilters(targetTable, targetTableName, whereArg, relationFilterCtx(filterCtx, targetTableName)) : void 0
3097
3372
  );
3098
3373
  const rows = await executor.select({ [GROUP_KEY]: foreignCol, ...request.selection }).from(targetTable).where(whereCondition).groupBy(foreignCol);
@@ -3108,15 +3383,15 @@ var createRelationAggregateFactory = (db, tables, cacheCtx, typeNameMapper, filt
3108
3383
  };
3109
3384
  };
3110
3385
  var GROUP_COL = `group${SEP}`;
3111
- var HAVING_OPS = { 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 };
3386
+ 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
3387
  var groupableColumns = (table, tableName) => {
3113
3388
  const { orderable } = classifyAggregateColumns(table, tableName);
3114
3389
  const groupable = { ...orderable };
3115
- for (const [columnName, column] of Object.entries((0, import_drizzle_orm4.getColumns)(table))) {
3390
+ for (const [columnName, column] of Object.entries((0, import_drizzle_orm5.getColumns)(table))) {
3116
3391
  if (groupable[columnName]) {
3117
3392
  continue;
3118
3393
  }
3119
- const { type: dataType } = (0, import_drizzle_orm4.extractExtendedColumnType)(column);
3394
+ const { type: dataType } = (0, import_drizzle_orm5.extractExtendedColumnType)(column);
3120
3395
  if (dataType !== "boolean") {
3121
3396
  continue;
3122
3397
  }
@@ -3136,10 +3411,10 @@ var generateGroupByEnum = (table, tableName, typeName) => {
3136
3411
  (_column, columnName) => Boolean(groupable[columnName])
3137
3412
  );
3138
3413
  };
3139
- var aggregateNumberFilter = new import_graphql5.GraphQLInputObjectType({
3414
+ var aggregateNumberFilter = new import_graphql6.GraphQLInputObjectType({
3140
3415
  name: "AggregateNumberFilter",
3141
3416
  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: import_graphql5.GraphQLFloat }]))
3417
+ fields: Object.fromEntries(Object.keys(HAVING_OPS).map((op) => [op, { type: import_graphql6.GraphQLFloat }]))
3143
3418
  });
3144
3419
  var generateHavingInput = (table, tableName, typeName) => {
3145
3420
  const { numeric, orderable, all } = classifyAggregateColumns(table, tableName);
@@ -3160,13 +3435,13 @@ var generateHavingInput = (table, tableName, typeName) => {
3160
3435
  continue;
3161
3436
  }
3162
3437
  fields[op] = {
3163
- type: new import_graphql5.GraphQLInputObjectType({
3438
+ type: new import_graphql6.GraphQLInputObjectType({
3164
3439
  name: `${typeName}${capitalize(op)}Having`,
3165
3440
  fields: Object.fromEntries(columnNames.map((columnName) => [columnName, { type: aggregateNumberFilter }]))
3166
3441
  })
3167
3442
  };
3168
3443
  }
3169
- return new import_graphql5.GraphQLInputObjectType({
3444
+ return new import_graphql6.GraphQLInputObjectType({
3170
3445
  name: `${typeName}Having`,
3171
3446
  description: `Filters ${typeName} groups by their aggregated values`,
3172
3447
  fields
@@ -3177,7 +3452,7 @@ var generateGroupByType = (table, tableName, typeName, cacheCtx) => {
3177
3452
  if (!Object.keys(groupable).length) {
3178
3453
  return void 0;
3179
3454
  }
3180
- const keysType = new import_graphql5.GraphQLObjectType({
3455
+ const keysType = new import_graphql6.GraphQLObjectType({
3181
3456
  name: `${typeName}GroupKeys`,
3182
3457
  description: `The grouped column values of one ${typeName} group. A column the query did not group by is null.`,
3183
3458
  fields: Object.fromEntries(
@@ -3194,9 +3469,9 @@ var generateGroupByType = (table, tableName, typeName, cacheCtx) => {
3194
3469
  { type: field.type, description: field.description ?? void 0 }
3195
3470
  ])
3196
3471
  );
3197
- return new import_graphql5.GraphQLObjectType({
3472
+ return new import_graphql6.GraphQLObjectType({
3198
3473
  name: `${typeName}GroupBy`,
3199
- fields: { group: { type: new import_graphql5.GraphQLNonNull(keysType) }, ...aggregateFields }
3474
+ fields: { group: { type: new import_graphql6.GraphQLNonNull(keysType) }, ...aggregateFields }
3200
3475
  });
3201
3476
  };
3202
3477
  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 +3485,7 @@ var buildHavingCondition = (having, columns) => {
3210
3485
  continue;
3211
3486
  }
3212
3487
  if (key === "count") {
3213
- conditions.push(...havingComparisons((0, import_drizzle_orm4.count)(), value));
3488
+ conditions.push(...havingComparisons((0, import_drizzle_orm5.count)(), value));
3214
3489
  continue;
3215
3490
  }
3216
3491
  if (!AGGREGATE_OPS.includes(key)) {
@@ -3224,16 +3499,16 @@ var buildHavingCondition = (having, columns) => {
3224
3499
  conditions.push(...havingComparisons(OP_FNS[key](column), filter));
3225
3500
  }
3226
3501
  }
3227
- return conditions.length ? (0, import_drizzle_orm4.and)(...conditions) : void 0;
3502
+ return conditions.length ? (0, import_drizzle_orm5.and)(...conditions) : void 0;
3228
3503
  };
3229
3504
  var generateGroupBy = (db, tableName, table, typeName, fieldName, filterArgs, groupByEnum, havingInput, filterCtx) => {
3230
3505
  const target = aggregateTarget(table, tableName, typeName);
3231
3506
  const groupable = groupableColumns(table, tableName);
3232
- const columns = (0, import_drizzle_orm4.getColumns)(table);
3507
+ const columns = (0, import_drizzle_orm5.getColumns)(table);
3233
3508
  const rootTypeName = `${typeName}GroupBy`;
3234
3509
  const queryArgs = {
3235
3510
  groupBy: {
3236
- type: new import_graphql5.GraphQLNonNull(new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(groupByEnum))),
3511
+ type: new import_graphql6.GraphQLNonNull(new import_graphql6.GraphQLList(new import_graphql6.GraphQLNonNull(groupByEnum))),
3237
3512
  description: "Columns to group by. One result row per distinct combination of their values."
3238
3513
  },
3239
3514
  where: { type: filterArgs, description: "Filters the rows before they are grouped." },
@@ -3245,12 +3520,12 @@ var generateGroupBy = (db, tableName, table, typeName, fieldName, filterArgs, gr
3245
3520
  try {
3246
3521
  const requestedKeys = [...new Set(args.groupBy ?? [])];
3247
3522
  if (!requestedKeys.length) {
3248
- throw new import_graphql5.GraphQLError("At least one column to group by is required!");
3523
+ throw new import_graphql6.GraphQLError("At least one column to group by is required!");
3249
3524
  }
3250
3525
  const keyColumns = requestedKeys.map((columnName) => {
3251
3526
  const groupableColumn = groupable[columnName];
3252
3527
  if (!groupableColumn) {
3253
- throw new import_graphql5.GraphQLError(`Cannot group ${typeName} by ${columnName}!`);
3528
+ throw new import_graphql6.GraphQLError(`Cannot group ${typeName} by ${columnName}!`);
3254
3529
  }
3255
3530
  return [columnName, groupableColumn.column];
3256
3531
  });
@@ -3372,7 +3647,7 @@ var generateSelectSingle = (db, tableName, tables, relationMap, orderArgs, filte
3372
3647
  var generateInsertArray = (db, _tableName, table, baseType, fieldName, txCtx) => {
3373
3648
  const queryArgs = {
3374
3649
  values: {
3375
- type: new import_graphql6.GraphQLNonNull(new import_graphql6.GraphQLList(new import_graphql6.GraphQLNonNull(baseType)))
3650
+ type: new import_graphql7.GraphQLNonNull(new import_graphql7.GraphQLList(new import_graphql7.GraphQLNonNull(baseType)))
3376
3651
  }
3377
3652
  };
3378
3653
  return {
@@ -3382,7 +3657,7 @@ var generateInsertArray = (db, _tableName, table, baseType, fieldName, txCtx) =>
3382
3657
  return await runMutation(db, context, info, txCtx, async (executor) => {
3383
3658
  const input = remapFromGraphQLArrayInput(args.values, table);
3384
3659
  if (!input.length) {
3385
- throw new import_graphql6.GraphQLError("No values were provided!");
3660
+ throw new import_graphql7.GraphQLError("No values were provided!");
3386
3661
  }
3387
3662
  await executor.insert(table).values(input);
3388
3663
  return { isSuccess: true };
@@ -3397,7 +3672,7 @@ var generateInsertArray = (db, _tableName, table, baseType, fieldName, txCtx) =>
3397
3672
  var generateInsertSingle = (db, _tableName, table, baseType, fieldName, txCtx) => {
3398
3673
  const queryArgs = {
3399
3674
  values: {
3400
- type: new import_graphql6.GraphQLNonNull(baseType)
3675
+ type: new import_graphql7.GraphQLNonNull(baseType)
3401
3676
  }
3402
3677
  };
3403
3678
  return {
@@ -3419,7 +3694,7 @@ var generateInsertSingle = (db, _tableName, table, baseType, fieldName, txCtx) =
3419
3694
  var generateUpsert = (db, table, baseType, onConflictType, fieldName, single, txCtx) => {
3420
3695
  const queryArgs = {
3421
3696
  values: {
3422
- type: single ? new import_graphql6.GraphQLNonNull(baseType) : new import_graphql6.GraphQLNonNull(new import_graphql6.GraphQLList(new import_graphql6.GraphQLNonNull(baseType)))
3697
+ type: single ? new import_graphql7.GraphQLNonNull(baseType) : new import_graphql7.GraphQLNonNull(new import_graphql7.GraphQLList(new import_graphql7.GraphQLNonNull(baseType)))
3423
3698
  },
3424
3699
  onConflict: {
3425
3700
  type: onConflictType,
@@ -3434,7 +3709,7 @@ var generateUpsert = (db, table, baseType, onConflictType, fieldName, single, tx
3434
3709
  return await runMutation(db, context, info, txCtx, async (executor) => {
3435
3710
  const input = single ? [remapFromGraphQLSingleInput(args.values, table)] : remapFromGraphQLArrayInput(args.values, table);
3436
3711
  if (!input.length) {
3437
- throw new import_graphql6.GraphQLError("No values were provided!");
3712
+ throw new import_graphql7.GraphQLError("No values were provided!");
3438
3713
  }
3439
3714
  const plan = resolveConflictPlan({
3440
3715
  table,
@@ -3462,10 +3737,10 @@ var generateUpsert = (db, table, baseType, onConflictType, fieldName, single, tx
3462
3737
  var generateUpdate = (db, tableName, table, setArgs, filterArgs, fieldName, single, requireWhere, filterCtx, txCtx) => {
3463
3738
  const queryArgs = {
3464
3739
  set: {
3465
- type: new import_graphql6.GraphQLNonNull(setArgs)
3740
+ type: new import_graphql7.GraphQLNonNull(setArgs)
3466
3741
  },
3467
3742
  where: {
3468
- type: single || requireWhere ? new import_graphql6.GraphQLNonNull(filterArgs) : filterArgs
3743
+ type: single || requireWhere ? new import_graphql7.GraphQLNonNull(filterArgs) : filterArgs
3469
3744
  }
3470
3745
  };
3471
3746
  return {
@@ -3474,9 +3749,9 @@ var generateUpdate = (db, tableName, table, setArgs, filterArgs, fieldName, sing
3474
3749
  try {
3475
3750
  return await runMutation(db, context, info, txCtx, async (executor) => {
3476
3751
  const { where, set } = args;
3477
- const input = remapFromGraphQLSingleInput(set, table);
3752
+ const input = remapUpdateInput(set, table, tableName);
3478
3753
  if (!Object.keys(input).length) {
3479
- throw new import_graphql6.GraphQLError("Unable to update with no values specified!");
3754
+ throw new import_graphql7.GraphQLError("Unable to update with no values specified!");
3480
3755
  }
3481
3756
  const relationCtx = relationFilterCtx(filterCtx, tableName);
3482
3757
  const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
@@ -3500,7 +3775,7 @@ var generateUpdate = (db, tableName, table, setArgs, filterArgs, fieldName, sing
3500
3775
  var generateUpdateMany = (db, tableName, table, updateManyInput, fieldName, filterCtx, txCtx) => {
3501
3776
  const queryArgs = {
3502
3777
  updates: {
3503
- type: new import_graphql6.GraphQLNonNull(new import_graphql6.GraphQLList(new import_graphql6.GraphQLNonNull(updateManyInput)))
3778
+ type: new import_graphql7.GraphQLNonNull(new import_graphql7.GraphQLList(new import_graphql7.GraphQLNonNull(updateManyInput)))
3504
3779
  }
3505
3780
  };
3506
3781
  return {
@@ -3510,12 +3785,12 @@ var generateUpdateMany = (db, tableName, table, updateManyInput, fieldName, filt
3510
3785
  return await runMutation(db, context, info, txCtx, async (executor) => {
3511
3786
  const { updates } = args;
3512
3787
  if (!updates.length) {
3513
- throw new import_graphql6.GraphQLError("No updates were provided!");
3788
+ throw new import_graphql7.GraphQLError("No updates were provided!");
3514
3789
  }
3515
3790
  const entries = updates.map(({ where, set }) => {
3516
- const input = remapFromGraphQLSingleInput(set, table);
3791
+ const input = remapUpdateInput(set, table, tableName);
3517
3792
  if (!Object.keys(input).length) {
3518
- throw new import_graphql6.GraphQLError("Unable to update with no values specified!");
3793
+ throw new import_graphql7.GraphQLError("Unable to update with no values specified!");
3519
3794
  }
3520
3795
  return {
3521
3796
  set: input,
@@ -3543,7 +3818,7 @@ var generateUpdateMany = (db, tableName, table, updateManyInput, fieldName, filt
3543
3818
  var generateDelete = (db, tableName, table, filterArgs, fieldName, single, requireWhere, filterCtx, txCtx) => {
3544
3819
  const queryArgs = {
3545
3820
  where: {
3546
- type: single || requireWhere ? new import_graphql6.GraphQLNonNull(filterArgs) : filterArgs
3821
+ type: single || requireWhere ? new import_graphql7.GraphQLNonNull(filterArgs) : filterArgs
3547
3822
  }
3548
3823
  };
3549
3824
  return {
@@ -3576,7 +3851,7 @@ var generateSchemaData = (db, schema, relations, options) => {
3576
3851
  const { relationsDepthLimit, prefixes, suffixes, typeNameMapper, shouldEagerLoad, features, complexity } = options;
3577
3852
  const rawSchema = schema;
3578
3853
  const schemaEntries = Object.entries(rawSchema);
3579
- const tableEntries = schemaEntries.filter(([_key, value]) => (0, import_drizzle_orm5.is)(value, import_mysql_core2.MySqlTable));
3854
+ const tableEntries = schemaEntries.filter(([_key, value]) => (0, import_drizzle_orm6.is)(value, import_mysql_core2.MySqlTable));
3580
3855
  const tables = Object.fromEntries(tableEntries);
3581
3856
  if (!tableEntries.length) {
3582
3857
  throw new Error(
@@ -3594,7 +3869,12 @@ var generateSchemaData = (db, schema, relations, options) => {
3594
3869
  attachTargetPrimaryKeys(namedRelations, tables, mysqlPrimaryKeyPropNames);
3595
3870
  const eagerRelations = pruneNonEagerRelations(namedRelations, shouldEagerLoad);
3596
3871
  const filterCtx = { tables, relationMap: namedRelations };
3597
- const resolverFactory = createRelationResolverFactory(db, tables, filterCtx);
3872
+ const resolverFactory = createRelationResolverFactory(
3873
+ db,
3874
+ tables,
3875
+ "nulls-smallest",
3876
+ filterCtx
3877
+ );
3598
3878
  const cacheCtx = {
3599
3879
  genericFilterCache: /* @__PURE__ */ new Map(),
3600
3880
  objectTypeCache: /* @__PURE__ */ new Map(),
@@ -3608,7 +3888,8 @@ var generateSchemaData = (db, schema, relations, options) => {
3608
3888
  listRelationFilterCache: /* @__PURE__ */ new Map(),
3609
3889
  aggregateTypeCache: /* @__PURE__ */ new Map(),
3610
3890
  complexity,
3611
- docs: options.docs ?? {}
3891
+ docs: options.docs ?? {},
3892
+ features
3612
3893
  };
3613
3894
  const relationAggregateFactory = features.relationAggregates ? createRelationAggregateFactory(db, tables, cacheCtx, typeNameMapper, filterCtx) : void 0;
3614
3895
  const queries = {};
@@ -3632,11 +3913,11 @@ var generateSchemaData = (db, schema, relations, options) => {
3632
3913
  )
3633
3914
  ])
3634
3915
  );
3635
- const mutationReturnType = new import_graphql6.GraphQLObjectType({
3916
+ const mutationReturnType = new import_graphql7.GraphQLObjectType({
3636
3917
  name: "MutationReturn",
3637
3918
  fields: {
3638
3919
  isSuccess: {
3639
- type: new import_graphql6.GraphQLNonNull(import_graphql6.GraphQLBoolean)
3920
+ type: new import_graphql7.GraphQLNonNull(import_graphql7.GraphQLBoolean)
3640
3921
  }
3641
3922
  }
3642
3923
  });
@@ -3661,8 +3942,10 @@ var generateSchemaData = (db, schema, relations, options) => {
3661
3942
  updateFieldName,
3662
3943
  updateManyFieldName,
3663
3944
  updateSingleFieldName,
3945
+ updateCountFieldName,
3664
3946
  deleteFieldName,
3665
- deleteSingleFieldName
3947
+ deleteSingleFieldName,
3948
+ deleteCountFieldName
3666
3949
  } = computeResolverFieldNames(tableName, typeNameMapper, prefixes, suffixes);
3667
3950
  const selectArrGenerated = generateSelectArray(
3668
3951
  db,
@@ -3786,6 +4069,29 @@ var generateSchemaData = (db, schema, relations, options) => {
3786
4069
  filterCtx,
3787
4070
  mutationTxCtx
3788
4071
  ) : void 0;
4072
+ const updateCountGenerated = features.update && features.countMutations ? generateWriteCount({
4073
+ db,
4074
+ tableName,
4075
+ table: schema[tableName],
4076
+ kind: "update",
4077
+ setArgs: updateInput,
4078
+ filterArgs: tableFilters,
4079
+ fieldName: updateCountFieldName,
4080
+ requireWhere: features.requireWhere,
4081
+ filterCtx,
4082
+ txCtx: mutationTxCtx
4083
+ }) : void 0;
4084
+ const deleteCountGenerated = features.delete && features.countMutations ? generateWriteCount({
4085
+ db,
4086
+ tableName,
4087
+ table: schema[tableName],
4088
+ kind: "delete",
4089
+ filterArgs: tableFilters,
4090
+ fieldName: deleteCountFieldName,
4091
+ requireWhere: features.requireWhere,
4092
+ filterCtx,
4093
+ txCtx: mutationTxCtx
4094
+ }) : void 0;
3789
4095
  const aggregateType = features.aggregates ? generateAggregateTypes(schema[tableName], tableName, typeName, cacheCtx) : void 0;
3790
4096
  const aggregateGenerated = features.aggregates ? generateAggregate(
3791
4097
  db,
@@ -3823,7 +4129,7 @@ var generateSchemaData = (db, schema, relations, options) => {
3823
4129
  };
3824
4130
  if (aggregateGenerated && aggregateType) {
3825
4131
  queries[aggregateGenerated.name] = {
3826
- type: new import_graphql6.GraphQLNonNull(aggregateType),
4132
+ type: new import_graphql7.GraphQLNonNull(aggregateType),
3827
4133
  args: aggregateGenerated.args,
3828
4134
  resolve: aggregateGenerated.resolver,
3829
4135
  ...complexity ? { extensions: { complexity: aggregateFieldComplexity(complexity) } } : {}
@@ -3831,7 +4137,7 @@ var generateSchemaData = (db, schema, relations, options) => {
3831
4137
  }
3832
4138
  if (groupByGenerated && groupByType) {
3833
4139
  queries[groupByGenerated.name] = {
3834
- type: new import_graphql6.GraphQLNonNull(new import_graphql6.GraphQLList(new import_graphql6.GraphQLNonNull(groupByType))),
4140
+ type: new import_graphql7.GraphQLNonNull(new import_graphql7.GraphQLList(new import_graphql7.GraphQLNonNull(groupByType))),
3835
4141
  args: groupByGenerated.args,
3836
4142
  resolve: groupByGenerated.resolver,
3837
4143
  ...complexity ? { extensions: { complexity: aggregateFieldComplexity(complexity) } } : {}
@@ -3856,6 +4162,22 @@ var generateSchemaData = (db, schema, relations, options) => {
3856
4162
  };
3857
4163
  }
3858
4164
  }
4165
+ if (updateCountGenerated) {
4166
+ mutations[updateCountGenerated.name] = {
4167
+ type: new import_graphql7.GraphQLNonNull(import_graphql7.GraphQLInt),
4168
+ args: updateCountGenerated.args,
4169
+ resolve: updateCountGenerated.resolver,
4170
+ description: "How many rows the update touched. The rows themselves are not read back, which is the point of this mutation."
4171
+ };
4172
+ }
4173
+ if (deleteCountGenerated) {
4174
+ mutations[deleteCountGenerated.name] = {
4175
+ type: new import_graphql7.GraphQLNonNull(import_graphql7.GraphQLInt),
4176
+ args: deleteCountGenerated.args,
4177
+ resolve: deleteCountGenerated.resolver,
4178
+ description: "How many rows the delete removed. The rows themselves are not read back, which is the point of this mutation."
4179
+ };
4180
+ }
3859
4181
  const activeInputs = [
3860
4182
  // The insert input types the upsert mutations too, so either feature keeps it.
3861
4183
  ...features.insert || onConflictInput ? [insertInput] : [],
@@ -3886,7 +4208,7 @@ var generateSchemaData = (db, schema, relations, options) => {
3886
4208
  for (const [tableName, tableRelations] of Object.entries(namedRelations)) {
3887
4209
  const relResolvers = {};
3888
4210
  for (const [relName, relEntry] of Object.entries(tableRelations)) {
3889
- const isOne = (0, import_drizzle_orm5.is)(relEntry.relation ?? relEntry, import_drizzle_orm5.One);
4211
+ const isOne = (0, import_drizzle_orm6.is)(relEntry.relation ?? relEntry, import_drizzle_orm6.One);
3890
4212
  const resolver = resolverFactory({ tableName, relationName: relName, relEntry, isOne });
3891
4213
  if (resolver) {
3892
4214
  relResolvers[relName] = resolver;
@@ -3900,14 +4222,14 @@ var generateSchemaData = (db, schema, relations, options) => {
3900
4222
  };
3901
4223
 
3902
4224
  // src/util/builders/pg.ts
3903
- var import_drizzle_orm7 = require("drizzle-orm");
4225
+ var import_drizzle_orm8 = require("drizzle-orm");
3904
4226
  var import_pg_core2 = require("drizzle-orm/pg-core");
3905
- var import_graphql8 = require("graphql");
4227
+ var import_graphql9 = require("graphql");
3906
4228
  var import_graphql_parse_resolve_info3 = require("graphql-parse-resolve-info");
3907
4229
 
3908
4230
  // src/util/builders/nested-writes.ts
3909
- var import_drizzle_orm6 = require("drizzle-orm");
3910
- var import_graphql7 = require("graphql");
4231
+ var import_drizzle_orm7 = require("drizzle-orm");
4232
+ var import_graphql8 = require("graphql");
3911
4233
  var isOptionalOnInsert = (column) => !column.notNull || !!column.hasDefault || !!column.defaultFn;
3912
4234
  var buildNestedWritePlans = (tables, relationMap, resolveUniqueSets, resolvePrimaryKeys, extractJoinColumns) => {
3913
4235
  const uniqueCache = /* @__PURE__ */ new Map();
@@ -3951,11 +4273,11 @@ var buildNestedWritePlans = (tables, relationMap, resolveUniqueSets, resolvePrim
3951
4273
  continue;
3952
4274
  }
3953
4275
  const { localColPropName, foreignCol, foreignColPropName } = joinColumns;
3954
- const localCol = (0, import_drizzle_orm6.getColumns)(table)[localColPropName];
4276
+ const localCol = (0, import_drizzle_orm7.getColumns)(table)[localColPropName];
3955
4277
  if (!localCol) {
3956
4278
  continue;
3957
4279
  }
3958
- const isOne = (0, import_drizzle_orm6.is)(relation, import_drizzle_orm6.One);
4280
+ const isOne = (0, import_drizzle_orm7.is)(relation, import_drizzle_orm7.One);
3959
4281
  const localIsPk = singleColumnPk(tableName, table) === localColPropName;
3960
4282
  const foreignIsPk = singleColumnPk(targetTableName, targetTable) === foreignColPropName;
3961
4283
  const localIsUnique = singleColumnUniques(tableName, table).has(localColPropName);
@@ -4007,12 +4329,12 @@ var createNestedWriteTypes = (params) => {
4007
4329
  }
4008
4330
  const omitted = plan.fkSide === "child" ? plan.foreignColPropName : void 0;
4009
4331
  const fields = Object.fromEntries(
4010
- Object.entries((0, import_drizzle_orm6.getColumns)(plan.targetTable)).filter(([columnName]) => columnName !== omitted).map(([columnName, column]) => [
4332
+ Object.entries((0, import_drizzle_orm7.getColumns)(plan.targetTable)).filter(([columnName]) => columnName !== omitted).map(([columnName, column]) => [
4011
4333
  columnName,
4012
4334
  drizzleColumnToGraphQLType(column, columnName, plan.targetTableName, false, true, true)
4013
4335
  ])
4014
4336
  );
4015
- const type = new import_graphql7.GraphQLInputObjectType({
4337
+ const type = new import_graphql8.GraphQLInputObjectType({
4016
4338
  name: `${capitalize(insertPrefix)}${typeName}${capitalize(plan.relationName)}Input`,
4017
4339
  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
4340
  fields
@@ -4021,7 +4343,7 @@ var createNestedWriteTypes = (params) => {
4021
4343
  return type;
4022
4344
  };
4023
4345
  const targetFilters = (plan) => cacheCtx.filterTypeCache.get(plan.targetTable);
4024
- const listOf = (type) => new import_graphql7.GraphQLList(new import_graphql7.GraphQLNonNull(type));
4346
+ const listOf = (type) => new import_graphql8.GraphQLList(new import_graphql8.GraphQLNonNull(type));
4025
4347
  const wrapperType = (tableName, typeName, plan, forUpdate) => {
4026
4348
  const key = `${tableName}.${plan.relationName}.${forUpdate ? "update" : "create"}`;
4027
4349
  const cached = wrapperCache.get(key);
@@ -4042,7 +4364,7 @@ var createNestedWriteTypes = (params) => {
4042
4364
  }
4043
4365
  if (forUpdate && plan.canDetach) {
4044
4366
  fields["disconnect"] = {
4045
- type: import_graphql7.GraphQLBoolean,
4367
+ type: import_graphql8.GraphQLBoolean,
4046
4368
  description: `Detach the currently attached ${targetTypeName} row, leaving it in place`
4047
4369
  };
4048
4370
  }
@@ -4065,7 +4387,7 @@ var createNestedWriteTypes = (params) => {
4065
4387
  }
4066
4388
  }
4067
4389
  }
4068
- const type = new import_graphql7.GraphQLInputObjectType({
4390
+ const type = new import_graphql8.GraphQLInputObjectType({
4069
4391
  name: `${typeName}${capitalize(plan.relationName)}Nested${forUpdate ? "Update" : "Create"}Input`,
4070
4392
  description: `Writes through ${typeName}.${plan.relationName}`,
4071
4393
  fields
@@ -4115,7 +4437,7 @@ var createNestedWriteRuntime = (params) => {
4115
4437
  relationFilterCtx(filterCtx, plan.targetTableName)
4116
4438
  );
4117
4439
  if (!condition) {
4118
- throw new import_graphql7.GraphQLError(
4440
+ throw new import_graphql8.GraphQLError(
4119
4441
  `Drizzle-GraphQL Error: '${operation}' on '${plan.relationName}' needs a filter that selects rows \u2014 it was given one that matches everything.`
4120
4442
  );
4121
4443
  }
@@ -4124,12 +4446,12 @@ var createNestedWriteRuntime = (params) => {
4124
4446
  const assertSingleOperation = (plan, op) => {
4125
4447
  const supplied = ["create", "connect", "disconnect"].filter((key) => op[key] !== void 0 && op[key] !== null);
4126
4448
  if (supplied.length > 1) {
4127
- throw new import_graphql7.GraphQLError(
4449
+ throw new import_graphql8.GraphQLError(
4128
4450
  `Drizzle-GraphQL Error: '${plan.relationName}' takes one of ${supplied.join(", ")} at a time \u2014 it holds a single row.`
4129
4451
  );
4130
4452
  }
4131
4453
  };
4132
- const detachAll = async (executor, plan, key) => executor.update(plan.targetTable).set({ [plan.foreignColPropName]: null }).where((0, import_drizzle_orm6.eq)(plan.foreignCol, key));
4454
+ const detachAll = async (executor, plan, key) => executor.update(plan.targetTable).set({ [plan.foreignColPropName]: null }).where((0, import_drizzle_orm7.eq)(plan.foreignCol, key));
4133
4455
  return {
4134
4456
  enabled: (tableName) => !!plans[tableName],
4135
4457
  split: (tableName, values) => {
@@ -4154,7 +4476,7 @@ var createNestedWriteRuntime = (params) => {
4154
4476
  if (!tablePlans) {
4155
4477
  return columns;
4156
4478
  }
4157
- const allColumns = (0, import_drizzle_orm6.getColumns)(table);
4479
+ const allColumns = (0, import_drizzle_orm7.getColumns)(table);
4158
4480
  for (const relationName of Object.keys(ops)) {
4159
4481
  const plan = tablePlans[relationName];
4160
4482
  if (plan?.fkSide === "child" && !(plan.localColPropName in columns) && allColumns[plan.localColPropName]) {
@@ -4180,7 +4502,7 @@ var createNestedWriteRuntime = (params) => {
4180
4502
  const inserted = await executor.insert(plan.targetTable).values(values).returning();
4181
4503
  const created = inserted[0];
4182
4504
  if (!created) {
4183
- throw new import_graphql7.GraphQLError(
4505
+ throw new import_graphql8.GraphQLError(
4184
4506
  `Drizzle-GraphQL Error: 'create' on '${relationName}' inserted no row, so there is nothing to attach.`
4185
4507
  );
4186
4508
  }
@@ -4188,7 +4510,7 @@ var createNestedWriteRuntime = (params) => {
4188
4510
  } else if (op["connect"] !== void 0) {
4189
4511
  const rows = await executor.select().from(plan.targetTable).where(conditionOf(plan, op["connect"], "connect"));
4190
4512
  if (rows.length !== 1) {
4191
- throw new import_graphql7.GraphQLError(
4513
+ throw new import_graphql8.GraphQLError(
4192
4514
  `Drizzle-GraphQL Error: 'connect' on '${relationName}' matched ${rows.length} rows \u2014 it attaches a single row, so its filter must match exactly one.`
4193
4515
  );
4194
4516
  }
@@ -4215,7 +4537,7 @@ var createNestedWriteRuntime = (params) => {
4215
4537
  for (const parentRow of parentRows) {
4216
4538
  const key = parentRow?.[plan.localColPropName];
4217
4539
  if (key === void 0 || key === null) {
4218
- throw new import_graphql7.GraphQLError(
4540
+ throw new import_graphql8.GraphQLError(
4219
4541
  `Drizzle-GraphQL Error: cannot write through '${relationName}': the ${tableName} row has no '${plan.localColPropName}' value to attach to.`
4220
4542
  );
4221
4543
  }
@@ -4232,7 +4554,7 @@ var createNestedWriteRuntime = (params) => {
4232
4554
  }
4233
4555
  } else {
4234
4556
  for (const filter of asArray(op["disconnect"])) {
4235
- await executor.update(plan.targetTable).set({ [plan.foreignColPropName]: null }).where((0, import_drizzle_orm6.and)((0, import_drizzle_orm6.eq)(plan.foreignCol, key), conditionOf(plan, filter, "disconnect")));
4557
+ 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
4558
  }
4237
4559
  }
4238
4560
  }
@@ -4327,24 +4649,24 @@ var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filte
4327
4649
  let cursorEntries;
4328
4650
  if (after != null || cursorSelected) {
4329
4651
  if (after != null && distinct?.length) {
4330
- throw new import_graphql8.GraphQLError("'after' cannot be combined with 'distinct'.");
4652
+ throw new import_graphql9.GraphQLError("'after' cannot be combined with 'distinct'.");
4331
4653
  }
4332
4654
  if (orderByHasRelationEntry(orderBy)) {
4333
4655
  if (after != null) {
4334
- throw new import_graphql8.GraphQLError(
4656
+ throw new import_graphql9.GraphQLError(
4335
4657
  "'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
4658
  );
4337
4659
  }
4338
4660
  } else if (!pkNames.length) {
4339
4661
  if (after != null) {
4340
- throw new import_graphql8.GraphQLError(
4662
+ throw new import_graphql9.GraphQLError(
4341
4663
  `Table ${tableName} has no primary key, so cursor pagination cannot be used on it.`
4342
4664
  );
4343
4665
  }
4344
4666
  } else {
4345
4667
  cursorEntries = cursorOrderingEntries(orderBy, pkNames);
4346
4668
  if (cursorSelected) {
4347
- const allColumns = (0, import_drizzle_orm7.getColumns)(table);
4669
+ const allColumns = (0, import_drizzle_orm8.getColumns)(table);
4348
4670
  for (const [column] of cursorEntries) {
4349
4671
  selectedColumnsSql[column] ??= allColumns[column];
4350
4672
  }
@@ -4353,7 +4675,7 @@ var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filte
4353
4675
  }
4354
4676
  const cursorCondition = after != null && cursorEntries ? buildCursorCondition(table, cursorEntries, decodeCursor(after, cursorEntries), "nulls-largest") : void 0;
4355
4677
  const baseWhereSql = where ? extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName)) : void 0;
4356
- const whereSql = cursorCondition ? (0, import_drizzle_orm7.and)(baseWhereSql, cursorCondition) : baseWhereSql;
4678
+ const whereSql = cursorCondition ? (0, import_drizzle_orm8.and)(baseWhereSql, cursorCondition) : baseWhereSql;
4357
4679
  let distinctKeys;
4358
4680
  if (distinct?.length) {
4359
4681
  distinctKeys = await selectDistinctKeys({
@@ -4467,7 +4789,7 @@ var pgPrimaryKeyPropNames = (table) => getPrimaryKeyPropNamesFromConfig(table, i
4467
4789
  var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested) => {
4468
4790
  const queryArgs = {
4469
4791
  values: {
4470
- type: new import_graphql8.GraphQLNonNull(new import_graphql8.GraphQLList(new import_graphql8.GraphQLNonNull(baseType)))
4792
+ type: new import_graphql9.GraphQLNonNull(new import_graphql9.GraphQLList(new import_graphql9.GraphQLNonNull(baseType)))
4471
4793
  }
4472
4794
  };
4473
4795
  const pkNames = pgPrimaryKeyPropNames(table);
@@ -4477,7 +4799,7 @@ var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType,
4477
4799
  try {
4478
4800
  return await runMutation(db, context, info, txCtx, async (executor) => {
4479
4801
  if (!args.values.length) {
4480
- throw new import_graphql8.GraphQLError("No values were provided!");
4802
+ throw new import_graphql9.GraphQLError("No values were provided!");
4481
4803
  }
4482
4804
  const entries = nested?.enabled(tableName) ? args.values.map((values) => nested.split(tableName, values)) : void 0;
4483
4805
  const nestedEntries = entries?.some((entry) => nested.hasOps(entry.ops)) ? entries : void 0;
@@ -4524,7 +4846,7 @@ var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType,
4524
4846
  var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested) => {
4525
4847
  const queryArgs = {
4526
4848
  values: {
4527
- type: new import_graphql8.GraphQLNonNull(baseType)
4849
+ type: new import_graphql9.GraphQLNonNull(baseType)
4528
4850
  }
4529
4851
  };
4530
4852
  const pkNames = pgPrimaryKeyPropNames(table);
@@ -4566,6 +4888,9 @@ var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType
4566
4888
  write: runInsert
4567
4889
  }) : await runInsert(executor, input);
4568
4890
  if (!result[0]) {
4891
+ if (!conflictDoNothing) {
4892
+ throw new import_graphql9.GraphQLError(`${fieldName}: the insert returned no row.`);
4893
+ }
4569
4894
  return void 0;
4570
4895
  }
4571
4896
  const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
@@ -4581,7 +4906,7 @@ var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType
4581
4906
  var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx, txCtx, nested) => {
4582
4907
  const queryArgs = {
4583
4908
  values: {
4584
- type: single ? new import_graphql8.GraphQLNonNull(baseType) : new import_graphql8.GraphQLNonNull(new import_graphql8.GraphQLList(new import_graphql8.GraphQLNonNull(baseType)))
4909
+ type: single ? new import_graphql9.GraphQLNonNull(baseType) : new import_graphql9.GraphQLNonNull(new import_graphql9.GraphQLList(new import_graphql9.GraphQLNonNull(baseType)))
4585
4910
  },
4586
4911
  onConflict: {
4587
4912
  type: onConflictType,
@@ -4596,7 +4921,7 @@ var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onCo
4596
4921
  return await runMutation(db, context, info, txCtx, async (executor) => {
4597
4922
  const supplied = single ? [args.values] : args.values;
4598
4923
  if (!supplied.length) {
4599
- throw new import_graphql8.GraphQLError("No values were provided!");
4924
+ throw new import_graphql9.GraphQLError("No values were provided!");
4600
4925
  }
4601
4926
  const entries = nested?.enabled(tableName) ? supplied.map((values) => nested.split(tableName, values)) : void 0;
4602
4927
  const nestedEntries = entries?.some((entry) => nested.hasOps(entry.ops)) ? entries : void 0;
@@ -4652,10 +4977,10 @@ var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onCo
4652
4977
  var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx, txCtx, nested) => {
4653
4978
  const queryArgs = {
4654
4979
  set: {
4655
- type: new import_graphql8.GraphQLNonNull(setArgs)
4980
+ type: new import_graphql9.GraphQLNonNull(setArgs)
4656
4981
  },
4657
4982
  where: {
4658
- type: single || requireWhere ? new import_graphql8.GraphQLNonNull(filterArgs) : filterArgs
4983
+ type: single || requireWhere ? new import_graphql9.GraphQLNonNull(filterArgs) : filterArgs
4659
4984
  }
4660
4985
  };
4661
4986
  const pkNames = pgPrimaryKeyPropNames(table);
@@ -4680,9 +5005,9 @@ var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filte
4680
5005
  });
4681
5006
  const entry = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
4682
5007
  const nestedOps = entry && nested.hasOps(entry.ops) ? entry.ops : void 0;
4683
- const input = remapFromGraphQLSingleInput(entry ? entry.columns : set, table);
5008
+ const input = remapUpdateInput(entry ? entry.columns : set, table, tableName);
4684
5009
  if (!Object.keys(input).length && !nestedOps) {
4685
- throw new import_graphql8.GraphQLError("Unable to update with no values specified!");
5010
+ throw new import_graphql9.GraphQLError("Unable to update with no values specified!");
4686
5011
  }
4687
5012
  const relationCtx = relationFilterCtx(filterCtx, tableName);
4688
5013
  const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
@@ -4708,7 +5033,7 @@ var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filte
4708
5033
  write: runUpdate
4709
5034
  }) : await runUpdate(executor, input);
4710
5035
  if (single && result.length > 1) {
4711
- throw new import_graphql8.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
5036
+ throw new import_graphql9.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
4712
5037
  }
4713
5038
  if (single && !result[0]) {
4714
5039
  return void 0;
@@ -4726,7 +5051,7 @@ var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filte
4726
5051
  var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx, txCtx, nested) => {
4727
5052
  const queryArgs = {
4728
5053
  updates: {
4729
- type: new import_graphql8.GraphQLNonNull(new import_graphql8.GraphQLList(new import_graphql8.GraphQLNonNull(updateManyInput)))
5054
+ type: new import_graphql9.GraphQLNonNull(new import_graphql9.GraphQLList(new import_graphql9.GraphQLNonNull(updateManyInput)))
4730
5055
  }
4731
5056
  };
4732
5057
  const pkNames = pgPrimaryKeyPropNames(table);
@@ -4737,7 +5062,7 @@ var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateMany
4737
5062
  return await runMutation(db, context, info, txCtx, async (executor) => {
4738
5063
  const { updates } = args;
4739
5064
  if (!updates.length) {
4740
- throw new import_graphql8.GraphQLError("No updates were provided!");
5065
+ throw new import_graphql9.GraphQLError("No updates were provided!");
4741
5066
  }
4742
5067
  const parsedInfo = (0, import_graphql_parse_resolve_info3.parseResolveInfo)(info, {
4743
5068
  deep: true
@@ -4755,9 +5080,9 @@ var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateMany
4755
5080
  const entries = updates.map(({ where, set }) => {
4756
5081
  const split = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
4757
5082
  const ops = split && nested.hasOps(split.ops) ? split.ops : void 0;
4758
- const input = remapFromGraphQLSingleInput(split ? split.columns : set, table);
5083
+ const input = remapUpdateInput(split ? split.columns : set, table, tableName);
4759
5084
  if (!Object.keys(input).length && !ops) {
4760
- throw new import_graphql8.GraphQLError("Unable to update with no values specified!");
5085
+ throw new import_graphql9.GraphQLError("Unable to update with no values specified!");
4761
5086
  }
4762
5087
  return {
4763
5088
  set: input,
@@ -4816,7 +5141,7 @@ var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateMany
4816
5141
  var generateDelete2 = (db, tableName, table, filterArgs, fieldName, typeName, single, requireWhere, filterCtx, selectionCtx, txCtx) => {
4817
5142
  const queryArgs = {
4818
5143
  where: {
4819
- type: single || requireWhere ? new import_graphql8.GraphQLNonNull(filterArgs) : filterArgs
5144
+ type: single || requireWhere ? new import_graphql9.GraphQLNonNull(filterArgs) : filterArgs
4820
5145
  }
4821
5146
  };
4822
5147
  return {
@@ -4845,7 +5170,7 @@ var generateDelete2 = (db, tableName, table, filterArgs, fieldName, typeName, si
4845
5170
  query = query.returning(columns);
4846
5171
  const result = await query;
4847
5172
  if (single && result.length > 1) {
4848
- throw new import_graphql8.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
5173
+ throw new import_graphql9.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
4849
5174
  }
4850
5175
  if (single) {
4851
5176
  return result[0] ? remapToGraphQLSingleOutput(result[0], tableName, table) : void 0;
@@ -4871,7 +5196,7 @@ function generateSchemaData2(db, schema, relations, options) {
4871
5196
  complexity
4872
5197
  } = options;
4873
5198
  const schemaEntries = Object.entries(schema);
4874
- const tableEntries = schemaEntries.filter(([_key, value]) => (0, import_drizzle_orm7.is)(value, import_pg_core2.PgTable));
5199
+ const tableEntries = schemaEntries.filter(([_key, value]) => (0, import_drizzle_orm8.is)(value, import_pg_core2.PgTable));
4875
5200
  const tables = Object.fromEntries(tableEntries);
4876
5201
  if (!tableEntries.length) {
4877
5202
  throw new Error(
@@ -4884,7 +5209,12 @@ function generateSchemaData2(db, schema, relations, options) {
4884
5209
  attachTargetPrimaryKeys(namedRelations, tables, pgPrimaryKeyPropNames);
4885
5210
  const eagerRelations = pruneNonEagerRelations(namedRelations, shouldEagerLoad);
4886
5211
  const filterCtx = { tables, relationMap: namedRelations };
4887
- const resolverFactory = createRelationResolverFactory(db, tables, filterCtx);
5212
+ const resolverFactory = createRelationResolverFactory(
5213
+ db,
5214
+ tables,
5215
+ "nulls-largest",
5216
+ filterCtx
5217
+ );
4888
5218
  const cacheCtx = {
4889
5219
  genericFilterCache: /* @__PURE__ */ new Map(),
4890
5220
  objectTypeCache: /* @__PURE__ */ new Map(),
@@ -4898,7 +5228,8 @@ function generateSchemaData2(db, schema, relations, options) {
4898
5228
  listRelationFilterCache: /* @__PURE__ */ new Map(),
4899
5229
  aggregateTypeCache: /* @__PURE__ */ new Map(),
4900
5230
  complexity,
4901
- docs: options.docs ?? {}
5231
+ docs: options.docs ?? {},
5232
+ features
4902
5233
  };
4903
5234
  const nestedPlans = features.nestedWrites ? buildNestedWritePlans(
4904
5235
  tables,
@@ -4950,8 +5281,10 @@ function generateSchemaData2(db, schema, relations, options) {
4950
5281
  updateFieldName,
4951
5282
  updateManyFieldName,
4952
5283
  updateSingleFieldName,
5284
+ updateCountFieldName,
4953
5285
  deleteFieldName,
4954
- deleteSingleFieldName
5286
+ deleteSingleFieldName,
5287
+ deleteCountFieldName
4955
5288
  } = computeResolverFieldNames(tableName, typeNameMapper, prefixes, suffixes);
4956
5289
  const selectArrGenerated = generateSelectArray2(
4957
5290
  db,
@@ -5123,6 +5456,30 @@ function generateSchemaData2(db, schema, relations, options) {
5123
5456
  { tableName, relationMap: namedRelations, tables },
5124
5457
  mutationTxCtx
5125
5458
  ) : void 0;
5459
+ const updateCountGenerated = features.update && features.countMutations ? generateWriteCount({
5460
+ db,
5461
+ tableName,
5462
+ table: schema[tableName],
5463
+ kind: "update",
5464
+ setArgs: updateInput,
5465
+ filterArgs: tableFilters,
5466
+ fieldName: updateCountFieldName,
5467
+ requireWhere: features.requireWhere,
5468
+ filterCtx,
5469
+ txCtx: mutationTxCtx,
5470
+ nested: nestedRuntime
5471
+ }) : void 0;
5472
+ const deleteCountGenerated = features.delete && features.countMutations ? generateWriteCount({
5473
+ db,
5474
+ tableName,
5475
+ table: schema[tableName],
5476
+ kind: "delete",
5477
+ filterArgs: tableFilters,
5478
+ fieldName: deleteCountFieldName,
5479
+ requireWhere: features.requireWhere,
5480
+ filterCtx,
5481
+ txCtx: mutationTxCtx
5482
+ }) : void 0;
5126
5483
  const aggregateType = features.aggregates ? generateAggregateTypes(schema[tableName], tableName, typeName, cacheCtx) : void 0;
5127
5484
  const aggregateGenerated = features.aggregates ? generateAggregate(
5128
5485
  db,
@@ -5160,7 +5517,7 @@ function generateSchemaData2(db, schema, relations, options) {
5160
5517
  };
5161
5518
  if (aggregateGenerated && aggregateType) {
5162
5519
  queries[aggregateGenerated.name] = {
5163
- type: new import_graphql8.GraphQLNonNull(aggregateType),
5520
+ type: new import_graphql9.GraphQLNonNull(aggregateType),
5164
5521
  args: aggregateGenerated.args,
5165
5522
  resolve: aggregateGenerated.resolver,
5166
5523
  ...complexity ? { extensions: { complexity: aggregateFieldComplexity(complexity) } } : {}
@@ -5168,7 +5525,7 @@ function generateSchemaData2(db, schema, relations, options) {
5168
5525
  }
5169
5526
  if (groupByGenerated && groupByType) {
5170
5527
  queries[groupByGenerated.name] = {
5171
- type: new import_graphql8.GraphQLNonNull(new import_graphql8.GraphQLList(new import_graphql8.GraphQLNonNull(groupByType))),
5528
+ type: new import_graphql9.GraphQLNonNull(new import_graphql9.GraphQLList(new import_graphql9.GraphQLNonNull(groupByType))),
5172
5529
  args: groupByGenerated.args,
5173
5530
  resolve: groupByGenerated.resolver,
5174
5531
  ...complexity ? { extensions: { complexity: aggregateFieldComplexity(complexity) } } : {}
@@ -5183,7 +5540,9 @@ function generateSchemaData2(db, schema, relations, options) {
5183
5540
  }
5184
5541
  if (insertSingleGenerated) {
5185
5542
  mutations[insertSingleGenerated.name] = {
5186
- type: singleTableItemOutput,
5543
+ // An insert either returns the row it inserted or throws — the one path to `null` is
5544
+ // `conflictDoNothing` swallowing the insert, so the field is nullable only there.
5545
+ type: conflictDoNothing ? singleTableItemOutput : new import_graphql9.GraphQLNonNull(singleTableItemOutput),
5187
5546
  args: insertSingleGenerated.args,
5188
5547
  resolve: insertSingleGenerated.resolver
5189
5548
  };
@@ -5211,10 +5570,13 @@ function generateSchemaData2(db, schema, relations, options) {
5211
5570
  }
5212
5571
  if (updateManyGenerated) {
5213
5572
  mutations[updateManyGenerated.name] = {
5214
- // Nullable items: a no-match entry yields `null` in its slot.
5215
- type: new import_graphql8.GraphQLNonNull(new import_graphql8.GraphQLList(singleTableItemOutput)),
5573
+ type: new import_graphql9.GraphQLNonNull(new import_graphql9.GraphQLList(singleTableItemOutput)),
5216
5574
  args: updateManyGenerated.args,
5217
- resolve: updateManyGenerated.resolver
5575
+ resolve: updateManyGenerated.resolver,
5576
+ // The nullable element is deliberate, and the reason this mutation's return type
5577
+ // differs from every sibling's: the result is aligned with the input, one slot per
5578
+ // entry, so an entry that matched nothing has to be able to say so.
5579
+ 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
5580
  };
5219
5581
  }
5220
5582
  if (updateSingleGenerated) {
@@ -5238,6 +5600,22 @@ function generateSchemaData2(db, schema, relations, options) {
5238
5600
  resolve: deleteSingleGenerated.resolver
5239
5601
  };
5240
5602
  }
5603
+ if (updateCountGenerated) {
5604
+ mutations[updateCountGenerated.name] = {
5605
+ type: new import_graphql9.GraphQLNonNull(import_graphql9.GraphQLInt),
5606
+ args: updateCountGenerated.args,
5607
+ resolve: updateCountGenerated.resolver,
5608
+ description: "How many rows the update touched. The rows themselves are not read back, which is the point of this mutation."
5609
+ };
5610
+ }
5611
+ if (deleteCountGenerated) {
5612
+ mutations[deleteCountGenerated.name] = {
5613
+ type: new import_graphql9.GraphQLNonNull(import_graphql9.GraphQLInt),
5614
+ args: deleteCountGenerated.args,
5615
+ resolve: deleteCountGenerated.resolver,
5616
+ description: "How many rows the delete removed. The rows themselves are not read back, which is the point of this mutation."
5617
+ };
5618
+ }
5241
5619
  const activeInputs = [
5242
5620
  // The insert input types the upsert mutations too, so either feature keeps it.
5243
5621
  ...features.insert || onConflictInput ? [insertInput] : [],
@@ -5269,7 +5647,7 @@ function generateSchemaData2(db, schema, relations, options) {
5269
5647
  for (const [tableName, tableRelations] of Object.entries(namedRelations)) {
5270
5648
  const relResolvers = {};
5271
5649
  for (const [relName, relEntry] of Object.entries(tableRelations)) {
5272
- const isOne = (0, import_drizzle_orm7.is)(relEntry.relation ?? relEntry, import_drizzle_orm7.One);
5650
+ const isOne = (0, import_drizzle_orm8.is)(relEntry.relation ?? relEntry, import_drizzle_orm8.One);
5273
5651
  const resolver = resolverFactory({ tableName, relationName: relName, relEntry, isOne });
5274
5652
  if (resolver) {
5275
5653
  relResolvers[relName] = resolver;
@@ -5283,9 +5661,9 @@ function generateSchemaData2(db, schema, relations, options) {
5283
5661
  }
5284
5662
 
5285
5663
  // src/util/builders/sqlite.ts
5286
- var import_drizzle_orm8 = require("drizzle-orm");
5664
+ var import_drizzle_orm9 = require("drizzle-orm");
5287
5665
  var import_sqlite_core2 = require("drizzle-orm/sqlite-core");
5288
- var import_graphql9 = require("graphql");
5666
+ var import_graphql10 = require("graphql");
5289
5667
  var import_graphql_parse_resolve_info4 = require("graphql-parse-resolve-info");
5290
5668
  var generateSelectArray3 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, distinctEnabled = true) => {
5291
5669
  const queryBase = db.query[tableName];
@@ -5373,7 +5751,7 @@ var sqlitePrimaryKeyPropNames = (table) => getPrimaryKeyPropNamesFromConfig(tabl
5373
5751
  var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested) => {
5374
5752
  const queryArgs = {
5375
5753
  values: {
5376
- type: new import_graphql9.GraphQLNonNull(new import_graphql9.GraphQLList(new import_graphql9.GraphQLNonNull(baseType)))
5754
+ type: new import_graphql10.GraphQLNonNull(new import_graphql10.GraphQLList(new import_graphql10.GraphQLNonNull(baseType)))
5377
5755
  }
5378
5756
  };
5379
5757
  const pkNames = sqlitePrimaryKeyPropNames(table);
@@ -5383,7 +5761,7 @@ var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType,
5383
5761
  try {
5384
5762
  return await runMutation(db, context, info, txCtx, async (executor) => {
5385
5763
  if (!args.values.length) {
5386
- throw new import_graphql9.GraphQLError("No values were provided!");
5764
+ throw new import_graphql10.GraphQLError("No values were provided!");
5387
5765
  }
5388
5766
  const entries = nested?.enabled(tableName) ? args.values.map((values) => nested.split(tableName, values)) : void 0;
5389
5767
  const nestedEntries = entries?.some((entry) => nested.hasOps(entry.ops)) ? entries : void 0;
@@ -5430,7 +5808,7 @@ var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType,
5430
5808
  var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested) => {
5431
5809
  const queryArgs = {
5432
5810
  values: {
5433
- type: new import_graphql9.GraphQLNonNull(baseType)
5811
+ type: new import_graphql10.GraphQLNonNull(baseType)
5434
5812
  }
5435
5813
  };
5436
5814
  const pkNames = sqlitePrimaryKeyPropNames(table);
@@ -5472,6 +5850,9 @@ var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType
5472
5850
  write: runInsert
5473
5851
  }) : await runInsert(executor, input);
5474
5852
  if (!result[0]) {
5853
+ if (!conflictDoNothing) {
5854
+ throw new import_graphql10.GraphQLError(`${fieldName}: the insert returned no row.`);
5855
+ }
5475
5856
  return void 0;
5476
5857
  }
5477
5858
  const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
@@ -5487,7 +5868,7 @@ var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType
5487
5868
  var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx, txCtx, nested) => {
5488
5869
  const queryArgs = {
5489
5870
  values: {
5490
- type: single ? new import_graphql9.GraphQLNonNull(baseType) : new import_graphql9.GraphQLNonNull(new import_graphql9.GraphQLList(new import_graphql9.GraphQLNonNull(baseType)))
5871
+ type: single ? new import_graphql10.GraphQLNonNull(baseType) : new import_graphql10.GraphQLNonNull(new import_graphql10.GraphQLList(new import_graphql10.GraphQLNonNull(baseType)))
5491
5872
  },
5492
5873
  onConflict: {
5493
5874
  type: onConflictType,
@@ -5502,7 +5883,7 @@ var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onCo
5502
5883
  return await runMutation(db, context, info, txCtx, async (executor) => {
5503
5884
  const supplied = single ? [args.values] : args.values;
5504
5885
  if (!supplied.length) {
5505
- throw new import_graphql9.GraphQLError("No values were provided!");
5886
+ throw new import_graphql10.GraphQLError("No values were provided!");
5506
5887
  }
5507
5888
  const entries = nested?.enabled(tableName) ? supplied.map((values) => nested.split(tableName, values)) : void 0;
5508
5889
  const nestedEntries = entries?.some((entry) => nested.hasOps(entry.ops)) ? entries : void 0;
@@ -5558,10 +5939,10 @@ var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onCo
5558
5939
  var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx, txCtx, nested) => {
5559
5940
  const queryArgs = {
5560
5941
  set: {
5561
- type: new import_graphql9.GraphQLNonNull(setArgs)
5942
+ type: new import_graphql10.GraphQLNonNull(setArgs)
5562
5943
  },
5563
5944
  where: {
5564
- type: single || requireWhere ? new import_graphql9.GraphQLNonNull(filterArgs) : filterArgs
5945
+ type: single || requireWhere ? new import_graphql10.GraphQLNonNull(filterArgs) : filterArgs
5565
5946
  }
5566
5947
  };
5567
5948
  const pkNames = sqlitePrimaryKeyPropNames(table);
@@ -5586,9 +5967,9 @@ var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filte
5586
5967
  });
5587
5968
  const entry = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
5588
5969
  const nestedOps = entry && nested.hasOps(entry.ops) ? entry.ops : void 0;
5589
- const input = remapFromGraphQLSingleInput(entry ? entry.columns : set, table);
5970
+ const input = remapUpdateInput(entry ? entry.columns : set, table, tableName);
5590
5971
  if (!Object.keys(input).length && !nestedOps) {
5591
- throw new import_graphql9.GraphQLError("Unable to update with no values specified!");
5972
+ throw new import_graphql10.GraphQLError("Unable to update with no values specified!");
5592
5973
  }
5593
5974
  const relationCtx = relationFilterCtx(filterCtx, tableName);
5594
5975
  const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
@@ -5614,7 +5995,7 @@ var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filte
5614
5995
  write: runUpdate
5615
5996
  }) : await runUpdate(executor, input);
5616
5997
  if (single && result.length > 1) {
5617
- throw new import_graphql9.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
5998
+ throw new import_graphql10.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
5618
5999
  }
5619
6000
  if (single && !result[0]) {
5620
6001
  return void 0;
@@ -5632,7 +6013,7 @@ var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filte
5632
6013
  var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx, txCtx, nested) => {
5633
6014
  const queryArgs = {
5634
6015
  updates: {
5635
- type: new import_graphql9.GraphQLNonNull(new import_graphql9.GraphQLList(new import_graphql9.GraphQLNonNull(updateManyInput)))
6016
+ type: new import_graphql10.GraphQLNonNull(new import_graphql10.GraphQLList(new import_graphql10.GraphQLNonNull(updateManyInput)))
5636
6017
  }
5637
6018
  };
5638
6019
  const pkNames = sqlitePrimaryKeyPropNames(table);
@@ -5643,7 +6024,7 @@ var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateMany
5643
6024
  return await runMutation(db, context, info, txCtx, async (executor) => {
5644
6025
  const { updates } = args;
5645
6026
  if (!updates.length) {
5646
- throw new import_graphql9.GraphQLError("No updates were provided!");
6027
+ throw new import_graphql10.GraphQLError("No updates were provided!");
5647
6028
  }
5648
6029
  const parsedInfo = (0, import_graphql_parse_resolve_info4.parseResolveInfo)(info, {
5649
6030
  deep: true
@@ -5661,9 +6042,9 @@ var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateMany
5661
6042
  const entries = updates.map(({ where, set }) => {
5662
6043
  const split = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
5663
6044
  const ops = split && nested.hasOps(split.ops) ? split.ops : void 0;
5664
- const input = remapFromGraphQLSingleInput(split ? split.columns : set, table);
6045
+ const input = remapUpdateInput(split ? split.columns : set, table, tableName);
5665
6046
  if (!Object.keys(input).length && !ops) {
5666
- throw new import_graphql9.GraphQLError("Unable to update with no values specified!");
6047
+ throw new import_graphql10.GraphQLError("Unable to update with no values specified!");
5667
6048
  }
5668
6049
  return {
5669
6050
  set: input,
@@ -5750,7 +6131,7 @@ var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateMany
5750
6131
  var generateDelete3 = (db, tableName, table, filterArgs, fieldName, typeName, single, requireWhere, filterCtx, selectionCtx, txCtx) => {
5751
6132
  const queryArgs = {
5752
6133
  where: {
5753
- type: single || requireWhere ? new import_graphql9.GraphQLNonNull(filterArgs) : filterArgs
6134
+ type: single || requireWhere ? new import_graphql10.GraphQLNonNull(filterArgs) : filterArgs
5754
6135
  }
5755
6136
  };
5756
6137
  return {
@@ -5779,7 +6160,7 @@ var generateDelete3 = (db, tableName, table, filterArgs, fieldName, typeName, si
5779
6160
  query = query.returning(columns);
5780
6161
  const result = await query;
5781
6162
  if (single && result.length > 1) {
5782
- throw new import_graphql9.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
6163
+ throw new import_graphql10.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
5783
6164
  }
5784
6165
  if (single) {
5785
6166
  return result[0] ? remapToGraphQLSingleOutput(result[0], tableName, table) : void 0;
@@ -5806,7 +6187,7 @@ var generateSchemaData3 = (db, schema, relations, options) => {
5806
6187
  } = options;
5807
6188
  const rawSchema = schema;
5808
6189
  const schemaEntries = Object.entries(rawSchema);
5809
- const tableEntries = schemaEntries.filter(([_key, value]) => (0, import_drizzle_orm8.is)(value, import_sqlite_core2.SQLiteTable));
6190
+ const tableEntries = schemaEntries.filter(([_key, value]) => (0, import_drizzle_orm9.is)(value, import_sqlite_core2.SQLiteTable));
5810
6191
  const tables = Object.fromEntries(tableEntries);
5811
6192
  if (!tableEntries.length) {
5812
6193
  throw new Error(
@@ -5819,7 +6200,12 @@ var generateSchemaData3 = (db, schema, relations, options) => {
5819
6200
  attachTargetPrimaryKeys(namedRelations, tables, sqlitePrimaryKeyPropNames);
5820
6201
  const eagerRelations = pruneNonEagerRelations(namedRelations, shouldEagerLoad);
5821
6202
  const filterCtx = { tables, relationMap: namedRelations };
5822
- const resolverFactory = createRelationResolverFactory(db, tables, filterCtx);
6203
+ const resolverFactory = createRelationResolverFactory(
6204
+ db,
6205
+ tables,
6206
+ "nulls-smallest",
6207
+ filterCtx
6208
+ );
5823
6209
  const cacheCtx = {
5824
6210
  genericFilterCache: /* @__PURE__ */ new Map(),
5825
6211
  objectTypeCache: /* @__PURE__ */ new Map(),
@@ -5833,7 +6219,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
5833
6219
  listRelationFilterCache: /* @__PURE__ */ new Map(),
5834
6220
  aggregateTypeCache: /* @__PURE__ */ new Map(),
5835
6221
  complexity,
5836
- docs: options.docs ?? {}
6222
+ docs: options.docs ?? {},
6223
+ features
5837
6224
  };
5838
6225
  if (features.nestedWrites && db.resultKind === "sync") {
5839
6226
  throw new Error(
@@ -5895,8 +6282,10 @@ var generateSchemaData3 = (db, schema, relations, options) => {
5895
6282
  updateFieldName,
5896
6283
  updateManyFieldName,
5897
6284
  updateSingleFieldName,
6285
+ updateCountFieldName,
5898
6286
  deleteFieldName,
5899
- deleteSingleFieldName
6287
+ deleteSingleFieldName,
6288
+ deleteCountFieldName
5900
6289
  } = computeResolverFieldNames(tableName, typeNameMapper, prefixes, suffixes);
5901
6290
  const selectArrGenerated = generateSelectArray3(
5902
6291
  db,
@@ -6068,6 +6457,30 @@ var generateSchemaData3 = (db, schema, relations, options) => {
6068
6457
  { tableName, relationMap: namedRelations, tables },
6069
6458
  mutationTxCtx
6070
6459
  ) : void 0;
6460
+ const updateCountGenerated = features.update && features.countMutations ? generateWriteCount({
6461
+ db,
6462
+ tableName,
6463
+ table: schema[tableName],
6464
+ kind: "update",
6465
+ setArgs: updateInput,
6466
+ filterArgs: tableFilters,
6467
+ fieldName: updateCountFieldName,
6468
+ requireWhere: features.requireWhere,
6469
+ filterCtx,
6470
+ txCtx: mutationTxCtx,
6471
+ nested: nestedRuntime
6472
+ }) : void 0;
6473
+ const deleteCountGenerated = features.delete && features.countMutations ? generateWriteCount({
6474
+ db,
6475
+ tableName,
6476
+ table: schema[tableName],
6477
+ kind: "delete",
6478
+ filterArgs: tableFilters,
6479
+ fieldName: deleteCountFieldName,
6480
+ requireWhere: features.requireWhere,
6481
+ filterCtx,
6482
+ txCtx: mutationTxCtx
6483
+ }) : void 0;
6071
6484
  const aggregateType = features.aggregates ? generateAggregateTypes(schema[tableName], tableName, typeName, cacheCtx) : void 0;
6072
6485
  const aggregateGenerated = features.aggregates ? generateAggregate(
6073
6486
  db,
@@ -6105,7 +6518,7 @@ var generateSchemaData3 = (db, schema, relations, options) => {
6105
6518
  };
6106
6519
  if (aggregateGenerated && aggregateType) {
6107
6520
  queries[aggregateGenerated.name] = {
6108
- type: new import_graphql9.GraphQLNonNull(aggregateType),
6521
+ type: new import_graphql10.GraphQLNonNull(aggregateType),
6109
6522
  args: aggregateGenerated.args,
6110
6523
  resolve: aggregateGenerated.resolver,
6111
6524
  ...complexity ? { extensions: { complexity: aggregateFieldComplexity(complexity) } } : {}
@@ -6113,7 +6526,7 @@ var generateSchemaData3 = (db, schema, relations, options) => {
6113
6526
  }
6114
6527
  if (groupByGenerated && groupByType) {
6115
6528
  queries[groupByGenerated.name] = {
6116
- type: new import_graphql9.GraphQLNonNull(new import_graphql9.GraphQLList(new import_graphql9.GraphQLNonNull(groupByType))),
6529
+ type: new import_graphql10.GraphQLNonNull(new import_graphql10.GraphQLList(new import_graphql10.GraphQLNonNull(groupByType))),
6117
6530
  args: groupByGenerated.args,
6118
6531
  resolve: groupByGenerated.resolver,
6119
6532
  ...complexity ? { extensions: { complexity: aggregateFieldComplexity(complexity) } } : {}
@@ -6128,7 +6541,9 @@ var generateSchemaData3 = (db, schema, relations, options) => {
6128
6541
  }
6129
6542
  if (insertSingleGenerated) {
6130
6543
  mutations[insertSingleGenerated.name] = {
6131
- type: singleTableItemOutput,
6544
+ // An insert either returns the row it inserted or throws — the one path to `null` is
6545
+ // `conflictDoNothing` swallowing the insert, so the field is nullable only there.
6546
+ type: conflictDoNothing ? singleTableItemOutput : new import_graphql10.GraphQLNonNull(singleTableItemOutput),
6132
6547
  args: insertSingleGenerated.args,
6133
6548
  resolve: insertSingleGenerated.resolver
6134
6549
  };
@@ -6156,10 +6571,13 @@ var generateSchemaData3 = (db, schema, relations, options) => {
6156
6571
  }
6157
6572
  if (updateManyGenerated) {
6158
6573
  mutations[updateManyGenerated.name] = {
6159
- // Nullable items: a no-match entry yields `null` in its slot.
6160
- type: new import_graphql9.GraphQLNonNull(new import_graphql9.GraphQLList(singleTableItemOutput)),
6574
+ type: new import_graphql10.GraphQLNonNull(new import_graphql10.GraphQLList(singleTableItemOutput)),
6161
6575
  args: updateManyGenerated.args,
6162
- resolve: updateManyGenerated.resolver
6576
+ resolve: updateManyGenerated.resolver,
6577
+ // The nullable element is deliberate, and the reason this mutation's return type
6578
+ // differs from every sibling's: the result is aligned with the input, one slot per
6579
+ // entry, so an entry that matched nothing has to be able to say so.
6580
+ 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
6581
  };
6164
6582
  }
6165
6583
  if (updateSingleGenerated) {
@@ -6183,6 +6601,22 @@ var generateSchemaData3 = (db, schema, relations, options) => {
6183
6601
  resolve: deleteSingleGenerated.resolver
6184
6602
  };
6185
6603
  }
6604
+ if (updateCountGenerated) {
6605
+ mutations[updateCountGenerated.name] = {
6606
+ type: new import_graphql10.GraphQLNonNull(import_graphql10.GraphQLInt),
6607
+ args: updateCountGenerated.args,
6608
+ resolve: updateCountGenerated.resolver,
6609
+ description: "How many rows the update touched. The rows themselves are not read back, which is the point of this mutation."
6610
+ };
6611
+ }
6612
+ if (deleteCountGenerated) {
6613
+ mutations[deleteCountGenerated.name] = {
6614
+ type: new import_graphql10.GraphQLNonNull(import_graphql10.GraphQLInt),
6615
+ args: deleteCountGenerated.args,
6616
+ resolve: deleteCountGenerated.resolver,
6617
+ description: "How many rows the delete removed. The rows themselves are not read back, which is the point of this mutation."
6618
+ };
6619
+ }
6186
6620
  const activeInputs = [
6187
6621
  // The insert input types the upsert mutations too, so either feature keeps it.
6188
6622
  ...features.insert || onConflictInput ? [insertInput] : [],
@@ -6214,7 +6648,7 @@ var generateSchemaData3 = (db, schema, relations, options) => {
6214
6648
  for (const [tableName, tableRelations] of Object.entries(namedRelations)) {
6215
6649
  const relResolvers = {};
6216
6650
  for (const [relName, relEntry] of Object.entries(tableRelations)) {
6217
- const isOne = (0, import_drizzle_orm8.is)(relEntry.relation ?? relEntry, import_drizzle_orm8.One);
6651
+ const isOne = (0, import_drizzle_orm9.is)(relEntry.relation ?? relEntry, import_drizzle_orm9.One);
6218
6652
  const resolver = resolverFactory({ tableName, relationName: relName, relEntry, isOne });
6219
6653
  if (resolver) {
6220
6654
  relResolvers[relName] = resolver;
@@ -6260,6 +6694,8 @@ var buildSchema = (db, config) => {
6260
6694
  delete: config?.features?.delete ?? true,
6261
6695
  upsert: config?.features?.upsert ?? false,
6262
6696
  nestedWrites: config?.features?.nestedWrites ?? false,
6697
+ fieldUpdateOperations: config?.features?.fieldUpdateOperations ?? false,
6698
+ countMutations: config?.features?.countMutations ?? false,
6263
6699
  requireWhere: config?.features?.requireWhere ?? false
6264
6700
  };
6265
6701
  const complexityConfig = config?.complexity ?? true;
@@ -6309,11 +6745,11 @@ var buildSchema = (db, config) => {
6309
6745
  }
6310
6746
  };
6311
6747
  let generatorOutput;
6312
- if ((0, import_drizzle_orm9.is)(db, import_mysql_core3.MySqlDatabase)) {
6748
+ if ((0, import_drizzle_orm10.is)(db, import_mysql_core3.MySqlDatabase)) {
6313
6749
  generatorOutput = generateSchemaData(db, schema, relations, generatorOptions);
6314
- } else if ((0, import_drizzle_orm9.is)(db, import_pg_core3.PgAsyncDatabase)) {
6750
+ } else if ((0, import_drizzle_orm10.is)(db, import_pg_core3.PgAsyncDatabase)) {
6315
6751
  generatorOutput = generateSchemaData2(db, schema, relations, generatorOptions);
6316
- } else if ((0, import_drizzle_orm9.is)(db, import_sqlite_core3.BaseSQLiteDatabase)) {
6752
+ } else if ((0, import_drizzle_orm10.is)(db, import_sqlite_core3.BaseSQLiteDatabase)) {
6317
6753
  generatorOutput = generateSchemaData3(db, schema, relations, generatorOptions);
6318
6754
  } else {
6319
6755
  throw new Error("Drizzle-GraphQL Error: Unknown database instance type");
@@ -6326,19 +6762,19 @@ var buildSchema = (db, config) => {
6326
6762
  const { queries, mutations, inputs, types } = generatorOutput;
6327
6763
  const graphQLSchemaConfig = {
6328
6764
  types: [...Object.values(inputs), ...Object.values(types)],
6329
- query: new import_graphql10.GraphQLObjectType({
6765
+ query: new import_graphql11.GraphQLObjectType({
6330
6766
  name: "Query",
6331
6767
  fields: queries
6332
6768
  })
6333
6769
  };
6334
6770
  if (config?.mutations !== false && Object.keys(mutations).length) {
6335
- const mutation = new import_graphql10.GraphQLObjectType({
6771
+ const mutation = new import_graphql11.GraphQLObjectType({
6336
6772
  name: "Mutation",
6337
6773
  fields: mutations
6338
6774
  });
6339
6775
  graphQLSchemaConfig.mutation = mutation;
6340
6776
  }
6341
- const outputSchema = new import_graphql10.GraphQLSchema(graphQLSchemaConfig);
6777
+ const outputSchema = new import_graphql11.GraphQLSchema(graphQLSchemaConfig);
6342
6778
  return { schema: outputSchema, entities: generatorOutput };
6343
6779
  };
6344
6780
  // Annotate the CommonJS export names for ESM import in node: