@vantreeseba/drizzle-graphql 5.4.0 → 5.6.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 +1178 -783
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +123 -3
- package/dist/index.d.ts +123 -3
- package/dist/index.js +1193 -796
- package/dist/index.js.map +1 -1
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -107,8 +107,276 @@ 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 enumMap = /* @__PURE__ */ new WeakMap();
|
|
193
|
+
var generateEnumCached = (column, columnName, tableName) => {
|
|
194
|
+
if (enumMap.has(column)) {
|
|
195
|
+
return enumMap.get(column);
|
|
196
|
+
}
|
|
197
|
+
const gqlEnum = new import_graphql2.GraphQLEnumType({
|
|
198
|
+
name: `${capitalize(tableName)}${capitalize(columnName)}Enum`,
|
|
199
|
+
values: Object.fromEntries(
|
|
200
|
+
column.enumValues.map((e, index) => [
|
|
201
|
+
allowedNameChars.test(e) ? e : `Option${index}`,
|
|
202
|
+
{
|
|
203
|
+
value: e,
|
|
204
|
+
description: `Value: ${e}`
|
|
205
|
+
}
|
|
206
|
+
])
|
|
207
|
+
)
|
|
208
|
+
});
|
|
209
|
+
enumMap.set(column, gqlEnum);
|
|
210
|
+
return gqlEnum;
|
|
211
|
+
};
|
|
212
|
+
var geoXyType = new import_graphql2.GraphQLObjectType({
|
|
213
|
+
name: "PgGeometryObject",
|
|
214
|
+
fields: {
|
|
215
|
+
x: { type: import_graphql2.GraphQLFloat },
|
|
216
|
+
y: { type: import_graphql2.GraphQLFloat }
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
var geoXyInputType = new import_graphql2.GraphQLInputObjectType({
|
|
220
|
+
name: "PgGeometryObjectInput",
|
|
221
|
+
fields: {
|
|
222
|
+
x: { type: import_graphql2.GraphQLFloat },
|
|
223
|
+
y: { type: import_graphql2.GraphQLFloat }
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
var columnToGraphQLCore = (column, columnName, tableName, isInput) => {
|
|
227
|
+
const dimensions = column.dimensions;
|
|
228
|
+
if (dimensions !== void 0 && dimensions > 0) {
|
|
229
|
+
const inner = columnBaseToGraphQLCore(column, columnName, tableName, isInput);
|
|
230
|
+
const innerDesc = inner.description ?? inner.type.name;
|
|
231
|
+
let type = inner.type;
|
|
232
|
+
let description = innerDesc;
|
|
233
|
+
for (let i = 0; i < dimensions; i++) {
|
|
234
|
+
type = new import_graphql2.GraphQLList(new import_graphql2.GraphQLNonNull(type));
|
|
235
|
+
description = `Array<${description}>`;
|
|
236
|
+
}
|
|
237
|
+
return { type, description };
|
|
238
|
+
}
|
|
239
|
+
return columnBaseToGraphQLCore(column, columnName, tableName, isInput);
|
|
240
|
+
};
|
|
241
|
+
var columnBaseToGraphQLCore = (column, columnName, tableName, isInput) => {
|
|
242
|
+
const { type: baseType, constraint } = (0, import_drizzle_orm.extractExtendedColumnType)(column);
|
|
243
|
+
switch (baseType) {
|
|
244
|
+
case "boolean":
|
|
245
|
+
return { type: import_graphql2.GraphQLBoolean, description: "Boolean" };
|
|
246
|
+
case "object":
|
|
247
|
+
if (column instanceof import_pg_core.PgTimestamp || column instanceof import_pg_core.PgDate) {
|
|
248
|
+
return { type: import_graphql_scalars.GraphQLDateTime, description: "DateTime" };
|
|
249
|
+
}
|
|
250
|
+
return column.columnType === "PgGeometryObject" ? {
|
|
251
|
+
type: isInput ? geoXyInputType : geoXyType,
|
|
252
|
+
description: "Geometry points XY"
|
|
253
|
+
} : column.columnType === "PgBytea" ? {
|
|
254
|
+
type: new import_graphql2.GraphQLList(new import_graphql2.GraphQLNonNull(import_graphql2.GraphQLInt)),
|
|
255
|
+
description: "Buffer"
|
|
256
|
+
} : { type: import_graphql_scalars.GraphQLJSON, description: "JSON" };
|
|
257
|
+
case "string":
|
|
258
|
+
if (column.enumValues?.length) {
|
|
259
|
+
return { type: generateEnumCached(column, columnName, tableName) };
|
|
260
|
+
}
|
|
261
|
+
if (constraint === "numeric" && !column.dimensions) {
|
|
262
|
+
return { type: GraphQLDecimalString, description: "Decimal" };
|
|
263
|
+
}
|
|
264
|
+
if (column instanceof import_pg_core.PgTimestamp || column instanceof import_pg_core.PgTimestampString) {
|
|
265
|
+
return { type: import_graphql_scalars.GraphQLDateTime, description: "DateTime" };
|
|
266
|
+
}
|
|
267
|
+
if (column instanceof import_pg_core.PgUUID) {
|
|
268
|
+
return { type: import_graphql_scalars.GraphQLUUID, description: "UUID" };
|
|
269
|
+
}
|
|
270
|
+
if (column instanceof import_pg_core.PgDateString) {
|
|
271
|
+
return isInput ? { type: import_graphql2.GraphQLString, description: "Date" } : { type: import_graphql_scalars.GraphQLDate, description: "Date" };
|
|
272
|
+
}
|
|
273
|
+
return { type: import_graphql2.GraphQLString, description: "String" };
|
|
274
|
+
case "bigint":
|
|
275
|
+
return { type: GraphQLBigIntString, description: "BigInt" };
|
|
276
|
+
case "number": {
|
|
277
|
+
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, description: "Integer" } : { type: import_graphql2.GraphQLFloat, description: "Float" };
|
|
278
|
+
}
|
|
279
|
+
case "array": {
|
|
280
|
+
if (column.columnType === "PgVector") {
|
|
281
|
+
return {
|
|
282
|
+
type: new import_graphql2.GraphQLList(new import_graphql2.GraphQLNonNull(import_graphql2.GraphQLFloat)),
|
|
283
|
+
description: "Array<Float>"
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
if (column.columnType === "PgGeometry") {
|
|
287
|
+
return {
|
|
288
|
+
type: new import_graphql2.GraphQLList(new import_graphql2.GraphQLNonNull(import_graphql2.GraphQLFloat)),
|
|
289
|
+
description: "Tuple<[Float, Float]>"
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
const innerType = columnToGraphQLCore(
|
|
293
|
+
column.baseColumn,
|
|
294
|
+
columnName,
|
|
295
|
+
tableName,
|
|
296
|
+
isInput
|
|
297
|
+
);
|
|
298
|
+
return {
|
|
299
|
+
type: new import_graphql2.GraphQLList(new import_graphql2.GraphQLNonNull(innerType.type)),
|
|
300
|
+
description: `Array<${innerType.description}>`
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
default:
|
|
304
|
+
throw new Error(`Drizzle-GraphQL Error: Type ${column.dataType} is not implemented!`);
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
var columnScalarOverrides = /* @__PURE__ */ new WeakMap();
|
|
308
|
+
var getColumnScalarOverride = (column, isInput) => {
|
|
309
|
+
const override = columnScalarOverrides.get(column);
|
|
310
|
+
return override ? isInput ? override.input : override.output : void 0;
|
|
311
|
+
};
|
|
312
|
+
var normalizeScalarOverride = (override, tableName, columnName) => {
|
|
313
|
+
const pair = override instanceof import_graphql2.GraphQLScalarType ? { output: override, input: override } : { output: override.output, input: override.input };
|
|
314
|
+
for (const scalar of [pair.output, pair.input]) {
|
|
315
|
+
if (scalar !== void 0 && !(scalar instanceof import_graphql2.GraphQLScalarType)) {
|
|
316
|
+
throw new Error(
|
|
317
|
+
`Drizzle-GraphQL Error: Scalar override for column '${tableName}.${columnName}' must be a GraphQLScalarType!`
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return pair;
|
|
322
|
+
};
|
|
323
|
+
var registerScalarOverrides = (tables, config) => {
|
|
324
|
+
for (const [tableName, table] of Object.entries(tables)) {
|
|
325
|
+
for (const [columnName, column] of Object.entries((0, import_drizzle_orm.getTableColumns)(table))) {
|
|
326
|
+
const declared = config.scalars?.[tableName]?.[columnName];
|
|
327
|
+
let resolved;
|
|
328
|
+
if (declared !== void 0) {
|
|
329
|
+
resolved = normalizeScalarOverride(declared, tableName, columnName);
|
|
330
|
+
} else if (config.mapColumnType) {
|
|
331
|
+
let defaultType;
|
|
332
|
+
let defaultInputType;
|
|
333
|
+
try {
|
|
334
|
+
defaultType = columnToGraphQLCore(column, columnName, tableName, false).type;
|
|
335
|
+
} catch {
|
|
336
|
+
}
|
|
337
|
+
try {
|
|
338
|
+
defaultInputType = columnToGraphQLCore(column, columnName, tableName, true).type;
|
|
339
|
+
} catch {
|
|
340
|
+
}
|
|
341
|
+
const mapped = config.mapColumnType(column, { tableName, columnName, defaultType, defaultInputType });
|
|
342
|
+
if (mapped !== void 0) {
|
|
343
|
+
resolved = normalizeScalarOverride(mapped, tableName, columnName);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if (resolved && (resolved.output !== void 0 || resolved.input !== void 0)) {
|
|
347
|
+
columnScalarOverrides.set(column, resolved);
|
|
348
|
+
} else {
|
|
349
|
+
columnScalarOverrides.delete(column);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
var drizzleColumnToGraphQLType = (column, columnName, tableName, forceNullable = false, defaultIsNullable = false, isInput = false) => {
|
|
355
|
+
const override = getColumnScalarOverride(column, isInput);
|
|
356
|
+
let typeDesc;
|
|
357
|
+
if (override) {
|
|
358
|
+
typeDesc = { type: override, description: override.name };
|
|
359
|
+
} else {
|
|
360
|
+
typeDesc = columnToGraphQLCore(column, columnName, tableName, isInput);
|
|
361
|
+
const noDesc = ["string", "boolean", "number"];
|
|
362
|
+
const { type: baseType } = (0, import_drizzle_orm.extractExtendedColumnType)(column);
|
|
363
|
+
if (noDesc.find((e) => e === baseType)) {
|
|
364
|
+
delete typeDesc.description;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
if (forceNullable) {
|
|
368
|
+
return typeDesc;
|
|
369
|
+
}
|
|
370
|
+
if (column.notNull && !(defaultIsNullable && (column.hasDefault || column.defaultFn))) {
|
|
371
|
+
return {
|
|
372
|
+
type: new import_graphql2.GraphQLNonNull(typeDesc.type),
|
|
373
|
+
description: typeDesc.description
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
return typeDesc;
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
// src/util/data-mappers/index.ts
|
|
112
380
|
var isJsonColumn = (column) => (column.dataType ?? "").includes("json") && column.columnType !== "PgGeometryObject";
|
|
113
381
|
var remapToGraphQLCore = (key, value, tableName, column, relationMap) => {
|
|
114
382
|
if (Array.isArray(value)) {
|
|
@@ -139,6 +407,9 @@ var remapToGraphQLCore = (key, value, tableName, column, relationMap) => {
|
|
|
139
407
|
if (!column) {
|
|
140
408
|
return value;
|
|
141
409
|
}
|
|
410
|
+
if (getColumnScalarOverride(column, false)) {
|
|
411
|
+
return value;
|
|
412
|
+
}
|
|
142
413
|
if (isJsonColumn(column)) {
|
|
143
414
|
return value;
|
|
144
415
|
}
|
|
@@ -169,7 +440,7 @@ var remapToGraphQLSingleOutput = (queryOutput, tableName, table, relationMap) =>
|
|
|
169
440
|
for (const [key, value] of Object.entries(queryOutput)) {
|
|
170
441
|
if (value === void 0 || value === null) {
|
|
171
442
|
const relEntry = value === null ? relationMap?.[tableName]?.[key] : void 0;
|
|
172
|
-
if (relEntry && (0,
|
|
443
|
+
if (relEntry && (0, import_drizzle_orm2.is)(relEntry.relation, import_drizzle_orm2.One)) {
|
|
173
444
|
queryOutput[key] = null;
|
|
174
445
|
continue;
|
|
175
446
|
}
|
|
@@ -192,13 +463,19 @@ var remapToGraphQLArrayOutput = (queryOutput, tableName, table, relationMap) =>
|
|
|
192
463
|
return queryOutput;
|
|
193
464
|
};
|
|
194
465
|
var remapFromGraphQLCore = (value, column, columnName) => {
|
|
466
|
+
if (getColumnScalarOverride(column, true)) {
|
|
467
|
+
if (typeof value === "object" && value !== null && Object.getPrototypeOf(value) === null) {
|
|
468
|
+
return Object.assign({}, value);
|
|
469
|
+
}
|
|
470
|
+
return value;
|
|
471
|
+
}
|
|
195
472
|
const dataType = column.dataType ?? "";
|
|
196
473
|
const columnType = column.columnType ?? "";
|
|
197
474
|
const isTimestampColumn = columnType === "SQLiteTimestamp" || columnType === "SQLiteTimestampMs" || columnType === "MySqlTimestamp" || columnType === "MySqlDateTime" || columnType === "PgTimestamp" || columnType === "PgTimestampString";
|
|
198
475
|
if (isTimestampColumn) {
|
|
199
476
|
const formatted = new Date(value);
|
|
200
477
|
if (Number.isNaN(formatted.getTime())) {
|
|
201
|
-
throw new
|
|
478
|
+
throw new import_graphql3.GraphQLError(`Field '${columnName}' is not a valid date!`);
|
|
202
479
|
}
|
|
203
480
|
return formatted;
|
|
204
481
|
}
|
|
@@ -207,7 +484,7 @@ var remapFromGraphQLCore = (value, column, columnName) => {
|
|
|
207
484
|
const dateOnly = value.includes("T") ? value.split("T")[0] : value;
|
|
208
485
|
const check = new Date(dateOnly);
|
|
209
486
|
if (Number.isNaN(check.getTime())) {
|
|
210
|
-
throw new
|
|
487
|
+
throw new import_graphql3.GraphQLError(`Field '${columnName}' is not a valid date!`);
|
|
211
488
|
}
|
|
212
489
|
return dateOnly;
|
|
213
490
|
}
|
|
@@ -215,7 +492,7 @@ var remapFromGraphQLCore = (value, column, columnName) => {
|
|
|
215
492
|
try {
|
|
216
493
|
return BigInt(value);
|
|
217
494
|
} catch {
|
|
218
|
-
throw new
|
|
495
|
+
throw new import_graphql3.GraphQLError(`Field '${columnName}' is not a BigInt!`);
|
|
219
496
|
}
|
|
220
497
|
}
|
|
221
498
|
if (dataType.includes("json") && column.columnType !== "PgGeometryObject") {
|
|
@@ -225,13 +502,13 @@ var remapFromGraphQLCore = (value, column, columnName) => {
|
|
|
225
502
|
case "date": {
|
|
226
503
|
const formatted = new Date(value);
|
|
227
504
|
if (Number.isNaN(formatted.getTime())) {
|
|
228
|
-
throw new
|
|
505
|
+
throw new import_graphql3.GraphQLError(`Field '${columnName}' is not a valid date!`);
|
|
229
506
|
}
|
|
230
507
|
return formatted;
|
|
231
508
|
}
|
|
232
509
|
case "buffer": {
|
|
233
510
|
if (!Array.isArray(value)) {
|
|
234
|
-
throw new
|
|
511
|
+
throw new import_graphql3.GraphQLError(`Field '${columnName}' is not an array!`);
|
|
235
512
|
}
|
|
236
513
|
return Buffer.from(value);
|
|
237
514
|
}
|
|
@@ -242,7 +519,7 @@ var remapFromGraphQLCore = (value, column, columnName) => {
|
|
|
242
519
|
try {
|
|
243
520
|
return JSON.parse(value);
|
|
244
521
|
} catch (e) {
|
|
245
|
-
throw new
|
|
522
|
+
throw new import_graphql3.GraphQLError(
|
|
246
523
|
`Invalid JSON in field '${columnName}':
|
|
247
524
|
${e instanceof Error ? e.message : "Unknown error"}`
|
|
248
525
|
);
|
|
@@ -250,10 +527,10 @@ ${e instanceof Error ? e.message : "Unknown error"}`
|
|
|
250
527
|
}
|
|
251
528
|
case "array": {
|
|
252
529
|
if (!Array.isArray(value)) {
|
|
253
|
-
throw new
|
|
530
|
+
throw new import_graphql3.GraphQLError(`Field '${columnName}' is not an array!`);
|
|
254
531
|
}
|
|
255
532
|
if (column.columnType === "PgGeometry" && value.length !== 2) {
|
|
256
|
-
throw new
|
|
533
|
+
throw new import_graphql3.GraphQLError(
|
|
257
534
|
`Invalid float tuple in field '${columnName}': expected array with length of 2, received ${value.length}`
|
|
258
535
|
);
|
|
259
536
|
}
|
|
@@ -263,7 +540,7 @@ ${e instanceof Error ? e.message : "Unknown error"}`
|
|
|
263
540
|
try {
|
|
264
541
|
return BigInt(value);
|
|
265
542
|
} catch (_error) {
|
|
266
|
-
throw new
|
|
543
|
+
throw new import_graphql3.GraphQLError(`Field '${columnName}' is not a BigInt!`);
|
|
267
544
|
}
|
|
268
545
|
}
|
|
269
546
|
default: {
|
|
@@ -279,235 +556,24 @@ var remapFromGraphQLSingleInput = (queryInput, table) => {
|
|
|
279
556
|
if (value === void 0) {
|
|
280
557
|
delete queryInput[key];
|
|
281
558
|
} else {
|
|
282
|
-
const column = (0,
|
|
559
|
+
const column = (0, import_drizzle_orm2.getTableColumns)(table)[key];
|
|
283
560
|
if (!column) {
|
|
284
|
-
throw new
|
|
285
|
-
}
|
|
286
|
-
if (value === null && column.notNull) {
|
|
287
|
-
delete queryInput[key];
|
|
288
|
-
continue;
|
|
289
|
-
}
|
|
290
|
-
queryInput[key] = remapFromGraphQLCore(value, column, key);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
return queryInput;
|
|
294
|
-
};
|
|
295
|
-
var remapFromGraphQLArrayInput = (queryInput, table) => {
|
|
296
|
-
for (const entry of queryInput) {
|
|
297
|
-
remapFromGraphQLSingleInput(entry, table);
|
|
298
|
-
}
|
|
299
|
-
return queryInput;
|
|
300
|
-
};
|
|
301
|
-
|
|
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
|
-
};
|
|
561
|
+
throw new import_graphql3.GraphQLError(`Unknown column: ${key}`);
|
|
472
562
|
}
|
|
473
|
-
if (
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
description: "Tuple<[Float, Float]>"
|
|
477
|
-
};
|
|
563
|
+
if (value === null && column.notNull) {
|
|
564
|
+
delete queryInput[key];
|
|
565
|
+
continue;
|
|
478
566
|
}
|
|
479
|
-
|
|
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
|
-
};
|
|
567
|
+
queryInput[key] = remapFromGraphQLCore(value, column, key);
|
|
489
568
|
}
|
|
490
|
-
default:
|
|
491
|
-
throw new Error(`Drizzle-GraphQL Error: Type ${column.dataType} is not implemented!`);
|
|
492
569
|
}
|
|
570
|
+
return queryInput;
|
|
493
571
|
};
|
|
494
|
-
var
|
|
495
|
-
|
|
496
|
-
|
|
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
|
-
};
|
|
572
|
+
var remapFromGraphQLArrayInput = (queryInput, table) => {
|
|
573
|
+
for (const entry of queryInput) {
|
|
574
|
+
remapFromGraphQLSingleInput(entry, table);
|
|
509
575
|
}
|
|
510
|
-
return
|
|
576
|
+
return queryInput;
|
|
511
577
|
};
|
|
512
578
|
|
|
513
579
|
// src/util/builders/common.ts
|
|
@@ -598,6 +664,203 @@ var resolveQueryExecutor = (db, context, tableName, buildTimeQueryBase) => {
|
|
|
598
664
|
queryBase: buildTimeQueryBase ? executor?.query?.[tableName] ?? buildTimeQueryBase : buildTimeQueryBase
|
|
599
665
|
};
|
|
600
666
|
};
|
|
667
|
+
var createMutationTxCtx = (options) => options ? { timeoutMs: options.timeoutMs, fieldNames: /* @__PURE__ */ new Set(), states: /* @__PURE__ */ new WeakMap() } : void 0;
|
|
668
|
+
var includedByDirectives = (node, variables) => {
|
|
669
|
+
for (const directive of node.directives ?? []) {
|
|
670
|
+
const name = directive.name.value;
|
|
671
|
+
if (name !== "skip" && name !== "include") {
|
|
672
|
+
continue;
|
|
673
|
+
}
|
|
674
|
+
const ifArg = directive.arguments?.find((arg) => arg.name.value === "if");
|
|
675
|
+
let value;
|
|
676
|
+
if (ifArg?.value.kind === "BooleanValue") {
|
|
677
|
+
value = ifArg.value.value;
|
|
678
|
+
} else if (ifArg?.value.kind === "Variable") {
|
|
679
|
+
value = variables?.[ifArg.value.name.value];
|
|
680
|
+
}
|
|
681
|
+
if (name === "skip" && value === true) {
|
|
682
|
+
return false;
|
|
683
|
+
}
|
|
684
|
+
if (name === "include" && value !== true) {
|
|
685
|
+
return false;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
return true;
|
|
689
|
+
};
|
|
690
|
+
var collectRootMutationKeys = (selectionSet, fragments, variables, known, keys, visitedFragments) => {
|
|
691
|
+
for (const selection of selectionSet.selections) {
|
|
692
|
+
if (!includedByDirectives(selection, variables)) {
|
|
693
|
+
continue;
|
|
694
|
+
}
|
|
695
|
+
if (selection.kind === "Field") {
|
|
696
|
+
const name = selection.name.value;
|
|
697
|
+
if (name === "__typename") {
|
|
698
|
+
continue;
|
|
699
|
+
}
|
|
700
|
+
if (!known.has(name)) {
|
|
701
|
+
return false;
|
|
702
|
+
}
|
|
703
|
+
keys.add(selection.alias?.value ?? name);
|
|
704
|
+
} else if (selection.kind === "InlineFragment") {
|
|
705
|
+
if (!collectRootMutationKeys(selection.selectionSet, fragments, variables, known, keys, visitedFragments)) {
|
|
706
|
+
return false;
|
|
707
|
+
}
|
|
708
|
+
} else if (selection.kind === "FragmentSpread") {
|
|
709
|
+
const fragmentName = selection.name.value;
|
|
710
|
+
if (visitedFragments.has(fragmentName)) {
|
|
711
|
+
continue;
|
|
712
|
+
}
|
|
713
|
+
visitedFragments.add(fragmentName);
|
|
714
|
+
const fragment = fragments?.[fragmentName];
|
|
715
|
+
if (!fragment) {
|
|
716
|
+
return false;
|
|
717
|
+
}
|
|
718
|
+
if (!collectRootMutationKeys(fragment.selectionSet, fragments, variables, known, keys, visitedFragments)) {
|
|
719
|
+
return false;
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
return true;
|
|
724
|
+
};
|
|
725
|
+
var abortedBatchError = () => new import_graphql4.GraphQLError(
|
|
726
|
+
"Drizzle-GraphQL Error: Mutation was not executed because an earlier mutation in the same request failed and the shared transaction was rolled back."
|
|
727
|
+
);
|
|
728
|
+
var openSharedTx = (db, context, txCtx, stateKey, expected) => {
|
|
729
|
+
let release;
|
|
730
|
+
let rejectLatch;
|
|
731
|
+
const latch = new Promise((resolve, reject) => {
|
|
732
|
+
release = resolve;
|
|
733
|
+
rejectLatch = reject;
|
|
734
|
+
});
|
|
735
|
+
let readyResolve;
|
|
736
|
+
let readyReject;
|
|
737
|
+
const ready = new Promise((resolve, reject) => {
|
|
738
|
+
readyResolve = resolve;
|
|
739
|
+
readyReject = reject;
|
|
740
|
+
});
|
|
741
|
+
ready.catch(() => {
|
|
742
|
+
});
|
|
743
|
+
const canStash = context !== null && typeof context === "object" && !Object.isFrozen(context);
|
|
744
|
+
const settled = db.transaction(async (tx) => {
|
|
745
|
+
if (canStash) {
|
|
746
|
+
context[drizzleExecutorKey] = tx;
|
|
747
|
+
}
|
|
748
|
+
readyResolve(tx);
|
|
749
|
+
await latch;
|
|
750
|
+
});
|
|
751
|
+
let timer;
|
|
752
|
+
const clearTimer = () => {
|
|
753
|
+
if (timer !== void 0) {
|
|
754
|
+
clearTimeout(timer);
|
|
755
|
+
timer = void 0;
|
|
756
|
+
}
|
|
757
|
+
};
|
|
758
|
+
const state = {
|
|
759
|
+
kind: "shared",
|
|
760
|
+
expected,
|
|
761
|
+
completed: 0,
|
|
762
|
+
failure: void 0,
|
|
763
|
+
aborted: false,
|
|
764
|
+
done: false,
|
|
765
|
+
ready,
|
|
766
|
+
settled,
|
|
767
|
+
release,
|
|
768
|
+
abort: (e) => {
|
|
769
|
+
if (!state.aborted) {
|
|
770
|
+
state.aborted = true;
|
|
771
|
+
state.failure = e;
|
|
772
|
+
}
|
|
773
|
+
rejectLatch(e);
|
|
774
|
+
},
|
|
775
|
+
suspendTimer: clearTimer,
|
|
776
|
+
bumpTimer: () => {
|
|
777
|
+
clearTimer();
|
|
778
|
+
if (state.done) {
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
781
|
+
timer = setTimeout(() => {
|
|
782
|
+
state.abort(
|
|
783
|
+
new import_graphql4.GraphQLError(
|
|
784
|
+
`Drizzle-GraphQL Error: Shared mutation transaction timed out after ${txCtx.timeoutMs}ms waiting for the remaining mutation fields; rolling back.`
|
|
785
|
+
)
|
|
786
|
+
);
|
|
787
|
+
}, txCtx.timeoutMs);
|
|
788
|
+
timer.unref?.();
|
|
789
|
+
}
|
|
790
|
+
};
|
|
791
|
+
const cleanup = () => {
|
|
792
|
+
state.done = true;
|
|
793
|
+
clearTimer();
|
|
794
|
+
if (canStash) {
|
|
795
|
+
delete context[drizzleExecutorKey];
|
|
796
|
+
}
|
|
797
|
+
if (!state.aborted) {
|
|
798
|
+
txCtx.states.delete(stateKey);
|
|
799
|
+
}
|
|
800
|
+
};
|
|
801
|
+
settled.then(cleanup, (e) => {
|
|
802
|
+
cleanup();
|
|
803
|
+
readyReject(e);
|
|
804
|
+
});
|
|
805
|
+
state.bumpTimer();
|
|
806
|
+
return state;
|
|
807
|
+
};
|
|
808
|
+
var runOnSharedTx = async (state, body) => {
|
|
809
|
+
if (state.aborted) {
|
|
810
|
+
await state.settled.catch(() => {
|
|
811
|
+
});
|
|
812
|
+
throw abortedBatchError();
|
|
813
|
+
}
|
|
814
|
+
state.suspendTimer();
|
|
815
|
+
const tx = await state.ready;
|
|
816
|
+
try {
|
|
817
|
+
if (state.aborted) {
|
|
818
|
+
throw abortedBatchError();
|
|
819
|
+
}
|
|
820
|
+
const result = await body(tx);
|
|
821
|
+
state.completed += 1;
|
|
822
|
+
if (state.completed >= state.expected) {
|
|
823
|
+
state.release();
|
|
824
|
+
await state.settled;
|
|
825
|
+
} else {
|
|
826
|
+
state.bumpTimer();
|
|
827
|
+
}
|
|
828
|
+
return result;
|
|
829
|
+
} catch (e) {
|
|
830
|
+
state.abort(e);
|
|
831
|
+
await state.settled.catch(() => {
|
|
832
|
+
});
|
|
833
|
+
throw e;
|
|
834
|
+
}
|
|
835
|
+
};
|
|
836
|
+
var runMutation = async (db, context, info, txCtx, body) => {
|
|
837
|
+
const contextIsObject = context !== null && (typeof context === "object" || typeof context === "function");
|
|
838
|
+
const stateKey = contextIsObject ? context : info.operation;
|
|
839
|
+
let state = txCtx?.states.get(stateKey);
|
|
840
|
+
if (!state) {
|
|
841
|
+
if (contextIsObject && context[drizzleExecutorKey]) {
|
|
842
|
+
return body(context[drizzleExecutorKey]);
|
|
843
|
+
}
|
|
844
|
+
if (!txCtx || info.operation.operation !== "mutation") {
|
|
845
|
+
return body(db);
|
|
846
|
+
}
|
|
847
|
+
const keys = /* @__PURE__ */ new Set();
|
|
848
|
+
const allKnown = collectRootMutationKeys(
|
|
849
|
+
info.operation.selectionSet,
|
|
850
|
+
info.fragments,
|
|
851
|
+
info.variableValues,
|
|
852
|
+
txCtx.fieldNames,
|
|
853
|
+
keys,
|
|
854
|
+
/* @__PURE__ */ new Set()
|
|
855
|
+
);
|
|
856
|
+
state = !allKnown || keys.size <= 1 ? { kind: "passthrough" } : openSharedTx(db, context, txCtx, stateKey, keys.size);
|
|
857
|
+
txCtx.states.set(stateKey, state);
|
|
858
|
+
}
|
|
859
|
+
if (state.kind === "passthrough") {
|
|
860
|
+
return body(resolveExecutor(db, context));
|
|
861
|
+
}
|
|
862
|
+
return runOnSharedTx(state, body);
|
|
863
|
+
};
|
|
601
864
|
var batchedPaginatedRelationQuery = async (db, targetTable, foreignCol, whereCondition, orderByArg, limit, offset, pkNames, orderCtx) => {
|
|
602
865
|
const cols = (0, import_drizzle_orm3.getColumns)(targetTable);
|
|
603
866
|
const orderExprs = [
|
|
@@ -891,9 +1154,31 @@ var arrayFilterFields = (colType, colArr, colDesc) => {
|
|
|
891
1154
|
};
|
|
892
1155
|
};
|
|
893
1156
|
var FILTERS_WITHOUT_STRING_OPS = /* @__PURE__ */ new Set(["Id", "Int", "Float", "BigInt", "Decimal"]);
|
|
1157
|
+
var BUILTIN_FILTER_SCALARS = /* @__PURE__ */ new Set([
|
|
1158
|
+
import_graphql4.GraphQLString,
|
|
1159
|
+
import_graphql4.GraphQLInt,
|
|
1160
|
+
import_graphql4.GraphQLFloat,
|
|
1161
|
+
import_graphql4.GraphQLBoolean,
|
|
1162
|
+
GraphQLBigIntString,
|
|
1163
|
+
GraphQLDecimalString,
|
|
1164
|
+
import_graphql_scalars.GraphQLUUID,
|
|
1165
|
+
import_graphql_scalars.GraphQLJSON,
|
|
1166
|
+
import_graphql_scalars.GraphQLDate,
|
|
1167
|
+
import_graphql_scalars.GraphQLDateTime
|
|
1168
|
+
]);
|
|
1169
|
+
var resolveOverrideFilterDescriptor = (scalar) => {
|
|
1170
|
+
if (scalar === import_graphql_scalars.GraphQLJSON) {
|
|
1171
|
+
return { name: "JSON", kind: "json" };
|
|
1172
|
+
}
|
|
1173
|
+
if (scalar === import_graphql_scalars.GraphQLUUID) {
|
|
1174
|
+
return { name: "Id", kind: "scalar" };
|
|
1175
|
+
}
|
|
1176
|
+
return { name: scalar.name, kind: "scalar" };
|
|
1177
|
+
};
|
|
894
1178
|
var generateColumnFilterValues = (column, tableName, columnName, cacheCtx) => {
|
|
895
1179
|
const columnGraphQLType = drizzleColumnToGraphQLType(column, columnName, tableName, true, false, true);
|
|
896
|
-
const
|
|
1180
|
+
const inputOverride = getColumnScalarOverride(column, true);
|
|
1181
|
+
const { name: genericName, kind } = inputOverride ? resolveOverrideFilterDescriptor(inputOverride) : resolveGenericFilterDescriptor(column, columnGraphQLType);
|
|
897
1182
|
const cached = cacheCtx.genericFilterCache.get(genericName);
|
|
898
1183
|
if (cached) {
|
|
899
1184
|
return cached;
|
|
@@ -901,7 +1186,9 @@ var generateColumnFilterValues = (column, tableName, columnName, cacheCtx) => {
|
|
|
901
1186
|
const colType = columnGraphQLType.type;
|
|
902
1187
|
const colDesc = columnGraphQLType.description;
|
|
903
1188
|
const colArr = new import_graphql4.GraphQLList(new import_graphql4.GraphQLNonNull(colType));
|
|
904
|
-
const
|
|
1189
|
+
const customOverrideFilter = inputOverride !== void 0 && !BUILTIN_FILTER_SCALARS.has(inputOverride);
|
|
1190
|
+
const underlying = (0, import_drizzle_orm3.extractExtendedColumnType)(column);
|
|
1191
|
+
const omitStringOps = customOverrideFilter ? underlying.type !== "string" || underlying.constraint === "numeric" : FILTERS_WITHOUT_STRING_OPS.has(genericName);
|
|
905
1192
|
const baseFields = kind === "json" ? jsonFilterFields(column, colType) : kind === "array" ? arrayFilterFields(colType, colArr, colDesc) : {
|
|
906
1193
|
eq: { type: colType, description: colDesc },
|
|
907
1194
|
ne: { type: colType, description: colDesc },
|
|
@@ -982,10 +1269,9 @@ var generateTableOrderCached = (table) => {
|
|
|
982
1269
|
}
|
|
983
1270
|
return remapped;
|
|
984
1271
|
};
|
|
985
|
-
var filterMap = /* @__PURE__ */ new WeakMap();
|
|
986
1272
|
var generateTableFilterValuesCached = (table, tableName, cacheCtx) => {
|
|
987
|
-
if (
|
|
988
|
-
return
|
|
1273
|
+
if (cacheCtx.filterFieldCache.has(table)) {
|
|
1274
|
+
return cacheCtx.filterFieldCache.get(table);
|
|
989
1275
|
}
|
|
990
1276
|
const columns = (0, import_drizzle_orm3.getColumns)(table);
|
|
991
1277
|
const columnEntries = Object.entries(columns);
|
|
@@ -997,13 +1283,12 @@ var generateTableFilterValuesCached = (table, tableName, cacheCtx) => {
|
|
|
997
1283
|
}
|
|
998
1284
|
])
|
|
999
1285
|
);
|
|
1000
|
-
|
|
1286
|
+
cacheCtx.filterFieldCache.set(table, remapped);
|
|
1001
1287
|
return remapped;
|
|
1002
1288
|
};
|
|
1003
|
-
var
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
return fieldMap.get(table);
|
|
1289
|
+
var generateTableSelectTypeFieldsCached = (table, tableName, cacheCtx) => {
|
|
1290
|
+
if (cacheCtx.selectFieldCache.has(table)) {
|
|
1291
|
+
return cacheCtx.selectFieldCache.get(table);
|
|
1007
1292
|
}
|
|
1008
1293
|
const columns = (0, import_drizzle_orm3.getColumns)(table);
|
|
1009
1294
|
const columnEntries = Object.entries(columns);
|
|
@@ -1020,7 +1305,7 @@ var generateTableSelectTypeFieldsCached = (table, tableName) => {
|
|
|
1020
1305
|
resolve: rowCursorResolver
|
|
1021
1306
|
};
|
|
1022
1307
|
}
|
|
1023
|
-
|
|
1308
|
+
cacheCtx.selectFieldCache.set(table, remapped);
|
|
1024
1309
|
return remapped;
|
|
1025
1310
|
};
|
|
1026
1311
|
var isFilterableRelation = (relation) => !relation.through;
|
|
@@ -1170,7 +1455,7 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
|
|
|
1170
1455
|
const table = tables[tableName];
|
|
1171
1456
|
const order = withOrder ? generateTableOrderTypeCached(table, tableName, typeNameMapper, cacheCtx, relationMap, tables) : void 0;
|
|
1172
1457
|
const filters = generateTableFilterTypeCached(table, tableName, cacheCtx, typeNameMapper, relationMap, tables);
|
|
1173
|
-
const tableFields = generateTableSelectTypeFieldsCached(table, tableName);
|
|
1458
|
+
const tableFields = generateTableSelectTypeFieldsCached(table, tableName, cacheCtx);
|
|
1174
1459
|
const relationsForTable = relationMap[tableName];
|
|
1175
1460
|
const relationEntries = relationsForTable ? Object.entries(relationsForTable) : [];
|
|
1176
1461
|
if (relationsDepthLimit !== void 0 && currentDepth >= relationsDepthLimit) {
|
|
@@ -1239,7 +1524,7 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
|
|
|
1239
1524
|
let relType = cacheCtx.objectTypeCache.get(targetTableName);
|
|
1240
1525
|
if (!relType) {
|
|
1241
1526
|
const targetTable = tables[targetTableName];
|
|
1242
|
-
const targetTableFields = generateTableSelectTypeFieldsCached(targetTable, targetTableName);
|
|
1527
|
+
const targetTableFields = generateTableSelectTypeFieldsCached(targetTable, targetTableName, cacheCtx);
|
|
1243
1528
|
let targetContainer = cacheCtx.relationFieldContainers.get(targetTableName);
|
|
1244
1529
|
if (!targetContainer) {
|
|
1245
1530
|
targetContainer = { fields: {} };
|
|
@@ -3009,7 +3294,7 @@ var generateSelectSingle = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
3009
3294
|
args: queryArgs
|
|
3010
3295
|
};
|
|
3011
3296
|
};
|
|
3012
|
-
var generateInsertArray = (db, _tableName, table, baseType, fieldName) => {
|
|
3297
|
+
var generateInsertArray = (db, _tableName, table, baseType, fieldName, txCtx) => {
|
|
3013
3298
|
const queryArgs = {
|
|
3014
3299
|
values: {
|
|
3015
3300
|
type: new import_graphql6.GraphQLNonNull(new import_graphql6.GraphQLList(new import_graphql6.GraphQLNonNull(baseType)))
|
|
@@ -3017,14 +3302,16 @@ var generateInsertArray = (db, _tableName, table, baseType, fieldName) => {
|
|
|
3017
3302
|
};
|
|
3018
3303
|
return {
|
|
3019
3304
|
name: fieldName,
|
|
3020
|
-
resolver: async (_source, args, context,
|
|
3305
|
+
resolver: async (_source, args, context, info) => {
|
|
3021
3306
|
try {
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3307
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
3308
|
+
const input = remapFromGraphQLArrayInput(args.values, table);
|
|
3309
|
+
if (!input.length) {
|
|
3310
|
+
throw new import_graphql6.GraphQLError("No values were provided!");
|
|
3311
|
+
}
|
|
3312
|
+
await executor.insert(table).values(input);
|
|
3313
|
+
return { isSuccess: true };
|
|
3314
|
+
});
|
|
3028
3315
|
} catch (e) {
|
|
3029
3316
|
throw toGraphQLError(e);
|
|
3030
3317
|
}
|
|
@@ -3032,7 +3319,7 @@ var generateInsertArray = (db, _tableName, table, baseType, fieldName) => {
|
|
|
3032
3319
|
args: queryArgs
|
|
3033
3320
|
};
|
|
3034
3321
|
};
|
|
3035
|
-
var generateInsertSingle = (db, _tableName, table, baseType, fieldName) => {
|
|
3322
|
+
var generateInsertSingle = (db, _tableName, table, baseType, fieldName, txCtx) => {
|
|
3036
3323
|
const queryArgs = {
|
|
3037
3324
|
values: {
|
|
3038
3325
|
type: new import_graphql6.GraphQLNonNull(baseType)
|
|
@@ -3040,11 +3327,13 @@ var generateInsertSingle = (db, _tableName, table, baseType, fieldName) => {
|
|
|
3040
3327
|
};
|
|
3041
3328
|
return {
|
|
3042
3329
|
name: fieldName,
|
|
3043
|
-
resolver: async (_source, args, context,
|
|
3330
|
+
resolver: async (_source, args, context, info) => {
|
|
3044
3331
|
try {
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3332
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
3333
|
+
const input = remapFromGraphQLSingleInput(args.values, table);
|
|
3334
|
+
await executor.insert(table).values(input);
|
|
3335
|
+
return { isSuccess: true };
|
|
3336
|
+
});
|
|
3048
3337
|
} catch (e) {
|
|
3049
3338
|
throw toGraphQLError(e);
|
|
3050
3339
|
}
|
|
@@ -3052,7 +3341,7 @@ var generateInsertSingle = (db, _tableName, table, baseType, fieldName) => {
|
|
|
3052
3341
|
args: queryArgs
|
|
3053
3342
|
};
|
|
3054
3343
|
};
|
|
3055
|
-
var generateUpsert = (db, table, baseType, onConflictType, fieldName, single) => {
|
|
3344
|
+
var generateUpsert = (db, table, baseType, onConflictType, fieldName, single, txCtx) => {
|
|
3056
3345
|
const queryArgs = {
|
|
3057
3346
|
values: {
|
|
3058
3347
|
type: single ? new import_graphql6.GraphQLNonNull(baseType) : new import_graphql6.GraphQLNonNull(new import_graphql6.GraphQLList(new import_graphql6.GraphQLNonNull(baseType)))
|
|
@@ -3065,28 +3354,29 @@ var generateUpsert = (db, table, baseType, onConflictType, fieldName, single) =>
|
|
|
3065
3354
|
const pkNames = mysqlPrimaryKeyPropNames(table);
|
|
3066
3355
|
return {
|
|
3067
3356
|
name: fieldName,
|
|
3068
|
-
resolver: async (_source, args, context,
|
|
3357
|
+
resolver: async (_source, args, context, info) => {
|
|
3069
3358
|
try {
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3359
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
3360
|
+
const input = single ? [remapFromGraphQLSingleInput(args.values, table)] : remapFromGraphQLArrayInput(args.values, table);
|
|
3361
|
+
if (!input.length) {
|
|
3362
|
+
throw new import_graphql6.GraphQLError("No values were provided!");
|
|
3363
|
+
}
|
|
3364
|
+
const plan = resolveConflictPlan({
|
|
3365
|
+
table,
|
|
3366
|
+
values: input,
|
|
3367
|
+
onConflict: args.onConflict,
|
|
3368
|
+
pkNames,
|
|
3369
|
+
uniqueSets: [],
|
|
3370
|
+
excludedRef: mysqlValuesColumnRef,
|
|
3371
|
+
withTarget: false
|
|
3372
|
+
});
|
|
3373
|
+
if (plan.action === "NOTHING") {
|
|
3374
|
+
await executor.insert(table).ignore().values(input);
|
|
3375
|
+
} else {
|
|
3376
|
+
await executor.insert(table).values(input).onDuplicateKeyUpdate({ set: plan.set });
|
|
3377
|
+
}
|
|
3378
|
+
return { isSuccess: true };
|
|
3082
3379
|
});
|
|
3083
|
-
const executor = resolveExecutor(db, context);
|
|
3084
|
-
if (plan.action === "NOTHING") {
|
|
3085
|
-
await executor.insert(table).ignore().values(input);
|
|
3086
|
-
} else {
|
|
3087
|
-
await executor.insert(table).values(input).onDuplicateKeyUpdate({ set: plan.set });
|
|
3088
|
-
}
|
|
3089
|
-
return { isSuccess: true };
|
|
3090
3380
|
} catch (e) {
|
|
3091
3381
|
throw toGraphQLError(e);
|
|
3092
3382
|
}
|
|
@@ -3094,7 +3384,7 @@ var generateUpsert = (db, table, baseType, onConflictType, fieldName, single) =>
|
|
|
3094
3384
|
args: queryArgs
|
|
3095
3385
|
};
|
|
3096
3386
|
};
|
|
3097
|
-
var generateUpdate = (db, tableName, table, setArgs, filterArgs, fieldName, single, requireWhere, filterCtx) => {
|
|
3387
|
+
var generateUpdate = (db, tableName, table, setArgs, filterArgs, fieldName, single, requireWhere, filterCtx, txCtx) => {
|
|
3098
3388
|
const queryArgs = {
|
|
3099
3389
|
set: {
|
|
3100
3390
|
type: new import_graphql6.GraphQLNonNull(setArgs)
|
|
@@ -3105,25 +3395,26 @@ var generateUpdate = (db, tableName, table, setArgs, filterArgs, fieldName, sing
|
|
|
3105
3395
|
};
|
|
3106
3396
|
return {
|
|
3107
3397
|
name: fieldName,
|
|
3108
|
-
resolver: async (_source, args, context,
|
|
3398
|
+
resolver: async (_source, args, context, info) => {
|
|
3109
3399
|
try {
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3400
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
3401
|
+
const { where, set } = args;
|
|
3402
|
+
const input = remapFromGraphQLSingleInput(set, table);
|
|
3403
|
+
if (!Object.keys(input).length) {
|
|
3404
|
+
throw new import_graphql6.GraphQLError("Unable to update with no values specified!");
|
|
3405
|
+
}
|
|
3406
|
+
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
3407
|
+
const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
3408
|
+
if (single) {
|
|
3409
|
+
await assertSingleMatch(executor, table, filters, fieldName);
|
|
3410
|
+
}
|
|
3411
|
+
let query = executor.update(table).set(input);
|
|
3412
|
+
if (filters) {
|
|
3413
|
+
query = query.where(filters);
|
|
3414
|
+
}
|
|
3415
|
+
await query;
|
|
3416
|
+
return { isSuccess: true };
|
|
3417
|
+
});
|
|
3127
3418
|
} catch (e) {
|
|
3128
3419
|
throw toGraphQLError(e);
|
|
3129
3420
|
}
|
|
@@ -3131,7 +3422,7 @@ var generateUpdate = (db, tableName, table, setArgs, filterArgs, fieldName, sing
|
|
|
3131
3422
|
args: queryArgs
|
|
3132
3423
|
};
|
|
3133
3424
|
};
|
|
3134
|
-
var generateUpdateMany = (db, tableName, table, updateManyInput, fieldName, filterCtx) => {
|
|
3425
|
+
var generateUpdateMany = (db, tableName, table, updateManyInput, fieldName, filterCtx, txCtx) => {
|
|
3135
3426
|
const queryArgs = {
|
|
3136
3427
|
updates: {
|
|
3137
3428
|
type: new import_graphql6.GraphQLNonNull(new import_graphql6.GraphQLList(new import_graphql6.GraphQLNonNull(updateManyInput)))
|
|
@@ -3139,33 +3430,34 @@ var generateUpdateMany = (db, tableName, table, updateManyInput, fieldName, filt
|
|
|
3139
3430
|
};
|
|
3140
3431
|
return {
|
|
3141
3432
|
name: fieldName,
|
|
3142
|
-
resolver: async (_source, args, context,
|
|
3433
|
+
resolver: async (_source, args, context, info) => {
|
|
3143
3434
|
try {
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
const entries = updates.map(({ where, set }) => {
|
|
3149
|
-
const input = remapFromGraphQLSingleInput(set, table);
|
|
3150
|
-
if (!Object.keys(input).length) {
|
|
3151
|
-
throw new import_graphql6.GraphQLError("Unable to update with no values specified!");
|
|
3435
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
3436
|
+
const { updates } = args;
|
|
3437
|
+
if (!updates.length) {
|
|
3438
|
+
throw new import_graphql6.GraphQLError("No updates were provided!");
|
|
3152
3439
|
}
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
});
|
|
3158
|
-
const executor = resolveExecutor(db, context);
|
|
3159
|
-
await executor.transaction(async (tx) => {
|
|
3160
|
-
for (const entry of entries) {
|
|
3161
|
-
let query = tx.update(table).set(entry.set);
|
|
3162
|
-
if (entry.filters) {
|
|
3163
|
-
query = query.where(entry.filters);
|
|
3440
|
+
const entries = updates.map(({ where, set }) => {
|
|
3441
|
+
const input = remapFromGraphQLSingleInput(set, table);
|
|
3442
|
+
if (!Object.keys(input).length) {
|
|
3443
|
+
throw new import_graphql6.GraphQLError("Unable to update with no values specified!");
|
|
3164
3444
|
}
|
|
3165
|
-
|
|
3166
|
-
|
|
3445
|
+
return {
|
|
3446
|
+
set: input,
|
|
3447
|
+
filters: where ? extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName)) : void 0
|
|
3448
|
+
};
|
|
3449
|
+
});
|
|
3450
|
+
await executor.transaction(async (tx) => {
|
|
3451
|
+
for (const entry of entries) {
|
|
3452
|
+
let query = tx.update(table).set(entry.set);
|
|
3453
|
+
if (entry.filters) {
|
|
3454
|
+
query = query.where(entry.filters);
|
|
3455
|
+
}
|
|
3456
|
+
await query;
|
|
3457
|
+
}
|
|
3458
|
+
});
|
|
3459
|
+
return { isSuccess: true };
|
|
3167
3460
|
});
|
|
3168
|
-
return { isSuccess: true };
|
|
3169
3461
|
} catch (e) {
|
|
3170
3462
|
throw toGraphQLError(e);
|
|
3171
3463
|
}
|
|
@@ -3173,7 +3465,7 @@ var generateUpdateMany = (db, tableName, table, updateManyInput, fieldName, filt
|
|
|
3173
3465
|
args: queryArgs
|
|
3174
3466
|
};
|
|
3175
3467
|
};
|
|
3176
|
-
var generateDelete = (db, tableName, table, filterArgs, fieldName, single, requireWhere, filterCtx) => {
|
|
3468
|
+
var generateDelete = (db, tableName, table, filterArgs, fieldName, single, requireWhere, filterCtx, txCtx) => {
|
|
3177
3469
|
const queryArgs = {
|
|
3178
3470
|
where: {
|
|
3179
3471
|
type: single || requireWhere ? new import_graphql6.GraphQLNonNull(filterArgs) : filterArgs
|
|
@@ -3181,21 +3473,22 @@ var generateDelete = (db, tableName, table, filterArgs, fieldName, single, requi
|
|
|
3181
3473
|
};
|
|
3182
3474
|
return {
|
|
3183
3475
|
name: fieldName,
|
|
3184
|
-
resolver: async (_source, args, context,
|
|
3476
|
+
resolver: async (_source, args, context, info) => {
|
|
3185
3477
|
try {
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3478
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
3479
|
+
const { where } = args;
|
|
3480
|
+
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
3481
|
+
const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
3482
|
+
if (single) {
|
|
3483
|
+
await assertSingleMatch(executor, table, filters, fieldName);
|
|
3484
|
+
}
|
|
3485
|
+
let query = executor.delete(table);
|
|
3486
|
+
if (filters) {
|
|
3487
|
+
query = query.where(filters);
|
|
3488
|
+
}
|
|
3489
|
+
await query;
|
|
3490
|
+
return { isSuccess: true };
|
|
3491
|
+
});
|
|
3199
3492
|
} catch (e) {
|
|
3200
3493
|
throw toGraphQLError(e);
|
|
3201
3494
|
}
|
|
@@ -3215,6 +3508,7 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3215
3508
|
"Drizzle-GraphQL Error: No tables detected in Drizzle-ORM's database instance. Did you forget to pass schema to drizzle constructor?"
|
|
3216
3509
|
);
|
|
3217
3510
|
}
|
|
3511
|
+
registerScalarOverrides(tables, options);
|
|
3218
3512
|
const namedRelations = buildNamedRelations(relations ?? {}, tableEntries);
|
|
3219
3513
|
attachTargetPrimaryKeys(namedRelations, tables, mysqlPrimaryKeyPropNames);
|
|
3220
3514
|
const eagerRelations = pruneNonEagerRelations(namedRelations, shouldEagerLoad);
|
|
@@ -3226,6 +3520,8 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3226
3520
|
relationFieldContainers: /* @__PURE__ */ new Map(),
|
|
3227
3521
|
fullyBuiltTables: /* @__PURE__ */ new Set(),
|
|
3228
3522
|
relationTypeCache: /* @__PURE__ */ new Map(),
|
|
3523
|
+
selectFieldCache: /* @__PURE__ */ new WeakMap(),
|
|
3524
|
+
filterFieldCache: /* @__PURE__ */ new WeakMap(),
|
|
3229
3525
|
orderTypeCache: /* @__PURE__ */ new WeakMap(),
|
|
3230
3526
|
filterTypeCache: /* @__PURE__ */ new WeakMap(),
|
|
3231
3527
|
listRelationFilterCache: /* @__PURE__ */ new Map(),
|
|
@@ -3235,6 +3531,7 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3235
3531
|
const relationAggregateFactory = features.relationAggregates ? createRelationAggregateFactory(db, tables, cacheCtx, typeNameMapper, filterCtx) : void 0;
|
|
3236
3532
|
const queries = {};
|
|
3237
3533
|
const mutations = {};
|
|
3534
|
+
const mutationTxCtx = createMutationTxCtx(options.transactions);
|
|
3238
3535
|
const gqlSchemaTypes = Object.fromEntries(
|
|
3239
3536
|
Object.entries(tables).map(([tableName, _table]) => [
|
|
3240
3537
|
tableName,
|
|
@@ -3310,8 +3607,22 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3310
3607
|
typeNameMapper,
|
|
3311
3608
|
filterCtx
|
|
3312
3609
|
);
|
|
3313
|
-
const insertArrGenerated = features.insert ? generateInsertArray(
|
|
3314
|
-
|
|
3610
|
+
const insertArrGenerated = features.insert ? generateInsertArray(
|
|
3611
|
+
db,
|
|
3612
|
+
tableName,
|
|
3613
|
+
schema[tableName],
|
|
3614
|
+
insertInput,
|
|
3615
|
+
createArrayFieldName,
|
|
3616
|
+
mutationTxCtx
|
|
3617
|
+
) : void 0;
|
|
3618
|
+
const insertSingleGenerated = features.insert ? generateInsertSingle(
|
|
3619
|
+
db,
|
|
3620
|
+
tableName,
|
|
3621
|
+
schema[tableName],
|
|
3622
|
+
insertInput,
|
|
3623
|
+
createSingleFieldName,
|
|
3624
|
+
mutationTxCtx
|
|
3625
|
+
) : void 0;
|
|
3315
3626
|
const onConflictInput = features.upsert ? generateOnConflictInput({
|
|
3316
3627
|
table: schema[tableName],
|
|
3317
3628
|
typeName,
|
|
@@ -3319,8 +3630,24 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3319
3630
|
tableFilters,
|
|
3320
3631
|
withTarget: false
|
|
3321
3632
|
}) : void 0;
|
|
3322
|
-
const upsertArrGenerated = onConflictInput ? generateUpsert(
|
|
3323
|
-
|
|
3633
|
+
const upsertArrGenerated = onConflictInput ? generateUpsert(
|
|
3634
|
+
db,
|
|
3635
|
+
schema[tableName],
|
|
3636
|
+
insertInput,
|
|
3637
|
+
onConflictInput,
|
|
3638
|
+
upsertArrayFieldName,
|
|
3639
|
+
false,
|
|
3640
|
+
mutationTxCtx
|
|
3641
|
+
) : void 0;
|
|
3642
|
+
const upsertSingleGenerated = onConflictInput ? generateUpsert(
|
|
3643
|
+
db,
|
|
3644
|
+
schema[tableName],
|
|
3645
|
+
insertInput,
|
|
3646
|
+
onConflictInput,
|
|
3647
|
+
upsertSingleFieldName,
|
|
3648
|
+
true,
|
|
3649
|
+
mutationTxCtx
|
|
3650
|
+
) : void 0;
|
|
3324
3651
|
const updateGenerated = features.update ? generateUpdate(
|
|
3325
3652
|
db,
|
|
3326
3653
|
tableName,
|
|
@@ -3330,7 +3657,8 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3330
3657
|
updateFieldName,
|
|
3331
3658
|
false,
|
|
3332
3659
|
features.requireWhere,
|
|
3333
|
-
filterCtx
|
|
3660
|
+
filterCtx,
|
|
3661
|
+
mutationTxCtx
|
|
3334
3662
|
) : void 0;
|
|
3335
3663
|
const updateSingleGenerated = features.update ? generateUpdate(
|
|
3336
3664
|
db,
|
|
@@ -3341,7 +3669,8 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3341
3669
|
updateSingleFieldName,
|
|
3342
3670
|
true,
|
|
3343
3671
|
features.requireWhere,
|
|
3344
|
-
filterCtx
|
|
3672
|
+
filterCtx,
|
|
3673
|
+
mutationTxCtx
|
|
3345
3674
|
) : void 0;
|
|
3346
3675
|
const updateManyInput = features.update && features.updateMany ? generateUpdateManyInput({ typeName, updatePrefix: prefixes.update, updateInput, tableFilters }) : void 0;
|
|
3347
3676
|
const updateManyGenerated = updateManyInput ? generateUpdateMany(
|
|
@@ -3350,7 +3679,8 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3350
3679
|
schema[tableName],
|
|
3351
3680
|
updateManyInput,
|
|
3352
3681
|
updateManyFieldName,
|
|
3353
|
-
filterCtx
|
|
3682
|
+
filterCtx,
|
|
3683
|
+
mutationTxCtx
|
|
3354
3684
|
) : void 0;
|
|
3355
3685
|
const deleteGenerated = features.delete ? generateDelete(
|
|
3356
3686
|
db,
|
|
@@ -3360,7 +3690,8 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3360
3690
|
deleteFieldName,
|
|
3361
3691
|
false,
|
|
3362
3692
|
features.requireWhere,
|
|
3363
|
-
filterCtx
|
|
3693
|
+
filterCtx,
|
|
3694
|
+
mutationTxCtx
|
|
3364
3695
|
) : void 0;
|
|
3365
3696
|
const deleteSingleGenerated = features.delete ? generateDelete(
|
|
3366
3697
|
db,
|
|
@@ -3370,7 +3701,8 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3370
3701
|
deleteSingleFieldName,
|
|
3371
3702
|
true,
|
|
3372
3703
|
features.requireWhere,
|
|
3373
|
-
filterCtx
|
|
3704
|
+
filterCtx,
|
|
3705
|
+
mutationTxCtx
|
|
3374
3706
|
) : void 0;
|
|
3375
3707
|
const aggregateType = features.aggregates ? generateAggregateTypes(schema[tableName], tableName, typeName, cacheCtx) : void 0;
|
|
3376
3708
|
const aggregateGenerated = features.aggregates ? generateAggregate(
|
|
@@ -3463,6 +3795,11 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3463
3795
|
inputs[havingInput.name] = havingInput;
|
|
3464
3796
|
}
|
|
3465
3797
|
}
|
|
3798
|
+
if (mutationTxCtx) {
|
|
3799
|
+
for (const name of Object.keys(mutations)) {
|
|
3800
|
+
mutationTxCtx.fieldNames.add(name);
|
|
3801
|
+
}
|
|
3802
|
+
}
|
|
3466
3803
|
const fieldResolvers = {};
|
|
3467
3804
|
for (const [tableName, tableRelations] of Object.entries(namedRelations)) {
|
|
3468
3805
|
const relResolvers = {};
|
|
@@ -3666,7 +4003,7 @@ var generateSelectSingle2 = (db, tableName, tables, relationMap, orderArgs, filt
|
|
|
3666
4003
|
};
|
|
3667
4004
|
};
|
|
3668
4005
|
var pgPrimaryKeyPropNames = (table) => getPrimaryKeyPropNamesFromConfig(table, import_pg_core2.getTableConfig);
|
|
3669
|
-
var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false) => {
|
|
4006
|
+
var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx) => {
|
|
3670
4007
|
const queryArgs = {
|
|
3671
4008
|
values: {
|
|
3672
4009
|
type: new import_graphql7.GraphQLNonNull(new import_graphql7.GraphQLList(new import_graphql7.GraphQLNonNull(baseType)))
|
|
@@ -3677,31 +4014,32 @@ var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
3677
4014
|
name: fieldName,
|
|
3678
4015
|
resolver: async (_source, args, context, info) => {
|
|
3679
4016
|
try {
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
4017
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4018
|
+
const input = remapFromGraphQLArrayInput(args.values, table);
|
|
4019
|
+
if (!input.length) {
|
|
4020
|
+
throw new import_graphql7.GraphQLError("No values were provided!");
|
|
4021
|
+
}
|
|
4022
|
+
const parsedInfo = (0, import_graphql_parse_resolve_info3.parseResolveInfo)(info, {
|
|
4023
|
+
deep: true
|
|
4024
|
+
});
|
|
4025
|
+
const { columns, hasRelations, withParams } = prepareMutationRelationColumns({
|
|
4026
|
+
relationMap,
|
|
4027
|
+
tables,
|
|
4028
|
+
tableName,
|
|
4029
|
+
typeName,
|
|
4030
|
+
typeNameMapper,
|
|
4031
|
+
table,
|
|
4032
|
+
pkNames,
|
|
4033
|
+
parsedInfo
|
|
4034
|
+
});
|
|
4035
|
+
let query = executor.insert(table).values(input).returning(columns);
|
|
4036
|
+
if (conflictDoNothing) {
|
|
4037
|
+
query = query.onConflictDoNothing();
|
|
4038
|
+
}
|
|
4039
|
+
const result = await query;
|
|
4040
|
+
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
4041
|
+
return remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
|
|
3696
4042
|
});
|
|
3697
|
-
const executor = resolveExecutor(db, context);
|
|
3698
|
-
let query = executor.insert(table).values(input).returning(columns);
|
|
3699
|
-
if (conflictDoNothing) {
|
|
3700
|
-
query = query.onConflictDoNothing();
|
|
3701
|
-
}
|
|
3702
|
-
const result = await query;
|
|
3703
|
-
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
3704
|
-
return remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
|
|
3705
4043
|
} catch (e) {
|
|
3706
4044
|
throw toGraphQLError(e);
|
|
3707
4045
|
}
|
|
@@ -3709,7 +4047,7 @@ var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
3709
4047
|
args: queryArgs
|
|
3710
4048
|
};
|
|
3711
4049
|
};
|
|
3712
|
-
var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false) => {
|
|
4050
|
+
var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx) => {
|
|
3713
4051
|
const queryArgs = {
|
|
3714
4052
|
values: {
|
|
3715
4053
|
type: new import_graphql7.GraphQLNonNull(baseType)
|
|
@@ -3720,31 +4058,32 @@ var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType
|
|
|
3720
4058
|
name: fieldName,
|
|
3721
4059
|
resolver: async (_source, args, context, info) => {
|
|
3722
4060
|
try {
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
4061
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4062
|
+
const input = remapFromGraphQLSingleInput(args.values, table);
|
|
4063
|
+
const parsedInfo = (0, import_graphql_parse_resolve_info3.parseResolveInfo)(info, {
|
|
4064
|
+
deep: true
|
|
4065
|
+
});
|
|
4066
|
+
const { columns, hasRelations, withParams } = prepareMutationRelationColumns({
|
|
4067
|
+
relationMap,
|
|
4068
|
+
tables,
|
|
4069
|
+
tableName,
|
|
4070
|
+
typeName,
|
|
4071
|
+
typeNameMapper,
|
|
4072
|
+
table,
|
|
4073
|
+
pkNames,
|
|
4074
|
+
parsedInfo
|
|
4075
|
+
});
|
|
4076
|
+
let query = executor.insert(table).values(input).returning(columns);
|
|
4077
|
+
if (conflictDoNothing) {
|
|
4078
|
+
query = query.onConflictDoNothing();
|
|
4079
|
+
}
|
|
4080
|
+
const result = await query;
|
|
4081
|
+
if (!result[0]) {
|
|
4082
|
+
return void 0;
|
|
4083
|
+
}
|
|
4084
|
+
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
4085
|
+
return remapToGraphQLSingleOutput(enriched[0], tableName, table, relationMap);
|
|
3736
4086
|
});
|
|
3737
|
-
const executor = resolveExecutor(db, context);
|
|
3738
|
-
let query = executor.insert(table).values(input).returning(columns);
|
|
3739
|
-
if (conflictDoNothing) {
|
|
3740
|
-
query = query.onConflictDoNothing();
|
|
3741
|
-
}
|
|
3742
|
-
const result = await query;
|
|
3743
|
-
if (!result[0]) {
|
|
3744
|
-
return void 0;
|
|
3745
|
-
}
|
|
3746
|
-
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
3747
|
-
return remapToGraphQLSingleOutput(enriched[0], tableName, table, relationMap);
|
|
3748
4087
|
} catch (e) {
|
|
3749
4088
|
throw toGraphQLError(e);
|
|
3750
4089
|
}
|
|
@@ -3752,7 +4091,7 @@ var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType
|
|
|
3752
4091
|
args: queryArgs
|
|
3753
4092
|
};
|
|
3754
4093
|
};
|
|
3755
|
-
var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx) => {
|
|
4094
|
+
var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx, txCtx) => {
|
|
3756
4095
|
const queryArgs = {
|
|
3757
4096
|
values: {
|
|
3758
4097
|
type: single ? new import_graphql7.GraphQLNonNull(baseType) : new import_graphql7.GraphQLNonNull(new import_graphql7.GraphQLList(new import_graphql7.GraphQLNonNull(baseType)))
|
|
@@ -3767,40 +4106,41 @@ var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
3767
4106
|
name: fieldName,
|
|
3768
4107
|
resolver: async (_source, args, context, info) => {
|
|
3769
4108
|
try {
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
4109
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4110
|
+
const input = single ? [remapFromGraphQLSingleInput(args.values, table)] : remapFromGraphQLArrayInput(args.values, table);
|
|
4111
|
+
if (!input.length) {
|
|
4112
|
+
throw new import_graphql7.GraphQLError("No values were provided!");
|
|
4113
|
+
}
|
|
4114
|
+
const parsedInfo = (0, import_graphql_parse_resolve_info3.parseResolveInfo)(info, { deep: true });
|
|
4115
|
+
const { columns, hasRelations, withParams } = prepareMutationRelationColumns({
|
|
4116
|
+
relationMap,
|
|
4117
|
+
tables,
|
|
4118
|
+
tableName,
|
|
4119
|
+
typeName,
|
|
4120
|
+
typeNameMapper,
|
|
4121
|
+
table,
|
|
4122
|
+
pkNames,
|
|
4123
|
+
parsedInfo
|
|
4124
|
+
});
|
|
4125
|
+
const plan = resolveConflictPlan({
|
|
4126
|
+
table,
|
|
4127
|
+
values: input,
|
|
4128
|
+
onConflict: args.onConflict,
|
|
4129
|
+
pkNames,
|
|
4130
|
+
uniqueSets,
|
|
4131
|
+
excludedRef: excludedColumnRef,
|
|
4132
|
+
withTarget: true,
|
|
4133
|
+
buildWhere: (where) => extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName))
|
|
4134
|
+
});
|
|
4135
|
+
let query = executor.insert(table).values(input).returning(columns);
|
|
4136
|
+
query = plan.action === "NOTHING" ? query.onConflictDoNothing(plan.target ? { target: plan.target } : void 0) : query.onConflictDoUpdate({ target: plan.target, set: plan.set, setWhere: plan.setWhere });
|
|
4137
|
+
const result = await query;
|
|
4138
|
+
if (single && !result[0]) {
|
|
4139
|
+
return void 0;
|
|
4140
|
+
}
|
|
4141
|
+
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
4142
|
+
return single ? remapToGraphQLSingleOutput(enriched[0], tableName, table, relationMap) : remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
|
|
3794
4143
|
});
|
|
3795
|
-
const executor = resolveExecutor(db, context);
|
|
3796
|
-
let query = executor.insert(table).values(input).returning(columns);
|
|
3797
|
-
query = plan.action === "NOTHING" ? query.onConflictDoNothing(plan.target ? { target: plan.target } : void 0) : query.onConflictDoUpdate({ target: plan.target, set: plan.set, setWhere: plan.setWhere });
|
|
3798
|
-
const result = await query;
|
|
3799
|
-
if (single && !result[0]) {
|
|
3800
|
-
return void 0;
|
|
3801
|
-
}
|
|
3802
|
-
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
3803
|
-
return single ? remapToGraphQLSingleOutput(enriched[0], tableName, table, relationMap) : remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
|
|
3804
4144
|
} catch (e) {
|
|
3805
4145
|
throw toGraphQLError(e);
|
|
3806
4146
|
}
|
|
@@ -3808,7 +4148,7 @@ var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
3808
4148
|
args: queryArgs
|
|
3809
4149
|
};
|
|
3810
4150
|
};
|
|
3811
|
-
var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx) => {
|
|
4151
|
+
var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx, txCtx) => {
|
|
3812
4152
|
const queryArgs = {
|
|
3813
4153
|
set: {
|
|
3814
4154
|
type: new import_graphql7.GraphQLNonNull(setArgs)
|
|
@@ -3819,47 +4159,48 @@ var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
3819
4159
|
};
|
|
3820
4160
|
const pkNames = pgPrimaryKeyPropNames(table);
|
|
3821
4161
|
return {
|
|
3822
|
-
name: fieldName,
|
|
3823
|
-
resolver: async (_source, args, context, info) => {
|
|
3824
|
-
try {
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
4162
|
+
name: fieldName,
|
|
4163
|
+
resolver: async (_source, args, context, info) => {
|
|
4164
|
+
try {
|
|
4165
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4166
|
+
const { where, set } = args;
|
|
4167
|
+
const parsedInfo = (0, import_graphql_parse_resolve_info3.parseResolveInfo)(info, {
|
|
4168
|
+
deep: true
|
|
4169
|
+
});
|
|
4170
|
+
const { columns, hasRelations, withParams } = prepareMutationRelationColumns({
|
|
4171
|
+
relationMap,
|
|
4172
|
+
tables,
|
|
4173
|
+
tableName,
|
|
4174
|
+
typeName,
|
|
4175
|
+
typeNameMapper,
|
|
4176
|
+
table,
|
|
4177
|
+
pkNames,
|
|
4178
|
+
parsedInfo
|
|
4179
|
+
});
|
|
4180
|
+
const input = remapFromGraphQLSingleInput(set, table);
|
|
4181
|
+
if (!Object.keys(input).length) {
|
|
4182
|
+
throw new import_graphql7.GraphQLError("Unable to update with no values specified!");
|
|
4183
|
+
}
|
|
4184
|
+
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
4185
|
+
const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
4186
|
+
if (single) {
|
|
4187
|
+
await assertSingleMatch(executor, table, filters, fieldName);
|
|
4188
|
+
}
|
|
4189
|
+
let query = executor.update(table).set(input);
|
|
4190
|
+
if (filters) {
|
|
4191
|
+
query = query.where(filters);
|
|
4192
|
+
}
|
|
4193
|
+
query = query.returning(columns);
|
|
4194
|
+
const result = await query;
|
|
4195
|
+
if (single && result.length > 1) {
|
|
4196
|
+
throw new import_graphql7.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
|
|
4197
|
+
}
|
|
4198
|
+
if (single && !result[0]) {
|
|
4199
|
+
return void 0;
|
|
4200
|
+
}
|
|
4201
|
+
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
4202
|
+
return single ? remapToGraphQLSingleOutput(enriched[0], tableName, table, relationMap) : remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
|
|
3838
4203
|
});
|
|
3839
|
-
const input = remapFromGraphQLSingleInput(set, table);
|
|
3840
|
-
if (!Object.keys(input).length) {
|
|
3841
|
-
throw new import_graphql7.GraphQLError("Unable to update with no values specified!");
|
|
3842
|
-
}
|
|
3843
|
-
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
3844
|
-
const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
3845
|
-
const executor = resolveExecutor(db, context);
|
|
3846
|
-
if (single) {
|
|
3847
|
-
await assertSingleMatch(executor, table, filters, fieldName);
|
|
3848
|
-
}
|
|
3849
|
-
let query = executor.update(table).set(input);
|
|
3850
|
-
if (filters) {
|
|
3851
|
-
query = query.where(filters);
|
|
3852
|
-
}
|
|
3853
|
-
query = query.returning(columns);
|
|
3854
|
-
const result = await query;
|
|
3855
|
-
if (single && result.length > 1) {
|
|
3856
|
-
throw new import_graphql7.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
|
|
3857
|
-
}
|
|
3858
|
-
if (single && !result[0]) {
|
|
3859
|
-
return void 0;
|
|
3860
|
-
}
|
|
3861
|
-
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
3862
|
-
return single ? remapToGraphQLSingleOutput(enriched[0], tableName, table, relationMap) : remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
|
|
3863
4204
|
} catch (e) {
|
|
3864
4205
|
throw toGraphQLError(e);
|
|
3865
4206
|
}
|
|
@@ -3867,7 +4208,7 @@ var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
3867
4208
|
args: queryArgs
|
|
3868
4209
|
};
|
|
3869
4210
|
};
|
|
3870
|
-
var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx) => {
|
|
4211
|
+
var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx, txCtx) => {
|
|
3871
4212
|
const queryArgs = {
|
|
3872
4213
|
updates: {
|
|
3873
4214
|
type: new import_graphql7.GraphQLNonNull(new import_graphql7.GraphQLList(new import_graphql7.GraphQLNonNull(updateManyInput)))
|
|
@@ -3878,60 +4219,61 @@ var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
3878
4219
|
name: fieldName,
|
|
3879
4220
|
resolver: async (_source, args, context, info) => {
|
|
3880
4221
|
try {
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
const parsedInfo = (0, import_graphql_parse_resolve_info3.parseResolveInfo)(info, {
|
|
3886
|
-
deep: true
|
|
3887
|
-
});
|
|
3888
|
-
const { columns, hasRelations, withParams } = prepareMutationRelationColumns({
|
|
3889
|
-
relationMap,
|
|
3890
|
-
tables,
|
|
3891
|
-
tableName,
|
|
3892
|
-
typeName,
|
|
3893
|
-
typeNameMapper,
|
|
3894
|
-
table,
|
|
3895
|
-
pkNames,
|
|
3896
|
-
parsedInfo
|
|
3897
|
-
});
|
|
3898
|
-
const entries = updates.map(({ where, set }) => {
|
|
3899
|
-
const input = remapFromGraphQLSingleInput(set, table);
|
|
3900
|
-
if (!Object.keys(input).length) {
|
|
3901
|
-
throw new import_graphql7.GraphQLError("Unable to update with no values specified!");
|
|
4222
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4223
|
+
const { updates } = args;
|
|
4224
|
+
if (!updates.length) {
|
|
4225
|
+
throw new import_graphql7.GraphQLError("No updates were provided!");
|
|
3902
4226
|
}
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
}
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
4227
|
+
const parsedInfo = (0, import_graphql_parse_resolve_info3.parseResolveInfo)(info, {
|
|
4228
|
+
deep: true
|
|
4229
|
+
});
|
|
4230
|
+
const { columns, hasRelations, withParams } = prepareMutationRelationColumns({
|
|
4231
|
+
relationMap,
|
|
4232
|
+
tables,
|
|
4233
|
+
tableName,
|
|
4234
|
+
typeName,
|
|
4235
|
+
typeNameMapper,
|
|
4236
|
+
table,
|
|
4237
|
+
pkNames,
|
|
4238
|
+
parsedInfo
|
|
4239
|
+
});
|
|
4240
|
+
const entries = updates.map(({ where, set }) => {
|
|
4241
|
+
const input = remapFromGraphQLSingleInput(set, table);
|
|
4242
|
+
if (!Object.keys(input).length) {
|
|
4243
|
+
throw new import_graphql7.GraphQLError("Unable to update with no values specified!");
|
|
4244
|
+
}
|
|
4245
|
+
return {
|
|
4246
|
+
set: input,
|
|
4247
|
+
filters: where ? extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName)) : void 0
|
|
4248
|
+
};
|
|
4249
|
+
});
|
|
4250
|
+
const perEntry = await executor.transaction(async (tx) => {
|
|
4251
|
+
const results = [];
|
|
4252
|
+
for (const entry of entries) {
|
|
4253
|
+
let query = tx.update(table).set(entry.set);
|
|
4254
|
+
if (entry.filters) {
|
|
4255
|
+
query = query.where(entry.filters);
|
|
4256
|
+
}
|
|
4257
|
+
results.push(await query.returning(columns));
|
|
4258
|
+
}
|
|
4259
|
+
return results;
|
|
4260
|
+
});
|
|
4261
|
+
const flatRows = perEntry.flat();
|
|
4262
|
+
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, flatRows, pkNames, withParams) : flatRows;
|
|
4263
|
+
const output = [];
|
|
4264
|
+
let offset = 0;
|
|
4265
|
+
for (const rows of perEntry) {
|
|
4266
|
+
if (!rows.length) {
|
|
4267
|
+
output.push(null);
|
|
4268
|
+
continue;
|
|
4269
|
+
}
|
|
4270
|
+
for (let i = 0; i < rows.length; i++) {
|
|
4271
|
+
output.push(remapToGraphQLSingleOutput(enriched[offset + i], tableName, table, relationMap));
|
|
3915
4272
|
}
|
|
3916
|
-
|
|
4273
|
+
offset += rows.length;
|
|
3917
4274
|
}
|
|
3918
|
-
return
|
|
4275
|
+
return output;
|
|
3919
4276
|
});
|
|
3920
|
-
const flatRows = perEntry.flat();
|
|
3921
|
-
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, flatRows, pkNames, withParams) : flatRows;
|
|
3922
|
-
const output = [];
|
|
3923
|
-
let offset = 0;
|
|
3924
|
-
for (const rows of perEntry) {
|
|
3925
|
-
if (!rows.length) {
|
|
3926
|
-
output.push(null);
|
|
3927
|
-
continue;
|
|
3928
|
-
}
|
|
3929
|
-
for (let i = 0; i < rows.length; i++) {
|
|
3930
|
-
output.push(remapToGraphQLSingleOutput(enriched[offset + i], tableName, table, relationMap));
|
|
3931
|
-
}
|
|
3932
|
-
offset += rows.length;
|
|
3933
|
-
}
|
|
3934
|
-
return output;
|
|
3935
4277
|
} catch (e) {
|
|
3936
4278
|
throw toGraphQLError(e);
|
|
3937
4279
|
}
|
|
@@ -3939,7 +4281,7 @@ var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
3939
4281
|
args: queryArgs
|
|
3940
4282
|
};
|
|
3941
4283
|
};
|
|
3942
|
-
var generateDelete2 = (db, tableName, table, filterArgs, fieldName, typeName, single, requireWhere, filterCtx, selectionCtx) => {
|
|
4284
|
+
var generateDelete2 = (db, tableName, table, filterArgs, fieldName, typeName, single, requireWhere, filterCtx, selectionCtx, txCtx) => {
|
|
3943
4285
|
const queryArgs = {
|
|
3944
4286
|
where: {
|
|
3945
4287
|
type: single || requireWhere ? new import_graphql7.GraphQLNonNull(filterArgs) : filterArgs
|
|
@@ -3949,34 +4291,35 @@ var generateDelete2 = (db, tableName, table, filterArgs, fieldName, typeName, si
|
|
|
3949
4291
|
name: fieldName,
|
|
3950
4292
|
resolver: async (_source, args, context, info) => {
|
|
3951
4293
|
try {
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
4294
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4295
|
+
const { where } = args;
|
|
4296
|
+
const parsedInfo = (0, import_graphql_parse_resolve_info3.parseResolveInfo)(info, {
|
|
4297
|
+
deep: true
|
|
4298
|
+
});
|
|
4299
|
+
const columns = extractSelectedColumnsFromTreeSQLFormat(
|
|
4300
|
+
parsedInfo.fieldsByTypeName[typeName],
|
|
4301
|
+
table,
|
|
4302
|
+
selectionCtx
|
|
4303
|
+
);
|
|
4304
|
+
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
4305
|
+
const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
4306
|
+
if (single) {
|
|
4307
|
+
await assertSingleMatch(executor, table, filters, fieldName);
|
|
4308
|
+
}
|
|
4309
|
+
let query = executor.delete(table);
|
|
4310
|
+
if (filters) {
|
|
4311
|
+
query = query.where(filters);
|
|
4312
|
+
}
|
|
4313
|
+
query = query.returning(columns);
|
|
4314
|
+
const result = await query;
|
|
4315
|
+
if (single && result.length > 1) {
|
|
4316
|
+
throw new import_graphql7.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
|
|
4317
|
+
}
|
|
4318
|
+
if (single) {
|
|
4319
|
+
return result[0] ? remapToGraphQLSingleOutput(result[0], tableName, table) : void 0;
|
|
4320
|
+
}
|
|
4321
|
+
return remapToGraphQLArrayOutput(result, tableName, table);
|
|
3955
4322
|
});
|
|
3956
|
-
const columns = extractSelectedColumnsFromTreeSQLFormat(
|
|
3957
|
-
parsedInfo.fieldsByTypeName[typeName],
|
|
3958
|
-
table,
|
|
3959
|
-
selectionCtx
|
|
3960
|
-
);
|
|
3961
|
-
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
3962
|
-
const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
3963
|
-
const executor = resolveExecutor(db, context);
|
|
3964
|
-
if (single) {
|
|
3965
|
-
await assertSingleMatch(executor, table, filters, fieldName);
|
|
3966
|
-
}
|
|
3967
|
-
let query = executor.delete(table);
|
|
3968
|
-
if (filters) {
|
|
3969
|
-
query = query.where(filters);
|
|
3970
|
-
}
|
|
3971
|
-
query = query.returning(columns);
|
|
3972
|
-
const result = await query;
|
|
3973
|
-
if (single && result.length > 1) {
|
|
3974
|
-
throw new import_graphql7.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
|
|
3975
|
-
}
|
|
3976
|
-
if (single) {
|
|
3977
|
-
return result[0] ? remapToGraphQLSingleOutput(result[0], tableName, table) : void 0;
|
|
3978
|
-
}
|
|
3979
|
-
return remapToGraphQLArrayOutput(result, tableName, table);
|
|
3980
4323
|
} catch (e) {
|
|
3981
4324
|
throw toGraphQLError(e);
|
|
3982
4325
|
}
|
|
@@ -4003,6 +4346,7 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4003
4346
|
"Drizzle-GraphQL Error: No tables detected in Drizzle-ORM's database instance. Did you forget to pass schema to drizzle constructor?"
|
|
4004
4347
|
);
|
|
4005
4348
|
}
|
|
4349
|
+
registerScalarOverrides(tables, options);
|
|
4006
4350
|
const namedRelations = buildNamedRelations(relations ?? {}, tableEntries);
|
|
4007
4351
|
attachTargetPrimaryKeys(namedRelations, tables, pgPrimaryKeyPropNames);
|
|
4008
4352
|
const eagerRelations = pruneNonEagerRelations(namedRelations, shouldEagerLoad);
|
|
@@ -4014,6 +4358,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4014
4358
|
relationFieldContainers: /* @__PURE__ */ new Map(),
|
|
4015
4359
|
fullyBuiltTables: /* @__PURE__ */ new Set(),
|
|
4016
4360
|
relationTypeCache: /* @__PURE__ */ new Map(),
|
|
4361
|
+
selectFieldCache: /* @__PURE__ */ new WeakMap(),
|
|
4362
|
+
filterFieldCache: /* @__PURE__ */ new WeakMap(),
|
|
4017
4363
|
orderTypeCache: /* @__PURE__ */ new WeakMap(),
|
|
4018
4364
|
filterTypeCache: /* @__PURE__ */ new WeakMap(),
|
|
4019
4365
|
listRelationFilterCache: /* @__PURE__ */ new Map(),
|
|
@@ -4023,6 +4369,7 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4023
4369
|
const relationAggregateFactory = features.relationAggregates ? createRelationAggregateFactory(db, tables, cacheCtx, typeNameMapper, filterCtx) : void 0;
|
|
4024
4370
|
const queries = {};
|
|
4025
4371
|
const mutations = {};
|
|
4372
|
+
const mutationTxCtx = createMutationTxCtx(options.transactions);
|
|
4026
4373
|
const gqlSchemaTypes = Object.fromEntries(
|
|
4027
4374
|
Object.entries(tables).map(([tableName, _table]) => [
|
|
4028
4375
|
tableName,
|
|
@@ -4097,7 +4444,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4097
4444
|
createArrayFieldName,
|
|
4098
4445
|
typeName,
|
|
4099
4446
|
typeNameMapper,
|
|
4100
|
-
conflictDoNothing
|
|
4447
|
+
conflictDoNothing,
|
|
4448
|
+
mutationTxCtx
|
|
4101
4449
|
) : void 0;
|
|
4102
4450
|
const insertSingleGenerated = features.insert ? generateInsertSingle2(
|
|
4103
4451
|
db,
|
|
@@ -4109,7 +4457,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4109
4457
|
createSingleFieldName,
|
|
4110
4458
|
typeName,
|
|
4111
4459
|
typeNameMapper,
|
|
4112
|
-
conflictDoNothing
|
|
4460
|
+
conflictDoNothing,
|
|
4461
|
+
mutationTxCtx
|
|
4113
4462
|
) : void 0;
|
|
4114
4463
|
const uniqueSets = features.upsert ? getUniqueColumnSets(schema[tableName], import_pg_core2.getTableConfig) : [];
|
|
4115
4464
|
const onConflictInput = features.upsert ? generateOnConflictInput({
|
|
@@ -4132,7 +4481,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4132
4481
|
typeName,
|
|
4133
4482
|
false,
|
|
4134
4483
|
typeNameMapper,
|
|
4135
|
-
filterCtx
|
|
4484
|
+
filterCtx,
|
|
4485
|
+
mutationTxCtx
|
|
4136
4486
|
) : void 0;
|
|
4137
4487
|
const upsertSingleGenerated = onConflictInput ? generateUpsert2(
|
|
4138
4488
|
db,
|
|
@@ -4147,7 +4497,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4147
4497
|
typeName,
|
|
4148
4498
|
true,
|
|
4149
4499
|
typeNameMapper,
|
|
4150
|
-
filterCtx
|
|
4500
|
+
filterCtx,
|
|
4501
|
+
mutationTxCtx
|
|
4151
4502
|
) : void 0;
|
|
4152
4503
|
const updateGenerated = features.update ? generateUpdate2(
|
|
4153
4504
|
db,
|
|
@@ -4162,7 +4513,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4162
4513
|
false,
|
|
4163
4514
|
features.requireWhere,
|
|
4164
4515
|
typeNameMapper,
|
|
4165
|
-
filterCtx
|
|
4516
|
+
filterCtx,
|
|
4517
|
+
mutationTxCtx
|
|
4166
4518
|
) : void 0;
|
|
4167
4519
|
const updateSingleGenerated = features.update ? generateUpdate2(
|
|
4168
4520
|
db,
|
|
@@ -4177,7 +4529,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4177
4529
|
true,
|
|
4178
4530
|
features.requireWhere,
|
|
4179
4531
|
typeNameMapper,
|
|
4180
|
-
filterCtx
|
|
4532
|
+
filterCtx,
|
|
4533
|
+
mutationTxCtx
|
|
4181
4534
|
) : void 0;
|
|
4182
4535
|
const updateManyInput = features.update && features.updateMany ? generateUpdateManyInput({ typeName, updatePrefix: prefixes.update, updateInput, tableFilters }) : void 0;
|
|
4183
4536
|
const updateManyGenerated = updateManyInput ? generateUpdateMany2(
|
|
@@ -4190,7 +4543,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4190
4543
|
updateManyFieldName,
|
|
4191
4544
|
typeName,
|
|
4192
4545
|
typeNameMapper,
|
|
4193
|
-
filterCtx
|
|
4546
|
+
filterCtx,
|
|
4547
|
+
mutationTxCtx
|
|
4194
4548
|
) : void 0;
|
|
4195
4549
|
const deleteGenerated = features.delete ? generateDelete2(
|
|
4196
4550
|
db,
|
|
@@ -4202,7 +4556,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4202
4556
|
false,
|
|
4203
4557
|
features.requireWhere,
|
|
4204
4558
|
filterCtx,
|
|
4205
|
-
{ tableName, relationMap: namedRelations, tables }
|
|
4559
|
+
{ tableName, relationMap: namedRelations, tables },
|
|
4560
|
+
mutationTxCtx
|
|
4206
4561
|
) : void 0;
|
|
4207
4562
|
const deleteSingleGenerated = features.delete ? generateDelete2(
|
|
4208
4563
|
db,
|
|
@@ -4214,7 +4569,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4214
4569
|
true,
|
|
4215
4570
|
features.requireWhere,
|
|
4216
4571
|
filterCtx,
|
|
4217
|
-
{ tableName, relationMap: namedRelations, tables }
|
|
4572
|
+
{ tableName, relationMap: namedRelations, tables },
|
|
4573
|
+
mutationTxCtx
|
|
4218
4574
|
) : void 0;
|
|
4219
4575
|
const aggregateType = features.aggregates ? generateAggregateTypes(schema[tableName], tableName, typeName, cacheCtx) : void 0;
|
|
4220
4576
|
const aggregateGenerated = features.aggregates ? generateAggregate(
|
|
@@ -4353,6 +4709,11 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4353
4709
|
inputs[havingInput.name] = havingInput;
|
|
4354
4710
|
}
|
|
4355
4711
|
}
|
|
4712
|
+
if (mutationTxCtx) {
|
|
4713
|
+
for (const name of Object.keys(mutations)) {
|
|
4714
|
+
mutationTxCtx.fieldNames.add(name);
|
|
4715
|
+
}
|
|
4716
|
+
}
|
|
4356
4717
|
const fieldResolvers = {};
|
|
4357
4718
|
for (const [tableName, tableRelations] of Object.entries(namedRelations)) {
|
|
4358
4719
|
const relResolvers = {};
|
|
@@ -4458,7 +4819,7 @@ var generateSelectSingle3 = (db, tableName, tables, relationMap, orderArgs, filt
|
|
|
4458
4819
|
};
|
|
4459
4820
|
};
|
|
4460
4821
|
var sqlitePrimaryKeyPropNames = (table) => getPrimaryKeyPropNamesFromConfig(table, import_sqlite_core2.getTableConfig);
|
|
4461
|
-
var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false) => {
|
|
4822
|
+
var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx) => {
|
|
4462
4823
|
const queryArgs = {
|
|
4463
4824
|
values: {
|
|
4464
4825
|
type: new import_graphql8.GraphQLNonNull(new import_graphql8.GraphQLList(new import_graphql8.GraphQLNonNull(baseType)))
|
|
@@ -4469,31 +4830,32 @@ var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
4469
4830
|
name: fieldName,
|
|
4470
4831
|
resolver: async (_source, args, context, info) => {
|
|
4471
4832
|
try {
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4833
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4834
|
+
const input = remapFromGraphQLArrayInput(args.values, table);
|
|
4835
|
+
if (!input.length) {
|
|
4836
|
+
throw new import_graphql8.GraphQLError("No values were provided!");
|
|
4837
|
+
}
|
|
4838
|
+
const parsedInfo = (0, import_graphql_parse_resolve_info4.parseResolveInfo)(info, {
|
|
4839
|
+
deep: true
|
|
4840
|
+
});
|
|
4841
|
+
const { columns, hasRelations, withParams } = prepareMutationRelationColumns({
|
|
4842
|
+
relationMap,
|
|
4843
|
+
tables,
|
|
4844
|
+
tableName,
|
|
4845
|
+
typeName,
|
|
4846
|
+
typeNameMapper,
|
|
4847
|
+
table,
|
|
4848
|
+
pkNames,
|
|
4849
|
+
parsedInfo
|
|
4850
|
+
});
|
|
4851
|
+
let query = executor.insert(table).values(input).returning(columns);
|
|
4852
|
+
if (conflictDoNothing) {
|
|
4853
|
+
query = query.onConflictDoNothing();
|
|
4854
|
+
}
|
|
4855
|
+
const result = await query;
|
|
4856
|
+
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
4857
|
+
return remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
|
|
4488
4858
|
});
|
|
4489
|
-
const executor = resolveExecutor(db, context);
|
|
4490
|
-
let query = executor.insert(table).values(input).returning(columns);
|
|
4491
|
-
if (conflictDoNothing) {
|
|
4492
|
-
query = query.onConflictDoNothing();
|
|
4493
|
-
}
|
|
4494
|
-
const result = await query;
|
|
4495
|
-
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
4496
|
-
return remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
|
|
4497
4859
|
} catch (e) {
|
|
4498
4860
|
throw toGraphQLError(e);
|
|
4499
4861
|
}
|
|
@@ -4501,7 +4863,7 @@ var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
4501
4863
|
args: queryArgs
|
|
4502
4864
|
};
|
|
4503
4865
|
};
|
|
4504
|
-
var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false) => {
|
|
4866
|
+
var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx) => {
|
|
4505
4867
|
const queryArgs = {
|
|
4506
4868
|
values: {
|
|
4507
4869
|
type: new import_graphql8.GraphQLNonNull(baseType)
|
|
@@ -4512,31 +4874,32 @@ var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType
|
|
|
4512
4874
|
name: fieldName,
|
|
4513
4875
|
resolver: async (_source, args, context, info) => {
|
|
4514
4876
|
try {
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
|
|
4520
|
-
|
|
4521
|
-
|
|
4522
|
-
|
|
4523
|
-
|
|
4524
|
-
|
|
4525
|
-
|
|
4526
|
-
|
|
4527
|
-
|
|
4877
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4878
|
+
const input = remapFromGraphQLSingleInput(args.values, table);
|
|
4879
|
+
const parsedInfo = (0, import_graphql_parse_resolve_info4.parseResolveInfo)(info, {
|
|
4880
|
+
deep: true
|
|
4881
|
+
});
|
|
4882
|
+
const { columns, hasRelations, withParams } = prepareMutationRelationColumns({
|
|
4883
|
+
relationMap,
|
|
4884
|
+
tables,
|
|
4885
|
+
tableName,
|
|
4886
|
+
typeName,
|
|
4887
|
+
typeNameMapper,
|
|
4888
|
+
table,
|
|
4889
|
+
pkNames,
|
|
4890
|
+
parsedInfo
|
|
4891
|
+
});
|
|
4892
|
+
let query = executor.insert(table).values(input).returning(columns);
|
|
4893
|
+
if (conflictDoNothing) {
|
|
4894
|
+
query = query.onConflictDoNothing();
|
|
4895
|
+
}
|
|
4896
|
+
const result = await query;
|
|
4897
|
+
if (!result[0]) {
|
|
4898
|
+
return void 0;
|
|
4899
|
+
}
|
|
4900
|
+
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
4901
|
+
return remapToGraphQLSingleOutput(enriched[0], tableName, table, relationMap);
|
|
4528
4902
|
});
|
|
4529
|
-
const executor = resolveExecutor(db, context);
|
|
4530
|
-
let query = executor.insert(table).values(input).returning(columns);
|
|
4531
|
-
if (conflictDoNothing) {
|
|
4532
|
-
query = query.onConflictDoNothing();
|
|
4533
|
-
}
|
|
4534
|
-
const result = await query;
|
|
4535
|
-
if (!result[0]) {
|
|
4536
|
-
return void 0;
|
|
4537
|
-
}
|
|
4538
|
-
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
4539
|
-
return remapToGraphQLSingleOutput(enriched[0], tableName, table, relationMap);
|
|
4540
4903
|
} catch (e) {
|
|
4541
4904
|
throw toGraphQLError(e);
|
|
4542
4905
|
}
|
|
@@ -4544,7 +4907,7 @@ var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType
|
|
|
4544
4907
|
args: queryArgs
|
|
4545
4908
|
};
|
|
4546
4909
|
};
|
|
4547
|
-
var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx) => {
|
|
4910
|
+
var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx, txCtx) => {
|
|
4548
4911
|
const queryArgs = {
|
|
4549
4912
|
values: {
|
|
4550
4913
|
type: single ? new import_graphql8.GraphQLNonNull(baseType) : new import_graphql8.GraphQLNonNull(new import_graphql8.GraphQLList(new import_graphql8.GraphQLNonNull(baseType)))
|
|
@@ -4559,40 +4922,41 @@ var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
4559
4922
|
name: fieldName,
|
|
4560
4923
|
resolver: async (_source, args, context, info) => {
|
|
4561
4924
|
try {
|
|
4562
|
-
|
|
4563
|
-
|
|
4564
|
-
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
|
|
4572
|
-
|
|
4573
|
-
|
|
4574
|
-
|
|
4575
|
-
|
|
4576
|
-
|
|
4577
|
-
|
|
4578
|
-
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4925
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4926
|
+
const input = single ? [remapFromGraphQLSingleInput(args.values, table)] : remapFromGraphQLArrayInput(args.values, table);
|
|
4927
|
+
if (!input.length) {
|
|
4928
|
+
throw new import_graphql8.GraphQLError("No values were provided!");
|
|
4929
|
+
}
|
|
4930
|
+
const parsedInfo = (0, import_graphql_parse_resolve_info4.parseResolveInfo)(info, { deep: true });
|
|
4931
|
+
const { columns, hasRelations, withParams } = prepareMutationRelationColumns({
|
|
4932
|
+
relationMap,
|
|
4933
|
+
tables,
|
|
4934
|
+
tableName,
|
|
4935
|
+
typeName,
|
|
4936
|
+
typeNameMapper,
|
|
4937
|
+
table,
|
|
4938
|
+
pkNames,
|
|
4939
|
+
parsedInfo
|
|
4940
|
+
});
|
|
4941
|
+
const plan = resolveConflictPlan({
|
|
4942
|
+
table,
|
|
4943
|
+
values: input,
|
|
4944
|
+
onConflict: args.onConflict,
|
|
4945
|
+
pkNames,
|
|
4946
|
+
uniqueSets,
|
|
4947
|
+
excludedRef: excludedColumnRef,
|
|
4948
|
+
withTarget: true,
|
|
4949
|
+
buildWhere: (where) => extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName))
|
|
4950
|
+
});
|
|
4951
|
+
let query = executor.insert(table).values(input).returning(columns);
|
|
4952
|
+
query = plan.action === "NOTHING" ? query.onConflictDoNothing(plan.target ? { target: plan.target } : void 0) : query.onConflictDoUpdate({ target: plan.target, set: plan.set, setWhere: plan.setWhere });
|
|
4953
|
+
const result = await query;
|
|
4954
|
+
if (single && !result[0]) {
|
|
4955
|
+
return void 0;
|
|
4956
|
+
}
|
|
4957
|
+
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
4958
|
+
return single ? remapToGraphQLSingleOutput(enriched[0], tableName, table, relationMap) : remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
|
|
4586
4959
|
});
|
|
4587
|
-
const executor = resolveExecutor(db, context);
|
|
4588
|
-
let query = executor.insert(table).values(input).returning(columns);
|
|
4589
|
-
query = plan.action === "NOTHING" ? query.onConflictDoNothing(plan.target ? { target: plan.target } : void 0) : query.onConflictDoUpdate({ target: plan.target, set: plan.set, setWhere: plan.setWhere });
|
|
4590
|
-
const result = await query;
|
|
4591
|
-
if (single && !result[0]) {
|
|
4592
|
-
return void 0;
|
|
4593
|
-
}
|
|
4594
|
-
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
4595
|
-
return single ? remapToGraphQLSingleOutput(enriched[0], tableName, table, relationMap) : remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
|
|
4596
4960
|
} catch (e) {
|
|
4597
4961
|
throw toGraphQLError(e);
|
|
4598
4962
|
}
|
|
@@ -4600,7 +4964,7 @@ var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
4600
4964
|
args: queryArgs
|
|
4601
4965
|
};
|
|
4602
4966
|
};
|
|
4603
|
-
var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx) => {
|
|
4967
|
+
var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx, txCtx) => {
|
|
4604
4968
|
const queryArgs = {
|
|
4605
4969
|
set: {
|
|
4606
4970
|
type: new import_graphql8.GraphQLNonNull(setArgs)
|
|
@@ -4614,44 +4978,45 @@ var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
4614
4978
|
name: fieldName,
|
|
4615
4979
|
resolver: async (_source, args, context, info) => {
|
|
4616
4980
|
try {
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4981
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4982
|
+
const { where, set } = args;
|
|
4983
|
+
const parsedInfo = (0, import_graphql_parse_resolve_info4.parseResolveInfo)(info, {
|
|
4984
|
+
deep: true
|
|
4985
|
+
});
|
|
4986
|
+
const { columns, hasRelations, withParams } = prepareMutationRelationColumns({
|
|
4987
|
+
relationMap,
|
|
4988
|
+
tables,
|
|
4989
|
+
tableName,
|
|
4990
|
+
typeName,
|
|
4991
|
+
typeNameMapper,
|
|
4992
|
+
table,
|
|
4993
|
+
pkNames,
|
|
4994
|
+
parsedInfo
|
|
4995
|
+
});
|
|
4996
|
+
const input = remapFromGraphQLSingleInput(set, table);
|
|
4997
|
+
if (!Object.keys(input).length) {
|
|
4998
|
+
throw new import_graphql8.GraphQLError("Unable to update with no values specified!");
|
|
4999
|
+
}
|
|
5000
|
+
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
5001
|
+
const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
5002
|
+
if (single) {
|
|
5003
|
+
await assertSingleMatch(executor, table, filters, fieldName);
|
|
5004
|
+
}
|
|
5005
|
+
let query = executor.update(table).set(input);
|
|
5006
|
+
if (filters) {
|
|
5007
|
+
query = query.where(filters);
|
|
5008
|
+
}
|
|
5009
|
+
query = query.returning(columns);
|
|
5010
|
+
const result = await query;
|
|
5011
|
+
if (single && result.length > 1) {
|
|
5012
|
+
throw new import_graphql8.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
|
|
5013
|
+
}
|
|
5014
|
+
if (single && !result[0]) {
|
|
5015
|
+
return void 0;
|
|
5016
|
+
}
|
|
5017
|
+
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
5018
|
+
return single ? remapToGraphQLSingleOutput(enriched[0], tableName, table, relationMap) : remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
|
|
4630
5019
|
});
|
|
4631
|
-
const input = remapFromGraphQLSingleInput(set, table);
|
|
4632
|
-
if (!Object.keys(input).length) {
|
|
4633
|
-
throw new import_graphql8.GraphQLError("Unable to update with no values specified!");
|
|
4634
|
-
}
|
|
4635
|
-
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
4636
|
-
const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
4637
|
-
const executor = resolveExecutor(db, context);
|
|
4638
|
-
if (single) {
|
|
4639
|
-
await assertSingleMatch(executor, table, filters, fieldName);
|
|
4640
|
-
}
|
|
4641
|
-
let query = executor.update(table).set(input);
|
|
4642
|
-
if (filters) {
|
|
4643
|
-
query = query.where(filters);
|
|
4644
|
-
}
|
|
4645
|
-
query = query.returning(columns);
|
|
4646
|
-
const result = await query;
|
|
4647
|
-
if (single && result.length > 1) {
|
|
4648
|
-
throw new import_graphql8.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
|
|
4649
|
-
}
|
|
4650
|
-
if (single && !result[0]) {
|
|
4651
|
-
return void 0;
|
|
4652
|
-
}
|
|
4653
|
-
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
4654
|
-
return single ? remapToGraphQLSingleOutput(enriched[0], tableName, table, relationMap) : remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
|
|
4655
5020
|
} catch (e) {
|
|
4656
5021
|
throw toGraphQLError(e);
|
|
4657
5022
|
}
|
|
@@ -4659,7 +5024,7 @@ var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
4659
5024
|
args: queryArgs
|
|
4660
5025
|
};
|
|
4661
5026
|
};
|
|
4662
|
-
var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx) => {
|
|
5027
|
+
var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx, txCtx) => {
|
|
4663
5028
|
const queryArgs = {
|
|
4664
5029
|
updates: {
|
|
4665
5030
|
type: new import_graphql8.GraphQLNonNull(new import_graphql8.GraphQLList(new import_graphql8.GraphQLNonNull(updateManyInput)))
|
|
@@ -4670,73 +5035,74 @@ var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
4670
5035
|
name: fieldName,
|
|
4671
5036
|
resolver: async (_source, args, context, info) => {
|
|
4672
5037
|
try {
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
|
|
4677
|
-
const parsedInfo = (0, import_graphql_parse_resolve_info4.parseResolveInfo)(info, {
|
|
4678
|
-
deep: true
|
|
4679
|
-
});
|
|
4680
|
-
const { columns, hasRelations, withParams } = prepareMutationRelationColumns({
|
|
4681
|
-
relationMap,
|
|
4682
|
-
tables,
|
|
4683
|
-
tableName,
|
|
4684
|
-
typeName,
|
|
4685
|
-
typeNameMapper,
|
|
4686
|
-
table,
|
|
4687
|
-
pkNames,
|
|
4688
|
-
parsedInfo
|
|
4689
|
-
});
|
|
4690
|
-
const entries = updates.map(({ where, set }) => {
|
|
4691
|
-
const input = remapFromGraphQLSingleInput(set, table);
|
|
4692
|
-
if (!Object.keys(input).length) {
|
|
4693
|
-
throw new import_graphql8.GraphQLError("Unable to update with no values specified!");
|
|
5038
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
5039
|
+
const { updates } = args;
|
|
5040
|
+
if (!updates.length) {
|
|
5041
|
+
throw new import_graphql8.GraphQLError("No updates were provided!");
|
|
4694
5042
|
}
|
|
4695
|
-
|
|
4696
|
-
|
|
4697
|
-
|
|
5043
|
+
const parsedInfo = (0, import_graphql_parse_resolve_info4.parseResolveInfo)(info, {
|
|
5044
|
+
deep: true
|
|
5045
|
+
});
|
|
5046
|
+
const { columns, hasRelations, withParams } = prepareMutationRelationColumns({
|
|
5047
|
+
relationMap,
|
|
5048
|
+
tables,
|
|
5049
|
+
tableName,
|
|
5050
|
+
typeName,
|
|
5051
|
+
typeNameMapper,
|
|
5052
|
+
table,
|
|
5053
|
+
pkNames,
|
|
5054
|
+
parsedInfo
|
|
5055
|
+
});
|
|
5056
|
+
const entries = updates.map(({ where, set }) => {
|
|
5057
|
+
const input = remapFromGraphQLSingleInput(set, table);
|
|
5058
|
+
if (!Object.keys(input).length) {
|
|
5059
|
+
throw new import_graphql8.GraphQLError("Unable to update with no values specified!");
|
|
5060
|
+
}
|
|
5061
|
+
return {
|
|
5062
|
+
set: input,
|
|
5063
|
+
filters: where ? extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName)) : void 0
|
|
5064
|
+
};
|
|
5065
|
+
});
|
|
5066
|
+
const runEntry = (tx, entry) => {
|
|
5067
|
+
let query = tx.update(table).set(entry.set);
|
|
5068
|
+
if (entry.filters) {
|
|
5069
|
+
query = query.where(entry.filters);
|
|
5070
|
+
}
|
|
5071
|
+
return query.returning(columns).all();
|
|
4698
5072
|
};
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
|
|
4719
|
-
|
|
4720
|
-
for (
|
|
4721
|
-
|
|
5073
|
+
const perEntry = await executor.transaction((tx) => {
|
|
5074
|
+
const first = runEntry(tx, entries[0]);
|
|
5075
|
+
if (typeof first?.then === "function") {
|
|
5076
|
+
return (async () => {
|
|
5077
|
+
const results2 = [await first];
|
|
5078
|
+
for (let i = 1; i < entries.length; i++) {
|
|
5079
|
+
results2.push(await runEntry(tx, entries[i]));
|
|
5080
|
+
}
|
|
5081
|
+
return results2;
|
|
5082
|
+
})();
|
|
5083
|
+
}
|
|
5084
|
+
const results = [first];
|
|
5085
|
+
for (let i = 1; i < entries.length; i++) {
|
|
5086
|
+
results.push(runEntry(tx, entries[i]));
|
|
5087
|
+
}
|
|
5088
|
+
return results;
|
|
5089
|
+
});
|
|
5090
|
+
const flatRows = perEntry.flat();
|
|
5091
|
+
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, flatRows, pkNames, withParams) : flatRows;
|
|
5092
|
+
const output = [];
|
|
5093
|
+
let offset = 0;
|
|
5094
|
+
for (const rows of perEntry) {
|
|
5095
|
+
if (!rows.length) {
|
|
5096
|
+
output.push(null);
|
|
5097
|
+
continue;
|
|
5098
|
+
}
|
|
5099
|
+
for (let i = 0; i < rows.length; i++) {
|
|
5100
|
+
output.push(remapToGraphQLSingleOutput(enriched[offset + i], tableName, table, relationMap));
|
|
5101
|
+
}
|
|
5102
|
+
offset += rows.length;
|
|
4722
5103
|
}
|
|
4723
|
-
return
|
|
5104
|
+
return output;
|
|
4724
5105
|
});
|
|
4725
|
-
const flatRows = perEntry.flat();
|
|
4726
|
-
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, flatRows, pkNames, withParams) : flatRows;
|
|
4727
|
-
const output = [];
|
|
4728
|
-
let offset = 0;
|
|
4729
|
-
for (const rows of perEntry) {
|
|
4730
|
-
if (!rows.length) {
|
|
4731
|
-
output.push(null);
|
|
4732
|
-
continue;
|
|
4733
|
-
}
|
|
4734
|
-
for (let i = 0; i < rows.length; i++) {
|
|
4735
|
-
output.push(remapToGraphQLSingleOutput(enriched[offset + i], tableName, table, relationMap));
|
|
4736
|
-
}
|
|
4737
|
-
offset += rows.length;
|
|
4738
|
-
}
|
|
4739
|
-
return output;
|
|
4740
5106
|
} catch (e) {
|
|
4741
5107
|
throw toGraphQLError(e);
|
|
4742
5108
|
}
|
|
@@ -4744,7 +5110,7 @@ var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
4744
5110
|
args: queryArgs
|
|
4745
5111
|
};
|
|
4746
5112
|
};
|
|
4747
|
-
var generateDelete3 = (db, tableName, table, filterArgs, fieldName, typeName, single, requireWhere, filterCtx, selectionCtx) => {
|
|
5113
|
+
var generateDelete3 = (db, tableName, table, filterArgs, fieldName, typeName, single, requireWhere, filterCtx, selectionCtx, txCtx) => {
|
|
4748
5114
|
const queryArgs = {
|
|
4749
5115
|
where: {
|
|
4750
5116
|
type: single || requireWhere ? new import_graphql8.GraphQLNonNull(filterArgs) : filterArgs
|
|
@@ -4754,34 +5120,35 @@ var generateDelete3 = (db, tableName, table, filterArgs, fieldName, typeName, si
|
|
|
4754
5120
|
name: fieldName,
|
|
4755
5121
|
resolver: async (_source, args, context, info) => {
|
|
4756
5122
|
try {
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
5123
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
5124
|
+
const { where } = args;
|
|
5125
|
+
const parsedInfo = (0, import_graphql_parse_resolve_info4.parseResolveInfo)(info, {
|
|
5126
|
+
deep: true
|
|
5127
|
+
});
|
|
5128
|
+
const columns = extractSelectedColumnsFromTreeSQLFormat(
|
|
5129
|
+
parsedInfo.fieldsByTypeName[typeName],
|
|
5130
|
+
table,
|
|
5131
|
+
selectionCtx
|
|
5132
|
+
);
|
|
5133
|
+
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
5134
|
+
const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
5135
|
+
if (single) {
|
|
5136
|
+
await assertSingleMatch(executor, table, filters, fieldName);
|
|
5137
|
+
}
|
|
5138
|
+
let query = executor.delete(table);
|
|
5139
|
+
if (filters) {
|
|
5140
|
+
query = query.where(filters);
|
|
5141
|
+
}
|
|
5142
|
+
query = query.returning(columns);
|
|
5143
|
+
const result = await query;
|
|
5144
|
+
if (single && result.length > 1) {
|
|
5145
|
+
throw new import_graphql8.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
|
|
5146
|
+
}
|
|
5147
|
+
if (single) {
|
|
5148
|
+
return result[0] ? remapToGraphQLSingleOutput(result[0], tableName, table) : void 0;
|
|
5149
|
+
}
|
|
5150
|
+
return remapToGraphQLArrayOutput(result, tableName, table);
|
|
4760
5151
|
});
|
|
4761
|
-
const columns = extractSelectedColumnsFromTreeSQLFormat(
|
|
4762
|
-
parsedInfo.fieldsByTypeName[typeName],
|
|
4763
|
-
table,
|
|
4764
|
-
selectionCtx
|
|
4765
|
-
);
|
|
4766
|
-
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
4767
|
-
const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
4768
|
-
const executor = resolveExecutor(db, context);
|
|
4769
|
-
if (single) {
|
|
4770
|
-
await assertSingleMatch(executor, table, filters, fieldName);
|
|
4771
|
-
}
|
|
4772
|
-
let query = executor.delete(table);
|
|
4773
|
-
if (filters) {
|
|
4774
|
-
query = query.where(filters);
|
|
4775
|
-
}
|
|
4776
|
-
query = query.returning(columns);
|
|
4777
|
-
const result = await query;
|
|
4778
|
-
if (single && result.length > 1) {
|
|
4779
|
-
throw new import_graphql8.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
|
|
4780
|
-
}
|
|
4781
|
-
if (single) {
|
|
4782
|
-
return result[0] ? remapToGraphQLSingleOutput(result[0], tableName, table) : void 0;
|
|
4783
|
-
}
|
|
4784
|
-
return remapToGraphQLArrayOutput(result, tableName, table);
|
|
4785
5152
|
} catch (e) {
|
|
4786
5153
|
throw toGraphQLError(e);
|
|
4787
5154
|
}
|
|
@@ -4809,6 +5176,7 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
4809
5176
|
"Drizzle-GraphQL Error: No tables detected in Drizzle-ORM's database instance. Did you forget to pass schema to drizzle constructor?"
|
|
4810
5177
|
);
|
|
4811
5178
|
}
|
|
5179
|
+
registerScalarOverrides(tables, options);
|
|
4812
5180
|
const namedRelations = buildNamedRelations(relations ?? {}, tableEntries);
|
|
4813
5181
|
attachTargetPrimaryKeys(namedRelations, tables, sqlitePrimaryKeyPropNames);
|
|
4814
5182
|
const eagerRelations = pruneNonEagerRelations(namedRelations, shouldEagerLoad);
|
|
@@ -4820,6 +5188,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
4820
5188
|
relationFieldContainers: /* @__PURE__ */ new Map(),
|
|
4821
5189
|
fullyBuiltTables: /* @__PURE__ */ new Set(),
|
|
4822
5190
|
relationTypeCache: /* @__PURE__ */ new Map(),
|
|
5191
|
+
selectFieldCache: /* @__PURE__ */ new WeakMap(),
|
|
5192
|
+
filterFieldCache: /* @__PURE__ */ new WeakMap(),
|
|
4823
5193
|
orderTypeCache: /* @__PURE__ */ new WeakMap(),
|
|
4824
5194
|
filterTypeCache: /* @__PURE__ */ new WeakMap(),
|
|
4825
5195
|
listRelationFilterCache: /* @__PURE__ */ new Map(),
|
|
@@ -4829,6 +5199,12 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
4829
5199
|
const relationAggregateFactory = features.relationAggregates ? createRelationAggregateFactory(db, tables, cacheCtx, typeNameMapper, filterCtx) : void 0;
|
|
4830
5200
|
const queries = {};
|
|
4831
5201
|
const mutations = {};
|
|
5202
|
+
if (options.transactions && db.resultKind === "sync") {
|
|
5203
|
+
throw new Error(
|
|
5204
|
+
"Drizzle-GraphQL Error: transactions: 'auto' requires an asynchronous SQLite driver (e.g. libsql). Synchronous drivers cannot hold a transaction open across resolvers."
|
|
5205
|
+
);
|
|
5206
|
+
}
|
|
5207
|
+
const mutationTxCtx = createMutationTxCtx(options.transactions);
|
|
4832
5208
|
const gqlSchemaTypes = Object.fromEntries(
|
|
4833
5209
|
Object.entries(tables).map(([tableName, _table]) => [
|
|
4834
5210
|
tableName,
|
|
@@ -4903,7 +5279,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
4903
5279
|
createArrayFieldName,
|
|
4904
5280
|
typeName,
|
|
4905
5281
|
typeNameMapper,
|
|
4906
|
-
conflictDoNothing
|
|
5282
|
+
conflictDoNothing,
|
|
5283
|
+
mutationTxCtx
|
|
4907
5284
|
) : void 0;
|
|
4908
5285
|
const insertSingleGenerated = features.insert ? generateInsertSingle3(
|
|
4909
5286
|
db,
|
|
@@ -4915,7 +5292,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
4915
5292
|
createSingleFieldName,
|
|
4916
5293
|
typeName,
|
|
4917
5294
|
typeNameMapper,
|
|
4918
|
-
conflictDoNothing
|
|
5295
|
+
conflictDoNothing,
|
|
5296
|
+
mutationTxCtx
|
|
4919
5297
|
) : void 0;
|
|
4920
5298
|
const uniqueSets = features.upsert ? getUniqueColumnSets(schema[tableName], import_sqlite_core2.getTableConfig) : [];
|
|
4921
5299
|
const onConflictInput = features.upsert ? generateOnConflictInput({
|
|
@@ -4938,7 +5316,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
4938
5316
|
typeName,
|
|
4939
5317
|
false,
|
|
4940
5318
|
typeNameMapper,
|
|
4941
|
-
filterCtx
|
|
5319
|
+
filterCtx,
|
|
5320
|
+
mutationTxCtx
|
|
4942
5321
|
) : void 0;
|
|
4943
5322
|
const upsertSingleGenerated = onConflictInput ? generateUpsert3(
|
|
4944
5323
|
db,
|
|
@@ -4953,7 +5332,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
4953
5332
|
typeName,
|
|
4954
5333
|
true,
|
|
4955
5334
|
typeNameMapper,
|
|
4956
|
-
filterCtx
|
|
5335
|
+
filterCtx,
|
|
5336
|
+
mutationTxCtx
|
|
4957
5337
|
) : void 0;
|
|
4958
5338
|
const updateGenerated = features.update ? generateUpdate3(
|
|
4959
5339
|
db,
|
|
@@ -4968,7 +5348,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
4968
5348
|
false,
|
|
4969
5349
|
features.requireWhere,
|
|
4970
5350
|
typeNameMapper,
|
|
4971
|
-
filterCtx
|
|
5351
|
+
filterCtx,
|
|
5352
|
+
mutationTxCtx
|
|
4972
5353
|
) : void 0;
|
|
4973
5354
|
const updateSingleGenerated = features.update ? generateUpdate3(
|
|
4974
5355
|
db,
|
|
@@ -4983,7 +5364,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
4983
5364
|
true,
|
|
4984
5365
|
features.requireWhere,
|
|
4985
5366
|
typeNameMapper,
|
|
4986
|
-
filterCtx
|
|
5367
|
+
filterCtx,
|
|
5368
|
+
mutationTxCtx
|
|
4987
5369
|
) : void 0;
|
|
4988
5370
|
const updateManyInput = features.update && features.updateMany ? generateUpdateManyInput({ typeName, updatePrefix: prefixes.update, updateInput, tableFilters }) : void 0;
|
|
4989
5371
|
const updateManyGenerated = updateManyInput ? generateUpdateMany3(
|
|
@@ -4996,7 +5378,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
4996
5378
|
updateManyFieldName,
|
|
4997
5379
|
typeName,
|
|
4998
5380
|
typeNameMapper,
|
|
4999
|
-
filterCtx
|
|
5381
|
+
filterCtx,
|
|
5382
|
+
mutationTxCtx
|
|
5000
5383
|
) : void 0;
|
|
5001
5384
|
const deleteGenerated = features.delete ? generateDelete3(
|
|
5002
5385
|
db,
|
|
@@ -5008,7 +5391,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5008
5391
|
false,
|
|
5009
5392
|
features.requireWhere,
|
|
5010
5393
|
filterCtx,
|
|
5011
|
-
{ tableName, relationMap: namedRelations, tables }
|
|
5394
|
+
{ tableName, relationMap: namedRelations, tables },
|
|
5395
|
+
mutationTxCtx
|
|
5012
5396
|
) : void 0;
|
|
5013
5397
|
const deleteSingleGenerated = features.delete ? generateDelete3(
|
|
5014
5398
|
db,
|
|
@@ -5020,7 +5404,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5020
5404
|
true,
|
|
5021
5405
|
features.requireWhere,
|
|
5022
5406
|
filterCtx,
|
|
5023
|
-
{ tableName, relationMap: namedRelations, tables }
|
|
5407
|
+
{ tableName, relationMap: namedRelations, tables },
|
|
5408
|
+
mutationTxCtx
|
|
5024
5409
|
) : void 0;
|
|
5025
5410
|
const aggregateType = features.aggregates ? generateAggregateTypes(schema[tableName], tableName, typeName, cacheCtx) : void 0;
|
|
5026
5411
|
const aggregateGenerated = features.aggregates ? generateAggregate(
|
|
@@ -5159,6 +5544,11 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5159
5544
|
inputs[havingInput.name] = havingInput;
|
|
5160
5545
|
}
|
|
5161
5546
|
}
|
|
5547
|
+
if (mutationTxCtx) {
|
|
5548
|
+
for (const name of Object.keys(mutations)) {
|
|
5549
|
+
mutationTxCtx.fieldNames.add(name);
|
|
5550
|
+
}
|
|
5551
|
+
}
|
|
5162
5552
|
const fieldResolvers = {};
|
|
5163
5553
|
for (const [tableName, tableRelations] of Object.entries(namedRelations)) {
|
|
5164
5554
|
const relResolvers = {};
|
|
@@ -5215,6 +5605,8 @@ var buildSchema = (db, config) => {
|
|
|
5215
5605
|
defaultListSize: (complexityConfig === true ? void 0 : complexityConfig.defaultListSize) ?? 10,
|
|
5216
5606
|
aggregateCost: (complexityConfig === true ? void 0 : complexityConfig.aggregateCost) ?? 10
|
|
5217
5607
|
};
|
|
5608
|
+
const transactionsOpt = config?.transactions;
|
|
5609
|
+
const transactions = transactionsOpt === void 0 || transactionsOpt === "none" ? void 0 : { timeoutMs: (transactionsOpt === "auto" ? void 0 : transactionsOpt.timeoutMs) ?? 3e4 };
|
|
5218
5610
|
const eagerOpt = config?.eagerLoadRelations;
|
|
5219
5611
|
const shouldEagerLoad = eagerOpt === void 0 || eagerOpt === true ? () => true : eagerOpt === false ? () => false : eagerOpt;
|
|
5220
5612
|
if (!typeNameMapper && suffixes.list === suffixes.single) {
|
|
@@ -5242,7 +5634,10 @@ var buildSchema = (db, config) => {
|
|
|
5242
5634
|
typeNameMapper,
|
|
5243
5635
|
shouldEagerLoad,
|
|
5244
5636
|
features,
|
|
5245
|
-
complexity
|
|
5637
|
+
complexity,
|
|
5638
|
+
scalars: config?.scalars,
|
|
5639
|
+
mapColumnType: config?.mapColumnType,
|
|
5640
|
+
transactions
|
|
5246
5641
|
};
|
|
5247
5642
|
let generatorOutput;
|
|
5248
5643
|
if ((0, import_drizzle_orm8.is)(db, import_mysql_core3.MySqlDatabase)) {
|