@vantreeseba/drizzle-graphql 5.5.0 → 6.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,11 +45,11 @@ __export(index_exports, {
45
45
  extractRelationJoinColumns: () => extractRelationJoinColumns
46
46
  });
47
47
  module.exports = __toCommonJS(index_exports);
48
- var import_drizzle_orm8 = require("drizzle-orm");
48
+ var import_drizzle_orm9 = 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_graphql9 = require("graphql");
52
+ var import_graphql10 = require("graphql");
53
53
 
54
54
  // src/util/builders/common.ts
55
55
  var import_drizzle_orm3 = require("drizzle-orm");
@@ -107,8 +107,293 @@ var uncapitalize = (input) => input?.length ? `${input[0].toLocaleLowerCase()}${
107
107
  var capitalize = (input) => input?.length ? `${input[0].toLocaleUpperCase()}${input.length > 1 ? input.slice(1, input.length) : ""}` : input;
108
108
 
109
109
  // src/util/data-mappers/index.ts
110
+ var import_drizzle_orm2 = require("drizzle-orm");
111
+ var import_graphql3 = require("graphql");
112
+
113
+ // src/util/type-converter/index.ts
110
114
  var import_drizzle_orm = require("drizzle-orm");
115
+ var import_mysql_core = require("drizzle-orm/mysql-core");
116
+ var import_pg_core = require("drizzle-orm/pg-core");
117
+ var import_sqlite_core = require("drizzle-orm/sqlite-core");
118
+ var import_graphql2 = require("graphql");
119
+
120
+ // src/util/scalars/index.ts
111
121
  var import_graphql = require("graphql");
122
+ var import_graphql_scalars = require("graphql-scalars");
123
+ var asDecimalString = (value) => {
124
+ if (typeof value === "bigint") {
125
+ return value.toString();
126
+ }
127
+ if (typeof value === "number") {
128
+ if (!Number.isInteger(value)) {
129
+ throw new import_graphql.GraphQLError(`BigInt cannot represent non-integer value: ${value}`);
130
+ }
131
+ if (!Number.isSafeInteger(value)) {
132
+ throw new import_graphql.GraphQLError(
133
+ `BigInt cannot represent the number ${value} without precision loss \u2014 pass it as a string instead`
134
+ );
135
+ }
136
+ return String(value);
137
+ }
138
+ if (typeof value === "string") {
139
+ if (!/^-?\d+$/.test(value)) {
140
+ throw new import_graphql.GraphQLError(`BigInt cannot represent non-integer value: "${value}"`);
141
+ }
142
+ return value;
143
+ }
144
+ throw new import_graphql.GraphQLError(`BigInt cannot represent value: ${JSON.stringify(value)}`);
145
+ };
146
+ var GraphQLBigIntString = new import_graphql.GraphQLScalarType({
147
+ name: "BigInt",
148
+ description: "A 64-bit integer, transported as a decimal string so that values beyond JavaScript's safe integer range survive the round-trip intact.",
149
+ serialize: asDecimalString,
150
+ parseValue: asDecimalString,
151
+ parseLiteral: (ast) => {
152
+ if (ast.kind !== import_graphql.Kind.STRING && ast.kind !== import_graphql.Kind.INT) {
153
+ throw new import_graphql.GraphQLError(`BigInt cannot represent a ${ast.kind}`, { nodes: ast });
154
+ }
155
+ return asDecimalString(ast.value);
156
+ }
157
+ });
158
+ var numericStringPattern = /^[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?$/;
159
+ var asNumericString = (value) => {
160
+ if (typeof value === "bigint") {
161
+ return value.toString();
162
+ }
163
+ if (typeof value === "number") {
164
+ if (!Number.isFinite(value)) {
165
+ throw new import_graphql.GraphQLError(`Decimal cannot represent non-finite value: ${value}`);
166
+ }
167
+ return String(value);
168
+ }
169
+ if (typeof value === "string") {
170
+ if (!numericStringPattern.test(value)) {
171
+ throw new import_graphql.GraphQLError(`Decimal cannot represent non-numeric value: "${value}"`);
172
+ }
173
+ return value;
174
+ }
175
+ throw new import_graphql.GraphQLError(`Decimal cannot represent value: ${JSON.stringify(value)}`);
176
+ };
177
+ var GraphQLDecimalString = new import_graphql.GraphQLScalarType({
178
+ name: "Decimal",
179
+ description: "An arbitrary-precision decimal, transported as a numeric string so that values beyond JavaScript's double-precision range survive the round-trip intact.",
180
+ serialize: asNumericString,
181
+ parseValue: asNumericString,
182
+ parseLiteral: (ast) => {
183
+ if (ast.kind !== import_graphql.Kind.STRING && ast.kind !== import_graphql.Kind.INT && ast.kind !== import_graphql.Kind.FLOAT) {
184
+ throw new import_graphql.GraphQLError(`Decimal cannot represent a ${ast.kind}`, { nodes: ast });
185
+ }
186
+ return asNumericString(ast.value);
187
+ }
188
+ });
189
+
190
+ // src/util/type-converter/index.ts
191
+ var allowedNameChars = /^[a-zA-Z0-9_]+$/;
192
+ var declaredEnum = (column) => {
193
+ const declared = column.enum;
194
+ return typeof declared?.enumName === "string" ? { enumName: declared.enumName, schema: typeof declared.schema === "string" ? declared.schema : void 0 } : void 0;
195
+ };
196
+ var pascalize = (input) => input.split(/[^a-zA-Z0-9]+/).filter(Boolean).map((part) => capitalize(part)).join("");
197
+ var enumValuesKey = (values) => JSON.stringify(values);
198
+ var enumNamesInUse = /* @__PURE__ */ new Map();
199
+ var enumNameMapper;
200
+ var registerEnumConfig = (config) => {
201
+ enumNameMapper = config.enumNameMapper;
202
+ enumNamesInUse = /* @__PURE__ */ new Map();
203
+ };
204
+ var generateEnumCached = (column, columnName, tableName) => {
205
+ const declared = declaredEnum(column);
206
+ const values = column.enumValues;
207
+ const name = enumNameMapper?.({
208
+ enumName: declared?.enumName,
209
+ schema: declared?.schema,
210
+ tableName,
211
+ columnName,
212
+ values
213
+ }) ?? (declared ? `${pascalize(declared.enumName)}Enum` : `${capitalize(tableName)}${capitalize(columnName)}Enum`);
214
+ const valuesKey = enumValuesKey(values);
215
+ const claimed = enumNamesInUse.get(name);
216
+ if (claimed) {
217
+ if (claimed.valuesKey !== valuesKey) {
218
+ throw new Error(
219
+ `Drizzle-GraphQL Error: Two different enums both map to the GraphQL type name '${name}' (most recently '${tableName}.${columnName}'). Give one of them a different name via config.enumNameMapper.`
220
+ );
221
+ }
222
+ return claimed.type;
223
+ }
224
+ const gqlEnum = new import_graphql2.GraphQLEnumType({
225
+ name,
226
+ values: Object.fromEntries(
227
+ values.map((e, index) => [
228
+ allowedNameChars.test(e) ? e : `Option${index}`,
229
+ {
230
+ value: e,
231
+ description: `Value: ${e}`
232
+ }
233
+ ])
234
+ )
235
+ });
236
+ enumNamesInUse.set(name, { type: gqlEnum, valuesKey });
237
+ return gqlEnum;
238
+ };
239
+ var geoXyType = new import_graphql2.GraphQLObjectType({
240
+ name: "PgGeometryObject",
241
+ fields: {
242
+ x: { type: import_graphql2.GraphQLFloat },
243
+ y: { type: import_graphql2.GraphQLFloat }
244
+ }
245
+ });
246
+ var geoXyInputType = new import_graphql2.GraphQLInputObjectType({
247
+ name: "PgGeometryObjectInput",
248
+ fields: {
249
+ x: { type: import_graphql2.GraphQLFloat },
250
+ y: { type: import_graphql2.GraphQLFloat }
251
+ }
252
+ });
253
+ var columnToGraphQLCore = (column, columnName, tableName, isInput) => {
254
+ const dimensions = column.dimensions;
255
+ if (dimensions !== void 0 && dimensions > 0) {
256
+ const inner = columnBaseToGraphQLCore(column, columnName, tableName, isInput);
257
+ const innerLabel = inner.typeLabel ?? inner.type.name;
258
+ let type = inner.type;
259
+ let typeLabel = innerLabel;
260
+ for (let i = 0; i < dimensions; i++) {
261
+ type = new import_graphql2.GraphQLList(new import_graphql2.GraphQLNonNull(type));
262
+ typeLabel = `Array<${typeLabel}>`;
263
+ }
264
+ return { type, typeLabel };
265
+ }
266
+ return columnBaseToGraphQLCore(column, columnName, tableName, isInput);
267
+ };
268
+ var columnBaseToGraphQLCore = (column, columnName, tableName, isInput) => {
269
+ const { type: baseType, constraint } = (0, import_drizzle_orm.extractExtendedColumnType)(column);
270
+ switch (baseType) {
271
+ case "boolean":
272
+ return { type: import_graphql2.GraphQLBoolean, typeLabel: "Boolean" };
273
+ case "object":
274
+ if (column instanceof import_pg_core.PgTimestamp || column instanceof import_pg_core.PgDate) {
275
+ return { type: import_graphql_scalars.GraphQLDateTime, typeLabel: "DateTime" };
276
+ }
277
+ return column.columnType === "PgGeometryObject" ? {
278
+ type: isInput ? geoXyInputType : geoXyType,
279
+ typeLabel: "Geometry points XY"
280
+ } : column.columnType === "PgBytea" ? {
281
+ type: new import_graphql2.GraphQLList(new import_graphql2.GraphQLNonNull(import_graphql2.GraphQLInt)),
282
+ typeLabel: "Buffer"
283
+ } : { type: import_graphql_scalars.GraphQLJSON, typeLabel: "JSON" };
284
+ case "string":
285
+ if (column.enumValues?.length) {
286
+ return { type: generateEnumCached(column, columnName, tableName) };
287
+ }
288
+ if (constraint === "numeric" && !column.dimensions) {
289
+ return { type: GraphQLDecimalString, typeLabel: "Decimal" };
290
+ }
291
+ if (column instanceof import_pg_core.PgTimestamp || column instanceof import_pg_core.PgTimestampString) {
292
+ return { type: import_graphql_scalars.GraphQLDateTime, typeLabel: "DateTime" };
293
+ }
294
+ if (column instanceof import_pg_core.PgUUID) {
295
+ return { type: import_graphql_scalars.GraphQLUUID, typeLabel: "UUID" };
296
+ }
297
+ if (column instanceof import_pg_core.PgDateString) {
298
+ return isInput ? { type: import_graphql2.GraphQLString, typeLabel: "Date" } : { type: import_graphql_scalars.GraphQLDate, typeLabel: "Date" };
299
+ }
300
+ return { type: import_graphql2.GraphQLString, typeLabel: "String" };
301
+ case "bigint":
302
+ return { type: GraphQLBigIntString, typeLabel: "BigInt" };
303
+ case "number": {
304
+ return (0, import_drizzle_orm.is)(column, import_pg_core.PgInteger) || (0, import_drizzle_orm.is)(column, import_pg_core.PgSerial) || (0, import_drizzle_orm.is)(column, import_mysql_core.MySqlInt) || (0, import_drizzle_orm.is)(column, import_mysql_core.MySqlSerial) || (0, import_drizzle_orm.is)(column, import_sqlite_core.SQLiteInteger) ? { type: import_graphql2.GraphQLInt, typeLabel: "Integer" } : { type: import_graphql2.GraphQLFloat, typeLabel: "Float" };
305
+ }
306
+ case "array": {
307
+ if (column.columnType === "PgVector") {
308
+ return {
309
+ type: new import_graphql2.GraphQLList(new import_graphql2.GraphQLNonNull(import_graphql2.GraphQLFloat)),
310
+ typeLabel: "Array<Float>"
311
+ };
312
+ }
313
+ if (column.columnType === "PgGeometry") {
314
+ return {
315
+ type: new import_graphql2.GraphQLList(new import_graphql2.GraphQLNonNull(import_graphql2.GraphQLFloat)),
316
+ typeLabel: "Tuple<[Float, Float]>"
317
+ };
318
+ }
319
+ const innerType = columnToGraphQLCore(
320
+ column.baseColumn,
321
+ columnName,
322
+ tableName,
323
+ isInput
324
+ );
325
+ return {
326
+ type: new import_graphql2.GraphQLList(new import_graphql2.GraphQLNonNull(innerType.type)),
327
+ typeLabel: `Array<${innerType.typeLabel}>`
328
+ };
329
+ }
330
+ default:
331
+ throw new Error(`Drizzle-GraphQL Error: Type ${column.dataType} is not implemented!`);
332
+ }
333
+ };
334
+ var columnScalarOverrides = /* @__PURE__ */ new WeakMap();
335
+ var getColumnScalarOverride = (column, isInput) => {
336
+ const override = columnScalarOverrides.get(column);
337
+ return override ? isInput ? override.input : override.output : void 0;
338
+ };
339
+ var normalizeScalarOverride = (override, tableName, columnName) => {
340
+ const pair = override instanceof import_graphql2.GraphQLScalarType ? { output: override, input: override } : { output: override.output, input: override.input };
341
+ for (const scalar of [pair.output, pair.input]) {
342
+ if (scalar !== void 0 && !(scalar instanceof import_graphql2.GraphQLScalarType)) {
343
+ throw new Error(
344
+ `Drizzle-GraphQL Error: Scalar override for column '${tableName}.${columnName}' must be a GraphQLScalarType!`
345
+ );
346
+ }
347
+ }
348
+ return pair;
349
+ };
350
+ var registerScalarOverrides = (tables, config) => {
351
+ for (const [tableName, table] of Object.entries(tables)) {
352
+ for (const [columnName, column] of Object.entries((0, import_drizzle_orm.getTableColumns)(table))) {
353
+ const declared = config.scalars?.[tableName]?.[columnName];
354
+ let resolved;
355
+ if (declared !== void 0) {
356
+ resolved = normalizeScalarOverride(declared, tableName, columnName);
357
+ } else if (config.mapColumnType) {
358
+ let defaultType;
359
+ let defaultInputType;
360
+ try {
361
+ defaultType = columnToGraphQLCore(column, columnName, tableName, false).type;
362
+ } catch {
363
+ }
364
+ try {
365
+ defaultInputType = columnToGraphQLCore(column, columnName, tableName, true).type;
366
+ } catch {
367
+ }
368
+ const mapped = config.mapColumnType(column, { tableName, columnName, defaultType, defaultInputType });
369
+ if (mapped !== void 0) {
370
+ resolved = normalizeScalarOverride(mapped, tableName, columnName);
371
+ }
372
+ }
373
+ if (resolved && (resolved.output !== void 0 || resolved.input !== void 0)) {
374
+ columnScalarOverrides.set(column, resolved);
375
+ } else {
376
+ columnScalarOverrides.delete(column);
377
+ }
378
+ }
379
+ }
380
+ };
381
+ var drizzleColumnToGraphQLType = (column, columnName, tableName, forceNullable = false, defaultIsNullable = false, isInput = false) => {
382
+ const override = getColumnScalarOverride(column, isInput);
383
+ const typeDesc = override ? { type: override, typeLabel: override.name } : columnToGraphQLCore(column, columnName, tableName, isInput);
384
+ if (forceNullable) {
385
+ return typeDesc;
386
+ }
387
+ if (column.notNull && !(defaultIsNullable && (column.hasDefault || column.defaultFn))) {
388
+ return {
389
+ type: new import_graphql2.GraphQLNonNull(typeDesc.type),
390
+ typeLabel: typeDesc.typeLabel
391
+ };
392
+ }
393
+ return typeDesc;
394
+ };
395
+
396
+ // src/util/data-mappers/index.ts
112
397
  var isJsonColumn = (column) => (column.dataType ?? "").includes("json") && column.columnType !== "PgGeometryObject";
113
398
  var remapToGraphQLCore = (key, value, tableName, column, relationMap) => {
114
399
  if (Array.isArray(value)) {
@@ -139,6 +424,9 @@ var remapToGraphQLCore = (key, value, tableName, column, relationMap) => {
139
424
  if (!column) {
140
425
  return value;
141
426
  }
427
+ if (getColumnScalarOverride(column, false)) {
428
+ return value;
429
+ }
142
430
  if (isJsonColumn(column)) {
143
431
  return value;
144
432
  }
@@ -169,7 +457,7 @@ var remapToGraphQLSingleOutput = (queryOutput, tableName, table, relationMap) =>
169
457
  for (const [key, value] of Object.entries(queryOutput)) {
170
458
  if (value === void 0 || value === null) {
171
459
  const relEntry = value === null ? relationMap?.[tableName]?.[key] : void 0;
172
- if (relEntry && (0, import_drizzle_orm.is)(relEntry.relation, import_drizzle_orm.One)) {
460
+ if (relEntry && (0, import_drizzle_orm2.is)(relEntry.relation, import_drizzle_orm2.One)) {
173
461
  queryOutput[key] = null;
174
462
  continue;
175
463
  }
@@ -192,13 +480,19 @@ var remapToGraphQLArrayOutput = (queryOutput, tableName, table, relationMap) =>
192
480
  return queryOutput;
193
481
  };
194
482
  var remapFromGraphQLCore = (value, column, columnName) => {
483
+ if (getColumnScalarOverride(column, true)) {
484
+ if (typeof value === "object" && value !== null && Object.getPrototypeOf(value) === null) {
485
+ return Object.assign({}, value);
486
+ }
487
+ return value;
488
+ }
195
489
  const dataType = column.dataType ?? "";
196
490
  const columnType = column.columnType ?? "";
197
491
  const isTimestampColumn = columnType === "SQLiteTimestamp" || columnType === "SQLiteTimestampMs" || columnType === "MySqlTimestamp" || columnType === "MySqlDateTime" || columnType === "PgTimestamp" || columnType === "PgTimestampString";
198
492
  if (isTimestampColumn) {
199
493
  const formatted = new Date(value);
200
494
  if (Number.isNaN(formatted.getTime())) {
201
- throw new import_graphql.GraphQLError(`Field '${columnName}' is not a valid date!`);
495
+ throw new import_graphql3.GraphQLError(`Field '${columnName}' is not a valid date!`);
202
496
  }
203
497
  return formatted;
204
498
  }
@@ -207,7 +501,7 @@ var remapFromGraphQLCore = (value, column, columnName) => {
207
501
  const dateOnly = value.includes("T") ? value.split("T")[0] : value;
208
502
  const check = new Date(dateOnly);
209
503
  if (Number.isNaN(check.getTime())) {
210
- throw new import_graphql.GraphQLError(`Field '${columnName}' is not a valid date!`);
504
+ throw new import_graphql3.GraphQLError(`Field '${columnName}' is not a valid date!`);
211
505
  }
212
506
  return dateOnly;
213
507
  }
@@ -215,7 +509,7 @@ var remapFromGraphQLCore = (value, column, columnName) => {
215
509
  try {
216
510
  return BigInt(value);
217
511
  } catch {
218
- throw new import_graphql.GraphQLError(`Field '${columnName}' is not a BigInt!`);
512
+ throw new import_graphql3.GraphQLError(`Field '${columnName}' is not a BigInt!`);
219
513
  }
220
514
  }
221
515
  if (dataType.includes("json") && column.columnType !== "PgGeometryObject") {
@@ -225,13 +519,13 @@ var remapFromGraphQLCore = (value, column, columnName) => {
225
519
  case "date": {
226
520
  const formatted = new Date(value);
227
521
  if (Number.isNaN(formatted.getTime())) {
228
- throw new import_graphql.GraphQLError(`Field '${columnName}' is not a valid date!`);
522
+ throw new import_graphql3.GraphQLError(`Field '${columnName}' is not a valid date!`);
229
523
  }
230
524
  return formatted;
231
525
  }
232
526
  case "buffer": {
233
527
  if (!Array.isArray(value)) {
234
- throw new import_graphql.GraphQLError(`Field '${columnName}' is not an array!`);
528
+ throw new import_graphql3.GraphQLError(`Field '${columnName}' is not an array!`);
235
529
  }
236
530
  return Buffer.from(value);
237
531
  }
@@ -242,7 +536,7 @@ var remapFromGraphQLCore = (value, column, columnName) => {
242
536
  try {
243
537
  return JSON.parse(value);
244
538
  } catch (e) {
245
- throw new import_graphql.GraphQLError(
539
+ throw new import_graphql3.GraphQLError(
246
540
  `Invalid JSON in field '${columnName}':
247
541
  ${e instanceof Error ? e.message : "Unknown error"}`
248
542
  );
@@ -250,10 +544,10 @@ ${e instanceof Error ? e.message : "Unknown error"}`
250
544
  }
251
545
  case "array": {
252
546
  if (!Array.isArray(value)) {
253
- throw new import_graphql.GraphQLError(`Field '${columnName}' is not an array!`);
547
+ throw new import_graphql3.GraphQLError(`Field '${columnName}' is not an array!`);
254
548
  }
255
549
  if (column.columnType === "PgGeometry" && value.length !== 2) {
256
- throw new import_graphql.GraphQLError(
550
+ throw new import_graphql3.GraphQLError(
257
551
  `Invalid float tuple in field '${columnName}': expected array with length of 2, received ${value.length}`
258
552
  );
259
553
  }
@@ -263,7 +557,7 @@ ${e instanceof Error ? e.message : "Unknown error"}`
263
557
  try {
264
558
  return BigInt(value);
265
559
  } catch (_error) {
266
- throw new import_graphql.GraphQLError(`Field '${columnName}' is not a BigInt!`);
560
+ throw new import_graphql3.GraphQLError(`Field '${columnName}' is not a BigInt!`);
267
561
  }
268
562
  }
269
563
  default: {
@@ -279,9 +573,9 @@ var remapFromGraphQLSingleInput = (queryInput, table) => {
279
573
  if (value === void 0) {
280
574
  delete queryInput[key];
281
575
  } else {
282
- const column = (0, import_drizzle_orm.getTableColumns)(table)[key];
576
+ const column = (0, import_drizzle_orm2.getTableColumns)(table)[key];
283
577
  if (!column) {
284
- throw new import_graphql.GraphQLError(`Unknown column: ${key}`);
578
+ throw new import_graphql3.GraphQLError(`Unknown column: ${key}`);
285
579
  }
286
580
  if (value === null && column.notNull) {
287
581
  delete queryInput[key];
@@ -299,217 +593,6 @@ var remapFromGraphQLArrayInput = (queryInput, table) => {
299
593
  return queryInput;
300
594
  };
301
595
 
302
- // src/util/scalars/index.ts
303
- var import_graphql2 = require("graphql");
304
- var import_graphql_scalars = require("graphql-scalars");
305
- var asDecimalString = (value) => {
306
- if (typeof value === "bigint") {
307
- return value.toString();
308
- }
309
- if (typeof value === "number") {
310
- if (!Number.isInteger(value)) {
311
- throw new import_graphql2.GraphQLError(`BigInt cannot represent non-integer value: ${value}`);
312
- }
313
- if (!Number.isSafeInteger(value)) {
314
- throw new import_graphql2.GraphQLError(
315
- `BigInt cannot represent the number ${value} without precision loss \u2014 pass it as a string instead`
316
- );
317
- }
318
- return String(value);
319
- }
320
- if (typeof value === "string") {
321
- if (!/^-?\d+$/.test(value)) {
322
- throw new import_graphql2.GraphQLError(`BigInt cannot represent non-integer value: "${value}"`);
323
- }
324
- return value;
325
- }
326
- throw new import_graphql2.GraphQLError(`BigInt cannot represent value: ${JSON.stringify(value)}`);
327
- };
328
- var GraphQLBigIntString = new import_graphql2.GraphQLScalarType({
329
- name: "BigInt",
330
- description: "A 64-bit integer, transported as a decimal string so that values beyond JavaScript's safe integer range survive the round-trip intact.",
331
- serialize: asDecimalString,
332
- parseValue: asDecimalString,
333
- parseLiteral: (ast) => {
334
- if (ast.kind !== import_graphql2.Kind.STRING && ast.kind !== import_graphql2.Kind.INT) {
335
- throw new import_graphql2.GraphQLError(`BigInt cannot represent a ${ast.kind}`, { nodes: ast });
336
- }
337
- return asDecimalString(ast.value);
338
- }
339
- });
340
- var numericStringPattern = /^[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?$/;
341
- var asNumericString = (value) => {
342
- if (typeof value === "bigint") {
343
- return value.toString();
344
- }
345
- if (typeof value === "number") {
346
- if (!Number.isFinite(value)) {
347
- throw new import_graphql2.GraphQLError(`Decimal cannot represent non-finite value: ${value}`);
348
- }
349
- return String(value);
350
- }
351
- if (typeof value === "string") {
352
- if (!numericStringPattern.test(value)) {
353
- throw new import_graphql2.GraphQLError(`Decimal cannot represent non-numeric value: "${value}"`);
354
- }
355
- return value;
356
- }
357
- throw new import_graphql2.GraphQLError(`Decimal cannot represent value: ${JSON.stringify(value)}`);
358
- };
359
- var GraphQLDecimalString = new import_graphql2.GraphQLScalarType({
360
- name: "Decimal",
361
- description: "An arbitrary-precision decimal, transported as a numeric string so that values beyond JavaScript's double-precision range survive the round-trip intact.",
362
- serialize: asNumericString,
363
- parseValue: asNumericString,
364
- parseLiteral: (ast) => {
365
- if (ast.kind !== import_graphql2.Kind.STRING && ast.kind !== import_graphql2.Kind.INT && ast.kind !== import_graphql2.Kind.FLOAT) {
366
- throw new import_graphql2.GraphQLError(`Decimal cannot represent a ${ast.kind}`, { nodes: ast });
367
- }
368
- return asNumericString(ast.value);
369
- }
370
- });
371
-
372
- // src/util/type-converter/index.ts
373
- var import_drizzle_orm2 = require("drizzle-orm");
374
- var import_mysql_core = require("drizzle-orm/mysql-core");
375
- var import_pg_core = require("drizzle-orm/pg-core");
376
- var import_sqlite_core = require("drizzle-orm/sqlite-core");
377
- var import_graphql3 = require("graphql");
378
- var allowedNameChars = /^[a-zA-Z0-9_]+$/;
379
- var enumMap = /* @__PURE__ */ new WeakMap();
380
- var generateEnumCached = (column, columnName, tableName) => {
381
- if (enumMap.has(column)) {
382
- return enumMap.get(column);
383
- }
384
- const gqlEnum = new import_graphql3.GraphQLEnumType({
385
- name: `${capitalize(tableName)}${capitalize(columnName)}Enum`,
386
- values: Object.fromEntries(
387
- column.enumValues.map((e, index) => [
388
- allowedNameChars.test(e) ? e : `Option${index}`,
389
- {
390
- value: e,
391
- description: `Value: ${e}`
392
- }
393
- ])
394
- )
395
- });
396
- enumMap.set(column, gqlEnum);
397
- return gqlEnum;
398
- };
399
- var geoXyType = new import_graphql3.GraphQLObjectType({
400
- name: "PgGeometryObject",
401
- fields: {
402
- x: { type: import_graphql3.GraphQLFloat },
403
- y: { type: import_graphql3.GraphQLFloat }
404
- }
405
- });
406
- var geoXyInputType = new import_graphql3.GraphQLInputObjectType({
407
- name: "PgGeometryObjectInput",
408
- fields: {
409
- x: { type: import_graphql3.GraphQLFloat },
410
- y: { type: import_graphql3.GraphQLFloat }
411
- }
412
- });
413
- var columnToGraphQLCore = (column, columnName, tableName, isInput) => {
414
- const dimensions = column.dimensions;
415
- if (dimensions !== void 0 && dimensions > 0) {
416
- const inner = columnBaseToGraphQLCore(column, columnName, tableName, isInput);
417
- const innerDesc = inner.description ?? inner.type.name;
418
- let type = inner.type;
419
- let description = innerDesc;
420
- for (let i = 0; i < dimensions; i++) {
421
- type = new import_graphql3.GraphQLList(new import_graphql3.GraphQLNonNull(type));
422
- description = `Array<${description}>`;
423
- }
424
- return { type, description };
425
- }
426
- return columnBaseToGraphQLCore(column, columnName, tableName, isInput);
427
- };
428
- var columnBaseToGraphQLCore = (column, columnName, tableName, isInput) => {
429
- const { type: baseType, constraint } = (0, import_drizzle_orm2.extractExtendedColumnType)(column);
430
- switch (baseType) {
431
- case "boolean":
432
- return { type: import_graphql3.GraphQLBoolean, description: "Boolean" };
433
- case "object":
434
- if (column instanceof import_pg_core.PgTimestamp || column instanceof import_pg_core.PgDate) {
435
- return { type: import_graphql_scalars.GraphQLDateTime, description: "DateTime" };
436
- }
437
- return column.columnType === "PgGeometryObject" ? {
438
- type: isInput ? geoXyInputType : geoXyType,
439
- description: "Geometry points XY"
440
- } : column.columnType === "PgBytea" ? {
441
- type: new import_graphql3.GraphQLList(new import_graphql3.GraphQLNonNull(import_graphql3.GraphQLInt)),
442
- description: "Buffer"
443
- } : { type: import_graphql_scalars.GraphQLJSON, description: "JSON" };
444
- case "string":
445
- if (column.enumValues?.length) {
446
- return { type: generateEnumCached(column, columnName, tableName) };
447
- }
448
- if (constraint === "numeric" && !column.dimensions) {
449
- return { type: GraphQLDecimalString, description: "Decimal" };
450
- }
451
- if (column instanceof import_pg_core.PgTimestamp || column instanceof import_pg_core.PgTimestampString) {
452
- return { type: import_graphql_scalars.GraphQLDateTime, description: "DateTime" };
453
- }
454
- if (column instanceof import_pg_core.PgUUID) {
455
- return { type: import_graphql_scalars.GraphQLUUID, description: "UUID" };
456
- }
457
- if (column instanceof import_pg_core.PgDateString) {
458
- return isInput ? { type: import_graphql3.GraphQLString, description: "Date" } : { type: import_graphql_scalars.GraphQLDate, description: "Date" };
459
- }
460
- return { type: import_graphql3.GraphQLString, description: "String" };
461
- case "bigint":
462
- return { type: GraphQLBigIntString, description: "BigInt" };
463
- case "number": {
464
- return (0, import_drizzle_orm2.is)(column, import_pg_core.PgInteger) || (0, import_drizzle_orm2.is)(column, import_pg_core.PgSerial) || (0, import_drizzle_orm2.is)(column, import_mysql_core.MySqlInt) || (0, import_drizzle_orm2.is)(column, import_mysql_core.MySqlSerial) || (0, import_drizzle_orm2.is)(column, import_sqlite_core.SQLiteInteger) ? { type: import_graphql3.GraphQLInt, description: "Integer" } : { type: import_graphql3.GraphQLFloat, description: "Float" };
465
- }
466
- case "array": {
467
- if (column.columnType === "PgVector") {
468
- return {
469
- type: new import_graphql3.GraphQLList(new import_graphql3.GraphQLNonNull(import_graphql3.GraphQLFloat)),
470
- description: "Array<Float>"
471
- };
472
- }
473
- if (column.columnType === "PgGeometry") {
474
- return {
475
- type: new import_graphql3.GraphQLList(new import_graphql3.GraphQLNonNull(import_graphql3.GraphQLFloat)),
476
- description: "Tuple<[Float, Float]>"
477
- };
478
- }
479
- const innerType = columnToGraphQLCore(
480
- column.baseColumn,
481
- columnName,
482
- tableName,
483
- isInput
484
- );
485
- return {
486
- type: new import_graphql3.GraphQLList(new import_graphql3.GraphQLNonNull(innerType.type)),
487
- description: `Array<${innerType.description}>`
488
- };
489
- }
490
- default:
491
- throw new Error(`Drizzle-GraphQL Error: Type ${column.dataType} is not implemented!`);
492
- }
493
- };
494
- var drizzleColumnToGraphQLType = (column, columnName, tableName, forceNullable = false, defaultIsNullable = false, isInput = false) => {
495
- const typeDesc = columnToGraphQLCore(column, columnName, tableName, isInput);
496
- const noDesc = ["string", "boolean", "number"];
497
- const { type: baseType } = (0, import_drizzle_orm2.extractExtendedColumnType)(column);
498
- if (noDesc.find((e) => e === baseType)) {
499
- delete typeDesc.description;
500
- }
501
- if (forceNullable) {
502
- return typeDesc;
503
- }
504
- if (column.notNull && !(defaultIsNullable && (column.hasDefault || column.defaultFn))) {
505
- return {
506
- type: new import_graphql3.GraphQLNonNull(typeDesc.type),
507
- description: typeDesc.description
508
- };
509
- }
510
- return typeDesc;
511
- };
512
-
513
596
  // src/util/builders/common.ts
514
597
  var rqbCrashTypes = ["SQLiteBigInt", "SQLiteBlobJson", "SQLiteBlobBuffer"];
515
598
  var resolveTypeName = (name, typeNameMapper) => {
@@ -887,6 +970,22 @@ var createRelationResolverFactory = (db, tables, filterCtx) => ({ tableName, rel
887
970
  return loader.load(localValue);
888
971
  };
889
972
  };
973
+ var columnDocs = (docs, column, tableName, columnName) => {
974
+ const description = docs.describeColumn?.(column, { tableName, columnName });
975
+ const deprecationReason = docs.deprecateColumn?.(column, { tableName, columnName });
976
+ return {
977
+ ...description !== void 0 ? { description } : {},
978
+ ...deprecationReason !== void 0 ? { deprecationReason } : {}
979
+ };
980
+ };
981
+ var inputFieldDocs = (docs, column, tableName, columnName, fieldType) => {
982
+ const resolved = columnDocs(docs, column, tableName, columnName);
983
+ if (resolved.deprecationReason !== void 0 && fieldType instanceof import_graphql4.GraphQLNonNull) {
984
+ const { deprecationReason: _dropped, ...rest } = resolved;
985
+ return rest;
986
+ }
987
+ return resolved;
988
+ };
890
989
  var listFieldComplexity = (options) => ({ args, childComplexity }) => {
891
990
  const limit = args["limit"];
892
991
  const rows = typeof limit === "number" && limit > 0 ? limit : options.defaultListSize;
@@ -894,18 +993,21 @@ var listFieldComplexity = (options) => ({ args, childComplexity }) => {
894
993
  };
895
994
  var aggregateFieldComplexity = (options) => ({ childComplexity }) => options.aggregateCost + childComplexity;
896
995
  var AGGREGATE_FIELD_SUFFIX = "Aggregate";
897
- var relationAggregateJoinColumns = (tree, table, selectionCtx) => {
898
- const relations = selectionCtx?.relationMap[selectionCtx.tableName];
899
- if (!relations || !selectionCtx) {
996
+ var relationJoinColumns = (tree, table, selectionCtx) => {
997
+ if (!selectionCtx) {
998
+ return [];
999
+ }
1000
+ const relations = (selectionCtx.allRelations ?? selectionCtx.relationMap)[selectionCtx.tableName] ?? selectionCtx.relationMap[selectionCtx.tableName];
1001
+ if (!relations) {
900
1002
  return [];
901
1003
  }
902
1004
  const tableColumns = (0, import_drizzle_orm3.getColumns)(table);
903
1005
  const needed = [];
904
1006
  for (const fieldData of Object.values(tree)) {
905
- if (tableColumns[fieldData.name] || !fieldData.name.endsWith(AGGREGATE_FIELD_SUFFIX)) {
1007
+ if (tableColumns[fieldData.name]) {
906
1008
  continue;
907
1009
  }
908
- const relEntry = relations[fieldData.name.slice(0, -AGGREGATE_FIELD_SUFFIX.length)];
1010
+ const relEntry = fieldData.name.endsWith(AGGREGATE_FIELD_SUFFIX) ? relations[fieldData.name.slice(0, -AGGREGATE_FIELD_SUFFIX.length)] : relations[fieldData.name];
909
1011
  const targetTable = relEntry ? selectionCtx.tables[relEntry.targetTableName] : void 0;
910
1012
  if (!relEntry || !targetTable) {
911
1013
  continue;
@@ -927,7 +1029,7 @@ var extractSelectedColumnsFromTree = (tree, table, selectionCtx) => {
927
1029
  }
928
1030
  selectedColumns.push([fieldData.name, true]);
929
1031
  }
930
- for (const columnName of relationAggregateJoinColumns(tree, table, selectionCtx)) {
1032
+ for (const columnName of relationJoinColumns(tree, table, selectionCtx)) {
931
1033
  selectedColumns.push([columnName, true]);
932
1034
  }
933
1035
  if (!selectedColumns.length) {
@@ -947,7 +1049,7 @@ var extractSelectedColumnsFromTreeSQLFormat = (tree, table, selectionCtx) => {
947
1049
  }
948
1050
  selectedColumns.push([fieldData.name, tableColumns[fieldData.name]]);
949
1051
  }
950
- for (const columnName of relationAggregateJoinColumns(tree, table, selectionCtx)) {
1052
+ for (const columnName of relationJoinColumns(tree, table, selectionCtx)) {
951
1053
  selectedColumns.push([columnName, tableColumns[columnName]]);
952
1054
  }
953
1055
  if (!selectedColumns.length) {
@@ -1068,44 +1170,69 @@ var jsonFilterFields = (column, colType) => {
1068
1170
  isNotNull: { type: import_graphql4.GraphQLBoolean }
1069
1171
  };
1070
1172
  };
1071
- var arrayFilterFields = (colType, colArr, colDesc) => {
1173
+ var IN_ARRAY_DESCRIPTION = "Matches any one of these values (SQL `IN`)";
1174
+ var NOT_IN_ARRAY_DESCRIPTION = "Matches none of these values (SQL `NOT IN`)";
1175
+ var arrayFilterFields = (colType, colArr) => {
1072
1176
  let element = colType.ofType;
1073
1177
  if (element instanceof import_graphql4.GraphQLNonNull) {
1074
1178
  element = element.ofType;
1075
1179
  }
1076
1180
  const elementList = new import_graphql4.GraphQLList(new import_graphql4.GraphQLNonNull(element));
1077
1181
  return {
1078
- eq: { type: colType, description: colDesc },
1079
- ne: { type: colType, description: colDesc },
1182
+ eq: { type: colType, description: "The whole array equals this array" },
1183
+ ne: { type: colType, description: "The whole array differs from this array" },
1080
1184
  has: { type: element, description: "Array contains this element" },
1081
1185
  hasSome: { type: elementList, description: "Array contains at least one of these elements (overlap, `&&`)" },
1082
1186
  hasEvery: { type: elementList, description: "Array contains every one of these elements (containment, `@>`)" },
1083
1187
  isEmpty: { type: import_graphql4.GraphQLBoolean, description: "When true, matches arrays with no elements" },
1084
- inArray: { type: colArr, description: `Array<${colDesc}>` },
1085
- notInArray: { type: colArr, description: `Array<${colDesc}>` },
1188
+ inArray: { type: colArr, description: IN_ARRAY_DESCRIPTION },
1189
+ notInArray: { type: colArr, description: NOT_IN_ARRAY_DESCRIPTION },
1086
1190
  isNull: { type: import_graphql4.GraphQLBoolean },
1087
1191
  isNotNull: { type: import_graphql4.GraphQLBoolean }
1088
1192
  };
1089
1193
  };
1090
1194
  var FILTERS_WITHOUT_STRING_OPS = /* @__PURE__ */ new Set(["Id", "Int", "Float", "BigInt", "Decimal"]);
1195
+ var BUILTIN_FILTER_SCALARS = /* @__PURE__ */ new Set([
1196
+ import_graphql4.GraphQLString,
1197
+ import_graphql4.GraphQLInt,
1198
+ import_graphql4.GraphQLFloat,
1199
+ import_graphql4.GraphQLBoolean,
1200
+ GraphQLBigIntString,
1201
+ GraphQLDecimalString,
1202
+ import_graphql_scalars.GraphQLUUID,
1203
+ import_graphql_scalars.GraphQLJSON,
1204
+ import_graphql_scalars.GraphQLDate,
1205
+ import_graphql_scalars.GraphQLDateTime
1206
+ ]);
1207
+ var resolveOverrideFilterDescriptor = (scalar) => {
1208
+ if (scalar === import_graphql_scalars.GraphQLJSON) {
1209
+ return { name: "JSON", kind: "json" };
1210
+ }
1211
+ if (scalar === import_graphql_scalars.GraphQLUUID) {
1212
+ return { name: "Id", kind: "scalar" };
1213
+ }
1214
+ return { name: scalar.name, kind: "scalar" };
1215
+ };
1091
1216
  var generateColumnFilterValues = (column, tableName, columnName, cacheCtx) => {
1092
1217
  const columnGraphQLType = drizzleColumnToGraphQLType(column, columnName, tableName, true, false, true);
1093
- const { name: genericName, kind } = resolveGenericFilterDescriptor(column, columnGraphQLType);
1218
+ const inputOverride = getColumnScalarOverride(column, true);
1219
+ const { name: genericName, kind } = inputOverride ? resolveOverrideFilterDescriptor(inputOverride) : resolveGenericFilterDescriptor(column, columnGraphQLType);
1094
1220
  const cached = cacheCtx.genericFilterCache.get(genericName);
1095
1221
  if (cached) {
1096
1222
  return cached;
1097
1223
  }
1098
1224
  const colType = columnGraphQLType.type;
1099
- const colDesc = columnGraphQLType.description;
1100
1225
  const colArr = new import_graphql4.GraphQLList(new import_graphql4.GraphQLNonNull(colType));
1101
- const omitStringOps = FILTERS_WITHOUT_STRING_OPS.has(genericName);
1102
- const baseFields = kind === "json" ? jsonFilterFields(column, colType) : kind === "array" ? arrayFilterFields(colType, colArr, colDesc) : {
1103
- eq: { type: colType, description: colDesc },
1104
- ne: { type: colType, description: colDesc },
1105
- lt: { type: colType, description: colDesc },
1106
- lte: { type: colType, description: colDesc },
1107
- gt: { type: colType, description: colDesc },
1108
- gte: { type: colType, description: colDesc },
1226
+ const customOverrideFilter = inputOverride !== void 0 && !BUILTIN_FILTER_SCALARS.has(inputOverride);
1227
+ const underlying = (0, import_drizzle_orm3.extractExtendedColumnType)(column);
1228
+ const omitStringOps = customOverrideFilter ? underlying.type !== "string" || underlying.constraint === "numeric" : FILTERS_WITHOUT_STRING_OPS.has(genericName);
1229
+ const baseFields = kind === "json" ? jsonFilterFields(column, colType) : kind === "array" ? arrayFilterFields(colType, colArr) : {
1230
+ eq: { type: colType, description: "Equal to" },
1231
+ ne: { type: colType, description: "Not equal to" },
1232
+ lt: { type: colType, description: "Less than" },
1233
+ lte: { type: colType, description: "Less than or equal to" },
1234
+ gt: { type: colType, description: "Greater than" },
1235
+ gte: { type: colType, description: "Greater than or equal to" },
1109
1236
  ...omitStringOps ? {} : {
1110
1237
  like: { type: import_graphql4.GraphQLString },
1111
1238
  notLike: { type: import_graphql4.GraphQLString },
@@ -1136,10 +1263,10 @@ var generateColumnFilterValues = (column, tableName, columnName, cacheCtx) => {
1136
1263
  description: "Case-insensitive `contains`."
1137
1264
  }
1138
1265
  },
1139
- inArray: { type: colArr, description: `Array<${colDesc}>` },
1140
- notInArray: { type: colArr, description: `Array<${colDesc}>` },
1141
- isNull: { type: import_graphql4.GraphQLBoolean },
1142
- isNotNull: { type: import_graphql4.GraphQLBoolean }
1266
+ inArray: { type: colArr, description: IN_ARRAY_DESCRIPTION },
1267
+ 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" }
1143
1270
  };
1144
1271
  const mainType = new import_graphql4.GraphQLInputObjectType({
1145
1272
  name: `${genericName}Filter`,
@@ -1179,35 +1306,40 @@ var generateTableOrderCached = (table) => {
1179
1306
  }
1180
1307
  return remapped;
1181
1308
  };
1182
- var filterMap = /* @__PURE__ */ new WeakMap();
1183
1309
  var generateTableFilterValuesCached = (table, tableName, cacheCtx) => {
1184
- if (filterMap.has(table)) {
1185
- return filterMap.get(table);
1310
+ if (cacheCtx.filterFieldCache.has(table)) {
1311
+ return cacheCtx.filterFieldCache.get(table);
1186
1312
  }
1187
1313
  const columns = (0, import_drizzle_orm3.getColumns)(table);
1188
1314
  const columnEntries = Object.entries(columns);
1189
1315
  const remapped = Object.fromEntries(
1190
- columnEntries.map(([columnName, columnDescription]) => [
1316
+ columnEntries.map(([columnName, column]) => [
1191
1317
  columnName,
1192
1318
  {
1193
- type: generateColumnFilterValues(columnDescription, tableName, columnName, cacheCtx)
1319
+ type: generateColumnFilterValues(column, tableName, columnName, cacheCtx),
1320
+ // A filter field is the same column, so it carries the same documentation. Deprecation
1321
+ // is not propagated: filtering on a deprecated column is how a caller finds the rows
1322
+ // that still use it.
1323
+ ...cacheCtx.docs.describeColumn ? { description: cacheCtx.docs.describeColumn(column, { tableName, columnName }) } : {}
1194
1324
  }
1195
1325
  ])
1196
1326
  );
1197
- filterMap.set(table, remapped);
1327
+ cacheCtx.filterFieldCache.set(table, remapped);
1198
1328
  return remapped;
1199
1329
  };
1200
- var fieldMap = /* @__PURE__ */ new WeakMap();
1201
- var generateTableSelectTypeFieldsCached = (table, tableName) => {
1202
- if (fieldMap.has(table)) {
1203
- return fieldMap.get(table);
1330
+ var generateTableSelectTypeFieldsCached = (table, tableName, cacheCtx) => {
1331
+ if (cacheCtx.selectFieldCache.has(table)) {
1332
+ return cacheCtx.selectFieldCache.get(table);
1204
1333
  }
1205
1334
  const columns = (0, import_drizzle_orm3.getColumns)(table);
1206
1335
  const columnEntries = Object.entries(columns);
1207
1336
  const remapped = Object.fromEntries(
1208
- columnEntries.map(([columnName, columnDescription]) => [
1337
+ columnEntries.map(([columnName, column]) => [
1209
1338
  columnName,
1210
- drizzleColumnToGraphQLType(columnDescription, columnName, tableName)
1339
+ {
1340
+ ...drizzleColumnToGraphQLType(column, columnName, tableName),
1341
+ ...columnDocs(cacheCtx.docs, column, tableName, columnName)
1342
+ }
1211
1343
  ])
1212
1344
  );
1213
1345
  if (!remapped[CURSOR_FIELD_NAME]) {
@@ -1217,7 +1349,7 @@ var generateTableSelectTypeFieldsCached = (table, tableName) => {
1217
1349
  resolve: rowCursorResolver
1218
1350
  };
1219
1351
  }
1220
- fieldMap.set(table, remapped);
1352
+ cacheCtx.selectFieldCache.set(table, remapped);
1221
1353
  return remapped;
1222
1354
  };
1223
1355
  var isFilterableRelation = (relation) => !relation.through;
@@ -1367,7 +1499,7 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
1367
1499
  const table = tables[tableName];
1368
1500
  const order = withOrder ? generateTableOrderTypeCached(table, tableName, typeNameMapper, cacheCtx, relationMap, tables) : void 0;
1369
1501
  const filters = generateTableFilterTypeCached(table, tableName, cacheCtx, typeNameMapper, relationMap, tables);
1370
- const tableFields = generateTableSelectTypeFieldsCached(table, tableName);
1502
+ const tableFields = generateTableSelectTypeFieldsCached(table, tableName, cacheCtx);
1371
1503
  const relationsForTable = relationMap[tableName];
1372
1504
  const relationEntries = relationsForTable ? Object.entries(relationsForTable) : [];
1373
1505
  if (relationsDepthLimit !== void 0 && currentDepth >= relationsDepthLimit) {
@@ -1404,6 +1536,7 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
1404
1536
  const typeName = resolveTypeName(tableName, typeNameMapper);
1405
1537
  const shell = new import_graphql4.GraphQLObjectType({
1406
1538
  name: typeName,
1539
+ description: cacheCtx.docs.describeTable?.(tableName),
1407
1540
  fields: () => ({ ...tableFields, ...container.fields })
1408
1541
  });
1409
1542
  cacheCtx.objectTypeCache.set(tableName, shell);
@@ -1436,7 +1569,7 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
1436
1569
  let relType = cacheCtx.objectTypeCache.get(targetTableName);
1437
1570
  if (!relType) {
1438
1571
  const targetTable = tables[targetTableName];
1439
- const targetTableFields = generateTableSelectTypeFieldsCached(targetTable, targetTableName);
1572
+ const targetTableFields = generateTableSelectTypeFieldsCached(targetTable, targetTableName, cacheCtx);
1440
1573
  let targetContainer = cacheCtx.relationFieldContainers.get(targetTableName);
1441
1574
  if (!targetContainer) {
1442
1575
  targetContainer = { fields: {} };
@@ -1445,11 +1578,14 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
1445
1578
  const capturedTargetContainer = targetContainer;
1446
1579
  relType = new import_graphql4.GraphQLObjectType({
1447
1580
  name: resolveTypeName(targetTableName, typeNameMapper),
1581
+ description: cacheCtx.docs.describeTable?.(targetTableName),
1448
1582
  fields: () => ({ ...targetTableFields, ...capturedTargetContainer.fields })
1449
1583
  });
1450
1584
  cacheCtx.objectTypeCache.set(targetTableName, relType);
1451
1585
  }
1452
1586
  const resolve = resolverFactory?.({ tableName, relationName, relEntry, isOne });
1587
+ const relationDescription = cacheCtx.docs.describeRelation?.(tableName, relationName);
1588
+ const relationDocs = relationDescription !== void 0 ? { description: relationDescription } : {};
1453
1589
  if (isOne) {
1454
1590
  const isRequired = relation.optional === false;
1455
1591
  rawRelationFields.push([
@@ -1459,7 +1595,8 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
1459
1595
  args: {
1460
1596
  where: { type: relSelectData.filters }
1461
1597
  },
1462
- resolve
1598
+ resolve,
1599
+ ...relationDocs
1463
1600
  }
1464
1601
  ]);
1465
1602
  continue;
@@ -1475,6 +1612,7 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
1475
1612
  limit: { type: import_graphql4.GraphQLInt }
1476
1613
  },
1477
1614
  resolve,
1615
+ ...relationDocs,
1478
1616
  ...cacheCtx.complexity ? { extensions: { complexity: listFieldComplexity(cacheCtx.complexity) } } : {}
1479
1617
  }
1480
1618
  ]);
@@ -1522,7 +1660,7 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
1522
1660
  relationFields: {}
1523
1661
  };
1524
1662
  };
1525
- var generateTableTypes = (tableName, tables, relationMap, withReturning, relationsDepthLimit, cacheCtx, typeNameMapper = void 0, insertPrefix = "create", updatePrefix = "update", resolverFactory, relationAggregateFactory) => {
1663
+ var generateTableTypes = (tableName, tables, relationMap, withReturning, relationsDepthLimit, cacheCtx, typeNameMapper = void 0, insertPrefix = "create", updatePrefix = "update", resolverFactory, relationAggregateFactory, nestedWrites) => {
1526
1664
  const { tableFields, relationFields, filters, order } = generateSelectFields(
1527
1665
  tables,
1528
1666
  tableName,
@@ -1543,28 +1681,44 @@ var generateTableTypes = (tableName, tables, relationMap, withReturning, relatio
1543
1681
  const table = tables[tableName];
1544
1682
  const columns = (0, import_drizzle_orm3.getColumns)(table);
1545
1683
  const columnEntries = Object.entries(columns);
1684
+ const relaxedColumns = nestedWrites?.relaxedColumns(tableName);
1546
1685
  const insertFields = Object.fromEntries(
1547
- columnEntries.map(([columnName, columnDescription]) => [
1548
- columnName,
1549
- drizzleColumnToGraphQLType(columnDescription, columnName, tableName, false, true, true)
1550
- ])
1686
+ columnEntries.map(([columnName, column]) => {
1687
+ const converted = drizzleColumnToGraphQLType(
1688
+ column,
1689
+ columnName,
1690
+ tableName,
1691
+ !!relaxedColumns?.has(columnName),
1692
+ true,
1693
+ true
1694
+ );
1695
+ return [
1696
+ columnName,
1697
+ { ...converted, ...inputFieldDocs(cacheCtx.docs, column, tableName, columnName, converted.type) }
1698
+ ];
1699
+ })
1551
1700
  );
1552
1701
  const updateFields = Object.fromEntries(
1553
- columnEntries.map(([columnName, columnDescription]) => [
1554
- columnName,
1555
- drizzleColumnToGraphQLType(columnDescription, columnName, tableName, true, false, true)
1556
- ])
1702
+ columnEntries.map(([columnName, column]) => {
1703
+ const converted = drizzleColumnToGraphQLType(column, columnName, tableName, true, false, true);
1704
+ return [
1705
+ columnName,
1706
+ { ...converted, ...inputFieldDocs(cacheCtx.docs, column, tableName, columnName, converted.type) }
1707
+ ];
1708
+ })
1557
1709
  );
1710
+ const typeName = resolveTypeName(tableName, typeNameMapper);
1558
1711
  const insertInput = new import_graphql4.GraphQLInputObjectType({
1559
- name: `${capitalize(insertPrefix)}${resolveTypeName(tableName, typeNameMapper)}Input`,
1560
- fields: insertFields
1712
+ name: `${capitalize(insertPrefix)}${typeName}Input`,
1713
+ fields: nestedWrites ? () => ({ ...insertFields, ...nestedWrites.createFields(tableName, typeName) }) : insertFields
1561
1714
  });
1562
1715
  const updateInput = new import_graphql4.GraphQLInputObjectType({
1563
- name: `${capitalize(updatePrefix)}${resolveTypeName(tableName, typeNameMapper)}Input`,
1564
- fields: updateFields
1716
+ name: `${capitalize(updatePrefix)}${typeName}Input`,
1717
+ fields: nestedWrites ? () => ({ ...updateFields, ...nestedWrites.updateFields(tableName, typeName) }) : updateFields
1565
1718
  });
1566
1719
  const selectSingleOutput = cacheCtx.objectTypeCache.get(tableName) ?? new import_graphql4.GraphQLObjectType({
1567
1720
  name: resolveTypeName(tableName, typeNameMapper),
1721
+ description: cacheCtx.docs.describeTable?.(tableName),
1568
1722
  fields: { ...tableFields, ...relationFields }
1569
1723
  });
1570
1724
  const selectArrOutput = new import_graphql4.GraphQLNonNull(new import_graphql4.GraphQLList(new import_graphql4.GraphQLNonNull(selectSingleOutput)));
@@ -1956,6 +2110,13 @@ var extractRelationsParamsInner = (relationMap, tables, tableName, typeName, ori
1956
2110
  if (!field) {
1957
2111
  continue;
1958
2112
  }
2113
+ const selectionCount = Object.values(baseField).reduce(
2114
+ (n, f) => n + (f.name === relName ? 1 : 0),
2115
+ 0
2116
+ );
2117
+ if (selectionCount > 1) {
2118
+ continue;
2119
+ }
1959
2120
  const relField = field?.fieldsByTypeName;
1960
2121
  const relFieldSelection = relField?.[relTypeName];
1961
2122
  if (!relFieldSelection) {
@@ -1964,7 +2125,8 @@ var extractRelationsParamsInner = (relationMap, tables, tableName, typeName, ori
1964
2125
  const columns = extractSelectedColumnsFromTree(relFieldSelection, tables[targetTableName], {
1965
2126
  tableName: targetTableName,
1966
2127
  relationMap,
1967
- tables
2128
+ tables,
2129
+ allRelations: filterCtx?.relationMap
1968
2130
  });
1969
2131
  const thisRecord = {};
1970
2132
  thisRecord.columns = columns;
@@ -2570,7 +2732,8 @@ var runRelationalSelect = async (opts) => {
2570
2732
  columns: extractSelectedColumnsFromTree(parsedInfo.fieldsByTypeName[typeName], table, {
2571
2733
  tableName,
2572
2734
  relationMap,
2573
- tables
2735
+ tables,
2736
+ allRelations: filterCtx?.relationMap
2574
2737
  }),
2575
2738
  offset: distinctKeys ? void 0 : offset,
2576
2739
  // drizzle-orm v1 RQB calls orderBy/where with the aliased table proxy — use it
@@ -2751,9 +2914,9 @@ var generateAggregateTypes = (table, tableName, typeName, cacheCtx) => {
2751
2914
  type: new import_graphql5.GraphQLObjectType({
2752
2915
  name: `${typeName}${capitalize(op)}Aggregate`,
2753
2916
  fields: Object.fromEntries(
2754
- Object.entries(orderable).map(([columnName, { converted }]) => [
2917
+ Object.entries(orderable).map(([columnName, { column, converted }]) => [
2755
2918
  columnName,
2756
- { type: converted.type, description: converted.description }
2919
+ { type: converted.type, ...columnDocs(cacheCtx?.docs ?? {}, column, tableName, columnName) }
2757
2920
  ])
2758
2921
  )
2759
2922
  })
@@ -2800,7 +2963,7 @@ var aggregateTarget = (table, tableName, typeName) => {
2800
2963
  typeName,
2801
2964
  columns: (0, import_drizzle_orm4.getColumns)(table),
2802
2965
  dateTimeColumns: new Set(
2803
- Object.entries(orderable).filter(([, { converted }]) => converted.description === "DateTime").map(([columnName]) => columnName)
2966
+ Object.entries(orderable).filter(([, { converted }]) => converted.typeLabel === "DateTime").map(([columnName]) => columnName)
2804
2967
  )
2805
2968
  };
2806
2969
  };
@@ -3018,9 +3181,9 @@ var generateGroupByType = (table, tableName, typeName, cacheCtx) => {
3018
3181
  name: `${typeName}GroupKeys`,
3019
3182
  description: `The grouped column values of one ${typeName} group. A column the query did not group by is null.`,
3020
3183
  fields: Object.fromEntries(
3021
- Object.entries(groupable).map(([columnName, { converted }]) => [
3184
+ Object.entries(groupable).map(([columnName, { column, converted }]) => [
3022
3185
  columnName,
3023
- { type: converted.type, description: converted.description }
3186
+ { type: converted.type, ...columnDocs(cacheCtx?.docs ?? {}, column, tableName, columnName) }
3024
3187
  ])
3025
3188
  )
3026
3189
  });
@@ -3420,6 +3583,13 @@ var generateSchemaData = (db, schema, relations, options) => {
3420
3583
  "Drizzle-GraphQL Error: No tables detected in Drizzle-ORM's database instance. Did you forget to pass schema to drizzle constructor?"
3421
3584
  );
3422
3585
  }
3586
+ if (features.nestedWrites) {
3587
+ throw new Error(
3588
+ "Drizzle-GraphQL Error: features.nestedWrites is not supported on MySQL \u2014 a nested write needs the parent row it just inserted returned to it, and MySQL has no RETURNING clause."
3589
+ );
3590
+ }
3591
+ registerScalarOverrides(tables, options);
3592
+ registerEnumConfig(options);
3423
3593
  const namedRelations = buildNamedRelations(relations ?? {}, tableEntries);
3424
3594
  attachTargetPrimaryKeys(namedRelations, tables, mysqlPrimaryKeyPropNames);
3425
3595
  const eagerRelations = pruneNonEagerRelations(namedRelations, shouldEagerLoad);
@@ -3431,11 +3601,14 @@ var generateSchemaData = (db, schema, relations, options) => {
3431
3601
  relationFieldContainers: /* @__PURE__ */ new Map(),
3432
3602
  fullyBuiltTables: /* @__PURE__ */ new Set(),
3433
3603
  relationTypeCache: /* @__PURE__ */ new Map(),
3604
+ selectFieldCache: /* @__PURE__ */ new WeakMap(),
3605
+ filterFieldCache: /* @__PURE__ */ new WeakMap(),
3434
3606
  orderTypeCache: /* @__PURE__ */ new WeakMap(),
3435
3607
  filterTypeCache: /* @__PURE__ */ new WeakMap(),
3436
3608
  listRelationFilterCache: /* @__PURE__ */ new Map(),
3437
3609
  aggregateTypeCache: /* @__PURE__ */ new Map(),
3438
- complexity
3610
+ complexity,
3611
+ docs: options.docs ?? {}
3439
3612
  };
3440
3613
  const relationAggregateFactory = features.relationAggregates ? createRelationAggregateFactory(db, tables, cacheCtx, typeNameMapper, filterCtx) : void 0;
3441
3614
  const queries = {};
@@ -3683,54 +3856,433 @@ var generateSchemaData = (db, schema, relations, options) => {
3683
3856
  };
3684
3857
  }
3685
3858
  }
3686
- const activeInputs = [
3687
- // The insert input types the upsert mutations too, so either feature keeps it.
3688
- ...features.insert || onConflictInput ? [insertInput] : [],
3689
- ...onConflictInput ? [onConflictInput] : [],
3690
- ...features.update ? [updateInput] : [],
3691
- ...updateManyInput ? [updateManyInput] : [],
3692
- tableFilters,
3693
- tableOrder
3694
- ];
3695
- activeInputs.forEach((e) => {
3696
- inputs[e.name] = e;
3859
+ const activeInputs = [
3860
+ // The insert input types the upsert mutations too, so either feature keeps it.
3861
+ ...features.insert || onConflictInput ? [insertInput] : [],
3862
+ ...onConflictInput ? [onConflictInput] : [],
3863
+ ...features.update ? [updateInput] : [],
3864
+ ...updateManyInput ? [updateManyInput] : [],
3865
+ tableFilters,
3866
+ tableOrder
3867
+ ];
3868
+ activeInputs.forEach((e) => {
3869
+ inputs[e.name] = e;
3870
+ });
3871
+ outputs[selectSingleOutput.name] = selectSingleOutput;
3872
+ if (aggregateType) {
3873
+ outputs[aggregateType.name] = aggregateType;
3874
+ }
3875
+ if (groupByType && havingInput) {
3876
+ outputs[groupByType.name] = groupByType;
3877
+ inputs[havingInput.name] = havingInput;
3878
+ }
3879
+ }
3880
+ if (mutationTxCtx) {
3881
+ for (const name of Object.keys(mutations)) {
3882
+ mutationTxCtx.fieldNames.add(name);
3883
+ }
3884
+ }
3885
+ const fieldResolvers = {};
3886
+ for (const [tableName, tableRelations] of Object.entries(namedRelations)) {
3887
+ const relResolvers = {};
3888
+ for (const [relName, relEntry] of Object.entries(tableRelations)) {
3889
+ const isOne = (0, import_drizzle_orm5.is)(relEntry.relation ?? relEntry, import_drizzle_orm5.One);
3890
+ const resolver = resolverFactory({ tableName, relationName: relName, relEntry, isOne });
3891
+ if (resolver) {
3892
+ relResolvers[relName] = resolver;
3893
+ }
3894
+ }
3895
+ if (Object.keys(relResolvers).length > 0) {
3896
+ fieldResolvers[tableName] = relResolvers;
3897
+ }
3898
+ }
3899
+ return { queries, mutations, inputs, types: outputs, fieldResolvers };
3900
+ };
3901
+
3902
+ // src/util/builders/pg.ts
3903
+ var import_drizzle_orm7 = require("drizzle-orm");
3904
+ var import_pg_core2 = require("drizzle-orm/pg-core");
3905
+ var import_graphql8 = require("graphql");
3906
+ var import_graphql_parse_resolve_info3 = require("graphql-parse-resolve-info");
3907
+
3908
+ // src/util/builders/nested-writes.ts
3909
+ var import_drizzle_orm6 = require("drizzle-orm");
3910
+ var import_graphql7 = require("graphql");
3911
+ var isOptionalOnInsert = (column) => !column.notNull || !!column.hasDefault || !!column.defaultFn;
3912
+ var buildNestedWritePlans = (tables, relationMap, resolveUniqueSets, resolvePrimaryKeys, extractJoinColumns) => {
3913
+ const uniqueCache = /* @__PURE__ */ new Map();
3914
+ const singleColumnUniques = (tableName, table) => {
3915
+ let cached = uniqueCache.get(tableName);
3916
+ if (!cached) {
3917
+ cached = new Set(
3918
+ resolveUniqueSets(table).filter((set) => set.length === 1).map((set) => set[0])
3919
+ );
3920
+ uniqueCache.set(tableName, cached);
3921
+ }
3922
+ return cached;
3923
+ };
3924
+ const pkCache = /* @__PURE__ */ new Map();
3925
+ const singleColumnPk = (tableName, table) => {
3926
+ if (!pkCache.has(tableName)) {
3927
+ const pk = resolvePrimaryKeys(table);
3928
+ pkCache.set(tableName, pk.length === 1 ? pk[0] : void 0);
3929
+ }
3930
+ return pkCache.get(tableName);
3931
+ };
3932
+ const plans = {};
3933
+ for (const [tableName, relations] of Object.entries(relationMap)) {
3934
+ const table = tables[tableName];
3935
+ if (!table) {
3936
+ continue;
3937
+ }
3938
+ const tablePlans = {};
3939
+ for (const [relationName, relEntry] of Object.entries(relations)) {
3940
+ const relation = relEntry.relation;
3941
+ if (relation.through) {
3942
+ continue;
3943
+ }
3944
+ const targetTableName = relEntry.targetTableName;
3945
+ const targetTable = tables[targetTableName];
3946
+ if (!targetTable) {
3947
+ continue;
3948
+ }
3949
+ const joinColumns = extractJoinColumns(relEntry, table, targetTable);
3950
+ if (!joinColumns) {
3951
+ continue;
3952
+ }
3953
+ const { localColPropName, foreignCol, foreignColPropName } = joinColumns;
3954
+ const localCol = (0, import_drizzle_orm6.getColumns)(table)[localColPropName];
3955
+ if (!localCol) {
3956
+ continue;
3957
+ }
3958
+ const isOne = (0, import_drizzle_orm6.is)(relation, import_drizzle_orm6.One);
3959
+ const localIsPk = singleColumnPk(tableName, table) === localColPropName;
3960
+ const foreignIsPk = singleColumnPk(targetTableName, targetTable) === foreignColPropName;
3961
+ const localIsUnique = singleColumnUniques(tableName, table).has(localColPropName);
3962
+ const foreignIsUnique = singleColumnUniques(targetTableName, targetTable).has(foreignColPropName);
3963
+ let fkSide;
3964
+ if (!isOne) {
3965
+ fkSide = "child";
3966
+ } else if (foreignIsPk && !localIsPk) {
3967
+ fkSide = "parent";
3968
+ } else if (localIsPk) {
3969
+ fkSide = "child";
3970
+ } else if (foreignIsUnique) {
3971
+ fkSide = "parent";
3972
+ } else if (localIsUnique) {
3973
+ fkSide = "child";
3974
+ } else {
3975
+ continue;
3976
+ }
3977
+ const fkColumn = fkSide === "child" ? foreignCol : localCol;
3978
+ tablePlans[relationName] = {
3979
+ relationName,
3980
+ targetTableName,
3981
+ targetTable,
3982
+ localColPropName,
3983
+ foreignColPropName,
3984
+ foreignCol,
3985
+ localCol,
3986
+ isOne,
3987
+ fkSide,
3988
+ canDetach: !fkColumn.notNull
3989
+ };
3990
+ }
3991
+ if (Object.keys(tablePlans).length) {
3992
+ plans[tableName] = tablePlans;
3993
+ }
3994
+ }
3995
+ return plans;
3996
+ };
3997
+ var NO_COLUMNS = /* @__PURE__ */ new Set();
3998
+ var createNestedWriteTypes = (params) => {
3999
+ const { plans, cacheCtx, typeNameMapper, insertPrefix } = params;
4000
+ const wrapperCache = /* @__PURE__ */ new Map();
4001
+ const payloadCache = /* @__PURE__ */ new Map();
4002
+ const payloadType = (tableName, typeName, plan) => {
4003
+ const key = `${tableName}.${plan.relationName}`;
4004
+ const cached = payloadCache.get(key);
4005
+ if (cached) {
4006
+ return cached;
4007
+ }
4008
+ const omitted = plan.fkSide === "child" ? plan.foreignColPropName : void 0;
4009
+ const fields = Object.fromEntries(
4010
+ Object.entries((0, import_drizzle_orm6.getColumns)(plan.targetTable)).filter(([columnName]) => columnName !== omitted).map(([columnName, column]) => [
4011
+ columnName,
4012
+ drizzleColumnToGraphQLType(column, columnName, plan.targetTableName, false, true, true)
4013
+ ])
4014
+ );
4015
+ const type = new import_graphql7.GraphQLInputObjectType({
4016
+ name: `${capitalize(insertPrefix)}${typeName}${capitalize(plan.relationName)}Input`,
4017
+ 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
+ fields
4019
+ });
4020
+ payloadCache.set(key, type);
4021
+ return type;
4022
+ };
4023
+ const targetFilters = (plan) => cacheCtx.filterTypeCache.get(plan.targetTable);
4024
+ const listOf = (type) => new import_graphql7.GraphQLList(new import_graphql7.GraphQLNonNull(type));
4025
+ const wrapperType = (tableName, typeName, plan, forUpdate) => {
4026
+ const key = `${tableName}.${plan.relationName}.${forUpdate ? "update" : "create"}`;
4027
+ const cached = wrapperCache.get(key);
4028
+ if (cached) {
4029
+ return cached;
4030
+ }
4031
+ const filters = targetFilters(plan);
4032
+ const payload = payloadType(tableName, typeName, plan);
4033
+ const targetTypeName = resolveTypeName(plan.targetTableName, typeNameMapper);
4034
+ const fields = {};
4035
+ if (plan.isOne) {
4036
+ fields["create"] = { type: payload, description: `Insert a ${targetTypeName} row and attach it` };
4037
+ if (filters) {
4038
+ fields["connect"] = {
4039
+ type: filters,
4040
+ description: `Attach the existing ${targetTypeName} row this matches. Must match exactly one row.`
4041
+ };
4042
+ }
4043
+ if (forUpdate && plan.canDetach) {
4044
+ fields["disconnect"] = {
4045
+ type: import_graphql7.GraphQLBoolean,
4046
+ description: `Detach the currently attached ${targetTypeName} row, leaving it in place`
4047
+ };
4048
+ }
4049
+ } else {
4050
+ fields["create"] = { type: listOf(payload), description: `Insert these ${targetTypeName} rows and attach them` };
4051
+ if (filters) {
4052
+ fields["connect"] = {
4053
+ type: listOf(filters),
4054
+ description: `Attach every existing ${targetTypeName} row these match`
4055
+ };
4056
+ if (forUpdate && plan.canDetach) {
4057
+ fields["disconnect"] = {
4058
+ type: listOf(filters),
4059
+ description: `Detach every attached ${targetTypeName} row these match, leaving the rows in place`
4060
+ };
4061
+ fields["set"] = {
4062
+ type: listOf(filters),
4063
+ description: `Replace the whole set: detach everything attached, then attach every ${targetTypeName} row these match. Applied before \`disconnect\`, \`connect\` and \`create\`.`
4064
+ };
4065
+ }
4066
+ }
4067
+ }
4068
+ const type = new import_graphql7.GraphQLInputObjectType({
4069
+ name: `${typeName}${capitalize(plan.relationName)}Nested${forUpdate ? "Update" : "Create"}Input`,
4070
+ description: `Writes through ${typeName}.${plan.relationName}`,
4071
+ fields
3697
4072
  });
3698
- outputs[selectSingleOutput.name] = selectSingleOutput;
3699
- if (aggregateType) {
3700
- outputs[aggregateType.name] = aggregateType;
4073
+ wrapperCache.set(key, type);
4074
+ return type;
4075
+ };
4076
+ const relationFields = (tableName, typeName, forUpdate) => {
4077
+ const tablePlans = plans[tableName];
4078
+ if (!tablePlans) {
4079
+ return {};
4080
+ }
4081
+ return Object.fromEntries(
4082
+ Object.values(tablePlans).flatMap((plan) => {
4083
+ const wrapper = wrapperType(tableName, typeName, plan, forUpdate);
4084
+ return wrapper ? [[plan.relationName, { type: wrapper, description: `Writes through ${typeName}.${plan.relationName}` }]] : [];
4085
+ })
4086
+ );
4087
+ };
4088
+ return {
4089
+ createFields: (tableName, typeName) => relationFields(tableName, typeName, false),
4090
+ updateFields: (tableName, typeName) => relationFields(tableName, typeName, true),
4091
+ relaxedColumns: (tableName) => {
4092
+ const tablePlans = plans[tableName];
4093
+ if (!tablePlans) {
4094
+ return NO_COLUMNS;
4095
+ }
4096
+ const relaxed = /* @__PURE__ */ new Set();
4097
+ for (const plan of Object.values(tablePlans)) {
4098
+ if (plan.fkSide === "parent" && !isOptionalOnInsert(plan.localCol)) {
4099
+ relaxed.add(plan.localColPropName);
4100
+ }
4101
+ }
4102
+ return relaxed.size ? relaxed : NO_COLUMNS;
3701
4103
  }
3702
- if (groupByType && havingInput) {
3703
- outputs[groupByType.name] = groupByType;
3704
- inputs[havingInput.name] = havingInput;
4104
+ };
4105
+ };
4106
+ var mergedOps = (entries) => Object.assign({}, ...entries.map((entry) => entry.ops));
4107
+ var asArray = (value) => Array.isArray(value) ? value : value === void 0 ? [] : [value];
4108
+ var createNestedWriteRuntime = (params) => {
4109
+ const { plans, filterCtx } = params;
4110
+ const conditionOf = (plan, filter, operation) => {
4111
+ const condition = extractFilters(
4112
+ plan.targetTable,
4113
+ plan.targetTableName,
4114
+ filter,
4115
+ relationFilterCtx(filterCtx, plan.targetTableName)
4116
+ );
4117
+ if (!condition) {
4118
+ throw new import_graphql7.GraphQLError(
4119
+ `Drizzle-GraphQL Error: '${operation}' on '${plan.relationName}' needs a filter that selects rows \u2014 it was given one that matches everything.`
4120
+ );
3705
4121
  }
3706
- }
3707
- if (mutationTxCtx) {
3708
- for (const name of Object.keys(mutations)) {
3709
- mutationTxCtx.fieldNames.add(name);
4122
+ return condition;
4123
+ };
4124
+ const assertSingleOperation = (plan, op) => {
4125
+ const supplied = ["create", "connect", "disconnect"].filter((key) => op[key] !== void 0 && op[key] !== null);
4126
+ if (supplied.length > 1) {
4127
+ throw new import_graphql7.GraphQLError(
4128
+ `Drizzle-GraphQL Error: '${plan.relationName}' takes one of ${supplied.join(", ")} at a time \u2014 it holds a single row.`
4129
+ );
3710
4130
  }
3711
- }
3712
- const fieldResolvers = {};
3713
- for (const [tableName, tableRelations] of Object.entries(namedRelations)) {
3714
- const relResolvers = {};
3715
- for (const [relName, relEntry] of Object.entries(tableRelations)) {
3716
- const isOne = (0, import_drizzle_orm5.is)(relEntry.relation ?? relEntry, import_drizzle_orm5.One);
3717
- const resolver = resolverFactory({ tableName, relationName: relName, relEntry, isOne });
3718
- if (resolver) {
3719
- relResolvers[relName] = resolver;
4131
+ };
4132
+ const detachAll = async (executor, plan, key) => executor.update(plan.targetTable).set({ [plan.foreignColPropName]: null }).where((0, import_drizzle_orm6.eq)(plan.foreignCol, key));
4133
+ return {
4134
+ enabled: (tableName) => !!plans[tableName],
4135
+ split: (tableName, values) => {
4136
+ const tablePlans = plans[tableName];
4137
+ if (!tablePlans) {
4138
+ return { columns: values, ops: {} };
4139
+ }
4140
+ const columns = {};
4141
+ const ops = {};
4142
+ for (const [key, value] of Object.entries(values)) {
4143
+ if (tablePlans[key] && value !== void 0 && value !== null) {
4144
+ ops[key] = value;
4145
+ } else if (!tablePlans[key]) {
4146
+ columns[key] = value;
4147
+ }
4148
+ }
4149
+ return { columns, ops };
4150
+ },
4151
+ hasOps: (ops) => Object.keys(ops).length > 0,
4152
+ withJoinColumns: (tableName, ops, columns, table) => {
4153
+ const tablePlans = plans[tableName];
4154
+ if (!tablePlans) {
4155
+ return columns;
4156
+ }
4157
+ const allColumns = (0, import_drizzle_orm6.getColumns)(table);
4158
+ for (const relationName of Object.keys(ops)) {
4159
+ const plan = tablePlans[relationName];
4160
+ if (plan?.fkSide === "child" && !(plan.localColPropName in columns) && allColumns[plan.localColPropName]) {
4161
+ columns[plan.localColPropName] = allColumns[plan.localColPropName];
4162
+ }
4163
+ }
4164
+ return columns;
4165
+ },
4166
+ applyParentSide: async (executor, tableName, ops) => {
4167
+ const tablePlans = plans[tableName];
4168
+ const patch = {};
4169
+ if (!tablePlans) {
4170
+ return patch;
4171
+ }
4172
+ for (const [relationName, op] of Object.entries(ops)) {
4173
+ const plan = tablePlans[relationName];
4174
+ if (!plan || plan.fkSide !== "parent") {
4175
+ continue;
4176
+ }
4177
+ assertSingleOperation(plan, op);
4178
+ if (op["create"] !== void 0) {
4179
+ const values = remapFromGraphQLSingleInput({ ...op["create"] }, plan.targetTable);
4180
+ const inserted = await executor.insert(plan.targetTable).values(values).returning();
4181
+ const created = inserted[0];
4182
+ if (!created) {
4183
+ throw new import_graphql7.GraphQLError(
4184
+ `Drizzle-GraphQL Error: 'create' on '${relationName}' inserted no row, so there is nothing to attach.`
4185
+ );
4186
+ }
4187
+ patch[plan.localColPropName] = created[plan.foreignColPropName];
4188
+ } else if (op["connect"] !== void 0) {
4189
+ const rows = await executor.select().from(plan.targetTable).where(conditionOf(plan, op["connect"], "connect"));
4190
+ if (rows.length !== 1) {
4191
+ throw new import_graphql7.GraphQLError(
4192
+ `Drizzle-GraphQL Error: 'connect' on '${relationName}' matched ${rows.length} rows \u2014 it attaches a single row, so its filter must match exactly one.`
4193
+ );
4194
+ }
4195
+ patch[plan.localColPropName] = rows[0][plan.foreignColPropName];
4196
+ } else if (op["disconnect"] === true) {
4197
+ patch[plan.localColPropName] = null;
4198
+ }
4199
+ }
4200
+ return patch;
4201
+ },
4202
+ applyChildSide: async (executor, tableName, ops, parentRows) => {
4203
+ const tablePlans = plans[tableName];
4204
+ if (!tablePlans) {
4205
+ return;
4206
+ }
4207
+ for (const [relationName, op] of Object.entries(ops)) {
4208
+ const plan = tablePlans[relationName];
4209
+ if (!plan || plan.fkSide !== "child") {
4210
+ continue;
4211
+ }
4212
+ if (plan.isOne) {
4213
+ assertSingleOperation(plan, op);
4214
+ }
4215
+ for (const parentRow of parentRows) {
4216
+ const key = parentRow?.[plan.localColPropName];
4217
+ if (key === void 0 || key === null) {
4218
+ throw new import_graphql7.GraphQLError(
4219
+ `Drizzle-GraphQL Error: cannot write through '${relationName}': the ${tableName} row has no '${plan.localColPropName}' value to attach to.`
4220
+ );
4221
+ }
4222
+ if (op["set"] !== void 0) {
4223
+ await detachAll(executor, plan, key);
4224
+ for (const filter of asArray(op["set"])) {
4225
+ await executor.update(plan.targetTable).set({ [plan.foreignColPropName]: key }).where(conditionOf(plan, filter, "set"));
4226
+ }
4227
+ }
4228
+ if (op["disconnect"] !== void 0) {
4229
+ if (plan.isOne) {
4230
+ if (op["disconnect"] === true) {
4231
+ await detachAll(executor, plan, key);
4232
+ }
4233
+ } else {
4234
+ 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")));
4236
+ }
4237
+ }
4238
+ }
4239
+ const attaches = op["connect"] !== void 0 || op["create"] !== void 0;
4240
+ if (plan.isOne && attaches && plan.canDetach && op["set"] === void 0) {
4241
+ await detachAll(executor, plan, key);
4242
+ }
4243
+ if (op["connect"] !== void 0) {
4244
+ for (const filter of asArray(op["connect"])) {
4245
+ await executor.update(plan.targetTable).set({ [plan.foreignColPropName]: key }).where(conditionOf(plan, filter, "connect"));
4246
+ }
4247
+ }
4248
+ if (op["create"] !== void 0) {
4249
+ const rows = asArray(op["create"]).map((row) => ({
4250
+ ...remapFromGraphQLSingleInput({ ...row }, plan.targetTable),
4251
+ [plan.foreignColPropName]: key
4252
+ }));
4253
+ if (rows.length) {
4254
+ await executor.insert(plan.targetTable).values(rows);
4255
+ }
4256
+ }
4257
+ }
3720
4258
  }
3721
4259
  }
3722
- if (Object.keys(relResolvers).length > 0) {
3723
- fieldResolvers[tableName] = relResolvers;
4260
+ };
4261
+ };
4262
+ var writeWithNestedOps = async (params) => {
4263
+ const { executor, runtime, tableName, entries, remapValues, write } = params;
4264
+ return executor.transaction(async (tx) => {
4265
+ const rows = [];
4266
+ for (const entry of entries) {
4267
+ const patch = await runtime.applyParentSide(tx, tableName, entry.ops);
4268
+ const written = await write(tx, { ...remapValues(entry.columns), ...patch });
4269
+ await runtime.applyChildSide(tx, tableName, entry.ops, written);
4270
+ rows.push(...written);
3724
4271
  }
3725
- }
3726
- return { queries, mutations, inputs, types: outputs, fieldResolvers };
4272
+ return rows;
4273
+ });
4274
+ };
4275
+ var updateWithNestedOps = async (params) => {
4276
+ const { executor, runtime, tableName, columns, ops, remapValues, write } = params;
4277
+ return executor.transaction(async (tx) => {
4278
+ const patch = await runtime.applyParentSide(tx, tableName, ops);
4279
+ const rows = await write(tx, { ...remapValues(columns), ...patch });
4280
+ await runtime.applyChildSide(tx, tableName, ops, rows);
4281
+ return rows;
4282
+ });
3727
4283
  };
3728
4284
 
3729
4285
  // src/util/builders/pg.ts
3730
- var import_drizzle_orm6 = require("drizzle-orm");
3731
- var import_pg_core2 = require("drizzle-orm/pg-core");
3732
- var import_graphql7 = require("graphql");
3733
- var import_graphql_parse_resolve_info3 = require("graphql-parse-resolve-info");
3734
4286
  var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, distinctEnabled = true) => {
3735
4287
  const queryBase = db.query[tableName];
3736
4288
  const table = tables[tableName];
@@ -3775,24 +4327,24 @@ var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filte
3775
4327
  let cursorEntries;
3776
4328
  if (after != null || cursorSelected) {
3777
4329
  if (after != null && distinct?.length) {
3778
- throw new import_graphql7.GraphQLError("'after' cannot be combined with 'distinct'.");
4330
+ throw new import_graphql8.GraphQLError("'after' cannot be combined with 'distinct'.");
3779
4331
  }
3780
4332
  if (orderByHasRelationEntry(orderBy)) {
3781
4333
  if (after != null) {
3782
- throw new import_graphql7.GraphQLError(
4334
+ throw new import_graphql8.GraphQLError(
3783
4335
  "'after' cannot be combined with an orderBy that orders through a relation \u2014 a related row's value cannot be encoded into a cursor."
3784
4336
  );
3785
4337
  }
3786
4338
  } else if (!pkNames.length) {
3787
4339
  if (after != null) {
3788
- throw new import_graphql7.GraphQLError(
4340
+ throw new import_graphql8.GraphQLError(
3789
4341
  `Table ${tableName} has no primary key, so cursor pagination cannot be used on it.`
3790
4342
  );
3791
4343
  }
3792
4344
  } else {
3793
4345
  cursorEntries = cursorOrderingEntries(orderBy, pkNames);
3794
4346
  if (cursorSelected) {
3795
- const allColumns = (0, import_drizzle_orm6.getColumns)(table);
4347
+ const allColumns = (0, import_drizzle_orm7.getColumns)(table);
3796
4348
  for (const [column] of cursorEntries) {
3797
4349
  selectedColumnsSql[column] ??= allColumns[column];
3798
4350
  }
@@ -3801,7 +4353,7 @@ var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filte
3801
4353
  }
3802
4354
  const cursorCondition = after != null && cursorEntries ? buildCursorCondition(table, cursorEntries, decodeCursor(after, cursorEntries), "nulls-largest") : void 0;
3803
4355
  const baseWhereSql = where ? extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName)) : void 0;
3804
- const whereSql = cursorCondition ? (0, import_drizzle_orm6.and)(baseWhereSql, cursorCondition) : baseWhereSql;
4356
+ const whereSql = cursorCondition ? (0, import_drizzle_orm7.and)(baseWhereSql, cursorCondition) : baseWhereSql;
3805
4357
  let distinctKeys;
3806
4358
  if (distinct?.length) {
3807
4359
  distinctKeys = await selectDistinctKeys({
@@ -3912,10 +4464,10 @@ var generateSelectSingle2 = (db, tableName, tables, relationMap, orderArgs, filt
3912
4464
  };
3913
4465
  };
3914
4466
  var pgPrimaryKeyPropNames = (table) => getPrimaryKeyPropNamesFromConfig(table, import_pg_core2.getTableConfig);
3915
- var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx) => {
4467
+ var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested) => {
3916
4468
  const queryArgs = {
3917
4469
  values: {
3918
- type: new import_graphql7.GraphQLNonNull(new import_graphql7.GraphQLList(new import_graphql7.GraphQLNonNull(baseType)))
4470
+ type: new import_graphql8.GraphQLNonNull(new import_graphql8.GraphQLList(new import_graphql8.GraphQLNonNull(baseType)))
3919
4471
  }
3920
4472
  };
3921
4473
  const pkNames = pgPrimaryKeyPropNames(table);
@@ -3924,10 +4476,12 @@ var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType,
3924
4476
  resolver: async (_source, args, context, info) => {
3925
4477
  try {
3926
4478
  return await runMutation(db, context, info, txCtx, async (executor) => {
3927
- const input = remapFromGraphQLArrayInput(args.values, table);
3928
- if (!input.length) {
3929
- throw new import_graphql7.GraphQLError("No values were provided!");
4479
+ if (!args.values.length) {
4480
+ throw new import_graphql8.GraphQLError("No values were provided!");
3930
4481
  }
4482
+ const entries = nested?.enabled(tableName) ? args.values.map((values) => nested.split(tableName, values)) : void 0;
4483
+ const nestedEntries = entries?.some((entry) => nested.hasOps(entry.ops)) ? entries : void 0;
4484
+ const input = nestedEntries ? [] : remapFromGraphQLArrayInput(entries ? entries.map((entry) => entry.columns) : args.values, table);
3931
4485
  const parsedInfo = (0, import_graphql_parse_resolve_info3.parseResolveInfo)(info, {
3932
4486
  deep: true
3933
4487
  });
@@ -3941,11 +4495,22 @@ var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType,
3941
4495
  pkNames,
3942
4496
  parsedInfo
3943
4497
  });
3944
- let query = executor.insert(table).values(input).returning(columns);
3945
- if (conflictDoNothing) {
3946
- query = query.onConflictDoNothing();
3947
- }
3948
- const result = await query;
4498
+ const returning = nestedEntries ? nested.withJoinColumns(tableName, mergedOps(nestedEntries), { ...columns }, table) : columns;
4499
+ const runInsert = async (target, values) => {
4500
+ let query = target.insert(table).values(values).returning(returning);
4501
+ if (conflictDoNothing) {
4502
+ query = query.onConflictDoNothing();
4503
+ }
4504
+ return await query;
4505
+ };
4506
+ const result = nestedEntries ? await writeWithNestedOps({
4507
+ executor,
4508
+ runtime: nested,
4509
+ tableName,
4510
+ entries: nestedEntries,
4511
+ remapValues: (values) => remapFromGraphQLSingleInput(values, table),
4512
+ write: (tx, values) => runInsert(tx, [values])
4513
+ }) : await runInsert(executor, input);
3949
4514
  const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
3950
4515
  return remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
3951
4516
  });
@@ -3956,10 +4521,10 @@ var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType,
3956
4521
  args: queryArgs
3957
4522
  };
3958
4523
  };
3959
- var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx) => {
4524
+ var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested) => {
3960
4525
  const queryArgs = {
3961
4526
  values: {
3962
- type: new import_graphql7.GraphQLNonNull(baseType)
4527
+ type: new import_graphql8.GraphQLNonNull(baseType)
3963
4528
  }
3964
4529
  };
3965
4530
  const pkNames = pgPrimaryKeyPropNames(table);
@@ -3968,7 +4533,9 @@ var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType
3968
4533
  resolver: async (_source, args, context, info) => {
3969
4534
  try {
3970
4535
  return await runMutation(db, context, info, txCtx, async (executor) => {
3971
- const input = remapFromGraphQLSingleInput(args.values, table);
4536
+ const entry = nested?.enabled(tableName) ? nested.split(tableName, args.values) : void 0;
4537
+ const nestedEntry = entry && nested.hasOps(entry.ops) ? entry : void 0;
4538
+ const input = nestedEntry ? {} : remapFromGraphQLSingleInput(entry ? entry.columns : args.values, table);
3972
4539
  const parsedInfo = (0, import_graphql_parse_resolve_info3.parseResolveInfo)(info, {
3973
4540
  deep: true
3974
4541
  });
@@ -3982,11 +4549,22 @@ var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType
3982
4549
  pkNames,
3983
4550
  parsedInfo
3984
4551
  });
3985
- let query = executor.insert(table).values(input).returning(columns);
3986
- if (conflictDoNothing) {
3987
- query = query.onConflictDoNothing();
3988
- }
3989
- const result = await query;
4552
+ const returning = nestedEntry ? nested.withJoinColumns(tableName, nestedEntry.ops, { ...columns }, table) : columns;
4553
+ const runInsert = async (target, values) => {
4554
+ let query = target.insert(table).values(values).returning(returning);
4555
+ if (conflictDoNothing) {
4556
+ query = query.onConflictDoNothing();
4557
+ }
4558
+ return await query;
4559
+ };
4560
+ const result = nestedEntry ? await writeWithNestedOps({
4561
+ executor,
4562
+ runtime: nested,
4563
+ tableName,
4564
+ entries: [nestedEntry],
4565
+ remapValues: (values) => remapFromGraphQLSingleInput(values, table),
4566
+ write: runInsert
4567
+ }) : await runInsert(executor, input);
3990
4568
  if (!result[0]) {
3991
4569
  return void 0;
3992
4570
  }
@@ -4000,10 +4578,10 @@ var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType
4000
4578
  args: queryArgs
4001
4579
  };
4002
4580
  };
4003
- var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx, txCtx) => {
4581
+ var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx, txCtx, nested) => {
4004
4582
  const queryArgs = {
4005
4583
  values: {
4006
- type: single ? new import_graphql7.GraphQLNonNull(baseType) : new import_graphql7.GraphQLNonNull(new import_graphql7.GraphQLList(new import_graphql7.GraphQLNonNull(baseType)))
4584
+ type: single ? new import_graphql8.GraphQLNonNull(baseType) : new import_graphql8.GraphQLNonNull(new import_graphql8.GraphQLList(new import_graphql8.GraphQLNonNull(baseType)))
4007
4585
  },
4008
4586
  onConflict: {
4009
4587
  type: onConflictType,
@@ -4016,10 +4594,13 @@ var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onCo
4016
4594
  resolver: async (_source, args, context, info) => {
4017
4595
  try {
4018
4596
  return await runMutation(db, context, info, txCtx, async (executor) => {
4019
- const input = single ? [remapFromGraphQLSingleInput(args.values, table)] : remapFromGraphQLArrayInput(args.values, table);
4020
- if (!input.length) {
4021
- throw new import_graphql7.GraphQLError("No values were provided!");
4597
+ const supplied = single ? [args.values] : args.values;
4598
+ if (!supplied.length) {
4599
+ throw new import_graphql8.GraphQLError("No values were provided!");
4022
4600
  }
4601
+ const entries = nested?.enabled(tableName) ? supplied.map((values) => nested.split(tableName, values)) : void 0;
4602
+ const nestedEntries = entries?.some((entry) => nested.hasOps(entry.ops)) ? entries : void 0;
4603
+ const input = nestedEntries ? [] : remapFromGraphQLArrayInput(entries ? entries.map((entry) => entry.columns) : supplied, table);
4023
4604
  const parsedInfo = (0, import_graphql_parse_resolve_info3.parseResolveInfo)(info, { deep: true });
4024
4605
  const { columns, hasRelations, withParams } = prepareMutationRelationColumns({
4025
4606
  relationMap,
@@ -4031,19 +4612,30 @@ var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onCo
4031
4612
  pkNames,
4032
4613
  parsedInfo
4033
4614
  });
4034
- const plan = resolveConflictPlan({
4035
- table,
4036
- values: input,
4037
- onConflict: args.onConflict,
4038
- pkNames,
4039
- uniqueSets,
4040
- excludedRef: excludedColumnRef,
4041
- withTarget: true,
4042
- buildWhere: (where) => extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName))
4043
- });
4044
- let query = executor.insert(table).values(input).returning(columns);
4045
- query = plan.action === "NOTHING" ? query.onConflictDoNothing(plan.target ? { target: plan.target } : void 0) : query.onConflictDoUpdate({ target: plan.target, set: plan.set, setWhere: plan.setWhere });
4046
- const result = await query;
4615
+ const returning = nestedEntries ? nested.withJoinColumns(tableName, mergedOps(nestedEntries), { ...columns }, table) : columns;
4616
+ const runUpsert = async (target, values) => {
4617
+ const plan = resolveConflictPlan({
4618
+ table,
4619
+ values,
4620
+ onConflict: args.onConflict,
4621
+ pkNames,
4622
+ uniqueSets,
4623
+ excludedRef: excludedColumnRef,
4624
+ withTarget: true,
4625
+ buildWhere: (where) => extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName))
4626
+ });
4627
+ let query = target.insert(table).values(values).returning(returning);
4628
+ query = plan.action === "NOTHING" ? query.onConflictDoNothing(plan.target ? { target: plan.target } : void 0) : query.onConflictDoUpdate({ target: plan.target, set: plan.set, setWhere: plan.setWhere });
4629
+ return await query;
4630
+ };
4631
+ const result = nestedEntries ? await writeWithNestedOps({
4632
+ executor,
4633
+ runtime: nested,
4634
+ tableName,
4635
+ entries: nestedEntries,
4636
+ remapValues: (values) => remapFromGraphQLSingleInput(values, table),
4637
+ write: (tx, values) => runUpsert(tx, [values])
4638
+ }) : await runUpsert(executor, input);
4047
4639
  if (single && !result[0]) {
4048
4640
  return void 0;
4049
4641
  }
@@ -4057,13 +4649,13 @@ var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onCo
4057
4649
  args: queryArgs
4058
4650
  };
4059
4651
  };
4060
- var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx, txCtx) => {
4652
+ var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx, txCtx, nested) => {
4061
4653
  const queryArgs = {
4062
4654
  set: {
4063
- type: new import_graphql7.GraphQLNonNull(setArgs)
4655
+ type: new import_graphql8.GraphQLNonNull(setArgs)
4064
4656
  },
4065
4657
  where: {
4066
- type: single || requireWhere ? new import_graphql7.GraphQLNonNull(filterArgs) : filterArgs
4658
+ type: single || requireWhere ? new import_graphql8.GraphQLNonNull(filterArgs) : filterArgs
4067
4659
  }
4068
4660
  };
4069
4661
  const pkNames = pgPrimaryKeyPropNames(table);
@@ -4086,23 +4678,37 @@ var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filte
4086
4678
  pkNames,
4087
4679
  parsedInfo
4088
4680
  });
4089
- const input = remapFromGraphQLSingleInput(set, table);
4090
- if (!Object.keys(input).length) {
4091
- throw new import_graphql7.GraphQLError("Unable to update with no values specified!");
4681
+ const entry = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
4682
+ const nestedOps = entry && nested.hasOps(entry.ops) ? entry.ops : void 0;
4683
+ const input = remapFromGraphQLSingleInput(entry ? entry.columns : set, table);
4684
+ if (!Object.keys(input).length && !nestedOps) {
4685
+ throw new import_graphql8.GraphQLError("Unable to update with no values specified!");
4092
4686
  }
4093
4687
  const relationCtx = relationFilterCtx(filterCtx, tableName);
4094
4688
  const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
4095
4689
  if (single) {
4096
4690
  await assertSingleMatch(executor, table, filters, fieldName);
4097
4691
  }
4098
- let query = executor.update(table).set(input);
4099
- if (filters) {
4100
- query = query.where(filters);
4101
- }
4102
- query = query.returning(columns);
4103
- const result = await query;
4692
+ const returning = nestedOps ? nested.withJoinColumns(tableName, nestedOps, { ...columns }, table) : columns;
4693
+ const runUpdate = async (target, values) => {
4694
+ const writes = Object.keys(values).length > 0;
4695
+ let query = writes ? target.update(table).set(values) : target.select(returning).from(table);
4696
+ if (filters) {
4697
+ query = query.where(filters);
4698
+ }
4699
+ return await (writes ? query.returning(returning) : query);
4700
+ };
4701
+ const result = nestedOps ? await updateWithNestedOps({
4702
+ executor,
4703
+ runtime: nested,
4704
+ tableName,
4705
+ columns: input,
4706
+ ops: nestedOps,
4707
+ remapValues: (values) => values,
4708
+ write: runUpdate
4709
+ }) : await runUpdate(executor, input);
4104
4710
  if (single && result.length > 1) {
4105
- throw new import_graphql7.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
4711
+ throw new import_graphql8.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
4106
4712
  }
4107
4713
  if (single && !result[0]) {
4108
4714
  return void 0;
@@ -4117,10 +4723,10 @@ var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filte
4117
4723
  args: queryArgs
4118
4724
  };
4119
4725
  };
4120
- var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx, txCtx) => {
4726
+ var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx, txCtx, nested) => {
4121
4727
  const queryArgs = {
4122
4728
  updates: {
4123
- type: new import_graphql7.GraphQLNonNull(new import_graphql7.GraphQLList(new import_graphql7.GraphQLNonNull(updateManyInput)))
4729
+ type: new import_graphql8.GraphQLNonNull(new import_graphql8.GraphQLList(new import_graphql8.GraphQLNonNull(updateManyInput)))
4124
4730
  }
4125
4731
  };
4126
4732
  const pkNames = pgPrimaryKeyPropNames(table);
@@ -4131,7 +4737,7 @@ var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateMany
4131
4737
  return await runMutation(db, context, info, txCtx, async (executor) => {
4132
4738
  const { updates } = args;
4133
4739
  if (!updates.length) {
4134
- throw new import_graphql7.GraphQLError("No updates were provided!");
4740
+ throw new import_graphql8.GraphQLError("No updates were provided!");
4135
4741
  }
4136
4742
  const parsedInfo = (0, import_graphql_parse_resolve_info3.parseResolveInfo)(info, {
4137
4743
  deep: true
@@ -4147,23 +4753,40 @@ var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateMany
4147
4753
  parsedInfo
4148
4754
  });
4149
4755
  const entries = updates.map(({ where, set }) => {
4150
- const input = remapFromGraphQLSingleInput(set, table);
4151
- if (!Object.keys(input).length) {
4152
- throw new import_graphql7.GraphQLError("Unable to update with no values specified!");
4756
+ const split = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
4757
+ const ops = split && nested.hasOps(split.ops) ? split.ops : void 0;
4758
+ const input = remapFromGraphQLSingleInput(split ? split.columns : set, table);
4759
+ if (!Object.keys(input).length && !ops) {
4760
+ throw new import_graphql8.GraphQLError("Unable to update with no values specified!");
4153
4761
  }
4154
4762
  return {
4155
4763
  set: input,
4764
+ ops,
4156
4765
  filters: where ? extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName)) : void 0
4157
4766
  };
4158
4767
  });
4768
+ const returning = entries.some((entry) => entry.ops) ? nested.withJoinColumns(
4769
+ tableName,
4770
+ mergedOps(entries.map((entry) => ({ ops: entry.ops ?? {} }))),
4771
+ {
4772
+ ...columns
4773
+ },
4774
+ table
4775
+ ) : columns;
4159
4776
  const perEntry = await executor.transaction(async (tx) => {
4160
4777
  const results = [];
4161
4778
  for (const entry of entries) {
4162
- let query = tx.update(table).set(entry.set);
4779
+ const values = entry.ops ? { ...entry.set, ...await nested.applyParentSide(tx, tableName, entry.ops) } : entry.set;
4780
+ const writes = Object.keys(values).length > 0;
4781
+ let query = writes ? tx.update(table).set(values) : tx.select(returning).from(table);
4163
4782
  if (entry.filters) {
4164
4783
  query = query.where(entry.filters);
4165
4784
  }
4166
- results.push(await query.returning(columns));
4785
+ const rows = await (writes ? query.returning(returning) : query);
4786
+ if (entry.ops) {
4787
+ await nested.applyChildSide(tx, tableName, entry.ops, rows);
4788
+ }
4789
+ results.push(rows);
4167
4790
  }
4168
4791
  return results;
4169
4792
  });
@@ -4193,7 +4816,7 @@ var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateMany
4193
4816
  var generateDelete2 = (db, tableName, table, filterArgs, fieldName, typeName, single, requireWhere, filterCtx, selectionCtx, txCtx) => {
4194
4817
  const queryArgs = {
4195
4818
  where: {
4196
- type: single || requireWhere ? new import_graphql7.GraphQLNonNull(filterArgs) : filterArgs
4819
+ type: single || requireWhere ? new import_graphql8.GraphQLNonNull(filterArgs) : filterArgs
4197
4820
  }
4198
4821
  };
4199
4822
  return {
@@ -4222,7 +4845,7 @@ var generateDelete2 = (db, tableName, table, filterArgs, fieldName, typeName, si
4222
4845
  query = query.returning(columns);
4223
4846
  const result = await query;
4224
4847
  if (single && result.length > 1) {
4225
- throw new import_graphql7.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
4848
+ throw new import_graphql8.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
4226
4849
  }
4227
4850
  if (single) {
4228
4851
  return result[0] ? remapToGraphQLSingleOutput(result[0], tableName, table) : void 0;
@@ -4248,13 +4871,15 @@ function generateSchemaData2(db, schema, relations, options) {
4248
4871
  complexity
4249
4872
  } = options;
4250
4873
  const schemaEntries = Object.entries(schema);
4251
- const tableEntries = schemaEntries.filter(([_key, value]) => (0, import_drizzle_orm6.is)(value, import_pg_core2.PgTable));
4874
+ const tableEntries = schemaEntries.filter(([_key, value]) => (0, import_drizzle_orm7.is)(value, import_pg_core2.PgTable));
4252
4875
  const tables = Object.fromEntries(tableEntries);
4253
4876
  if (!tableEntries.length) {
4254
4877
  throw new Error(
4255
4878
  "Drizzle-GraphQL Error: No tables detected in Drizzle-ORM's database instance. Did you forget to pass schema to drizzle constructor?"
4256
4879
  );
4257
4880
  }
4881
+ registerScalarOverrides(tables, options);
4882
+ registerEnumConfig(options);
4258
4883
  const namedRelations = buildNamedRelations(relations ?? {}, tableEntries);
4259
4884
  attachTargetPrimaryKeys(namedRelations, tables, pgPrimaryKeyPropNames);
4260
4885
  const eagerRelations = pruneNonEagerRelations(namedRelations, shouldEagerLoad);
@@ -4266,12 +4891,24 @@ function generateSchemaData2(db, schema, relations, options) {
4266
4891
  relationFieldContainers: /* @__PURE__ */ new Map(),
4267
4892
  fullyBuiltTables: /* @__PURE__ */ new Set(),
4268
4893
  relationTypeCache: /* @__PURE__ */ new Map(),
4894
+ selectFieldCache: /* @__PURE__ */ new WeakMap(),
4895
+ filterFieldCache: /* @__PURE__ */ new WeakMap(),
4269
4896
  orderTypeCache: /* @__PURE__ */ new WeakMap(),
4270
4897
  filterTypeCache: /* @__PURE__ */ new WeakMap(),
4271
4898
  listRelationFilterCache: /* @__PURE__ */ new Map(),
4272
4899
  aggregateTypeCache: /* @__PURE__ */ new Map(),
4273
- complexity
4900
+ complexity,
4901
+ docs: options.docs ?? {}
4274
4902
  };
4903
+ const nestedPlans = features.nestedWrites ? buildNestedWritePlans(
4904
+ tables,
4905
+ namedRelations,
4906
+ (target) => getUniqueColumnSets(target, import_pg_core2.getTableConfig),
4907
+ (target) => pgPrimaryKeyPropNames(target),
4908
+ extractRelationJoinColumns
4909
+ ) : void 0;
4910
+ const nestedTypes = nestedPlans ? createNestedWriteTypes({ plans: nestedPlans, cacheCtx, typeNameMapper, insertPrefix: prefixes.insert }) : void 0;
4911
+ const nestedRuntime = nestedPlans ? createNestedWriteRuntime({ plans: nestedPlans, filterCtx }) : void 0;
4275
4912
  const relationAggregateFactory = features.relationAggregates ? createRelationAggregateFactory(db, tables, cacheCtx, typeNameMapper, filterCtx) : void 0;
4276
4913
  const queries = {};
4277
4914
  const mutations = {};
@@ -4290,7 +4927,8 @@ function generateSchemaData2(db, schema, relations, options) {
4290
4927
  prefixes.insert,
4291
4928
  prefixes.update,
4292
4929
  resolverFactory,
4293
- relationAggregateFactory
4930
+ relationAggregateFactory,
4931
+ nestedTypes
4294
4932
  )
4295
4933
  ])
4296
4934
  );
@@ -4351,7 +4989,8 @@ function generateSchemaData2(db, schema, relations, options) {
4351
4989
  typeName,
4352
4990
  typeNameMapper,
4353
4991
  conflictDoNothing,
4354
- mutationTxCtx
4992
+ mutationTxCtx,
4993
+ nestedRuntime
4355
4994
  ) : void 0;
4356
4995
  const insertSingleGenerated = features.insert ? generateInsertSingle2(
4357
4996
  db,
@@ -4364,7 +5003,8 @@ function generateSchemaData2(db, schema, relations, options) {
4364
5003
  typeName,
4365
5004
  typeNameMapper,
4366
5005
  conflictDoNothing,
4367
- mutationTxCtx
5006
+ mutationTxCtx,
5007
+ nestedRuntime
4368
5008
  ) : void 0;
4369
5009
  const uniqueSets = features.upsert ? getUniqueColumnSets(schema[tableName], import_pg_core2.getTableConfig) : [];
4370
5010
  const onConflictInput = features.upsert ? generateOnConflictInput({
@@ -4388,7 +5028,8 @@ function generateSchemaData2(db, schema, relations, options) {
4388
5028
  false,
4389
5029
  typeNameMapper,
4390
5030
  filterCtx,
4391
- mutationTxCtx
5031
+ mutationTxCtx,
5032
+ nestedRuntime
4392
5033
  ) : void 0;
4393
5034
  const upsertSingleGenerated = onConflictInput ? generateUpsert2(
4394
5035
  db,
@@ -4404,7 +5045,8 @@ function generateSchemaData2(db, schema, relations, options) {
4404
5045
  true,
4405
5046
  typeNameMapper,
4406
5047
  filterCtx,
4407
- mutationTxCtx
5048
+ mutationTxCtx,
5049
+ nestedRuntime
4408
5050
  ) : void 0;
4409
5051
  const updateGenerated = features.update ? generateUpdate2(
4410
5052
  db,
@@ -4420,7 +5062,8 @@ function generateSchemaData2(db, schema, relations, options) {
4420
5062
  features.requireWhere,
4421
5063
  typeNameMapper,
4422
5064
  filterCtx,
4423
- mutationTxCtx
5065
+ mutationTxCtx,
5066
+ nestedRuntime
4424
5067
  ) : void 0;
4425
5068
  const updateSingleGenerated = features.update ? generateUpdate2(
4426
5069
  db,
@@ -4436,7 +5079,8 @@ function generateSchemaData2(db, schema, relations, options) {
4436
5079
  features.requireWhere,
4437
5080
  typeNameMapper,
4438
5081
  filterCtx,
4439
- mutationTxCtx
5082
+ mutationTxCtx,
5083
+ nestedRuntime
4440
5084
  ) : void 0;
4441
5085
  const updateManyInput = features.update && features.updateMany ? generateUpdateManyInput({ typeName, updatePrefix: prefixes.update, updateInput, tableFilters }) : void 0;
4442
5086
  const updateManyGenerated = updateManyInput ? generateUpdateMany2(
@@ -4450,7 +5094,8 @@ function generateSchemaData2(db, schema, relations, options) {
4450
5094
  typeName,
4451
5095
  typeNameMapper,
4452
5096
  filterCtx,
4453
- mutationTxCtx
5097
+ mutationTxCtx,
5098
+ nestedRuntime
4454
5099
  ) : void 0;
4455
5100
  const deleteGenerated = features.delete ? generateDelete2(
4456
5101
  db,
@@ -4515,7 +5160,7 @@ function generateSchemaData2(db, schema, relations, options) {
4515
5160
  };
4516
5161
  if (aggregateGenerated && aggregateType) {
4517
5162
  queries[aggregateGenerated.name] = {
4518
- type: new import_graphql7.GraphQLNonNull(aggregateType),
5163
+ type: new import_graphql8.GraphQLNonNull(aggregateType),
4519
5164
  args: aggregateGenerated.args,
4520
5165
  resolve: aggregateGenerated.resolver,
4521
5166
  ...complexity ? { extensions: { complexity: aggregateFieldComplexity(complexity) } } : {}
@@ -4523,7 +5168,7 @@ function generateSchemaData2(db, schema, relations, options) {
4523
5168
  }
4524
5169
  if (groupByGenerated && groupByType) {
4525
5170
  queries[groupByGenerated.name] = {
4526
- type: new import_graphql7.GraphQLNonNull(new import_graphql7.GraphQLList(new import_graphql7.GraphQLNonNull(groupByType))),
5171
+ type: new import_graphql8.GraphQLNonNull(new import_graphql8.GraphQLList(new import_graphql8.GraphQLNonNull(groupByType))),
4527
5172
  args: groupByGenerated.args,
4528
5173
  resolve: groupByGenerated.resolver,
4529
5174
  ...complexity ? { extensions: { complexity: aggregateFieldComplexity(complexity) } } : {}
@@ -4567,7 +5212,7 @@ function generateSchemaData2(db, schema, relations, options) {
4567
5212
  if (updateManyGenerated) {
4568
5213
  mutations[updateManyGenerated.name] = {
4569
5214
  // Nullable items: a no-match entry yields `null` in its slot.
4570
- type: new import_graphql7.GraphQLNonNull(new import_graphql7.GraphQLList(singleTableItemOutput)),
5215
+ type: new import_graphql8.GraphQLNonNull(new import_graphql8.GraphQLList(singleTableItemOutput)),
4571
5216
  args: updateManyGenerated.args,
4572
5217
  resolve: updateManyGenerated.resolver
4573
5218
  };
@@ -4624,7 +5269,7 @@ function generateSchemaData2(db, schema, relations, options) {
4624
5269
  for (const [tableName, tableRelations] of Object.entries(namedRelations)) {
4625
5270
  const relResolvers = {};
4626
5271
  for (const [relName, relEntry] of Object.entries(tableRelations)) {
4627
- const isOne = (0, import_drizzle_orm6.is)(relEntry.relation ?? relEntry, import_drizzle_orm6.One);
5272
+ const isOne = (0, import_drizzle_orm7.is)(relEntry.relation ?? relEntry, import_drizzle_orm7.One);
4628
5273
  const resolver = resolverFactory({ tableName, relationName: relName, relEntry, isOne });
4629
5274
  if (resolver) {
4630
5275
  relResolvers[relName] = resolver;
@@ -4638,9 +5283,9 @@ function generateSchemaData2(db, schema, relations, options) {
4638
5283
  }
4639
5284
 
4640
5285
  // src/util/builders/sqlite.ts
4641
- var import_drizzle_orm7 = require("drizzle-orm");
5286
+ var import_drizzle_orm8 = require("drizzle-orm");
4642
5287
  var import_sqlite_core2 = require("drizzle-orm/sqlite-core");
4643
- var import_graphql8 = require("graphql");
5288
+ var import_graphql9 = require("graphql");
4644
5289
  var import_graphql_parse_resolve_info4 = require("graphql-parse-resolve-info");
4645
5290
  var generateSelectArray3 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, distinctEnabled = true) => {
4646
5291
  const queryBase = db.query[tableName];
@@ -4725,10 +5370,10 @@ var generateSelectSingle3 = (db, tableName, tables, relationMap, orderArgs, filt
4725
5370
  };
4726
5371
  };
4727
5372
  var sqlitePrimaryKeyPropNames = (table) => getPrimaryKeyPropNamesFromConfig(table, import_sqlite_core2.getTableConfig);
4728
- var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx) => {
5373
+ var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested) => {
4729
5374
  const queryArgs = {
4730
5375
  values: {
4731
- type: new import_graphql8.GraphQLNonNull(new import_graphql8.GraphQLList(new import_graphql8.GraphQLNonNull(baseType)))
5376
+ type: new import_graphql9.GraphQLNonNull(new import_graphql9.GraphQLList(new import_graphql9.GraphQLNonNull(baseType)))
4732
5377
  }
4733
5378
  };
4734
5379
  const pkNames = sqlitePrimaryKeyPropNames(table);
@@ -4737,10 +5382,12 @@ var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType,
4737
5382
  resolver: async (_source, args, context, info) => {
4738
5383
  try {
4739
5384
  return await runMutation(db, context, info, txCtx, async (executor) => {
4740
- const input = remapFromGraphQLArrayInput(args.values, table);
4741
- if (!input.length) {
4742
- throw new import_graphql8.GraphQLError("No values were provided!");
5385
+ if (!args.values.length) {
5386
+ throw new import_graphql9.GraphQLError("No values were provided!");
4743
5387
  }
5388
+ const entries = nested?.enabled(tableName) ? args.values.map((values) => nested.split(tableName, values)) : void 0;
5389
+ const nestedEntries = entries?.some((entry) => nested.hasOps(entry.ops)) ? entries : void 0;
5390
+ const input = nestedEntries ? [] : remapFromGraphQLArrayInput(entries ? entries.map((entry) => entry.columns) : args.values, table);
4744
5391
  const parsedInfo = (0, import_graphql_parse_resolve_info4.parseResolveInfo)(info, {
4745
5392
  deep: true
4746
5393
  });
@@ -4754,11 +5401,22 @@ var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType,
4754
5401
  pkNames,
4755
5402
  parsedInfo
4756
5403
  });
4757
- let query = executor.insert(table).values(input).returning(columns);
4758
- if (conflictDoNothing) {
4759
- query = query.onConflictDoNothing();
4760
- }
4761
- const result = await query;
5404
+ const returning = nestedEntries ? nested.withJoinColumns(tableName, mergedOps(nestedEntries), { ...columns }, table) : columns;
5405
+ const runInsert = async (target, values) => {
5406
+ let query = target.insert(table).values(values).returning(returning);
5407
+ if (conflictDoNothing) {
5408
+ query = query.onConflictDoNothing();
5409
+ }
5410
+ return await query;
5411
+ };
5412
+ const result = nestedEntries ? await writeWithNestedOps({
5413
+ executor,
5414
+ runtime: nested,
5415
+ tableName,
5416
+ entries: nestedEntries,
5417
+ remapValues: (values) => remapFromGraphQLSingleInput(values, table),
5418
+ write: (tx, values) => runInsert(tx, [values])
5419
+ }) : await runInsert(executor, input);
4762
5420
  const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
4763
5421
  return remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
4764
5422
  });
@@ -4769,10 +5427,10 @@ var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType,
4769
5427
  args: queryArgs
4770
5428
  };
4771
5429
  };
4772
- var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx) => {
5430
+ var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested) => {
4773
5431
  const queryArgs = {
4774
5432
  values: {
4775
- type: new import_graphql8.GraphQLNonNull(baseType)
5433
+ type: new import_graphql9.GraphQLNonNull(baseType)
4776
5434
  }
4777
5435
  };
4778
5436
  const pkNames = sqlitePrimaryKeyPropNames(table);
@@ -4781,7 +5439,9 @@ var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType
4781
5439
  resolver: async (_source, args, context, info) => {
4782
5440
  try {
4783
5441
  return await runMutation(db, context, info, txCtx, async (executor) => {
4784
- const input = remapFromGraphQLSingleInput(args.values, table);
5442
+ const entry = nested?.enabled(tableName) ? nested.split(tableName, args.values) : void 0;
5443
+ const nestedEntry = entry && nested.hasOps(entry.ops) ? entry : void 0;
5444
+ const input = nestedEntry ? {} : remapFromGraphQLSingleInput(entry ? entry.columns : args.values, table);
4785
5445
  const parsedInfo = (0, import_graphql_parse_resolve_info4.parseResolveInfo)(info, {
4786
5446
  deep: true
4787
5447
  });
@@ -4795,11 +5455,22 @@ var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType
4795
5455
  pkNames,
4796
5456
  parsedInfo
4797
5457
  });
4798
- let query = executor.insert(table).values(input).returning(columns);
4799
- if (conflictDoNothing) {
4800
- query = query.onConflictDoNothing();
4801
- }
4802
- const result = await query;
5458
+ const returning = nestedEntry ? nested.withJoinColumns(tableName, nestedEntry.ops, { ...columns }, table) : columns;
5459
+ const runInsert = async (target, values) => {
5460
+ let query = target.insert(table).values(values).returning(returning);
5461
+ if (conflictDoNothing) {
5462
+ query = query.onConflictDoNothing();
5463
+ }
5464
+ return await query;
5465
+ };
5466
+ const result = nestedEntry ? await writeWithNestedOps({
5467
+ executor,
5468
+ runtime: nested,
5469
+ tableName,
5470
+ entries: [nestedEntry],
5471
+ remapValues: (values) => remapFromGraphQLSingleInput(values, table),
5472
+ write: runInsert
5473
+ }) : await runInsert(executor, input);
4803
5474
  if (!result[0]) {
4804
5475
  return void 0;
4805
5476
  }
@@ -4813,10 +5484,10 @@ var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType
4813
5484
  args: queryArgs
4814
5485
  };
4815
5486
  };
4816
- var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx, txCtx) => {
5487
+ var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx, txCtx, nested) => {
4817
5488
  const queryArgs = {
4818
5489
  values: {
4819
- type: single ? new import_graphql8.GraphQLNonNull(baseType) : new import_graphql8.GraphQLNonNull(new import_graphql8.GraphQLList(new import_graphql8.GraphQLNonNull(baseType)))
5490
+ type: single ? new import_graphql9.GraphQLNonNull(baseType) : new import_graphql9.GraphQLNonNull(new import_graphql9.GraphQLList(new import_graphql9.GraphQLNonNull(baseType)))
4820
5491
  },
4821
5492
  onConflict: {
4822
5493
  type: onConflictType,
@@ -4829,10 +5500,13 @@ var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onCo
4829
5500
  resolver: async (_source, args, context, info) => {
4830
5501
  try {
4831
5502
  return await runMutation(db, context, info, txCtx, async (executor) => {
4832
- const input = single ? [remapFromGraphQLSingleInput(args.values, table)] : remapFromGraphQLArrayInput(args.values, table);
4833
- if (!input.length) {
4834
- throw new import_graphql8.GraphQLError("No values were provided!");
5503
+ const supplied = single ? [args.values] : args.values;
5504
+ if (!supplied.length) {
5505
+ throw new import_graphql9.GraphQLError("No values were provided!");
4835
5506
  }
5507
+ const entries = nested?.enabled(tableName) ? supplied.map((values) => nested.split(tableName, values)) : void 0;
5508
+ const nestedEntries = entries?.some((entry) => nested.hasOps(entry.ops)) ? entries : void 0;
5509
+ const input = nestedEntries ? [] : remapFromGraphQLArrayInput(entries ? entries.map((entry) => entry.columns) : supplied, table);
4836
5510
  const parsedInfo = (0, import_graphql_parse_resolve_info4.parseResolveInfo)(info, { deep: true });
4837
5511
  const { columns, hasRelations, withParams } = prepareMutationRelationColumns({
4838
5512
  relationMap,
@@ -4844,19 +5518,30 @@ var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onCo
4844
5518
  pkNames,
4845
5519
  parsedInfo
4846
5520
  });
4847
- const plan = resolveConflictPlan({
4848
- table,
4849
- values: input,
4850
- onConflict: args.onConflict,
4851
- pkNames,
4852
- uniqueSets,
4853
- excludedRef: excludedColumnRef,
4854
- withTarget: true,
4855
- buildWhere: (where) => extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName))
4856
- });
4857
- let query = executor.insert(table).values(input).returning(columns);
4858
- query = plan.action === "NOTHING" ? query.onConflictDoNothing(plan.target ? { target: plan.target } : void 0) : query.onConflictDoUpdate({ target: plan.target, set: plan.set, setWhere: plan.setWhere });
4859
- const result = await query;
5521
+ const returning = nestedEntries ? nested.withJoinColumns(tableName, mergedOps(nestedEntries), { ...columns }, table) : columns;
5522
+ const runUpsert = async (target, values) => {
5523
+ const plan = resolveConflictPlan({
5524
+ table,
5525
+ values,
5526
+ onConflict: args.onConflict,
5527
+ pkNames,
5528
+ uniqueSets,
5529
+ excludedRef: excludedColumnRef,
5530
+ withTarget: true,
5531
+ buildWhere: (where) => extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName))
5532
+ });
5533
+ let query = target.insert(table).values(values).returning(returning);
5534
+ query = plan.action === "NOTHING" ? query.onConflictDoNothing(plan.target ? { target: plan.target } : void 0) : query.onConflictDoUpdate({ target: plan.target, set: plan.set, setWhere: plan.setWhere });
5535
+ return await query;
5536
+ };
5537
+ const result = nestedEntries ? await writeWithNestedOps({
5538
+ executor,
5539
+ runtime: nested,
5540
+ tableName,
5541
+ entries: nestedEntries,
5542
+ remapValues: (values) => remapFromGraphQLSingleInput(values, table),
5543
+ write: (tx, values) => runUpsert(tx, [values])
5544
+ }) : await runUpsert(executor, input);
4860
5545
  if (single && !result[0]) {
4861
5546
  return void 0;
4862
5547
  }
@@ -4870,13 +5555,13 @@ var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onCo
4870
5555
  args: queryArgs
4871
5556
  };
4872
5557
  };
4873
- var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx, txCtx) => {
5558
+ var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx, txCtx, nested) => {
4874
5559
  const queryArgs = {
4875
5560
  set: {
4876
- type: new import_graphql8.GraphQLNonNull(setArgs)
5561
+ type: new import_graphql9.GraphQLNonNull(setArgs)
4877
5562
  },
4878
5563
  where: {
4879
- type: single || requireWhere ? new import_graphql8.GraphQLNonNull(filterArgs) : filterArgs
5564
+ type: single || requireWhere ? new import_graphql9.GraphQLNonNull(filterArgs) : filterArgs
4880
5565
  }
4881
5566
  };
4882
5567
  const pkNames = sqlitePrimaryKeyPropNames(table);
@@ -4899,23 +5584,37 @@ var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filte
4899
5584
  pkNames,
4900
5585
  parsedInfo
4901
5586
  });
4902
- const input = remapFromGraphQLSingleInput(set, table);
4903
- if (!Object.keys(input).length) {
4904
- throw new import_graphql8.GraphQLError("Unable to update with no values specified!");
5587
+ const entry = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
5588
+ const nestedOps = entry && nested.hasOps(entry.ops) ? entry.ops : void 0;
5589
+ const input = remapFromGraphQLSingleInput(entry ? entry.columns : set, table);
5590
+ if (!Object.keys(input).length && !nestedOps) {
5591
+ throw new import_graphql9.GraphQLError("Unable to update with no values specified!");
4905
5592
  }
4906
5593
  const relationCtx = relationFilterCtx(filterCtx, tableName);
4907
5594
  const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
4908
5595
  if (single) {
4909
5596
  await assertSingleMatch(executor, table, filters, fieldName);
4910
5597
  }
4911
- let query = executor.update(table).set(input);
4912
- if (filters) {
4913
- query = query.where(filters);
4914
- }
4915
- query = query.returning(columns);
4916
- const result = await query;
5598
+ const returning = nestedOps ? nested.withJoinColumns(tableName, nestedOps, { ...columns }, table) : columns;
5599
+ const runUpdate = async (target, values) => {
5600
+ const writes = Object.keys(values).length > 0;
5601
+ let query = writes ? target.update(table).set(values) : target.select(returning).from(table);
5602
+ if (filters) {
5603
+ query = query.where(filters);
5604
+ }
5605
+ return await (writes ? query.returning(returning) : query);
5606
+ };
5607
+ const result = nestedOps ? await updateWithNestedOps({
5608
+ executor,
5609
+ runtime: nested,
5610
+ tableName,
5611
+ columns: input,
5612
+ ops: nestedOps,
5613
+ remapValues: (values) => values,
5614
+ write: runUpdate
5615
+ }) : await runUpdate(executor, input);
4917
5616
  if (single && result.length > 1) {
4918
- throw new import_graphql8.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
5617
+ throw new import_graphql9.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
4919
5618
  }
4920
5619
  if (single && !result[0]) {
4921
5620
  return void 0;
@@ -4930,10 +5629,10 @@ var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filte
4930
5629
  args: queryArgs
4931
5630
  };
4932
5631
  };
4933
- var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx, txCtx) => {
5632
+ var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx, txCtx, nested) => {
4934
5633
  const queryArgs = {
4935
5634
  updates: {
4936
- type: new import_graphql8.GraphQLNonNull(new import_graphql8.GraphQLList(new import_graphql8.GraphQLNonNull(updateManyInput)))
5635
+ type: new import_graphql9.GraphQLNonNull(new import_graphql9.GraphQLList(new import_graphql9.GraphQLNonNull(updateManyInput)))
4937
5636
  }
4938
5637
  };
4939
5638
  const pkNames = sqlitePrimaryKeyPropNames(table);
@@ -4944,7 +5643,7 @@ var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateMany
4944
5643
  return await runMutation(db, context, info, txCtx, async (executor) => {
4945
5644
  const { updates } = args;
4946
5645
  if (!updates.length) {
4947
- throw new import_graphql8.GraphQLError("No updates were provided!");
5646
+ throw new import_graphql9.GraphQLError("No updates were provided!");
4948
5647
  }
4949
5648
  const parsedInfo = (0, import_graphql_parse_resolve_info4.parseResolveInfo)(info, {
4950
5649
  deep: true
@@ -4960,23 +5659,55 @@ var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateMany
4960
5659
  parsedInfo
4961
5660
  });
4962
5661
  const entries = updates.map(({ where, set }) => {
4963
- const input = remapFromGraphQLSingleInput(set, table);
4964
- if (!Object.keys(input).length) {
4965
- throw new import_graphql8.GraphQLError("Unable to update with no values specified!");
5662
+ const split = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
5663
+ const ops = split && nested.hasOps(split.ops) ? split.ops : void 0;
5664
+ const input = remapFromGraphQLSingleInput(split ? split.columns : set, table);
5665
+ if (!Object.keys(input).length && !ops) {
5666
+ throw new import_graphql9.GraphQLError("Unable to update with no values specified!");
4966
5667
  }
4967
5668
  return {
4968
5669
  set: input,
5670
+ ops,
4969
5671
  filters: where ? extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName)) : void 0
4970
5672
  };
4971
5673
  });
5674
+ const anyNested = entries.some((entry) => entry.ops);
5675
+ const returning = anyNested ? nested.withJoinColumns(
5676
+ tableName,
5677
+ mergedOps(entries.map((entry) => ({ ops: entry.ops ?? {} }))),
5678
+ { ...columns },
5679
+ table
5680
+ ) : columns;
4972
5681
  const runEntry = (tx, entry) => {
4973
5682
  let query = tx.update(table).set(entry.set);
4974
5683
  if (entry.filters) {
4975
5684
  query = query.where(entry.filters);
4976
5685
  }
4977
- return query.returning(columns).all();
5686
+ return query.returning(returning).all();
5687
+ };
5688
+ const runNestedEntry = async (tx, entry) => {
5689
+ const values = entry.ops ? { ...entry.set, ...await nested.applyParentSide(tx, tableName, entry.ops) } : entry.set;
5690
+ const writes = Object.keys(values).length > 0;
5691
+ let query = writes ? tx.update(table).set(values) : tx.select(returning).from(table);
5692
+ if (entry.filters) {
5693
+ query = query.where(entry.filters);
5694
+ }
5695
+ const rows = await (writes ? query.returning(returning) : query);
5696
+ if (entry.ops) {
5697
+ await nested.applyChildSide(tx, tableName, entry.ops, rows);
5698
+ }
5699
+ return rows;
4978
5700
  };
4979
5701
  const perEntry = await executor.transaction((tx) => {
5702
+ if (anyNested) {
5703
+ return (async () => {
5704
+ const results2 = [];
5705
+ for (const entry of entries) {
5706
+ results2.push(await runNestedEntry(tx, entry));
5707
+ }
5708
+ return results2;
5709
+ })();
5710
+ }
4980
5711
  const first = runEntry(tx, entries[0]);
4981
5712
  if (typeof first?.then === "function") {
4982
5713
  return (async () => {
@@ -5019,7 +5750,7 @@ var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateMany
5019
5750
  var generateDelete3 = (db, tableName, table, filterArgs, fieldName, typeName, single, requireWhere, filterCtx, selectionCtx, txCtx) => {
5020
5751
  const queryArgs = {
5021
5752
  where: {
5022
- type: single || requireWhere ? new import_graphql8.GraphQLNonNull(filterArgs) : filterArgs
5753
+ type: single || requireWhere ? new import_graphql9.GraphQLNonNull(filterArgs) : filterArgs
5023
5754
  }
5024
5755
  };
5025
5756
  return {
@@ -5048,7 +5779,7 @@ var generateDelete3 = (db, tableName, table, filterArgs, fieldName, typeName, si
5048
5779
  query = query.returning(columns);
5049
5780
  const result = await query;
5050
5781
  if (single && result.length > 1) {
5051
- throw new import_graphql8.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
5782
+ throw new import_graphql9.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
5052
5783
  }
5053
5784
  if (single) {
5054
5785
  return result[0] ? remapToGraphQLSingleOutput(result[0], tableName, table) : void 0;
@@ -5075,13 +5806,15 @@ var generateSchemaData3 = (db, schema, relations, options) => {
5075
5806
  } = options;
5076
5807
  const rawSchema = schema;
5077
5808
  const schemaEntries = Object.entries(rawSchema);
5078
- const tableEntries = schemaEntries.filter(([_key, value]) => (0, import_drizzle_orm7.is)(value, import_sqlite_core2.SQLiteTable));
5809
+ const tableEntries = schemaEntries.filter(([_key, value]) => (0, import_drizzle_orm8.is)(value, import_sqlite_core2.SQLiteTable));
5079
5810
  const tables = Object.fromEntries(tableEntries);
5080
5811
  if (!tableEntries.length) {
5081
5812
  throw new Error(
5082
5813
  "Drizzle-GraphQL Error: No tables detected in Drizzle-ORM's database instance. Did you forget to pass schema to drizzle constructor?"
5083
5814
  );
5084
5815
  }
5816
+ registerScalarOverrides(tables, options);
5817
+ registerEnumConfig(options);
5085
5818
  const namedRelations = buildNamedRelations(relations ?? {}, tableEntries);
5086
5819
  attachTargetPrimaryKeys(namedRelations, tables, sqlitePrimaryKeyPropNames);
5087
5820
  const eagerRelations = pruneNonEagerRelations(namedRelations, shouldEagerLoad);
@@ -5093,12 +5826,29 @@ var generateSchemaData3 = (db, schema, relations, options) => {
5093
5826
  relationFieldContainers: /* @__PURE__ */ new Map(),
5094
5827
  fullyBuiltTables: /* @__PURE__ */ new Set(),
5095
5828
  relationTypeCache: /* @__PURE__ */ new Map(),
5829
+ selectFieldCache: /* @__PURE__ */ new WeakMap(),
5830
+ filterFieldCache: /* @__PURE__ */ new WeakMap(),
5096
5831
  orderTypeCache: /* @__PURE__ */ new WeakMap(),
5097
5832
  filterTypeCache: /* @__PURE__ */ new WeakMap(),
5098
5833
  listRelationFilterCache: /* @__PURE__ */ new Map(),
5099
5834
  aggregateTypeCache: /* @__PURE__ */ new Map(),
5100
- complexity
5835
+ complexity,
5836
+ docs: options.docs ?? {}
5101
5837
  };
5838
+ if (features.nestedWrites && db.resultKind === "sync") {
5839
+ throw new Error(
5840
+ "Drizzle-GraphQL Error: features.nestedWrites requires an asynchronous SQLite driver (e.g. libsql). Synchronous drivers cannot run the multi-statement transaction a nested write needs."
5841
+ );
5842
+ }
5843
+ const nestedPlans = features.nestedWrites ? buildNestedWritePlans(
5844
+ tables,
5845
+ namedRelations,
5846
+ (target) => getUniqueColumnSets(target, import_sqlite_core2.getTableConfig),
5847
+ (target) => sqlitePrimaryKeyPropNames(target),
5848
+ extractRelationJoinColumns
5849
+ ) : void 0;
5850
+ const nestedTypes = nestedPlans ? createNestedWriteTypes({ plans: nestedPlans, cacheCtx, typeNameMapper, insertPrefix: prefixes.insert }) : void 0;
5851
+ const nestedRuntime = nestedPlans ? createNestedWriteRuntime({ plans: nestedPlans, filterCtx }) : void 0;
5102
5852
  const relationAggregateFactory = features.relationAggregates ? createRelationAggregateFactory(db, tables, cacheCtx, typeNameMapper, filterCtx) : void 0;
5103
5853
  const queries = {};
5104
5854
  const mutations = {};
@@ -5122,7 +5872,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
5122
5872
  prefixes.insert,
5123
5873
  prefixes.update,
5124
5874
  resolverFactory,
5125
- relationAggregateFactory
5875
+ relationAggregateFactory,
5876
+ nestedTypes
5126
5877
  )
5127
5878
  ])
5128
5879
  );
@@ -5183,7 +5934,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
5183
5934
  typeName,
5184
5935
  typeNameMapper,
5185
5936
  conflictDoNothing,
5186
- mutationTxCtx
5937
+ mutationTxCtx,
5938
+ nestedRuntime
5187
5939
  ) : void 0;
5188
5940
  const insertSingleGenerated = features.insert ? generateInsertSingle3(
5189
5941
  db,
@@ -5196,7 +5948,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
5196
5948
  typeName,
5197
5949
  typeNameMapper,
5198
5950
  conflictDoNothing,
5199
- mutationTxCtx
5951
+ mutationTxCtx,
5952
+ nestedRuntime
5200
5953
  ) : void 0;
5201
5954
  const uniqueSets = features.upsert ? getUniqueColumnSets(schema[tableName], import_sqlite_core2.getTableConfig) : [];
5202
5955
  const onConflictInput = features.upsert ? generateOnConflictInput({
@@ -5220,7 +5973,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
5220
5973
  false,
5221
5974
  typeNameMapper,
5222
5975
  filterCtx,
5223
- mutationTxCtx
5976
+ mutationTxCtx,
5977
+ nestedRuntime
5224
5978
  ) : void 0;
5225
5979
  const upsertSingleGenerated = onConflictInput ? generateUpsert3(
5226
5980
  db,
@@ -5236,7 +5990,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
5236
5990
  true,
5237
5991
  typeNameMapper,
5238
5992
  filterCtx,
5239
- mutationTxCtx
5993
+ mutationTxCtx,
5994
+ nestedRuntime
5240
5995
  ) : void 0;
5241
5996
  const updateGenerated = features.update ? generateUpdate3(
5242
5997
  db,
@@ -5252,7 +6007,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
5252
6007
  features.requireWhere,
5253
6008
  typeNameMapper,
5254
6009
  filterCtx,
5255
- mutationTxCtx
6010
+ mutationTxCtx,
6011
+ nestedRuntime
5256
6012
  ) : void 0;
5257
6013
  const updateSingleGenerated = features.update ? generateUpdate3(
5258
6014
  db,
@@ -5268,7 +6024,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
5268
6024
  features.requireWhere,
5269
6025
  typeNameMapper,
5270
6026
  filterCtx,
5271
- mutationTxCtx
6027
+ mutationTxCtx,
6028
+ nestedRuntime
5272
6029
  ) : void 0;
5273
6030
  const updateManyInput = features.update && features.updateMany ? generateUpdateManyInput({ typeName, updatePrefix: prefixes.update, updateInput, tableFilters }) : void 0;
5274
6031
  const updateManyGenerated = updateManyInput ? generateUpdateMany3(
@@ -5282,7 +6039,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
5282
6039
  typeName,
5283
6040
  typeNameMapper,
5284
6041
  filterCtx,
5285
- mutationTxCtx
6042
+ mutationTxCtx,
6043
+ nestedRuntime
5286
6044
  ) : void 0;
5287
6045
  const deleteGenerated = features.delete ? generateDelete3(
5288
6046
  db,
@@ -5347,7 +6105,7 @@ var generateSchemaData3 = (db, schema, relations, options) => {
5347
6105
  };
5348
6106
  if (aggregateGenerated && aggregateType) {
5349
6107
  queries[aggregateGenerated.name] = {
5350
- type: new import_graphql8.GraphQLNonNull(aggregateType),
6108
+ type: new import_graphql9.GraphQLNonNull(aggregateType),
5351
6109
  args: aggregateGenerated.args,
5352
6110
  resolve: aggregateGenerated.resolver,
5353
6111
  ...complexity ? { extensions: { complexity: aggregateFieldComplexity(complexity) } } : {}
@@ -5355,7 +6113,7 @@ var generateSchemaData3 = (db, schema, relations, options) => {
5355
6113
  }
5356
6114
  if (groupByGenerated && groupByType) {
5357
6115
  queries[groupByGenerated.name] = {
5358
- type: new import_graphql8.GraphQLNonNull(new import_graphql8.GraphQLList(new import_graphql8.GraphQLNonNull(groupByType))),
6116
+ type: new import_graphql9.GraphQLNonNull(new import_graphql9.GraphQLList(new import_graphql9.GraphQLNonNull(groupByType))),
5359
6117
  args: groupByGenerated.args,
5360
6118
  resolve: groupByGenerated.resolver,
5361
6119
  ...complexity ? { extensions: { complexity: aggregateFieldComplexity(complexity) } } : {}
@@ -5399,7 +6157,7 @@ var generateSchemaData3 = (db, schema, relations, options) => {
5399
6157
  if (updateManyGenerated) {
5400
6158
  mutations[updateManyGenerated.name] = {
5401
6159
  // Nullable items: a no-match entry yields `null` in its slot.
5402
- type: new import_graphql8.GraphQLNonNull(new import_graphql8.GraphQLList(singleTableItemOutput)),
6160
+ type: new import_graphql9.GraphQLNonNull(new import_graphql9.GraphQLList(singleTableItemOutput)),
5403
6161
  args: updateManyGenerated.args,
5404
6162
  resolve: updateManyGenerated.resolver
5405
6163
  };
@@ -5456,7 +6214,7 @@ var generateSchemaData3 = (db, schema, relations, options) => {
5456
6214
  for (const [tableName, tableRelations] of Object.entries(namedRelations)) {
5457
6215
  const relResolvers = {};
5458
6216
  for (const [relName, relEntry] of Object.entries(tableRelations)) {
5459
- const isOne = (0, import_drizzle_orm7.is)(relEntry.relation ?? relEntry, import_drizzle_orm7.One);
6217
+ const isOne = (0, import_drizzle_orm8.is)(relEntry.relation ?? relEntry, import_drizzle_orm8.One);
5460
6218
  const resolver = resolverFactory({ tableName, relationName: relName, relEntry, isOne });
5461
6219
  if (resolver) {
5462
6220
  relResolvers[relName] = resolver;
@@ -5501,6 +6259,7 @@ var buildSchema = (db, config) => {
5501
6259
  updateMany: config?.features?.updateMany ?? true,
5502
6260
  delete: config?.features?.delete ?? true,
5503
6261
  upsert: config?.features?.upsert ?? false,
6262
+ nestedWrites: config?.features?.nestedWrites ?? false,
5504
6263
  requireWhere: config?.features?.requireWhere ?? false
5505
6264
  };
5506
6265
  const complexityConfig = config?.complexity ?? true;
@@ -5538,14 +6297,23 @@ var buildSchema = (db, config) => {
5538
6297
  shouldEagerLoad,
5539
6298
  features,
5540
6299
  complexity,
5541
- transactions
6300
+ scalars: config?.scalars,
6301
+ mapColumnType: config?.mapColumnType,
6302
+ enumNameMapper: config?.enumNameMapper,
6303
+ transactions,
6304
+ docs: {
6305
+ describeColumn: config?.describeColumn,
6306
+ describeTable: config?.describeTable,
6307
+ describeRelation: config?.describeRelation,
6308
+ deprecateColumn: config?.deprecateColumn
6309
+ }
5542
6310
  };
5543
6311
  let generatorOutput;
5544
- if ((0, import_drizzle_orm8.is)(db, import_mysql_core3.MySqlDatabase)) {
6312
+ if ((0, import_drizzle_orm9.is)(db, import_mysql_core3.MySqlDatabase)) {
5545
6313
  generatorOutput = generateSchemaData(db, schema, relations, generatorOptions);
5546
- } else if ((0, import_drizzle_orm8.is)(db, import_pg_core3.PgAsyncDatabase)) {
6314
+ } else if ((0, import_drizzle_orm9.is)(db, import_pg_core3.PgAsyncDatabase)) {
5547
6315
  generatorOutput = generateSchemaData2(db, schema, relations, generatorOptions);
5548
- } else if ((0, import_drizzle_orm8.is)(db, import_sqlite_core3.BaseSQLiteDatabase)) {
6316
+ } else if ((0, import_drizzle_orm9.is)(db, import_sqlite_core3.BaseSQLiteDatabase)) {
5549
6317
  generatorOutput = generateSchemaData3(db, schema, relations, generatorOptions);
5550
6318
  } else {
5551
6319
  throw new Error("Drizzle-GraphQL Error: Unknown database instance type");
@@ -5558,19 +6326,19 @@ var buildSchema = (db, config) => {
5558
6326
  const { queries, mutations, inputs, types } = generatorOutput;
5559
6327
  const graphQLSchemaConfig = {
5560
6328
  types: [...Object.values(inputs), ...Object.values(types)],
5561
- query: new import_graphql9.GraphQLObjectType({
6329
+ query: new import_graphql10.GraphQLObjectType({
5562
6330
  name: "Query",
5563
6331
  fields: queries
5564
6332
  })
5565
6333
  };
5566
6334
  if (config?.mutations !== false && Object.keys(mutations).length) {
5567
- const mutation = new import_graphql9.GraphQLObjectType({
6335
+ const mutation = new import_graphql10.GraphQLObjectType({
5568
6336
  name: "Mutation",
5569
6337
  fields: mutations
5570
6338
  });
5571
6339
  graphQLSchemaConfig.mutation = mutation;
5572
6340
  }
5573
- const outputSchema = new import_graphql9.GraphQLSchema(graphQLSchemaConfig);
6341
+ const outputSchema = new import_graphql10.GraphQLSchema(graphQLSchemaConfig);
5574
6342
  return { schema: outputSchema, entities: generatorOutput };
5575
6343
  };
5576
6344
  // Annotate the CommonJS export names for ESM import in node: