@vantreeseba/drizzle-graphql 7.0.0 → 7.2.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
@@ -1017,7 +1017,7 @@ var batchedPaginatedRelationQuery = async (db, targetTable, foreignCol, whereCon
1017
1017
  }
1018
1018
  return rows;
1019
1019
  };
1020
- var createRelationResolverFactory = (db, tables, nullOrdering, filterCtx) => ({ tableName, relationName, relEntry, isOne }) => {
1020
+ var createRelationResolverFactory = (db, tables, nullOrdering, filterCtx, limits) => ({ tableName, relationName, relEntry, isOne }) => {
1021
1021
  const parentTable = tables[tableName];
1022
1022
  const targetTableName = relEntry.targetTableName;
1023
1023
  const targetTable = tables[targetTableName];
@@ -1029,6 +1029,7 @@ var createRelationResolverFactory = (db, tables, nullOrdering, filterCtx) => ({
1029
1029
  return void 0;
1030
1030
  }
1031
1031
  const { localColPropName, foreignCol, foreignColPropName } = joinCols;
1032
+ const limitPolicy = isOne ? void 0 : limits?.(targetTableName);
1032
1033
  const targetPkNames = relEntry.targetPkNames ?? [];
1033
1034
  return async (parent, args, context, info) => {
1034
1035
  if (parent[relationName] !== void 0) {
@@ -1038,7 +1039,8 @@ var createRelationResolverFactory = (db, tables, nullOrdering, filterCtx) => ({
1038
1039
  if (localValue == null) {
1039
1040
  return isOne ? null : [];
1040
1041
  }
1041
- const { where: whereArg, orderBy: orderByArg, limit, offset, after } = args ?? {};
1042
+ const { where: whereArg, orderBy: orderByArg, limit: requestedLimit, offset, after } = args ?? {};
1043
+ const limit = applyLimitPolicy(requestedLimit, limitPolicy, `${tableName}.${relationName}`);
1042
1044
  const distinct = (args ?? {}).distinct?.length ? (args ?? {}).distinct : void 0;
1043
1045
  const cursorSelected = !isOne && !!info && selectsCursorField(info, targetTable);
1044
1046
  let cursorEntries;
@@ -1152,9 +1154,65 @@ var inputFieldDocs = (docs, column, tableName, columnName, fieldType) => {
1152
1154
  }
1153
1155
  return resolved;
1154
1156
  };
1155
- var listFieldComplexity = (options) => ({ args, childComplexity }) => {
1157
+ var applyLimitPolicy = (limit, policy, fieldName) => {
1158
+ if (!policy) {
1159
+ return limit ?? void 0;
1160
+ }
1161
+ const { defaultLimit, maxLimit, clampToMax } = policy;
1162
+ if (limit == null) {
1163
+ const fallback = defaultLimit ?? maxLimit;
1164
+ if (fallback === void 0) {
1165
+ return void 0;
1166
+ }
1167
+ return maxLimit === void 0 ? fallback : Math.min(fallback, maxLimit);
1168
+ }
1169
+ if (maxLimit !== void 0 && limit > maxLimit) {
1170
+ if (clampToMax) {
1171
+ return maxLimit;
1172
+ }
1173
+ throw new import_graphql5.GraphQLError(`${fieldName}: 'limit' of ${limit} exceeds the maximum of ${maxLimit}.`);
1174
+ }
1175
+ return limit;
1176
+ };
1177
+ var resolveLimitPolicy = (global, table) => {
1178
+ const defaultLimit = table?.defaultLimit ?? global?.defaultLimit;
1179
+ const maxLimit = table?.maxLimit ?? global?.maxLimit;
1180
+ if (defaultLimit === void 0 && maxLimit === void 0) {
1181
+ return void 0;
1182
+ }
1183
+ return { defaultLimit, maxLimit, clampToMax: table?.clampToMax ?? global?.clampToMax ?? false };
1184
+ };
1185
+ var excludedColumnRegistry = /* @__PURE__ */ new WeakMap();
1186
+ var registerColumnExclusions = (tables, exclude) => {
1187
+ for (const [tableName, table] of Object.entries(tables)) {
1188
+ const hidden = exclude?.columns?.[tableName];
1189
+ if (hidden?.length) {
1190
+ excludedColumnRegistry.set(table, new Set(hidden));
1191
+ } else {
1192
+ excludedColumnRegistry.delete(table);
1193
+ }
1194
+ }
1195
+ };
1196
+ var hasExcludedColumns = (table) => excludedColumnRegistry.has(table);
1197
+ var excludedColumnsKey = (table) => {
1198
+ const hidden = excludedColumnRegistry.get(table);
1199
+ return hidden ? [...hidden].sort().join(",") : "";
1200
+ };
1201
+ var visibleColumns = (table) => {
1202
+ const columns = (0, import_drizzle_orm4.getColumns)(table);
1203
+ const hidden = excludedColumnRegistry.get(table);
1204
+ if (!hidden) {
1205
+ return columns;
1206
+ }
1207
+ return Object.fromEntries(Object.entries(columns).filter(([columnName]) => !hidden.has(columnName)));
1208
+ };
1209
+ var listFieldComplexity = (options, policy) => ({ args, childComplexity }) => {
1156
1210
  const limit = args["limit"];
1157
- const rows = typeof limit === "number" && limit > 0 ? limit : options.defaultListSize;
1211
+ const requested = typeof limit === "number" && limit > 0 ? limit : void 0;
1212
+ let rows = requested ?? policy?.defaultLimit ?? options.defaultListSize;
1213
+ if (policy?.maxLimit !== void 0) {
1214
+ rows = Math.min(rows, policy.maxLimit);
1215
+ }
1158
1216
  return rows * Math.max(childComplexity, 1);
1159
1217
  };
1160
1218
  var aggregateFieldComplexity = (options) => ({ childComplexity }) => options.aggregateCost + childComplexity;
@@ -1457,17 +1515,20 @@ var generateColumnFilterValues = (column, tableName, columnName, cacheCtx) => {
1457
1515
  };
1458
1516
  var orderMap = /* @__PURE__ */ new WeakMap();
1459
1517
  var generateTableOrderCached = (table) => {
1460
- if (orderMap.has(table)) {
1518
+ const cacheable = !hasExcludedColumns(table);
1519
+ if (cacheable && orderMap.has(table)) {
1461
1520
  return orderMap.get(table);
1462
1521
  }
1463
1522
  let remapped = {};
1464
1523
  try {
1465
- const columns = (0, import_drizzle_orm4.getColumns)(table);
1524
+ const columns = visibleColumns(table);
1466
1525
  const columnEntries = Object.entries(columns);
1467
1526
  remapped = Object.fromEntries(
1468
1527
  columnEntries.map(([columnName, _columnDescription]) => [columnName, { type: innerOrder }])
1469
1528
  );
1470
- orderMap.set(table, remapped);
1529
+ if (cacheable) {
1530
+ orderMap.set(table, remapped);
1531
+ }
1471
1532
  } catch (_err) {
1472
1533
  }
1473
1534
  return remapped;
@@ -1476,7 +1537,7 @@ var generateTableFilterValuesCached = (table, tableName, cacheCtx) => {
1476
1537
  if (cacheCtx.filterFieldCache.has(table)) {
1477
1538
  return cacheCtx.filterFieldCache.get(table);
1478
1539
  }
1479
- const columns = (0, import_drizzle_orm4.getColumns)(table);
1540
+ const columns = visibleColumns(table);
1480
1541
  const columnEntries = Object.entries(columns);
1481
1542
  const remapped = Object.fromEntries(
1482
1543
  columnEntries.map(([columnName, column]) => [
@@ -1497,7 +1558,7 @@ var generateTableSelectTypeFieldsCached = (table, tableName, cacheCtx) => {
1497
1558
  if (cacheCtx.selectFieldCache.has(table)) {
1498
1559
  return cacheCtx.selectFieldCache.get(table);
1499
1560
  }
1500
- const columns = (0, import_drizzle_orm4.getColumns)(table);
1561
+ const columns = visibleColumns(table);
1501
1562
  const columnEntries = Object.entries(columns);
1502
1563
  const remapped = Object.fromEntries(
1503
1564
  columnEntries.map(([columnName, column]) => [
@@ -1785,7 +1846,11 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
1785
1846
  },
1786
1847
  resolve,
1787
1848
  ...relationDocs,
1788
- ...cacheCtx.complexity ? { extensions: { complexity: listFieldComplexity(cacheCtx.complexity) } } : {}
1849
+ ...cacheCtx.complexity ? {
1850
+ extensions: {
1851
+ complexity: listFieldComplexity(cacheCtx.complexity, cacheCtx.limits?.(targetTableName))
1852
+ }
1853
+ } : {}
1789
1854
  }
1790
1855
  ]);
1791
1856
  const aggregateFieldName = `${relationName}Aggregate`;
@@ -1851,7 +1916,7 @@ var generateTableTypes = (tableName, tables, relationMap, withReturning, relatio
1851
1916
  relationAggregateFactory
1852
1917
  );
1853
1918
  const table = tables[tableName];
1854
- const columns = (0, import_drizzle_orm4.getColumns)(table);
1919
+ const columns = visibleColumns(table);
1855
1920
  const columnEntries = Object.entries(columns);
1856
1921
  const relaxedColumns = nestedWrites?.relaxedColumns(tableName);
1857
1922
  const insertFields = Object.fromEntries(
@@ -2264,7 +2329,7 @@ var extractFilters = (table, tableName, filters, relationCtx) => {
2264
2329
  }
2265
2330
  return variants.length ? variants.length > 1 ? (0, import_drizzle_orm4.and)(...variants) : variants[0] : void 0;
2266
2331
  };
2267
- var extractRelationsParamsInner = (relationMap, tables, tableName, typeName, originField, typeNameMapper, _isInitial = false, filterCtx) => {
2332
+ var extractRelationsParamsInner = (relationMap, tables, tableName, typeName, originField, typeNameMapper, _isInitial = false, filterCtx, limits) => {
2268
2333
  const relationsForTable = relationMap[tableName];
2269
2334
  if (!relationsForTable) {
2270
2335
  return void 0;
@@ -2308,7 +2373,7 @@ var extractRelationsParamsInner = (relationMap, tables, tableName, typeName, ori
2308
2373
  const relationField = Object.values(baseField).find((e) => e.name === relName);
2309
2374
  const relationArgs = relationField?.args;
2310
2375
  const offset = relationArgs?.offset ?? void 0;
2311
- const limit = relationArgs?.limit ?? void 0;
2376
+ const limit = (0, import_drizzle_orm4.is)(relEntry.relation, import_drizzle_orm4.One) ? relationArgs?.limit ?? void 0 : applyLimitPolicy(relationArgs?.limit, limits?.(targetTableName), `${tableName}.${relName}`);
2312
2377
  const relWhere = relationArgs?.where;
2313
2378
  thisRecord.where = relWhere ? {
2314
2379
  RAW: (aliasedTable2) => extractFilters(aliasedTable2, relName, relWhere, relationFilterCtx(filterCtx, targetTableName))
@@ -2326,18 +2391,29 @@ var extractRelationsParamsInner = (relationMap, tables, tableName, typeName, ori
2326
2391
  relationField,
2327
2392
  typeNameMapper,
2328
2393
  false,
2329
- filterCtx
2394
+ filterCtx,
2395
+ limits
2330
2396
  ) : void 0;
2331
2397
  thisRecord.with = relWith;
2332
2398
  args[relName] = thisRecord;
2333
2399
  }
2334
2400
  return args;
2335
2401
  };
2336
- var extractRelationsParams = (relationMap, tables, tableName, info, typeName, typeNameMapper, filterCtx) => {
2402
+ var extractRelationsParams = (relationMap, tables, tableName, info, typeName, typeNameMapper, filterCtx, limits) => {
2337
2403
  if (!info) {
2338
2404
  return void 0;
2339
2405
  }
2340
- return extractRelationsParamsInner(relationMap, tables, tableName, typeName, info, typeNameMapper, true, filterCtx);
2406
+ return extractRelationsParamsInner(
2407
+ relationMap,
2408
+ tables,
2409
+ tableName,
2410
+ typeName,
2411
+ info,
2412
+ typeNameMapper,
2413
+ true,
2414
+ filterCtx,
2415
+ limits
2416
+ );
2341
2417
  };
2342
2418
  var pruneNonEagerRelations = (relationMap, shouldEagerLoad) => {
2343
2419
  const out = {};
@@ -2515,7 +2591,7 @@ var attachRowCursors = (rows, entries) => {
2515
2591
  };
2516
2592
  var rowCursorResolver = (source) => source?.[ROW_CURSOR_PROP] ?? null;
2517
2593
  var getUniqueColumnSets = (table, getTableConfig4) => {
2518
- const cols = (0, import_drizzle_orm4.getColumns)(table);
2594
+ const cols = visibleColumns(table);
2519
2595
  const propNameByColumnName = new Map(Object.entries(cols).map(([propName, col]) => [col.name, propName]));
2520
2596
  const toPropNames = (columnNames) => {
2521
2597
  const propNames = [];
@@ -2555,12 +2631,13 @@ var getUniqueColumnSets = (table, getTableConfig4) => {
2555
2631
  var DISTINCT_RN = "__drizzle_graphql_distinct_rn";
2556
2632
  var columnEnumCache = /* @__PURE__ */ new WeakMap();
2557
2633
  var generateColumnEnum = (table, enumName, description, predicate = () => true) => {
2634
+ const cacheKey = `${enumName}\0${excludedColumnsKey(table)}`;
2558
2635
  let tableCache = columnEnumCache.get(table);
2559
- const cached = tableCache?.get(enumName);
2636
+ const cached = tableCache?.get(cacheKey);
2560
2637
  if (cached) {
2561
2638
  return cached;
2562
2639
  }
2563
- const columnNames = Object.entries((0, import_drizzle_orm4.getColumns)(table)).filter(([columnName, column]) => predicate(column, columnName)).map(([columnName]) => columnName);
2640
+ const columnNames = Object.entries(visibleColumns(table)).filter(([columnName, column]) => predicate(column, columnName)).map(([columnName]) => columnName);
2564
2641
  if (!columnNames.length) {
2565
2642
  return void 0;
2566
2643
  }
@@ -2573,7 +2650,7 @@ var generateColumnEnum = (table, enumName, description, predicate = () => true)
2573
2650
  tableCache = /* @__PURE__ */ new Map();
2574
2651
  columnEnumCache.set(table, tableCache);
2575
2652
  }
2576
- tableCache.set(enumName, enumType);
2653
+ tableCache.set(cacheKey, enumType);
2577
2654
  return enumType;
2578
2655
  };
2579
2656
  var generateDistinctEnum = (table, typeName) => generateColumnEnum(table, `${typeName}DistinctColumn`, `Columns of ${typeName} that a query can be made distinct on`);
@@ -2728,7 +2805,16 @@ var primaryKeyRestriction = (table, pkNames, keys) => {
2728
2805
  };
2729
2806
  var prepareMutationRelationColumns = (params) => {
2730
2807
  const { relationMap, tables, tableName, typeName, typeNameMapper, table, pkNames, parsedInfo } = params;
2731
- const withParams = relationMap[tableName] ? extractRelationsParams(relationMap, tables, tableName, parsedInfo, typeName, typeNameMapper) : void 0;
2808
+ const withParams = relationMap[tableName] ? extractRelationsParams(
2809
+ relationMap,
2810
+ tables,
2811
+ tableName,
2812
+ parsedInfo,
2813
+ typeName,
2814
+ typeNameMapper,
2815
+ void 0,
2816
+ params.limits
2817
+ ) : void 0;
2732
2818
  const hasRelations = !!(withParams && Object.keys(withParams).length);
2733
2819
  const baseColumns = extractSelectedColumnsFromTreeSQLFormat(parsedInfo.fieldsByTypeName[typeName], table, {
2734
2820
  tableName,
@@ -3032,7 +3118,16 @@ var runRelationalSelect = async (opts) => {
3032
3118
  ) : void 0
3033
3119
  )
3034
3120
  } : void 0,
3035
- with: relationMap[tableName] ? extractRelationsParams(relationMap, tables, tableName, parsedInfo, typeName, typeNameMapper, filterCtx) : void 0
3121
+ with: relationMap[tableName] ? extractRelationsParams(
3122
+ relationMap,
3123
+ tables,
3124
+ tableName,
3125
+ parsedInfo,
3126
+ typeName,
3127
+ typeNameMapper,
3128
+ filterCtx,
3129
+ opts.limits
3130
+ ) : void 0
3036
3131
  };
3037
3132
  if (single) {
3038
3133
  const result2 = await queryBase.findFirst(params);
@@ -3143,7 +3238,7 @@ var classifyAggregateColumns = (table, tableName) => {
3143
3238
  const numeric = {};
3144
3239
  const orderable = {};
3145
3240
  const all = {};
3146
- for (const [columnName, column] of Object.entries((0, import_drizzle_orm5.getColumns)(table))) {
3241
+ for (const [columnName, column] of Object.entries(visibleColumns(table))) {
3147
3242
  all[columnName] = column;
3148
3243
  const converted = drizzleColumnToGraphQLType(column, columnName, tableName, true, false, false);
3149
3244
  const gqlType = converted.type;
@@ -3387,7 +3482,7 @@ var HAVING_OPS = { eq: import_drizzle_orm5.eq, ne: import_drizzle_orm5.ne, gt: i
3387
3482
  var groupableColumns = (table, tableName) => {
3388
3483
  const { orderable } = classifyAggregateColumns(table, tableName);
3389
3484
  const groupable = { ...orderable };
3390
- for (const [columnName, column] of Object.entries((0, import_drizzle_orm5.getColumns)(table))) {
3485
+ for (const [columnName, column] of Object.entries(visibleColumns(table))) {
3391
3486
  if (groupable[columnName]) {
3392
3487
  continue;
3393
3488
  }
@@ -3562,7 +3657,7 @@ var generateGroupBy = (db, tableName, table, typeName, fieldName, filterArgs, gr
3562
3657
  };
3563
3658
 
3564
3659
  // src/util/builders/mysql.ts
3565
- var generateSelectArray = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, distinctEnabled = true) => {
3660
+ var generateSelectArray = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, distinctEnabled = true, limits) => {
3566
3661
  const queryBase = db.query[tableName];
3567
3662
  if (!queryBase) {
3568
3663
  throw new Error(
@@ -3570,6 +3665,7 @@ var generateSelectArray = (db, tableName, tables, relationMap, orderArgs, filter
3570
3665
  );
3571
3666
  }
3572
3667
  const table = tables[tableName];
3668
+ const limitPolicy = limits?.(tableName);
3573
3669
  const pkNames = mysqlPrimaryKeyPropNames(table);
3574
3670
  const queryArgs = selectArrayArgs(
3575
3671
  orderArgs,
@@ -3592,8 +3688,10 @@ var generateSelectArray = (db, tableName, tables, relationMap, orderArgs, filter
3592
3688
  typeNameMapper,
3593
3689
  parsedInfo,
3594
3690
  ...args,
3691
+ limit: applyLimitPolicy(args.limit, limitPolicy, fieldName),
3595
3692
  single: false,
3596
3693
  filterCtx,
3694
+ limits,
3597
3695
  pkNames,
3598
3696
  db: executor,
3599
3697
  // MySQL sorts NULLs as the smallest values (first in ASC).
@@ -3606,7 +3704,7 @@ var generateSelectArray = (db, tableName, tables, relationMap, orderArgs, filter
3606
3704
  args: queryArgs
3607
3705
  };
3608
3706
  };
3609
- var generateSelectSingle = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx) => {
3707
+ var generateSelectSingle = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, limits) => {
3610
3708
  const queryBase = db.query[tableName];
3611
3709
  if (!queryBase) {
3612
3710
  throw new Error(
@@ -3634,6 +3732,7 @@ var generateSelectSingle = (db, tableName, tables, relationMap, orderArgs, filte
3634
3732
  ...args,
3635
3733
  single: true,
3636
3734
  filterCtx,
3735
+ limits,
3637
3736
  pkNames,
3638
3737
  db: executor
3639
3738
  });
@@ -3848,10 +3947,11 @@ var generateDelete = (db, tableName, table, filterArgs, fieldName, single, requi
3848
3947
  };
3849
3948
  var mysqlPrimaryKeyPropNames = (table) => getPrimaryKeyPropNamesFromConfig(table, import_mysql_core2.getTableConfig);
3850
3949
  var generateSchemaData = (db, schema, relations, options) => {
3851
- const { relationsDepthLimit, prefixes, suffixes, typeNameMapper, shouldEagerLoad, features, complexity } = options;
3950
+ const { relationsDepthLimit, prefixes, suffixes, typeNameMapper, shouldEagerLoad, features, complexity, limits } = options;
3852
3951
  const rawSchema = schema;
3853
3952
  const schemaEntries = Object.entries(rawSchema);
3854
- const tableEntries = schemaEntries.filter(([_key, value]) => (0, import_drizzle_orm6.is)(value, import_mysql_core2.MySqlTable));
3953
+ const excludedTables = new Set(options.exclude?.tables ?? []);
3954
+ const tableEntries = schemaEntries.filter(([key, value]) => (0, import_drizzle_orm6.is)(value, import_mysql_core2.MySqlTable) && !excludedTables.has(key));
3855
3955
  const tables = Object.fromEntries(tableEntries);
3856
3956
  if (!tableEntries.length) {
3857
3957
  throw new Error(
@@ -3865,7 +3965,11 @@ var generateSchemaData = (db, schema, relations, options) => {
3865
3965
  }
3866
3966
  registerScalarOverrides(tables, options);
3867
3967
  registerEnumConfig(options);
3968
+ registerColumnExclusions(tables, options.exclude);
3868
3969
  const namedRelations = buildNamedRelations(relations ?? {}, tableEntries);
3970
+ for (const excluded of excludedTables) {
3971
+ delete namedRelations[excluded];
3972
+ }
3869
3973
  attachTargetPrimaryKeys(namedRelations, tables, mysqlPrimaryKeyPropNames);
3870
3974
  const eagerRelations = pruneNonEagerRelations(namedRelations, shouldEagerLoad);
3871
3975
  const filterCtx = { tables, relationMap: namedRelations };
@@ -3873,7 +3977,8 @@ var generateSchemaData = (db, schema, relations, options) => {
3873
3977
  db,
3874
3978
  tables,
3875
3979
  "nulls-smallest",
3876
- filterCtx
3980
+ filterCtx,
3981
+ limits
3877
3982
  );
3878
3983
  const cacheCtx = {
3879
3984
  genericFilterCache: /* @__PURE__ */ new Map(),
@@ -3888,6 +3993,7 @@ var generateSchemaData = (db, schema, relations, options) => {
3888
3993
  listRelationFilterCache: /* @__PURE__ */ new Map(),
3889
3994
  aggregateTypeCache: /* @__PURE__ */ new Map(),
3890
3995
  complexity,
3996
+ limits,
3891
3997
  docs: options.docs ?? {},
3892
3998
  features
3893
3999
  };
@@ -3958,7 +4064,8 @@ var generateSchemaData = (db, schema, relations, options) => {
3958
4064
  typeName,
3959
4065
  typeNameMapper,
3960
4066
  filterCtx,
3961
- features.distinct
4067
+ features.distinct,
4068
+ limits
3962
4069
  );
3963
4070
  const selectSingleGenerated = generateSelectSingle(
3964
4071
  db,
@@ -3970,7 +4077,8 @@ var generateSchemaData = (db, schema, relations, options) => {
3970
4077
  singleFieldName,
3971
4078
  typeName,
3972
4079
  typeNameMapper,
3973
- filterCtx
4080
+ filterCtx,
4081
+ limits
3974
4082
  );
3975
4083
  const insertArrGenerated = features.insert ? generateInsertArray(
3976
4084
  db,
@@ -4120,7 +4228,7 @@ var generateSchemaData = (db, schema, relations, options) => {
4120
4228
  type: selectArrOutput,
4121
4229
  args: selectArrGenerated.args,
4122
4230
  resolve: selectArrGenerated.resolver,
4123
- ...complexity ? { extensions: { complexity: listFieldComplexity(complexity) } } : {}
4231
+ ...complexity ? { extensions: { complexity: listFieldComplexity(complexity, limits?.(tableName)) } } : {}
4124
4232
  };
4125
4233
  queries[selectSingleGenerated.name] = {
4126
4234
  type: selectSingleOutput,
@@ -4329,7 +4437,7 @@ var createNestedWriteTypes = (params) => {
4329
4437
  }
4330
4438
  const omitted = plan.fkSide === "child" ? plan.foreignColPropName : void 0;
4331
4439
  const fields = Object.fromEntries(
4332
- Object.entries((0, import_drizzle_orm7.getColumns)(plan.targetTable)).filter(([columnName]) => columnName !== omitted).map(([columnName, column]) => [
4440
+ Object.entries(visibleColumns(plan.targetTable)).filter(([columnName]) => columnName !== omitted).map(([columnName, column]) => [
4333
4441
  columnName,
4334
4442
  drizzleColumnToGraphQLType(column, columnName, plan.targetTableName, false, true, true)
4335
4443
  ])
@@ -4605,9 +4713,10 @@ var updateWithNestedOps = async (params) => {
4605
4713
  };
4606
4714
 
4607
4715
  // src/util/builders/pg.ts
4608
- var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, distinctEnabled = true) => {
4716
+ var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, distinctEnabled = true, limits) => {
4609
4717
  const queryBase = db.query[tableName];
4610
4718
  const table = tables[tableName];
4719
+ const limitPolicy = limits?.(tableName);
4611
4720
  const pkNames = pgPrimaryKeyPropNames(table);
4612
4721
  const queryArgs = selectArrayArgs(
4613
4722
  orderArgs,
@@ -4620,6 +4729,7 @@ var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filte
4620
4729
  try {
4621
4730
  const parsedInfo = (0, import_graphql_parse_resolve_info3.parseResolveInfo)(info, { deep: true });
4622
4731
  const { executor, queryBase: requestQueryBase } = resolveQueryExecutor(db, context, tableName, queryBase);
4732
+ const limit = applyLimitPolicy(args.limit, limitPolicy, fieldName);
4623
4733
  if (requestQueryBase) {
4624
4734
  return await runRelationalSelect({
4625
4735
  queryBase: requestQueryBase,
@@ -4631,15 +4741,17 @@ var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filte
4631
4741
  typeNameMapper,
4632
4742
  parsedInfo,
4633
4743
  ...args,
4744
+ limit,
4634
4745
  single: false,
4635
4746
  filterCtx,
4747
+ limits,
4636
4748
  pkNames,
4637
4749
  db: executor,
4638
4750
  // PostgreSQL sorts NULLs as the largest values (last in ASC).
4639
4751
  nullOrdering: "nulls-largest"
4640
4752
  });
4641
4753
  }
4642
- const { offset, limit, orderBy, where, distinct, after } = args;
4754
+ const { offset, orderBy, where, distinct, after } = args;
4643
4755
  const selectedColumnsSql = extractSelectedColumnsFromTreeSQLFormat(
4644
4756
  parsedInfo.fieldsByTypeName[typeName],
4645
4757
  table,
@@ -4729,7 +4841,7 @@ var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filte
4729
4841
  args: queryArgs
4730
4842
  };
4731
4843
  };
4732
- var generateSelectSingle2 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx) => {
4844
+ var generateSelectSingle2 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, limits) => {
4733
4845
  const queryBase = db.query[tableName];
4734
4846
  const queryArgs = selectSingleArgs(orderArgs, filterArgs);
4735
4847
  const table = tables[tableName];
@@ -4753,6 +4865,7 @@ var generateSelectSingle2 = (db, tableName, tables, relationMap, orderArgs, filt
4753
4865
  ...args,
4754
4866
  single: true,
4755
4867
  filterCtx,
4868
+ limits,
4756
4869
  pkNames,
4757
4870
  db: executor
4758
4871
  });
@@ -4786,7 +4899,7 @@ var generateSelectSingle2 = (db, tableName, tables, relationMap, orderArgs, filt
4786
4899
  };
4787
4900
  };
4788
4901
  var pgPrimaryKeyPropNames = (table) => getPrimaryKeyPropNamesFromConfig(table, import_pg_core2.getTableConfig);
4789
- var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested) => {
4902
+ var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested, limits) => {
4790
4903
  const queryArgs = {
4791
4904
  values: {
4792
4905
  type: new import_graphql9.GraphQLNonNull(new import_graphql9.GraphQLList(new import_graphql9.GraphQLNonNull(baseType)))
@@ -4815,7 +4928,8 @@ var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType,
4815
4928
  typeNameMapper,
4816
4929
  table,
4817
4930
  pkNames,
4818
- parsedInfo
4931
+ parsedInfo,
4932
+ limits
4819
4933
  });
4820
4934
  const returning = nestedEntries ? nested.withJoinColumns(tableName, mergedOps(nestedEntries), { ...columns }, table) : columns;
4821
4935
  const runInsert = async (target, values) => {
@@ -4843,7 +4957,7 @@ var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType,
4843
4957
  args: queryArgs
4844
4958
  };
4845
4959
  };
4846
- var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested) => {
4960
+ var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested, limits) => {
4847
4961
  const queryArgs = {
4848
4962
  values: {
4849
4963
  type: new import_graphql9.GraphQLNonNull(baseType)
@@ -4869,7 +4983,8 @@ var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType
4869
4983
  typeNameMapper,
4870
4984
  table,
4871
4985
  pkNames,
4872
- parsedInfo
4986
+ parsedInfo,
4987
+ limits
4873
4988
  });
4874
4989
  const returning = nestedEntry ? nested.withJoinColumns(tableName, nestedEntry.ops, { ...columns }, table) : columns;
4875
4990
  const runInsert = async (target, values) => {
@@ -4903,7 +5018,7 @@ var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType
4903
5018
  args: queryArgs
4904
5019
  };
4905
5020
  };
4906
- var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx, txCtx, nested) => {
5021
+ var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx, txCtx, nested, limits) => {
4907
5022
  const queryArgs = {
4908
5023
  values: {
4909
5024
  type: single ? new import_graphql9.GraphQLNonNull(baseType) : new import_graphql9.GraphQLNonNull(new import_graphql9.GraphQLList(new import_graphql9.GraphQLNonNull(baseType)))
@@ -4935,7 +5050,8 @@ var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onCo
4935
5050
  typeNameMapper,
4936
5051
  table,
4937
5052
  pkNames,
4938
- parsedInfo
5053
+ parsedInfo,
5054
+ limits
4939
5055
  });
4940
5056
  const returning = nestedEntries ? nested.withJoinColumns(tableName, mergedOps(nestedEntries), { ...columns }, table) : columns;
4941
5057
  const runUpsert = async (target, values) => {
@@ -4974,7 +5090,7 @@ var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onCo
4974
5090
  args: queryArgs
4975
5091
  };
4976
5092
  };
4977
- var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx, txCtx, nested) => {
5093
+ var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx, txCtx, nested, limits) => {
4978
5094
  const queryArgs = {
4979
5095
  set: {
4980
5096
  type: new import_graphql9.GraphQLNonNull(setArgs)
@@ -5001,7 +5117,8 @@ var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filte
5001
5117
  typeNameMapper,
5002
5118
  table,
5003
5119
  pkNames,
5004
- parsedInfo
5120
+ parsedInfo,
5121
+ limits
5005
5122
  });
5006
5123
  const entry = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
5007
5124
  const nestedOps = entry && nested.hasOps(entry.ops) ? entry.ops : void 0;
@@ -5048,7 +5165,7 @@ var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filte
5048
5165
  args: queryArgs
5049
5166
  };
5050
5167
  };
5051
- var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx, txCtx, nested) => {
5168
+ var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx, txCtx, nested, limits) => {
5052
5169
  const queryArgs = {
5053
5170
  updates: {
5054
5171
  type: new import_graphql9.GraphQLNonNull(new import_graphql9.GraphQLList(new import_graphql9.GraphQLNonNull(updateManyInput)))
@@ -5075,7 +5192,8 @@ var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateMany
5075
5192
  typeNameMapper,
5076
5193
  table,
5077
5194
  pkNames,
5078
- parsedInfo
5195
+ parsedInfo,
5196
+ limits
5079
5197
  });
5080
5198
  const entries = updates.map(({ where, set }) => {
5081
5199
  const split = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
@@ -5193,10 +5311,12 @@ function generateSchemaData2(db, schema, relations, options) {
5193
5311
  typeNameMapper,
5194
5312
  shouldEagerLoad,
5195
5313
  features,
5196
- complexity
5314
+ complexity,
5315
+ limits
5197
5316
  } = options;
5198
5317
  const schemaEntries = Object.entries(schema);
5199
- const tableEntries = schemaEntries.filter(([_key, value]) => (0, import_drizzle_orm8.is)(value, import_pg_core2.PgTable));
5318
+ const excludedTables = new Set(options.exclude?.tables ?? []);
5319
+ const tableEntries = schemaEntries.filter(([key, value]) => (0, import_drizzle_orm8.is)(value, import_pg_core2.PgTable) && !excludedTables.has(key));
5200
5320
  const tables = Object.fromEntries(tableEntries);
5201
5321
  if (!tableEntries.length) {
5202
5322
  throw new Error(
@@ -5205,7 +5325,11 @@ function generateSchemaData2(db, schema, relations, options) {
5205
5325
  }
5206
5326
  registerScalarOverrides(tables, options);
5207
5327
  registerEnumConfig(options);
5328
+ registerColumnExclusions(tables, options.exclude);
5208
5329
  const namedRelations = buildNamedRelations(relations ?? {}, tableEntries);
5330
+ for (const excluded of excludedTables) {
5331
+ delete namedRelations[excluded];
5332
+ }
5209
5333
  attachTargetPrimaryKeys(namedRelations, tables, pgPrimaryKeyPropNames);
5210
5334
  const eagerRelations = pruneNonEagerRelations(namedRelations, shouldEagerLoad);
5211
5335
  const filterCtx = { tables, relationMap: namedRelations };
@@ -5213,7 +5337,8 @@ function generateSchemaData2(db, schema, relations, options) {
5213
5337
  db,
5214
5338
  tables,
5215
5339
  "nulls-largest",
5216
- filterCtx
5340
+ filterCtx,
5341
+ limits
5217
5342
  );
5218
5343
  const cacheCtx = {
5219
5344
  genericFilterCache: /* @__PURE__ */ new Map(),
@@ -5228,6 +5353,7 @@ function generateSchemaData2(db, schema, relations, options) {
5228
5353
  listRelationFilterCache: /* @__PURE__ */ new Map(),
5229
5354
  aggregateTypeCache: /* @__PURE__ */ new Map(),
5230
5355
  complexity,
5356
+ limits,
5231
5357
  docs: options.docs ?? {},
5232
5358
  features
5233
5359
  };
@@ -5297,7 +5423,8 @@ function generateSchemaData2(db, schema, relations, options) {
5297
5423
  typeName,
5298
5424
  typeNameMapper,
5299
5425
  filterCtx,
5300
- features.distinct
5426
+ features.distinct,
5427
+ limits
5301
5428
  );
5302
5429
  const selectSingleGenerated = generateSelectSingle2(
5303
5430
  db,
@@ -5309,7 +5436,8 @@ function generateSchemaData2(db, schema, relations, options) {
5309
5436
  singleFieldName,
5310
5437
  typeName,
5311
5438
  typeNameMapper,
5312
- filterCtx
5439
+ filterCtx,
5440
+ limits
5313
5441
  );
5314
5442
  const insertArrGenerated = features.insert ? generateInsertArray2(
5315
5443
  db,
@@ -5323,7 +5451,8 @@ function generateSchemaData2(db, schema, relations, options) {
5323
5451
  typeNameMapper,
5324
5452
  conflictDoNothing,
5325
5453
  mutationTxCtx,
5326
- nestedRuntime
5454
+ nestedRuntime,
5455
+ limits
5327
5456
  ) : void 0;
5328
5457
  const insertSingleGenerated = features.insert ? generateInsertSingle2(
5329
5458
  db,
@@ -5337,7 +5466,8 @@ function generateSchemaData2(db, schema, relations, options) {
5337
5466
  typeNameMapper,
5338
5467
  conflictDoNothing,
5339
5468
  mutationTxCtx,
5340
- nestedRuntime
5469
+ nestedRuntime,
5470
+ limits
5341
5471
  ) : void 0;
5342
5472
  const uniqueSets = features.upsert ? getUniqueColumnSets(schema[tableName], import_pg_core2.getTableConfig) : [];
5343
5473
  const onConflictInput = features.upsert ? generateOnConflictInput({
@@ -5362,7 +5492,8 @@ function generateSchemaData2(db, schema, relations, options) {
5362
5492
  typeNameMapper,
5363
5493
  filterCtx,
5364
5494
  mutationTxCtx,
5365
- nestedRuntime
5495
+ nestedRuntime,
5496
+ limits
5366
5497
  ) : void 0;
5367
5498
  const upsertSingleGenerated = onConflictInput ? generateUpsert2(
5368
5499
  db,
@@ -5379,7 +5510,8 @@ function generateSchemaData2(db, schema, relations, options) {
5379
5510
  typeNameMapper,
5380
5511
  filterCtx,
5381
5512
  mutationTxCtx,
5382
- nestedRuntime
5513
+ nestedRuntime,
5514
+ limits
5383
5515
  ) : void 0;
5384
5516
  const updateGenerated = features.update ? generateUpdate2(
5385
5517
  db,
@@ -5396,7 +5528,8 @@ function generateSchemaData2(db, schema, relations, options) {
5396
5528
  typeNameMapper,
5397
5529
  filterCtx,
5398
5530
  mutationTxCtx,
5399
- nestedRuntime
5531
+ nestedRuntime,
5532
+ limits
5400
5533
  ) : void 0;
5401
5534
  const updateSingleGenerated = features.update ? generateUpdate2(
5402
5535
  db,
@@ -5413,7 +5546,8 @@ function generateSchemaData2(db, schema, relations, options) {
5413
5546
  typeNameMapper,
5414
5547
  filterCtx,
5415
5548
  mutationTxCtx,
5416
- nestedRuntime
5549
+ nestedRuntime,
5550
+ limits
5417
5551
  ) : void 0;
5418
5552
  const updateManyInput = features.update && features.updateMany ? generateUpdateManyInput({ typeName, updatePrefix: prefixes.update, updateInput, tableFilters }) : void 0;
5419
5553
  const updateManyGenerated = updateManyInput ? generateUpdateMany2(
@@ -5428,7 +5562,8 @@ function generateSchemaData2(db, schema, relations, options) {
5428
5562
  typeNameMapper,
5429
5563
  filterCtx,
5430
5564
  mutationTxCtx,
5431
- nestedRuntime
5565
+ nestedRuntime,
5566
+ limits
5432
5567
  ) : void 0;
5433
5568
  const deleteGenerated = features.delete ? generateDelete2(
5434
5569
  db,
@@ -5508,7 +5643,7 @@ function generateSchemaData2(db, schema, relations, options) {
5508
5643
  type: selectArrOutput,
5509
5644
  args: selectArrGenerated.args,
5510
5645
  resolve: selectArrGenerated.resolver,
5511
- ...complexity ? { extensions: { complexity: listFieldComplexity(complexity) } } : {}
5646
+ ...complexity ? { extensions: { complexity: listFieldComplexity(complexity, limits?.(tableName)) } } : {}
5512
5647
  };
5513
5648
  queries[selectSingleGenerated.name] = {
5514
5649
  type: selectSingleOutput,
@@ -5665,7 +5800,7 @@ var import_drizzle_orm9 = require("drizzle-orm");
5665
5800
  var import_sqlite_core2 = require("drizzle-orm/sqlite-core");
5666
5801
  var import_graphql10 = require("graphql");
5667
5802
  var import_graphql_parse_resolve_info4 = require("graphql-parse-resolve-info");
5668
- var generateSelectArray3 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, distinctEnabled = true) => {
5803
+ var generateSelectArray3 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, distinctEnabled = true, limits) => {
5669
5804
  const queryBase = db.query[tableName];
5670
5805
  if (!queryBase) {
5671
5806
  throw new Error(
@@ -5673,6 +5808,7 @@ var generateSelectArray3 = (db, tableName, tables, relationMap, orderArgs, filte
5673
5808
  );
5674
5809
  }
5675
5810
  const table = tables[tableName];
5811
+ const limitPolicy = limits?.(tableName);
5676
5812
  const pkNames = sqlitePrimaryKeyPropNames(table);
5677
5813
  const queryArgs = selectArrayArgs(
5678
5814
  orderArgs,
@@ -5695,8 +5831,10 @@ var generateSelectArray3 = (db, tableName, tables, relationMap, orderArgs, filte
5695
5831
  typeNameMapper,
5696
5832
  parsedInfo,
5697
5833
  ...args,
5834
+ limit: applyLimitPolicy(args.limit, limitPolicy, fieldName),
5698
5835
  single: false,
5699
5836
  filterCtx,
5837
+ limits,
5700
5838
  pkNames,
5701
5839
  db: executor,
5702
5840
  // SQLite sorts NULLs as the smallest values (first in ASC).
@@ -5709,7 +5847,7 @@ var generateSelectArray3 = (db, tableName, tables, relationMap, orderArgs, filte
5709
5847
  args: queryArgs
5710
5848
  };
5711
5849
  };
5712
- var generateSelectSingle3 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx) => {
5850
+ var generateSelectSingle3 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, limits) => {
5713
5851
  const queryBase = db.query[tableName];
5714
5852
  if (!queryBase) {
5715
5853
  throw new Error(
@@ -5737,6 +5875,7 @@ var generateSelectSingle3 = (db, tableName, tables, relationMap, orderArgs, filt
5737
5875
  ...args,
5738
5876
  single: true,
5739
5877
  filterCtx,
5878
+ limits,
5740
5879
  pkNames,
5741
5880
  db: executor
5742
5881
  });
@@ -5748,7 +5887,7 @@ var generateSelectSingle3 = (db, tableName, tables, relationMap, orderArgs, filt
5748
5887
  };
5749
5888
  };
5750
5889
  var sqlitePrimaryKeyPropNames = (table) => getPrimaryKeyPropNamesFromConfig(table, import_sqlite_core2.getTableConfig);
5751
- var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested) => {
5890
+ var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested, limits) => {
5752
5891
  const queryArgs = {
5753
5892
  values: {
5754
5893
  type: new import_graphql10.GraphQLNonNull(new import_graphql10.GraphQLList(new import_graphql10.GraphQLNonNull(baseType)))
@@ -5777,7 +5916,8 @@ var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType,
5777
5916
  typeNameMapper,
5778
5917
  table,
5779
5918
  pkNames,
5780
- parsedInfo
5919
+ parsedInfo,
5920
+ limits
5781
5921
  });
5782
5922
  const returning = nestedEntries ? nested.withJoinColumns(tableName, mergedOps(nestedEntries), { ...columns }, table) : columns;
5783
5923
  const runInsert = async (target, values) => {
@@ -5805,7 +5945,7 @@ var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType,
5805
5945
  args: queryArgs
5806
5946
  };
5807
5947
  };
5808
- var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested) => {
5948
+ var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested, limits) => {
5809
5949
  const queryArgs = {
5810
5950
  values: {
5811
5951
  type: new import_graphql10.GraphQLNonNull(baseType)
@@ -5831,7 +5971,8 @@ var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType
5831
5971
  typeNameMapper,
5832
5972
  table,
5833
5973
  pkNames,
5834
- parsedInfo
5974
+ parsedInfo,
5975
+ limits
5835
5976
  });
5836
5977
  const returning = nestedEntry ? nested.withJoinColumns(tableName, nestedEntry.ops, { ...columns }, table) : columns;
5837
5978
  const runInsert = async (target, values) => {
@@ -5865,7 +6006,7 @@ var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType
5865
6006
  args: queryArgs
5866
6007
  };
5867
6008
  };
5868
- var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx, txCtx, nested) => {
6009
+ var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx, txCtx, nested, limits) => {
5869
6010
  const queryArgs = {
5870
6011
  values: {
5871
6012
  type: single ? new import_graphql10.GraphQLNonNull(baseType) : new import_graphql10.GraphQLNonNull(new import_graphql10.GraphQLList(new import_graphql10.GraphQLNonNull(baseType)))
@@ -5897,7 +6038,8 @@ var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onCo
5897
6038
  typeNameMapper,
5898
6039
  table,
5899
6040
  pkNames,
5900
- parsedInfo
6041
+ parsedInfo,
6042
+ limits
5901
6043
  });
5902
6044
  const returning = nestedEntries ? nested.withJoinColumns(tableName, mergedOps(nestedEntries), { ...columns }, table) : columns;
5903
6045
  const runUpsert = async (target, values) => {
@@ -5936,7 +6078,7 @@ var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onCo
5936
6078
  args: queryArgs
5937
6079
  };
5938
6080
  };
5939
- var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx, txCtx, nested) => {
6081
+ var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx, txCtx, nested, limits) => {
5940
6082
  const queryArgs = {
5941
6083
  set: {
5942
6084
  type: new import_graphql10.GraphQLNonNull(setArgs)
@@ -5963,7 +6105,8 @@ var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filte
5963
6105
  typeNameMapper,
5964
6106
  table,
5965
6107
  pkNames,
5966
- parsedInfo
6108
+ parsedInfo,
6109
+ limits
5967
6110
  });
5968
6111
  const entry = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
5969
6112
  const nestedOps = entry && nested.hasOps(entry.ops) ? entry.ops : void 0;
@@ -6010,7 +6153,7 @@ var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filte
6010
6153
  args: queryArgs
6011
6154
  };
6012
6155
  };
6013
- var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx, txCtx, nested) => {
6156
+ var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx, txCtx, nested, limits) => {
6014
6157
  const queryArgs = {
6015
6158
  updates: {
6016
6159
  type: new import_graphql10.GraphQLNonNull(new import_graphql10.GraphQLList(new import_graphql10.GraphQLNonNull(updateManyInput)))
@@ -6037,7 +6180,8 @@ var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateMany
6037
6180
  typeNameMapper,
6038
6181
  table,
6039
6182
  pkNames,
6040
- parsedInfo
6183
+ parsedInfo,
6184
+ limits
6041
6185
  });
6042
6186
  const entries = updates.map(({ where, set }) => {
6043
6187
  const split = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
@@ -6183,11 +6327,13 @@ var generateSchemaData3 = (db, schema, relations, options) => {
6183
6327
  typeNameMapper,
6184
6328
  shouldEagerLoad,
6185
6329
  features,
6186
- complexity
6330
+ complexity,
6331
+ limits
6187
6332
  } = options;
6188
6333
  const rawSchema = schema;
6189
6334
  const schemaEntries = Object.entries(rawSchema);
6190
- const tableEntries = schemaEntries.filter(([_key, value]) => (0, import_drizzle_orm9.is)(value, import_sqlite_core2.SQLiteTable));
6335
+ const excludedTables = new Set(options.exclude?.tables ?? []);
6336
+ const tableEntries = schemaEntries.filter(([key, value]) => (0, import_drizzle_orm9.is)(value, import_sqlite_core2.SQLiteTable) && !excludedTables.has(key));
6191
6337
  const tables = Object.fromEntries(tableEntries);
6192
6338
  if (!tableEntries.length) {
6193
6339
  throw new Error(
@@ -6196,7 +6342,11 @@ var generateSchemaData3 = (db, schema, relations, options) => {
6196
6342
  }
6197
6343
  registerScalarOverrides(tables, options);
6198
6344
  registerEnumConfig(options);
6345
+ registerColumnExclusions(tables, options.exclude);
6199
6346
  const namedRelations = buildNamedRelations(relations ?? {}, tableEntries);
6347
+ for (const excluded of excludedTables) {
6348
+ delete namedRelations[excluded];
6349
+ }
6200
6350
  attachTargetPrimaryKeys(namedRelations, tables, sqlitePrimaryKeyPropNames);
6201
6351
  const eagerRelations = pruneNonEagerRelations(namedRelations, shouldEagerLoad);
6202
6352
  const filterCtx = { tables, relationMap: namedRelations };
@@ -6204,7 +6354,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
6204
6354
  db,
6205
6355
  tables,
6206
6356
  "nulls-smallest",
6207
- filterCtx
6357
+ filterCtx,
6358
+ limits
6208
6359
  );
6209
6360
  const cacheCtx = {
6210
6361
  genericFilterCache: /* @__PURE__ */ new Map(),
@@ -6219,6 +6370,7 @@ var generateSchemaData3 = (db, schema, relations, options) => {
6219
6370
  listRelationFilterCache: /* @__PURE__ */ new Map(),
6220
6371
  aggregateTypeCache: /* @__PURE__ */ new Map(),
6221
6372
  complexity,
6373
+ limits,
6222
6374
  docs: options.docs ?? {},
6223
6375
  features
6224
6376
  };
@@ -6298,7 +6450,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
6298
6450
  typeName,
6299
6451
  typeNameMapper,
6300
6452
  filterCtx,
6301
- features.distinct
6453
+ features.distinct,
6454
+ limits
6302
6455
  );
6303
6456
  const selectSingleGenerated = generateSelectSingle3(
6304
6457
  db,
@@ -6310,7 +6463,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
6310
6463
  singleFieldName,
6311
6464
  typeName,
6312
6465
  typeNameMapper,
6313
- filterCtx
6466
+ filterCtx,
6467
+ limits
6314
6468
  );
6315
6469
  const insertArrGenerated = features.insert ? generateInsertArray3(
6316
6470
  db,
@@ -6324,7 +6478,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
6324
6478
  typeNameMapper,
6325
6479
  conflictDoNothing,
6326
6480
  mutationTxCtx,
6327
- nestedRuntime
6481
+ nestedRuntime,
6482
+ limits
6328
6483
  ) : void 0;
6329
6484
  const insertSingleGenerated = features.insert ? generateInsertSingle3(
6330
6485
  db,
@@ -6338,7 +6493,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
6338
6493
  typeNameMapper,
6339
6494
  conflictDoNothing,
6340
6495
  mutationTxCtx,
6341
- nestedRuntime
6496
+ nestedRuntime,
6497
+ limits
6342
6498
  ) : void 0;
6343
6499
  const uniqueSets = features.upsert ? getUniqueColumnSets(schema[tableName], import_sqlite_core2.getTableConfig) : [];
6344
6500
  const onConflictInput = features.upsert ? generateOnConflictInput({
@@ -6363,7 +6519,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
6363
6519
  typeNameMapper,
6364
6520
  filterCtx,
6365
6521
  mutationTxCtx,
6366
- nestedRuntime
6522
+ nestedRuntime,
6523
+ limits
6367
6524
  ) : void 0;
6368
6525
  const upsertSingleGenerated = onConflictInput ? generateUpsert3(
6369
6526
  db,
@@ -6380,7 +6537,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
6380
6537
  typeNameMapper,
6381
6538
  filterCtx,
6382
6539
  mutationTxCtx,
6383
- nestedRuntime
6540
+ nestedRuntime,
6541
+ limits
6384
6542
  ) : void 0;
6385
6543
  const updateGenerated = features.update ? generateUpdate3(
6386
6544
  db,
@@ -6397,7 +6555,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
6397
6555
  typeNameMapper,
6398
6556
  filterCtx,
6399
6557
  mutationTxCtx,
6400
- nestedRuntime
6558
+ nestedRuntime,
6559
+ limits
6401
6560
  ) : void 0;
6402
6561
  const updateSingleGenerated = features.update ? generateUpdate3(
6403
6562
  db,
@@ -6414,7 +6573,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
6414
6573
  typeNameMapper,
6415
6574
  filterCtx,
6416
6575
  mutationTxCtx,
6417
- nestedRuntime
6576
+ nestedRuntime,
6577
+ limits
6418
6578
  ) : void 0;
6419
6579
  const updateManyInput = features.update && features.updateMany ? generateUpdateManyInput({ typeName, updatePrefix: prefixes.update, updateInput, tableFilters }) : void 0;
6420
6580
  const updateManyGenerated = updateManyInput ? generateUpdateMany3(
@@ -6429,7 +6589,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
6429
6589
  typeNameMapper,
6430
6590
  filterCtx,
6431
6591
  mutationTxCtx,
6432
- nestedRuntime
6592
+ nestedRuntime,
6593
+ limits
6433
6594
  ) : void 0;
6434
6595
  const deleteGenerated = features.delete ? generateDelete3(
6435
6596
  db,
@@ -6509,7 +6670,7 @@ var generateSchemaData3 = (db, schema, relations, options) => {
6509
6670
  type: selectArrOutput,
6510
6671
  args: selectArrGenerated.args,
6511
6672
  resolve: selectArrGenerated.resolver,
6512
- ...complexity ? { extensions: { complexity: listFieldComplexity(complexity) } } : {}
6673
+ ...complexity ? { extensions: { complexity: listFieldComplexity(complexity, limits?.(tableName)) } } : {}
6513
6674
  };
6514
6675
  queries[selectSingleGenerated.name] = {
6515
6676
  type: selectSingleOutput,
@@ -6705,6 +6866,76 @@ var buildSchema = (db, config) => {
6705
6866
  };
6706
6867
  const transactionsOpt = config?.transactions;
6707
6868
  const transactions = transactionsOpt === void 0 || transactionsOpt === "none" ? void 0 : { timeoutMs: (transactionsOpt === "auto" ? void 0 : transactionsOpt.timeoutMs) ?? 3e4 };
6869
+ const limitsConfig = config?.limits;
6870
+ if (limitsConfig) {
6871
+ const check = (policy, where) => {
6872
+ for (const key of ["defaultLimit", "maxLimit"]) {
6873
+ const value = policy[key];
6874
+ if (value === void 0) {
6875
+ continue;
6876
+ }
6877
+ if (!Number.isInteger(value) || value < 1) {
6878
+ throw new Error(`Drizzle-GraphQL Error: config.limits${where}.${key} must be a positive integer.`);
6879
+ }
6880
+ }
6881
+ };
6882
+ check(limitsConfig, "");
6883
+ for (const [tableName, policy] of Object.entries(limitsConfig.tables ?? {})) {
6884
+ check(policy, `.tables.${tableName}`);
6885
+ }
6886
+ }
6887
+ const limitPolicyCache = /* @__PURE__ */ new Map();
6888
+ const limits = limitsConfig ? (tableName) => {
6889
+ if (limitPolicyCache.has(tableName)) {
6890
+ return limitPolicyCache.get(tableName);
6891
+ }
6892
+ const resolved = resolveLimitPolicy(limitsConfig, limitsConfig.tables?.[tableName]);
6893
+ limitPolicyCache.set(tableName, resolved);
6894
+ return resolved;
6895
+ } : void 0;
6896
+ const exclude = config?.exclude;
6897
+ if (exclude) {
6898
+ const tableNames = new Set(
6899
+ Object.entries(schema).filter(([, value]) => (0, import_drizzle_orm10.is)(value, import_drizzle_orm10.Table)).map(([key]) => key)
6900
+ );
6901
+ const excludedTables = new Set(exclude.tables ?? []);
6902
+ for (const tableName of excludedTables) {
6903
+ if (!tableNames.has(tableName)) {
6904
+ throw new Error(
6905
+ `Drizzle-GraphQL Error: config.exclude.tables names '${tableName}', which is not a table in the Drizzle schema.`
6906
+ );
6907
+ }
6908
+ }
6909
+ if (excludedTables.size >= tableNames.size) {
6910
+ throw new Error(
6911
+ "Drizzle-GraphQL Error: config.exclude.tables excludes every table in the schema, leaving nothing to generate."
6912
+ );
6913
+ }
6914
+ for (const [tableName, columnNames] of Object.entries(exclude.columns ?? {})) {
6915
+ if (!tableNames.has(tableName)) {
6916
+ throw new Error(
6917
+ `Drizzle-GraphQL Error: config.exclude.columns names table '${tableName}', which is not a table in the Drizzle schema.`
6918
+ );
6919
+ }
6920
+ if (excludedTables.has(tableName)) {
6921
+ continue;
6922
+ }
6923
+ const columns = (0, import_drizzle_orm10.getColumns)(schema[tableName]);
6924
+ for (const columnName of columnNames) {
6925
+ const column = columns[columnName];
6926
+ if (!column) {
6927
+ throw new Error(
6928
+ `Drizzle-GraphQL Error: config.exclude.columns names '${tableName}.${columnName}', which is not a column of that table.`
6929
+ );
6930
+ }
6931
+ if (column.notNull && !column.hasDefault && !column.defaultFn) {
6932
+ console.warn(
6933
+ `Drizzle-GraphQL Warning: excluded column '${tableName}.${columnName}' is NOT NULL with no default, so generated inserts for '${tableName}' can never succeed.`
6934
+ );
6935
+ }
6936
+ }
6937
+ }
6938
+ }
6708
6939
  const eagerOpt = config?.eagerLoadRelations;
6709
6940
  const shouldEagerLoad = eagerOpt === void 0 || eagerOpt === true ? () => true : eagerOpt === false ? () => false : eagerOpt;
6710
6941
  if (!typeNameMapper && suffixes.list === suffixes.single) {
@@ -6737,6 +6968,8 @@ var buildSchema = (db, config) => {
6737
6968
  mapColumnType: config?.mapColumnType,
6738
6969
  enumNameMapper: config?.enumNameMapper,
6739
6970
  transactions,
6971
+ limits,
6972
+ exclude,
6740
6973
  docs: {
6741
6974
  describeColumn: config?.describeColumn,
6742
6975
  describeTable: config?.describeTable,