@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.js
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
asc,
|
|
18
18
|
desc,
|
|
19
19
|
eq,
|
|
20
|
+
extractExtendedColumnType as extractExtendedColumnType2,
|
|
20
21
|
getColumns,
|
|
21
22
|
getTableAsAliasSQL,
|
|
22
23
|
gt,
|
|
@@ -104,8 +105,287 @@ var uncapitalize = (input) => input?.length ? `${input[0].toLocaleLowerCase()}${
|
|
|
104
105
|
var capitalize = (input) => input?.length ? `${input[0].toLocaleUpperCase()}${input.length > 1 ? input.slice(1, input.length) : ""}` : input;
|
|
105
106
|
|
|
106
107
|
// src/util/data-mappers/index.ts
|
|
107
|
-
import { getTableColumns, is, One } from "drizzle-orm";
|
|
108
|
-
import { GraphQLError } from "graphql";
|
|
108
|
+
import { getTableColumns as getTableColumns2, is as is2, One } from "drizzle-orm";
|
|
109
|
+
import { GraphQLError as GraphQLError2 } from "graphql";
|
|
110
|
+
|
|
111
|
+
// src/util/type-converter/index.ts
|
|
112
|
+
import { extractExtendedColumnType, getTableColumns, is } from "drizzle-orm";
|
|
113
|
+
import { MySqlInt, MySqlSerial } from "drizzle-orm/mysql-core";
|
|
114
|
+
import { PgDate, PgDateString, PgInteger, PgSerial, PgTimestamp, PgTimestampString, PgUUID } from "drizzle-orm/pg-core";
|
|
115
|
+
import { SQLiteInteger } from "drizzle-orm/sqlite-core";
|
|
116
|
+
import {
|
|
117
|
+
GraphQLBoolean,
|
|
118
|
+
GraphQLEnumType,
|
|
119
|
+
GraphQLFloat,
|
|
120
|
+
GraphQLInputObjectType,
|
|
121
|
+
GraphQLInt,
|
|
122
|
+
GraphQLList,
|
|
123
|
+
GraphQLNonNull,
|
|
124
|
+
GraphQLObjectType,
|
|
125
|
+
GraphQLScalarType as GraphQLScalarType2,
|
|
126
|
+
GraphQLString
|
|
127
|
+
} from "graphql";
|
|
128
|
+
|
|
129
|
+
// src/util/scalars/index.ts
|
|
130
|
+
import { GraphQLError, GraphQLScalarType, Kind } from "graphql";
|
|
131
|
+
import { GraphQLDate, GraphQLDateTime, GraphQLJSON, GraphQLUUID } from "graphql-scalars";
|
|
132
|
+
var asDecimalString = (value) => {
|
|
133
|
+
if (typeof value === "bigint") {
|
|
134
|
+
return value.toString();
|
|
135
|
+
}
|
|
136
|
+
if (typeof value === "number") {
|
|
137
|
+
if (!Number.isInteger(value)) {
|
|
138
|
+
throw new GraphQLError(`BigInt cannot represent non-integer value: ${value}`);
|
|
139
|
+
}
|
|
140
|
+
if (!Number.isSafeInteger(value)) {
|
|
141
|
+
throw new GraphQLError(
|
|
142
|
+
`BigInt cannot represent the number ${value} without precision loss \u2014 pass it as a string instead`
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
return String(value);
|
|
146
|
+
}
|
|
147
|
+
if (typeof value === "string") {
|
|
148
|
+
if (!/^-?\d+$/.test(value)) {
|
|
149
|
+
throw new GraphQLError(`BigInt cannot represent non-integer value: "${value}"`);
|
|
150
|
+
}
|
|
151
|
+
return value;
|
|
152
|
+
}
|
|
153
|
+
throw new GraphQLError(`BigInt cannot represent value: ${JSON.stringify(value)}`);
|
|
154
|
+
};
|
|
155
|
+
var GraphQLBigIntString = new GraphQLScalarType({
|
|
156
|
+
name: "BigInt",
|
|
157
|
+
description: "A 64-bit integer, transported as a decimal string so that values beyond JavaScript's safe integer range survive the round-trip intact.",
|
|
158
|
+
serialize: asDecimalString,
|
|
159
|
+
parseValue: asDecimalString,
|
|
160
|
+
parseLiteral: (ast) => {
|
|
161
|
+
if (ast.kind !== Kind.STRING && ast.kind !== Kind.INT) {
|
|
162
|
+
throw new GraphQLError(`BigInt cannot represent a ${ast.kind}`, { nodes: ast });
|
|
163
|
+
}
|
|
164
|
+
return asDecimalString(ast.value);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
var numericStringPattern = /^[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?$/;
|
|
168
|
+
var asNumericString = (value) => {
|
|
169
|
+
if (typeof value === "bigint") {
|
|
170
|
+
return value.toString();
|
|
171
|
+
}
|
|
172
|
+
if (typeof value === "number") {
|
|
173
|
+
if (!Number.isFinite(value)) {
|
|
174
|
+
throw new GraphQLError(`Decimal cannot represent non-finite value: ${value}`);
|
|
175
|
+
}
|
|
176
|
+
return String(value);
|
|
177
|
+
}
|
|
178
|
+
if (typeof value === "string") {
|
|
179
|
+
if (!numericStringPattern.test(value)) {
|
|
180
|
+
throw new GraphQLError(`Decimal cannot represent non-numeric value: "${value}"`);
|
|
181
|
+
}
|
|
182
|
+
return value;
|
|
183
|
+
}
|
|
184
|
+
throw new GraphQLError(`Decimal cannot represent value: ${JSON.stringify(value)}`);
|
|
185
|
+
};
|
|
186
|
+
var GraphQLDecimalString = new GraphQLScalarType({
|
|
187
|
+
name: "Decimal",
|
|
188
|
+
description: "An arbitrary-precision decimal, transported as a numeric string so that values beyond JavaScript's double-precision range survive the round-trip intact.",
|
|
189
|
+
serialize: asNumericString,
|
|
190
|
+
parseValue: asNumericString,
|
|
191
|
+
parseLiteral: (ast) => {
|
|
192
|
+
if (ast.kind !== Kind.STRING && ast.kind !== Kind.INT && ast.kind !== Kind.FLOAT) {
|
|
193
|
+
throw new GraphQLError(`Decimal cannot represent a ${ast.kind}`, { nodes: ast });
|
|
194
|
+
}
|
|
195
|
+
return asNumericString(ast.value);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
// src/util/type-converter/index.ts
|
|
200
|
+
var allowedNameChars = /^[a-zA-Z0-9_]+$/;
|
|
201
|
+
var enumMap = /* @__PURE__ */ new WeakMap();
|
|
202
|
+
var generateEnumCached = (column, columnName, tableName) => {
|
|
203
|
+
if (enumMap.has(column)) {
|
|
204
|
+
return enumMap.get(column);
|
|
205
|
+
}
|
|
206
|
+
const gqlEnum = new GraphQLEnumType({
|
|
207
|
+
name: `${capitalize(tableName)}${capitalize(columnName)}Enum`,
|
|
208
|
+
values: Object.fromEntries(
|
|
209
|
+
column.enumValues.map((e, index) => [
|
|
210
|
+
allowedNameChars.test(e) ? e : `Option${index}`,
|
|
211
|
+
{
|
|
212
|
+
value: e,
|
|
213
|
+
description: `Value: ${e}`
|
|
214
|
+
}
|
|
215
|
+
])
|
|
216
|
+
)
|
|
217
|
+
});
|
|
218
|
+
enumMap.set(column, gqlEnum);
|
|
219
|
+
return gqlEnum;
|
|
220
|
+
};
|
|
221
|
+
var geoXyType = new GraphQLObjectType({
|
|
222
|
+
name: "PgGeometryObject",
|
|
223
|
+
fields: {
|
|
224
|
+
x: { type: GraphQLFloat },
|
|
225
|
+
y: { type: GraphQLFloat }
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
var geoXyInputType = new GraphQLInputObjectType({
|
|
229
|
+
name: "PgGeometryObjectInput",
|
|
230
|
+
fields: {
|
|
231
|
+
x: { type: GraphQLFloat },
|
|
232
|
+
y: { type: GraphQLFloat }
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
var columnToGraphQLCore = (column, columnName, tableName, isInput) => {
|
|
236
|
+
const dimensions = column.dimensions;
|
|
237
|
+
if (dimensions !== void 0 && dimensions > 0) {
|
|
238
|
+
const inner = columnBaseToGraphQLCore(column, columnName, tableName, isInput);
|
|
239
|
+
const innerDesc = inner.description ?? inner.type.name;
|
|
240
|
+
let type = inner.type;
|
|
241
|
+
let description = innerDesc;
|
|
242
|
+
for (let i = 0; i < dimensions; i++) {
|
|
243
|
+
type = new GraphQLList(new GraphQLNonNull(type));
|
|
244
|
+
description = `Array<${description}>`;
|
|
245
|
+
}
|
|
246
|
+
return { type, description };
|
|
247
|
+
}
|
|
248
|
+
return columnBaseToGraphQLCore(column, columnName, tableName, isInput);
|
|
249
|
+
};
|
|
250
|
+
var columnBaseToGraphQLCore = (column, columnName, tableName, isInput) => {
|
|
251
|
+
const { type: baseType, constraint } = extractExtendedColumnType(column);
|
|
252
|
+
switch (baseType) {
|
|
253
|
+
case "boolean":
|
|
254
|
+
return { type: GraphQLBoolean, description: "Boolean" };
|
|
255
|
+
case "object":
|
|
256
|
+
if (column instanceof PgTimestamp || column instanceof PgDate) {
|
|
257
|
+
return { type: GraphQLDateTime, description: "DateTime" };
|
|
258
|
+
}
|
|
259
|
+
return column.columnType === "PgGeometryObject" ? {
|
|
260
|
+
type: isInput ? geoXyInputType : geoXyType,
|
|
261
|
+
description: "Geometry points XY"
|
|
262
|
+
} : column.columnType === "PgBytea" ? {
|
|
263
|
+
type: new GraphQLList(new GraphQLNonNull(GraphQLInt)),
|
|
264
|
+
description: "Buffer"
|
|
265
|
+
} : { type: GraphQLJSON, description: "JSON" };
|
|
266
|
+
case "string":
|
|
267
|
+
if (column.enumValues?.length) {
|
|
268
|
+
return { type: generateEnumCached(column, columnName, tableName) };
|
|
269
|
+
}
|
|
270
|
+
if (constraint === "numeric" && !column.dimensions) {
|
|
271
|
+
return { type: GraphQLDecimalString, description: "Decimal" };
|
|
272
|
+
}
|
|
273
|
+
if (column instanceof PgTimestamp || column instanceof PgTimestampString) {
|
|
274
|
+
return { type: GraphQLDateTime, description: "DateTime" };
|
|
275
|
+
}
|
|
276
|
+
if (column instanceof PgUUID) {
|
|
277
|
+
return { type: GraphQLUUID, description: "UUID" };
|
|
278
|
+
}
|
|
279
|
+
if (column instanceof PgDateString) {
|
|
280
|
+
return isInput ? { type: GraphQLString, description: "Date" } : { type: GraphQLDate, description: "Date" };
|
|
281
|
+
}
|
|
282
|
+
return { type: GraphQLString, description: "String" };
|
|
283
|
+
case "bigint":
|
|
284
|
+
return { type: GraphQLBigIntString, description: "BigInt" };
|
|
285
|
+
case "number": {
|
|
286
|
+
return is(column, PgInteger) || is(column, PgSerial) || is(column, MySqlInt) || is(column, MySqlSerial) || is(column, SQLiteInteger) ? { type: GraphQLInt, description: "Integer" } : { type: GraphQLFloat, description: "Float" };
|
|
287
|
+
}
|
|
288
|
+
case "array": {
|
|
289
|
+
if (column.columnType === "PgVector") {
|
|
290
|
+
return {
|
|
291
|
+
type: new GraphQLList(new GraphQLNonNull(GraphQLFloat)),
|
|
292
|
+
description: "Array<Float>"
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
if (column.columnType === "PgGeometry") {
|
|
296
|
+
return {
|
|
297
|
+
type: new GraphQLList(new GraphQLNonNull(GraphQLFloat)),
|
|
298
|
+
description: "Tuple<[Float, Float]>"
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
const innerType = columnToGraphQLCore(
|
|
302
|
+
column.baseColumn,
|
|
303
|
+
columnName,
|
|
304
|
+
tableName,
|
|
305
|
+
isInput
|
|
306
|
+
);
|
|
307
|
+
return {
|
|
308
|
+
type: new GraphQLList(new GraphQLNonNull(innerType.type)),
|
|
309
|
+
description: `Array<${innerType.description}>`
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
default:
|
|
313
|
+
throw new Error(`Drizzle-GraphQL Error: Type ${column.dataType} is not implemented!`);
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
var columnScalarOverrides = /* @__PURE__ */ new WeakMap();
|
|
317
|
+
var getColumnScalarOverride = (column, isInput) => {
|
|
318
|
+
const override = columnScalarOverrides.get(column);
|
|
319
|
+
return override ? isInput ? override.input : override.output : void 0;
|
|
320
|
+
};
|
|
321
|
+
var normalizeScalarOverride = (override, tableName, columnName) => {
|
|
322
|
+
const pair = override instanceof GraphQLScalarType2 ? { output: override, input: override } : { output: override.output, input: override.input };
|
|
323
|
+
for (const scalar of [pair.output, pair.input]) {
|
|
324
|
+
if (scalar !== void 0 && !(scalar instanceof GraphQLScalarType2)) {
|
|
325
|
+
throw new Error(
|
|
326
|
+
`Drizzle-GraphQL Error: Scalar override for column '${tableName}.${columnName}' must be a GraphQLScalarType!`
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return pair;
|
|
331
|
+
};
|
|
332
|
+
var registerScalarOverrides = (tables, config) => {
|
|
333
|
+
for (const [tableName, table] of Object.entries(tables)) {
|
|
334
|
+
for (const [columnName, column] of Object.entries(getTableColumns(table))) {
|
|
335
|
+
const declared = config.scalars?.[tableName]?.[columnName];
|
|
336
|
+
let resolved;
|
|
337
|
+
if (declared !== void 0) {
|
|
338
|
+
resolved = normalizeScalarOverride(declared, tableName, columnName);
|
|
339
|
+
} else if (config.mapColumnType) {
|
|
340
|
+
let defaultType;
|
|
341
|
+
let defaultInputType;
|
|
342
|
+
try {
|
|
343
|
+
defaultType = columnToGraphQLCore(column, columnName, tableName, false).type;
|
|
344
|
+
} catch {
|
|
345
|
+
}
|
|
346
|
+
try {
|
|
347
|
+
defaultInputType = columnToGraphQLCore(column, columnName, tableName, true).type;
|
|
348
|
+
} catch {
|
|
349
|
+
}
|
|
350
|
+
const mapped = config.mapColumnType(column, { tableName, columnName, defaultType, defaultInputType });
|
|
351
|
+
if (mapped !== void 0) {
|
|
352
|
+
resolved = normalizeScalarOverride(mapped, tableName, columnName);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
if (resolved && (resolved.output !== void 0 || resolved.input !== void 0)) {
|
|
356
|
+
columnScalarOverrides.set(column, resolved);
|
|
357
|
+
} else {
|
|
358
|
+
columnScalarOverrides.delete(column);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
var drizzleColumnToGraphQLType = (column, columnName, tableName, forceNullable = false, defaultIsNullable = false, isInput = false) => {
|
|
364
|
+
const override = getColumnScalarOverride(column, isInput);
|
|
365
|
+
let typeDesc;
|
|
366
|
+
if (override) {
|
|
367
|
+
typeDesc = { type: override, description: override.name };
|
|
368
|
+
} else {
|
|
369
|
+
typeDesc = columnToGraphQLCore(column, columnName, tableName, isInput);
|
|
370
|
+
const noDesc = ["string", "boolean", "number"];
|
|
371
|
+
const { type: baseType } = extractExtendedColumnType(column);
|
|
372
|
+
if (noDesc.find((e) => e === baseType)) {
|
|
373
|
+
delete typeDesc.description;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
if (forceNullable) {
|
|
377
|
+
return typeDesc;
|
|
378
|
+
}
|
|
379
|
+
if (column.notNull && !(defaultIsNullable && (column.hasDefault || column.defaultFn))) {
|
|
380
|
+
return {
|
|
381
|
+
type: new GraphQLNonNull(typeDesc.type),
|
|
382
|
+
description: typeDesc.description
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
return typeDesc;
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
// src/util/data-mappers/index.ts
|
|
109
389
|
var isJsonColumn = (column) => (column.dataType ?? "").includes("json") && column.columnType !== "PgGeometryObject";
|
|
110
390
|
var remapToGraphQLCore = (key, value, tableName, column, relationMap) => {
|
|
111
391
|
if (Array.isArray(value)) {
|
|
@@ -136,6 +416,9 @@ var remapToGraphQLCore = (key, value, tableName, column, relationMap) => {
|
|
|
136
416
|
if (!column) {
|
|
137
417
|
return value;
|
|
138
418
|
}
|
|
419
|
+
if (getColumnScalarOverride(column, false)) {
|
|
420
|
+
return value;
|
|
421
|
+
}
|
|
139
422
|
if (isJsonColumn(column)) {
|
|
140
423
|
return value;
|
|
141
424
|
}
|
|
@@ -166,7 +449,7 @@ var remapToGraphQLSingleOutput = (queryOutput, tableName, table, relationMap) =>
|
|
|
166
449
|
for (const [key, value] of Object.entries(queryOutput)) {
|
|
167
450
|
if (value === void 0 || value === null) {
|
|
168
451
|
const relEntry = value === null ? relationMap?.[tableName]?.[key] : void 0;
|
|
169
|
-
if (relEntry &&
|
|
452
|
+
if (relEntry && is2(relEntry.relation, One)) {
|
|
170
453
|
queryOutput[key] = null;
|
|
171
454
|
continue;
|
|
172
455
|
}
|
|
@@ -189,13 +472,19 @@ var remapToGraphQLArrayOutput = (queryOutput, tableName, table, relationMap) =>
|
|
|
189
472
|
return queryOutput;
|
|
190
473
|
};
|
|
191
474
|
var remapFromGraphQLCore = (value, column, columnName) => {
|
|
475
|
+
if (getColumnScalarOverride(column, true)) {
|
|
476
|
+
if (typeof value === "object" && value !== null && Object.getPrototypeOf(value) === null) {
|
|
477
|
+
return Object.assign({}, value);
|
|
478
|
+
}
|
|
479
|
+
return value;
|
|
480
|
+
}
|
|
192
481
|
const dataType = column.dataType ?? "";
|
|
193
482
|
const columnType = column.columnType ?? "";
|
|
194
483
|
const isTimestampColumn = columnType === "SQLiteTimestamp" || columnType === "SQLiteTimestampMs" || columnType === "MySqlTimestamp" || columnType === "MySqlDateTime" || columnType === "PgTimestamp" || columnType === "PgTimestampString";
|
|
195
484
|
if (isTimestampColumn) {
|
|
196
485
|
const formatted = new Date(value);
|
|
197
486
|
if (Number.isNaN(formatted.getTime())) {
|
|
198
|
-
throw new
|
|
487
|
+
throw new GraphQLError2(`Field '${columnName}' is not a valid date!`);
|
|
199
488
|
}
|
|
200
489
|
return formatted;
|
|
201
490
|
}
|
|
@@ -204,7 +493,7 @@ var remapFromGraphQLCore = (value, column, columnName) => {
|
|
|
204
493
|
const dateOnly = value.includes("T") ? value.split("T")[0] : value;
|
|
205
494
|
const check = new Date(dateOnly);
|
|
206
495
|
if (Number.isNaN(check.getTime())) {
|
|
207
|
-
throw new
|
|
496
|
+
throw new GraphQLError2(`Field '${columnName}' is not a valid date!`);
|
|
208
497
|
}
|
|
209
498
|
return dateOnly;
|
|
210
499
|
}
|
|
@@ -212,7 +501,7 @@ var remapFromGraphQLCore = (value, column, columnName) => {
|
|
|
212
501
|
try {
|
|
213
502
|
return BigInt(value);
|
|
214
503
|
} catch {
|
|
215
|
-
throw new
|
|
504
|
+
throw new GraphQLError2(`Field '${columnName}' is not a BigInt!`);
|
|
216
505
|
}
|
|
217
506
|
}
|
|
218
507
|
if (dataType.includes("json") && column.columnType !== "PgGeometryObject") {
|
|
@@ -222,13 +511,13 @@ var remapFromGraphQLCore = (value, column, columnName) => {
|
|
|
222
511
|
case "date": {
|
|
223
512
|
const formatted = new Date(value);
|
|
224
513
|
if (Number.isNaN(formatted.getTime())) {
|
|
225
|
-
throw new
|
|
514
|
+
throw new GraphQLError2(`Field '${columnName}' is not a valid date!`);
|
|
226
515
|
}
|
|
227
516
|
return formatted;
|
|
228
517
|
}
|
|
229
518
|
case "buffer": {
|
|
230
519
|
if (!Array.isArray(value)) {
|
|
231
|
-
throw new
|
|
520
|
+
throw new GraphQLError2(`Field '${columnName}' is not an array!`);
|
|
232
521
|
}
|
|
233
522
|
return Buffer.from(value);
|
|
234
523
|
}
|
|
@@ -239,7 +528,7 @@ var remapFromGraphQLCore = (value, column, columnName) => {
|
|
|
239
528
|
try {
|
|
240
529
|
return JSON.parse(value);
|
|
241
530
|
} catch (e) {
|
|
242
|
-
throw new
|
|
531
|
+
throw new GraphQLError2(
|
|
243
532
|
`Invalid JSON in field '${columnName}':
|
|
244
533
|
${e instanceof Error ? e.message : "Unknown error"}`
|
|
245
534
|
);
|
|
@@ -247,10 +536,10 @@ ${e instanceof Error ? e.message : "Unknown error"}`
|
|
|
247
536
|
}
|
|
248
537
|
case "array": {
|
|
249
538
|
if (!Array.isArray(value)) {
|
|
250
|
-
throw new
|
|
539
|
+
throw new GraphQLError2(`Field '${columnName}' is not an array!`);
|
|
251
540
|
}
|
|
252
541
|
if (column.columnType === "PgGeometry" && value.length !== 2) {
|
|
253
|
-
throw new
|
|
542
|
+
throw new GraphQLError2(
|
|
254
543
|
`Invalid float tuple in field '${columnName}': expected array with length of 2, received ${value.length}`
|
|
255
544
|
);
|
|
256
545
|
}
|
|
@@ -260,7 +549,7 @@ ${e instanceof Error ? e.message : "Unknown error"}`
|
|
|
260
549
|
try {
|
|
261
550
|
return BigInt(value);
|
|
262
551
|
} catch (_error) {
|
|
263
|
-
throw new
|
|
552
|
+
throw new GraphQLError2(`Field '${columnName}' is not a BigInt!`);
|
|
264
553
|
}
|
|
265
554
|
}
|
|
266
555
|
default: {
|
|
@@ -276,245 +565,24 @@ var remapFromGraphQLSingleInput = (queryInput, table) => {
|
|
|
276
565
|
if (value === void 0) {
|
|
277
566
|
delete queryInput[key];
|
|
278
567
|
} else {
|
|
279
|
-
const column =
|
|
568
|
+
const column = getTableColumns2(table)[key];
|
|
280
569
|
if (!column) {
|
|
281
|
-
throw new
|
|
570
|
+
throw new GraphQLError2(`Unknown column: ${key}`);
|
|
282
571
|
}
|
|
283
572
|
if (value === null && column.notNull) {
|
|
284
573
|
delete queryInput[key];
|
|
285
|
-
continue;
|
|
286
|
-
}
|
|
287
|
-
queryInput[key] = remapFromGraphQLCore(value, column, key);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
return queryInput;
|
|
291
|
-
};
|
|
292
|
-
var remapFromGraphQLArrayInput = (queryInput, table) => {
|
|
293
|
-
for (const entry of queryInput) {
|
|
294
|
-
remapFromGraphQLSingleInput(entry, table);
|
|
295
|
-
}
|
|
296
|
-
return queryInput;
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
// src/util/scalars/index.ts
|
|
300
|
-
import { GraphQLError as GraphQLError2, GraphQLScalarType, Kind } from "graphql";
|
|
301
|
-
import { GraphQLDate, GraphQLDateTime, GraphQLJSON, GraphQLUUID } from "graphql-scalars";
|
|
302
|
-
var asDecimalString = (value) => {
|
|
303
|
-
if (typeof value === "bigint") {
|
|
304
|
-
return value.toString();
|
|
305
|
-
}
|
|
306
|
-
if (typeof value === "number") {
|
|
307
|
-
if (!Number.isInteger(value)) {
|
|
308
|
-
throw new GraphQLError2(`BigInt cannot represent non-integer value: ${value}`);
|
|
309
|
-
}
|
|
310
|
-
if (!Number.isSafeInteger(value)) {
|
|
311
|
-
throw new GraphQLError2(
|
|
312
|
-
`BigInt cannot represent the number ${value} without precision loss \u2014 pass it as a string instead`
|
|
313
|
-
);
|
|
314
|
-
}
|
|
315
|
-
return String(value);
|
|
316
|
-
}
|
|
317
|
-
if (typeof value === "string") {
|
|
318
|
-
if (!/^-?\d+$/.test(value)) {
|
|
319
|
-
throw new GraphQLError2(`BigInt cannot represent non-integer value: "${value}"`);
|
|
320
|
-
}
|
|
321
|
-
return value;
|
|
322
|
-
}
|
|
323
|
-
throw new GraphQLError2(`BigInt cannot represent value: ${JSON.stringify(value)}`);
|
|
324
|
-
};
|
|
325
|
-
var GraphQLBigIntString = new GraphQLScalarType({
|
|
326
|
-
name: "BigInt",
|
|
327
|
-
description: "A 64-bit integer, transported as a decimal string so that values beyond JavaScript's safe integer range survive the round-trip intact.",
|
|
328
|
-
serialize: asDecimalString,
|
|
329
|
-
parseValue: asDecimalString,
|
|
330
|
-
parseLiteral: (ast) => {
|
|
331
|
-
if (ast.kind !== Kind.STRING && ast.kind !== Kind.INT) {
|
|
332
|
-
throw new GraphQLError2(`BigInt cannot represent a ${ast.kind}`, { nodes: ast });
|
|
333
|
-
}
|
|
334
|
-
return asDecimalString(ast.value);
|
|
335
|
-
}
|
|
336
|
-
});
|
|
337
|
-
var numericStringPattern = /^[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?$/;
|
|
338
|
-
var asNumericString = (value) => {
|
|
339
|
-
if (typeof value === "bigint") {
|
|
340
|
-
return value.toString();
|
|
341
|
-
}
|
|
342
|
-
if (typeof value === "number") {
|
|
343
|
-
if (!Number.isFinite(value)) {
|
|
344
|
-
throw new GraphQLError2(`Decimal cannot represent non-finite value: ${value}`);
|
|
345
|
-
}
|
|
346
|
-
return String(value);
|
|
347
|
-
}
|
|
348
|
-
if (typeof value === "string") {
|
|
349
|
-
if (!numericStringPattern.test(value)) {
|
|
350
|
-
throw new GraphQLError2(`Decimal cannot represent non-numeric value: "${value}"`);
|
|
351
|
-
}
|
|
352
|
-
return value;
|
|
353
|
-
}
|
|
354
|
-
throw new GraphQLError2(`Decimal cannot represent value: ${JSON.stringify(value)}`);
|
|
355
|
-
};
|
|
356
|
-
var GraphQLDecimalString = new GraphQLScalarType({
|
|
357
|
-
name: "Decimal",
|
|
358
|
-
description: "An arbitrary-precision decimal, transported as a numeric string so that values beyond JavaScript's double-precision range survive the round-trip intact.",
|
|
359
|
-
serialize: asNumericString,
|
|
360
|
-
parseValue: asNumericString,
|
|
361
|
-
parseLiteral: (ast) => {
|
|
362
|
-
if (ast.kind !== Kind.STRING && ast.kind !== Kind.INT && ast.kind !== Kind.FLOAT) {
|
|
363
|
-
throw new GraphQLError2(`Decimal cannot represent a ${ast.kind}`, { nodes: ast });
|
|
364
|
-
}
|
|
365
|
-
return asNumericString(ast.value);
|
|
366
|
-
}
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
// src/util/type-converter/index.ts
|
|
370
|
-
import { extractExtendedColumnType, is as is2 } from "drizzle-orm";
|
|
371
|
-
import { MySqlInt, MySqlSerial } from "drizzle-orm/mysql-core";
|
|
372
|
-
import { PgDate, PgDateString, PgInteger, PgSerial, PgTimestamp, PgTimestampString, PgUUID } from "drizzle-orm/pg-core";
|
|
373
|
-
import { SQLiteInteger } from "drizzle-orm/sqlite-core";
|
|
374
|
-
import {
|
|
375
|
-
GraphQLBoolean,
|
|
376
|
-
GraphQLEnumType,
|
|
377
|
-
GraphQLFloat,
|
|
378
|
-
GraphQLInputObjectType,
|
|
379
|
-
GraphQLInt,
|
|
380
|
-
GraphQLList,
|
|
381
|
-
GraphQLNonNull,
|
|
382
|
-
GraphQLObjectType,
|
|
383
|
-
GraphQLString
|
|
384
|
-
} from "graphql";
|
|
385
|
-
var allowedNameChars = /^[a-zA-Z0-9_]+$/;
|
|
386
|
-
var enumMap = /* @__PURE__ */ new WeakMap();
|
|
387
|
-
var generateEnumCached = (column, columnName, tableName) => {
|
|
388
|
-
if (enumMap.has(column)) {
|
|
389
|
-
return enumMap.get(column);
|
|
390
|
-
}
|
|
391
|
-
const gqlEnum = new GraphQLEnumType({
|
|
392
|
-
name: `${capitalize(tableName)}${capitalize(columnName)}Enum`,
|
|
393
|
-
values: Object.fromEntries(
|
|
394
|
-
column.enumValues.map((e, index) => [
|
|
395
|
-
allowedNameChars.test(e) ? e : `Option${index}`,
|
|
396
|
-
{
|
|
397
|
-
value: e,
|
|
398
|
-
description: `Value: ${e}`
|
|
399
|
-
}
|
|
400
|
-
])
|
|
401
|
-
)
|
|
402
|
-
});
|
|
403
|
-
enumMap.set(column, gqlEnum);
|
|
404
|
-
return gqlEnum;
|
|
405
|
-
};
|
|
406
|
-
var geoXyType = new GraphQLObjectType({
|
|
407
|
-
name: "PgGeometryObject",
|
|
408
|
-
fields: {
|
|
409
|
-
x: { type: GraphQLFloat },
|
|
410
|
-
y: { type: GraphQLFloat }
|
|
411
|
-
}
|
|
412
|
-
});
|
|
413
|
-
var geoXyInputType = new GraphQLInputObjectType({
|
|
414
|
-
name: "PgGeometryObjectInput",
|
|
415
|
-
fields: {
|
|
416
|
-
x: { type: GraphQLFloat },
|
|
417
|
-
y: { type: GraphQLFloat }
|
|
418
|
-
}
|
|
419
|
-
});
|
|
420
|
-
var columnToGraphQLCore = (column, columnName, tableName, isInput) => {
|
|
421
|
-
const dimensions = column.dimensions;
|
|
422
|
-
if (dimensions !== void 0 && dimensions > 0) {
|
|
423
|
-
const inner = columnBaseToGraphQLCore(column, columnName, tableName, isInput);
|
|
424
|
-
const innerDesc = inner.description ?? inner.type.name;
|
|
425
|
-
let type = inner.type;
|
|
426
|
-
let description = innerDesc;
|
|
427
|
-
for (let i = 0; i < dimensions; i++) {
|
|
428
|
-
type = new GraphQLList(new GraphQLNonNull(type));
|
|
429
|
-
description = `Array<${description}>`;
|
|
430
|
-
}
|
|
431
|
-
return { type, description };
|
|
432
|
-
}
|
|
433
|
-
return columnBaseToGraphQLCore(column, columnName, tableName, isInput);
|
|
434
|
-
};
|
|
435
|
-
var columnBaseToGraphQLCore = (column, columnName, tableName, isInput) => {
|
|
436
|
-
const { type: baseType, constraint } = extractExtendedColumnType(column);
|
|
437
|
-
switch (baseType) {
|
|
438
|
-
case "boolean":
|
|
439
|
-
return { type: GraphQLBoolean, description: "Boolean" };
|
|
440
|
-
case "object":
|
|
441
|
-
if (column instanceof PgTimestamp || column instanceof PgDate) {
|
|
442
|
-
return { type: GraphQLDateTime, description: "DateTime" };
|
|
443
|
-
}
|
|
444
|
-
return column.columnType === "PgGeometryObject" ? {
|
|
445
|
-
type: isInput ? geoXyInputType : geoXyType,
|
|
446
|
-
description: "Geometry points XY"
|
|
447
|
-
} : column.columnType === "PgBytea" ? {
|
|
448
|
-
type: new GraphQLList(new GraphQLNonNull(GraphQLInt)),
|
|
449
|
-
description: "Buffer"
|
|
450
|
-
} : { type: GraphQLJSON, description: "JSON" };
|
|
451
|
-
case "string":
|
|
452
|
-
if (column.enumValues?.length) {
|
|
453
|
-
return { type: generateEnumCached(column, columnName, tableName) };
|
|
454
|
-
}
|
|
455
|
-
if (constraint === "numeric" && !column.dimensions) {
|
|
456
|
-
return { type: GraphQLDecimalString, description: "Decimal" };
|
|
457
|
-
}
|
|
458
|
-
if (column instanceof PgTimestamp || column instanceof PgTimestampString) {
|
|
459
|
-
return { type: GraphQLDateTime, description: "DateTime" };
|
|
460
|
-
}
|
|
461
|
-
if (column instanceof PgUUID) {
|
|
462
|
-
return { type: GraphQLUUID, description: "UUID" };
|
|
463
|
-
}
|
|
464
|
-
if (column instanceof PgDateString) {
|
|
465
|
-
return isInput ? { type: GraphQLString, description: "Date" } : { type: GraphQLDate, description: "Date" };
|
|
466
|
-
}
|
|
467
|
-
return { type: GraphQLString, description: "String" };
|
|
468
|
-
case "bigint":
|
|
469
|
-
return { type: GraphQLBigIntString, description: "BigInt" };
|
|
470
|
-
case "number": {
|
|
471
|
-
return is2(column, PgInteger) || is2(column, PgSerial) || is2(column, MySqlInt) || is2(column, MySqlSerial) || is2(column, SQLiteInteger) ? { type: GraphQLInt, description: "Integer" } : { type: GraphQLFloat, description: "Float" };
|
|
472
|
-
}
|
|
473
|
-
case "array": {
|
|
474
|
-
if (column.columnType === "PgVector") {
|
|
475
|
-
return {
|
|
476
|
-
type: new GraphQLList(new GraphQLNonNull(GraphQLFloat)),
|
|
477
|
-
description: "Array<Float>"
|
|
478
|
-
};
|
|
479
|
-
}
|
|
480
|
-
if (column.columnType === "PgGeometry") {
|
|
481
|
-
return {
|
|
482
|
-
type: new GraphQLList(new GraphQLNonNull(GraphQLFloat)),
|
|
483
|
-
description: "Tuple<[Float, Float]>"
|
|
484
|
-
};
|
|
574
|
+
continue;
|
|
485
575
|
}
|
|
486
|
-
|
|
487
|
-
column.baseColumn,
|
|
488
|
-
columnName,
|
|
489
|
-
tableName,
|
|
490
|
-
isInput
|
|
491
|
-
);
|
|
492
|
-
return {
|
|
493
|
-
type: new GraphQLList(new GraphQLNonNull(innerType.type)),
|
|
494
|
-
description: `Array<${innerType.description}>`
|
|
495
|
-
};
|
|
576
|
+
queryInput[key] = remapFromGraphQLCore(value, column, key);
|
|
496
577
|
}
|
|
497
|
-
default:
|
|
498
|
-
throw new Error(`Drizzle-GraphQL Error: Type ${column.dataType} is not implemented!`);
|
|
499
578
|
}
|
|
579
|
+
return queryInput;
|
|
500
580
|
};
|
|
501
|
-
var
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
const { type: baseType } = extractExtendedColumnType(column);
|
|
505
|
-
if (noDesc.find((e) => e === baseType)) {
|
|
506
|
-
delete typeDesc.description;
|
|
507
|
-
}
|
|
508
|
-
if (forceNullable) {
|
|
509
|
-
return typeDesc;
|
|
510
|
-
}
|
|
511
|
-
if (column.notNull && !(defaultIsNullable && (column.hasDefault || column.defaultFn))) {
|
|
512
|
-
return {
|
|
513
|
-
type: new GraphQLNonNull(typeDesc.type),
|
|
514
|
-
description: typeDesc.description
|
|
515
|
-
};
|
|
581
|
+
var remapFromGraphQLArrayInput = (queryInput, table) => {
|
|
582
|
+
for (const entry of queryInput) {
|
|
583
|
+
remapFromGraphQLSingleInput(entry, table);
|
|
516
584
|
}
|
|
517
|
-
return
|
|
585
|
+
return queryInput;
|
|
518
586
|
};
|
|
519
587
|
|
|
520
588
|
// src/util/builders/common.ts
|
|
@@ -605,6 +673,203 @@ var resolveQueryExecutor = (db, context, tableName, buildTimeQueryBase) => {
|
|
|
605
673
|
queryBase: buildTimeQueryBase ? executor?.query?.[tableName] ?? buildTimeQueryBase : buildTimeQueryBase
|
|
606
674
|
};
|
|
607
675
|
};
|
|
676
|
+
var createMutationTxCtx = (options) => options ? { timeoutMs: options.timeoutMs, fieldNames: /* @__PURE__ */ new Set(), states: /* @__PURE__ */ new WeakMap() } : void 0;
|
|
677
|
+
var includedByDirectives = (node, variables) => {
|
|
678
|
+
for (const directive of node.directives ?? []) {
|
|
679
|
+
const name = directive.name.value;
|
|
680
|
+
if (name !== "skip" && name !== "include") {
|
|
681
|
+
continue;
|
|
682
|
+
}
|
|
683
|
+
const ifArg = directive.arguments?.find((arg) => arg.name.value === "if");
|
|
684
|
+
let value;
|
|
685
|
+
if (ifArg?.value.kind === "BooleanValue") {
|
|
686
|
+
value = ifArg.value.value;
|
|
687
|
+
} else if (ifArg?.value.kind === "Variable") {
|
|
688
|
+
value = variables?.[ifArg.value.name.value];
|
|
689
|
+
}
|
|
690
|
+
if (name === "skip" && value === true) {
|
|
691
|
+
return false;
|
|
692
|
+
}
|
|
693
|
+
if (name === "include" && value !== true) {
|
|
694
|
+
return false;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
return true;
|
|
698
|
+
};
|
|
699
|
+
var collectRootMutationKeys = (selectionSet, fragments, variables, known, keys, visitedFragments) => {
|
|
700
|
+
for (const selection of selectionSet.selections) {
|
|
701
|
+
if (!includedByDirectives(selection, variables)) {
|
|
702
|
+
continue;
|
|
703
|
+
}
|
|
704
|
+
if (selection.kind === "Field") {
|
|
705
|
+
const name = selection.name.value;
|
|
706
|
+
if (name === "__typename") {
|
|
707
|
+
continue;
|
|
708
|
+
}
|
|
709
|
+
if (!known.has(name)) {
|
|
710
|
+
return false;
|
|
711
|
+
}
|
|
712
|
+
keys.add(selection.alias?.value ?? name);
|
|
713
|
+
} else if (selection.kind === "InlineFragment") {
|
|
714
|
+
if (!collectRootMutationKeys(selection.selectionSet, fragments, variables, known, keys, visitedFragments)) {
|
|
715
|
+
return false;
|
|
716
|
+
}
|
|
717
|
+
} else if (selection.kind === "FragmentSpread") {
|
|
718
|
+
const fragmentName = selection.name.value;
|
|
719
|
+
if (visitedFragments.has(fragmentName)) {
|
|
720
|
+
continue;
|
|
721
|
+
}
|
|
722
|
+
visitedFragments.add(fragmentName);
|
|
723
|
+
const fragment = fragments?.[fragmentName];
|
|
724
|
+
if (!fragment) {
|
|
725
|
+
return false;
|
|
726
|
+
}
|
|
727
|
+
if (!collectRootMutationKeys(fragment.selectionSet, fragments, variables, known, keys, visitedFragments)) {
|
|
728
|
+
return false;
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
return true;
|
|
733
|
+
};
|
|
734
|
+
var abortedBatchError = () => new GraphQLError3(
|
|
735
|
+
"Drizzle-GraphQL Error: Mutation was not executed because an earlier mutation in the same request failed and the shared transaction was rolled back."
|
|
736
|
+
);
|
|
737
|
+
var openSharedTx = (db, context, txCtx, stateKey, expected) => {
|
|
738
|
+
let release;
|
|
739
|
+
let rejectLatch;
|
|
740
|
+
const latch = new Promise((resolve, reject) => {
|
|
741
|
+
release = resolve;
|
|
742
|
+
rejectLatch = reject;
|
|
743
|
+
});
|
|
744
|
+
let readyResolve;
|
|
745
|
+
let readyReject;
|
|
746
|
+
const ready = new Promise((resolve, reject) => {
|
|
747
|
+
readyResolve = resolve;
|
|
748
|
+
readyReject = reject;
|
|
749
|
+
});
|
|
750
|
+
ready.catch(() => {
|
|
751
|
+
});
|
|
752
|
+
const canStash = context !== null && typeof context === "object" && !Object.isFrozen(context);
|
|
753
|
+
const settled = db.transaction(async (tx) => {
|
|
754
|
+
if (canStash) {
|
|
755
|
+
context[drizzleExecutorKey] = tx;
|
|
756
|
+
}
|
|
757
|
+
readyResolve(tx);
|
|
758
|
+
await latch;
|
|
759
|
+
});
|
|
760
|
+
let timer;
|
|
761
|
+
const clearTimer = () => {
|
|
762
|
+
if (timer !== void 0) {
|
|
763
|
+
clearTimeout(timer);
|
|
764
|
+
timer = void 0;
|
|
765
|
+
}
|
|
766
|
+
};
|
|
767
|
+
const state = {
|
|
768
|
+
kind: "shared",
|
|
769
|
+
expected,
|
|
770
|
+
completed: 0,
|
|
771
|
+
failure: void 0,
|
|
772
|
+
aborted: false,
|
|
773
|
+
done: false,
|
|
774
|
+
ready,
|
|
775
|
+
settled,
|
|
776
|
+
release,
|
|
777
|
+
abort: (e) => {
|
|
778
|
+
if (!state.aborted) {
|
|
779
|
+
state.aborted = true;
|
|
780
|
+
state.failure = e;
|
|
781
|
+
}
|
|
782
|
+
rejectLatch(e);
|
|
783
|
+
},
|
|
784
|
+
suspendTimer: clearTimer,
|
|
785
|
+
bumpTimer: () => {
|
|
786
|
+
clearTimer();
|
|
787
|
+
if (state.done) {
|
|
788
|
+
return;
|
|
789
|
+
}
|
|
790
|
+
timer = setTimeout(() => {
|
|
791
|
+
state.abort(
|
|
792
|
+
new GraphQLError3(
|
|
793
|
+
`Drizzle-GraphQL Error: Shared mutation transaction timed out after ${txCtx.timeoutMs}ms waiting for the remaining mutation fields; rolling back.`
|
|
794
|
+
)
|
|
795
|
+
);
|
|
796
|
+
}, txCtx.timeoutMs);
|
|
797
|
+
timer.unref?.();
|
|
798
|
+
}
|
|
799
|
+
};
|
|
800
|
+
const cleanup = () => {
|
|
801
|
+
state.done = true;
|
|
802
|
+
clearTimer();
|
|
803
|
+
if (canStash) {
|
|
804
|
+
delete context[drizzleExecutorKey];
|
|
805
|
+
}
|
|
806
|
+
if (!state.aborted) {
|
|
807
|
+
txCtx.states.delete(stateKey);
|
|
808
|
+
}
|
|
809
|
+
};
|
|
810
|
+
settled.then(cleanup, (e) => {
|
|
811
|
+
cleanup();
|
|
812
|
+
readyReject(e);
|
|
813
|
+
});
|
|
814
|
+
state.bumpTimer();
|
|
815
|
+
return state;
|
|
816
|
+
};
|
|
817
|
+
var runOnSharedTx = async (state, body) => {
|
|
818
|
+
if (state.aborted) {
|
|
819
|
+
await state.settled.catch(() => {
|
|
820
|
+
});
|
|
821
|
+
throw abortedBatchError();
|
|
822
|
+
}
|
|
823
|
+
state.suspendTimer();
|
|
824
|
+
const tx = await state.ready;
|
|
825
|
+
try {
|
|
826
|
+
if (state.aborted) {
|
|
827
|
+
throw abortedBatchError();
|
|
828
|
+
}
|
|
829
|
+
const result = await body(tx);
|
|
830
|
+
state.completed += 1;
|
|
831
|
+
if (state.completed >= state.expected) {
|
|
832
|
+
state.release();
|
|
833
|
+
await state.settled;
|
|
834
|
+
} else {
|
|
835
|
+
state.bumpTimer();
|
|
836
|
+
}
|
|
837
|
+
return result;
|
|
838
|
+
} catch (e) {
|
|
839
|
+
state.abort(e);
|
|
840
|
+
await state.settled.catch(() => {
|
|
841
|
+
});
|
|
842
|
+
throw e;
|
|
843
|
+
}
|
|
844
|
+
};
|
|
845
|
+
var runMutation = async (db, context, info, txCtx, body) => {
|
|
846
|
+
const contextIsObject = context !== null && (typeof context === "object" || typeof context === "function");
|
|
847
|
+
const stateKey = contextIsObject ? context : info.operation;
|
|
848
|
+
let state = txCtx?.states.get(stateKey);
|
|
849
|
+
if (!state) {
|
|
850
|
+
if (contextIsObject && context[drizzleExecutorKey]) {
|
|
851
|
+
return body(context[drizzleExecutorKey]);
|
|
852
|
+
}
|
|
853
|
+
if (!txCtx || info.operation.operation !== "mutation") {
|
|
854
|
+
return body(db);
|
|
855
|
+
}
|
|
856
|
+
const keys = /* @__PURE__ */ new Set();
|
|
857
|
+
const allKnown = collectRootMutationKeys(
|
|
858
|
+
info.operation.selectionSet,
|
|
859
|
+
info.fragments,
|
|
860
|
+
info.variableValues,
|
|
861
|
+
txCtx.fieldNames,
|
|
862
|
+
keys,
|
|
863
|
+
/* @__PURE__ */ new Set()
|
|
864
|
+
);
|
|
865
|
+
state = !allKnown || keys.size <= 1 ? { kind: "passthrough" } : openSharedTx(db, context, txCtx, stateKey, keys.size);
|
|
866
|
+
txCtx.states.set(stateKey, state);
|
|
867
|
+
}
|
|
868
|
+
if (state.kind === "passthrough") {
|
|
869
|
+
return body(resolveExecutor(db, context));
|
|
870
|
+
}
|
|
871
|
+
return runOnSharedTx(state, body);
|
|
872
|
+
};
|
|
608
873
|
var batchedPaginatedRelationQuery = async (db, targetTable, foreignCol, whereCondition, orderByArg, limit, offset, pkNames, orderCtx) => {
|
|
609
874
|
const cols = getColumns(targetTable);
|
|
610
875
|
const orderExprs = [
|
|
@@ -898,9 +1163,31 @@ var arrayFilterFields = (colType, colArr, colDesc) => {
|
|
|
898
1163
|
};
|
|
899
1164
|
};
|
|
900
1165
|
var FILTERS_WITHOUT_STRING_OPS = /* @__PURE__ */ new Set(["Id", "Int", "Float", "BigInt", "Decimal"]);
|
|
1166
|
+
var BUILTIN_FILTER_SCALARS = /* @__PURE__ */ new Set([
|
|
1167
|
+
GraphQLString2,
|
|
1168
|
+
GraphQLInt2,
|
|
1169
|
+
GraphQLFloat2,
|
|
1170
|
+
GraphQLBoolean2,
|
|
1171
|
+
GraphQLBigIntString,
|
|
1172
|
+
GraphQLDecimalString,
|
|
1173
|
+
GraphQLUUID,
|
|
1174
|
+
GraphQLJSON,
|
|
1175
|
+
GraphQLDate,
|
|
1176
|
+
GraphQLDateTime
|
|
1177
|
+
]);
|
|
1178
|
+
var resolveOverrideFilterDescriptor = (scalar) => {
|
|
1179
|
+
if (scalar === GraphQLJSON) {
|
|
1180
|
+
return { name: "JSON", kind: "json" };
|
|
1181
|
+
}
|
|
1182
|
+
if (scalar === GraphQLUUID) {
|
|
1183
|
+
return { name: "Id", kind: "scalar" };
|
|
1184
|
+
}
|
|
1185
|
+
return { name: scalar.name, kind: "scalar" };
|
|
1186
|
+
};
|
|
901
1187
|
var generateColumnFilterValues = (column, tableName, columnName, cacheCtx) => {
|
|
902
1188
|
const columnGraphQLType = drizzleColumnToGraphQLType(column, columnName, tableName, true, false, true);
|
|
903
|
-
const
|
|
1189
|
+
const inputOverride = getColumnScalarOverride(column, true);
|
|
1190
|
+
const { name: genericName, kind } = inputOverride ? resolveOverrideFilterDescriptor(inputOverride) : resolveGenericFilterDescriptor(column, columnGraphQLType);
|
|
904
1191
|
const cached = cacheCtx.genericFilterCache.get(genericName);
|
|
905
1192
|
if (cached) {
|
|
906
1193
|
return cached;
|
|
@@ -908,7 +1195,9 @@ var generateColumnFilterValues = (column, tableName, columnName, cacheCtx) => {
|
|
|
908
1195
|
const colType = columnGraphQLType.type;
|
|
909
1196
|
const colDesc = columnGraphQLType.description;
|
|
910
1197
|
const colArr = new GraphQLList2(new GraphQLNonNull2(colType));
|
|
911
|
-
const
|
|
1198
|
+
const customOverrideFilter = inputOverride !== void 0 && !BUILTIN_FILTER_SCALARS.has(inputOverride);
|
|
1199
|
+
const underlying = extractExtendedColumnType2(column);
|
|
1200
|
+
const omitStringOps = customOverrideFilter ? underlying.type !== "string" || underlying.constraint === "numeric" : FILTERS_WITHOUT_STRING_OPS.has(genericName);
|
|
912
1201
|
const baseFields = kind === "json" ? jsonFilterFields(column, colType) : kind === "array" ? arrayFilterFields(colType, colArr, colDesc) : {
|
|
913
1202
|
eq: { type: colType, description: colDesc },
|
|
914
1203
|
ne: { type: colType, description: colDesc },
|
|
@@ -989,10 +1278,9 @@ var generateTableOrderCached = (table) => {
|
|
|
989
1278
|
}
|
|
990
1279
|
return remapped;
|
|
991
1280
|
};
|
|
992
|
-
var filterMap = /* @__PURE__ */ new WeakMap();
|
|
993
1281
|
var generateTableFilterValuesCached = (table, tableName, cacheCtx) => {
|
|
994
|
-
if (
|
|
995
|
-
return
|
|
1282
|
+
if (cacheCtx.filterFieldCache.has(table)) {
|
|
1283
|
+
return cacheCtx.filterFieldCache.get(table);
|
|
996
1284
|
}
|
|
997
1285
|
const columns = getColumns(table);
|
|
998
1286
|
const columnEntries = Object.entries(columns);
|
|
@@ -1004,13 +1292,12 @@ var generateTableFilterValuesCached = (table, tableName, cacheCtx) => {
|
|
|
1004
1292
|
}
|
|
1005
1293
|
])
|
|
1006
1294
|
);
|
|
1007
|
-
|
|
1295
|
+
cacheCtx.filterFieldCache.set(table, remapped);
|
|
1008
1296
|
return remapped;
|
|
1009
1297
|
};
|
|
1010
|
-
var
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
return fieldMap.get(table);
|
|
1298
|
+
var generateTableSelectTypeFieldsCached = (table, tableName, cacheCtx) => {
|
|
1299
|
+
if (cacheCtx.selectFieldCache.has(table)) {
|
|
1300
|
+
return cacheCtx.selectFieldCache.get(table);
|
|
1014
1301
|
}
|
|
1015
1302
|
const columns = getColumns(table);
|
|
1016
1303
|
const columnEntries = Object.entries(columns);
|
|
@@ -1027,7 +1314,7 @@ var generateTableSelectTypeFieldsCached = (table, tableName) => {
|
|
|
1027
1314
|
resolve: rowCursorResolver
|
|
1028
1315
|
};
|
|
1029
1316
|
}
|
|
1030
|
-
|
|
1317
|
+
cacheCtx.selectFieldCache.set(table, remapped);
|
|
1031
1318
|
return remapped;
|
|
1032
1319
|
};
|
|
1033
1320
|
var isFilterableRelation = (relation) => !relation.through;
|
|
@@ -1177,7 +1464,7 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
|
|
|
1177
1464
|
const table = tables[tableName];
|
|
1178
1465
|
const order = withOrder ? generateTableOrderTypeCached(table, tableName, typeNameMapper, cacheCtx, relationMap, tables) : void 0;
|
|
1179
1466
|
const filters = generateTableFilterTypeCached(table, tableName, cacheCtx, typeNameMapper, relationMap, tables);
|
|
1180
|
-
const tableFields = generateTableSelectTypeFieldsCached(table, tableName);
|
|
1467
|
+
const tableFields = generateTableSelectTypeFieldsCached(table, tableName, cacheCtx);
|
|
1181
1468
|
const relationsForTable = relationMap[tableName];
|
|
1182
1469
|
const relationEntries = relationsForTable ? Object.entries(relationsForTable) : [];
|
|
1183
1470
|
if (relationsDepthLimit !== void 0 && currentDepth >= relationsDepthLimit) {
|
|
@@ -1246,7 +1533,7 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
|
|
|
1246
1533
|
let relType = cacheCtx.objectTypeCache.get(targetTableName);
|
|
1247
1534
|
if (!relType) {
|
|
1248
1535
|
const targetTable = tables[targetTableName];
|
|
1249
|
-
const targetTableFields = generateTableSelectTypeFieldsCached(targetTable, targetTableName);
|
|
1536
|
+
const targetTableFields = generateTableSelectTypeFieldsCached(targetTable, targetTableName, cacheCtx);
|
|
1250
1537
|
let targetContainer = cacheCtx.relationFieldContainers.get(targetTableName);
|
|
1251
1538
|
if (!targetContainer) {
|
|
1252
1539
|
targetContainer = { fields: {} };
|
|
@@ -2509,7 +2796,7 @@ import {
|
|
|
2509
2796
|
count,
|
|
2510
2797
|
countDistinct,
|
|
2511
2798
|
eq as eq2,
|
|
2512
|
-
extractExtendedColumnType as
|
|
2799
|
+
extractExtendedColumnType as extractExtendedColumnType3,
|
|
2513
2800
|
getColumns as getColumns2,
|
|
2514
2801
|
gt as gt2,
|
|
2515
2802
|
gte as gte2,
|
|
@@ -2553,7 +2840,7 @@ var classifyAggregateColumns = (table, tableName) => {
|
|
|
2553
2840
|
if (gqlType instanceof GraphQLList3 || gqlType instanceof GraphQLObjectType3) {
|
|
2554
2841
|
continue;
|
|
2555
2842
|
}
|
|
2556
|
-
const { type: dataType, constraint } =
|
|
2843
|
+
const { type: dataType, constraint } = extractExtendedColumnType3(column);
|
|
2557
2844
|
if (dataType === "boolean" || dataType === "array" || dataType === "custom") {
|
|
2558
2845
|
continue;
|
|
2559
2846
|
}
|
|
@@ -2794,7 +3081,7 @@ var groupableColumns = (table, tableName) => {
|
|
|
2794
3081
|
if (groupable[columnName]) {
|
|
2795
3082
|
continue;
|
|
2796
3083
|
}
|
|
2797
|
-
const { type: dataType } =
|
|
3084
|
+
const { type: dataType } = extractExtendedColumnType3(column);
|
|
2798
3085
|
if (dataType !== "boolean") {
|
|
2799
3086
|
continue;
|
|
2800
3087
|
}
|
|
@@ -3047,7 +3334,7 @@ var generateSelectSingle = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
3047
3334
|
args: queryArgs
|
|
3048
3335
|
};
|
|
3049
3336
|
};
|
|
3050
|
-
var generateInsertArray = (db, _tableName, table, baseType, fieldName) => {
|
|
3337
|
+
var generateInsertArray = (db, _tableName, table, baseType, fieldName, txCtx) => {
|
|
3051
3338
|
const queryArgs = {
|
|
3052
3339
|
values: {
|
|
3053
3340
|
type: new GraphQLNonNull4(new GraphQLList4(new GraphQLNonNull4(baseType)))
|
|
@@ -3055,14 +3342,16 @@ var generateInsertArray = (db, _tableName, table, baseType, fieldName) => {
|
|
|
3055
3342
|
};
|
|
3056
3343
|
return {
|
|
3057
3344
|
name: fieldName,
|
|
3058
|
-
resolver: async (_source, args, context,
|
|
3345
|
+
resolver: async (_source, args, context, info) => {
|
|
3059
3346
|
try {
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3347
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
3348
|
+
const input = remapFromGraphQLArrayInput(args.values, table);
|
|
3349
|
+
if (!input.length) {
|
|
3350
|
+
throw new GraphQLError5("No values were provided!");
|
|
3351
|
+
}
|
|
3352
|
+
await executor.insert(table).values(input);
|
|
3353
|
+
return { isSuccess: true };
|
|
3354
|
+
});
|
|
3066
3355
|
} catch (e) {
|
|
3067
3356
|
throw toGraphQLError(e);
|
|
3068
3357
|
}
|
|
@@ -3070,7 +3359,7 @@ var generateInsertArray = (db, _tableName, table, baseType, fieldName) => {
|
|
|
3070
3359
|
args: queryArgs
|
|
3071
3360
|
};
|
|
3072
3361
|
};
|
|
3073
|
-
var generateInsertSingle = (db, _tableName, table, baseType, fieldName) => {
|
|
3362
|
+
var generateInsertSingle = (db, _tableName, table, baseType, fieldName, txCtx) => {
|
|
3074
3363
|
const queryArgs = {
|
|
3075
3364
|
values: {
|
|
3076
3365
|
type: new GraphQLNonNull4(baseType)
|
|
@@ -3078,11 +3367,13 @@ var generateInsertSingle = (db, _tableName, table, baseType, fieldName) => {
|
|
|
3078
3367
|
};
|
|
3079
3368
|
return {
|
|
3080
3369
|
name: fieldName,
|
|
3081
|
-
resolver: async (_source, args, context,
|
|
3370
|
+
resolver: async (_source, args, context, info) => {
|
|
3082
3371
|
try {
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3372
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
3373
|
+
const input = remapFromGraphQLSingleInput(args.values, table);
|
|
3374
|
+
await executor.insert(table).values(input);
|
|
3375
|
+
return { isSuccess: true };
|
|
3376
|
+
});
|
|
3086
3377
|
} catch (e) {
|
|
3087
3378
|
throw toGraphQLError(e);
|
|
3088
3379
|
}
|
|
@@ -3090,7 +3381,7 @@ var generateInsertSingle = (db, _tableName, table, baseType, fieldName) => {
|
|
|
3090
3381
|
args: queryArgs
|
|
3091
3382
|
};
|
|
3092
3383
|
};
|
|
3093
|
-
var generateUpsert = (db, table, baseType, onConflictType, fieldName, single) => {
|
|
3384
|
+
var generateUpsert = (db, table, baseType, onConflictType, fieldName, single, txCtx) => {
|
|
3094
3385
|
const queryArgs = {
|
|
3095
3386
|
values: {
|
|
3096
3387
|
type: single ? new GraphQLNonNull4(baseType) : new GraphQLNonNull4(new GraphQLList4(new GraphQLNonNull4(baseType)))
|
|
@@ -3103,28 +3394,29 @@ var generateUpsert = (db, table, baseType, onConflictType, fieldName, single) =>
|
|
|
3103
3394
|
const pkNames = mysqlPrimaryKeyPropNames(table);
|
|
3104
3395
|
return {
|
|
3105
3396
|
name: fieldName,
|
|
3106
|
-
resolver: async (_source, args, context,
|
|
3397
|
+
resolver: async (_source, args, context, info) => {
|
|
3107
3398
|
try {
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3399
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
3400
|
+
const input = single ? [remapFromGraphQLSingleInput(args.values, table)] : remapFromGraphQLArrayInput(args.values, table);
|
|
3401
|
+
if (!input.length) {
|
|
3402
|
+
throw new GraphQLError5("No values were provided!");
|
|
3403
|
+
}
|
|
3404
|
+
const plan = resolveConflictPlan({
|
|
3405
|
+
table,
|
|
3406
|
+
values: input,
|
|
3407
|
+
onConflict: args.onConflict,
|
|
3408
|
+
pkNames,
|
|
3409
|
+
uniqueSets: [],
|
|
3410
|
+
excludedRef: mysqlValuesColumnRef,
|
|
3411
|
+
withTarget: false
|
|
3412
|
+
});
|
|
3413
|
+
if (plan.action === "NOTHING") {
|
|
3414
|
+
await executor.insert(table).ignore().values(input);
|
|
3415
|
+
} else {
|
|
3416
|
+
await executor.insert(table).values(input).onDuplicateKeyUpdate({ set: plan.set });
|
|
3417
|
+
}
|
|
3418
|
+
return { isSuccess: true };
|
|
3120
3419
|
});
|
|
3121
|
-
const executor = resolveExecutor(db, context);
|
|
3122
|
-
if (plan.action === "NOTHING") {
|
|
3123
|
-
await executor.insert(table).ignore().values(input);
|
|
3124
|
-
} else {
|
|
3125
|
-
await executor.insert(table).values(input).onDuplicateKeyUpdate({ set: plan.set });
|
|
3126
|
-
}
|
|
3127
|
-
return { isSuccess: true };
|
|
3128
3420
|
} catch (e) {
|
|
3129
3421
|
throw toGraphQLError(e);
|
|
3130
3422
|
}
|
|
@@ -3132,7 +3424,7 @@ var generateUpsert = (db, table, baseType, onConflictType, fieldName, single) =>
|
|
|
3132
3424
|
args: queryArgs
|
|
3133
3425
|
};
|
|
3134
3426
|
};
|
|
3135
|
-
var generateUpdate = (db, tableName, table, setArgs, filterArgs, fieldName, single, requireWhere, filterCtx) => {
|
|
3427
|
+
var generateUpdate = (db, tableName, table, setArgs, filterArgs, fieldName, single, requireWhere, filterCtx, txCtx) => {
|
|
3136
3428
|
const queryArgs = {
|
|
3137
3429
|
set: {
|
|
3138
3430
|
type: new GraphQLNonNull4(setArgs)
|
|
@@ -3143,25 +3435,26 @@ var generateUpdate = (db, tableName, table, setArgs, filterArgs, fieldName, sing
|
|
|
3143
3435
|
};
|
|
3144
3436
|
return {
|
|
3145
3437
|
name: fieldName,
|
|
3146
|
-
resolver: async (_source, args, context,
|
|
3438
|
+
resolver: async (_source, args, context, info) => {
|
|
3147
3439
|
try {
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3440
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
3441
|
+
const { where, set } = args;
|
|
3442
|
+
const input = remapFromGraphQLSingleInput(set, table);
|
|
3443
|
+
if (!Object.keys(input).length) {
|
|
3444
|
+
throw new GraphQLError5("Unable to update with no values specified!");
|
|
3445
|
+
}
|
|
3446
|
+
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
3447
|
+
const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
3448
|
+
if (single) {
|
|
3449
|
+
await assertSingleMatch(executor, table, filters, fieldName);
|
|
3450
|
+
}
|
|
3451
|
+
let query = executor.update(table).set(input);
|
|
3452
|
+
if (filters) {
|
|
3453
|
+
query = query.where(filters);
|
|
3454
|
+
}
|
|
3455
|
+
await query;
|
|
3456
|
+
return { isSuccess: true };
|
|
3457
|
+
});
|
|
3165
3458
|
} catch (e) {
|
|
3166
3459
|
throw toGraphQLError(e);
|
|
3167
3460
|
}
|
|
@@ -3169,7 +3462,7 @@ var generateUpdate = (db, tableName, table, setArgs, filterArgs, fieldName, sing
|
|
|
3169
3462
|
args: queryArgs
|
|
3170
3463
|
};
|
|
3171
3464
|
};
|
|
3172
|
-
var generateUpdateMany = (db, tableName, table, updateManyInput, fieldName, filterCtx) => {
|
|
3465
|
+
var generateUpdateMany = (db, tableName, table, updateManyInput, fieldName, filterCtx, txCtx) => {
|
|
3173
3466
|
const queryArgs = {
|
|
3174
3467
|
updates: {
|
|
3175
3468
|
type: new GraphQLNonNull4(new GraphQLList4(new GraphQLNonNull4(updateManyInput)))
|
|
@@ -3177,33 +3470,34 @@ var generateUpdateMany = (db, tableName, table, updateManyInput, fieldName, filt
|
|
|
3177
3470
|
};
|
|
3178
3471
|
return {
|
|
3179
3472
|
name: fieldName,
|
|
3180
|
-
resolver: async (_source, args, context,
|
|
3473
|
+
resolver: async (_source, args, context, info) => {
|
|
3181
3474
|
try {
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
const entries = updates.map(({ where, set }) => {
|
|
3187
|
-
const input = remapFromGraphQLSingleInput(set, table);
|
|
3188
|
-
if (!Object.keys(input).length) {
|
|
3189
|
-
throw new GraphQLError5("Unable to update with no values specified!");
|
|
3475
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
3476
|
+
const { updates } = args;
|
|
3477
|
+
if (!updates.length) {
|
|
3478
|
+
throw new GraphQLError5("No updates were provided!");
|
|
3190
3479
|
}
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
});
|
|
3196
|
-
const executor = resolveExecutor(db, context);
|
|
3197
|
-
await executor.transaction(async (tx) => {
|
|
3198
|
-
for (const entry of entries) {
|
|
3199
|
-
let query = tx.update(table).set(entry.set);
|
|
3200
|
-
if (entry.filters) {
|
|
3201
|
-
query = query.where(entry.filters);
|
|
3480
|
+
const entries = updates.map(({ where, set }) => {
|
|
3481
|
+
const input = remapFromGraphQLSingleInput(set, table);
|
|
3482
|
+
if (!Object.keys(input).length) {
|
|
3483
|
+
throw new GraphQLError5("Unable to update with no values specified!");
|
|
3202
3484
|
}
|
|
3203
|
-
|
|
3204
|
-
|
|
3485
|
+
return {
|
|
3486
|
+
set: input,
|
|
3487
|
+
filters: where ? extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName)) : void 0
|
|
3488
|
+
};
|
|
3489
|
+
});
|
|
3490
|
+
await executor.transaction(async (tx) => {
|
|
3491
|
+
for (const entry of entries) {
|
|
3492
|
+
let query = tx.update(table).set(entry.set);
|
|
3493
|
+
if (entry.filters) {
|
|
3494
|
+
query = query.where(entry.filters);
|
|
3495
|
+
}
|
|
3496
|
+
await query;
|
|
3497
|
+
}
|
|
3498
|
+
});
|
|
3499
|
+
return { isSuccess: true };
|
|
3205
3500
|
});
|
|
3206
|
-
return { isSuccess: true };
|
|
3207
3501
|
} catch (e) {
|
|
3208
3502
|
throw toGraphQLError(e);
|
|
3209
3503
|
}
|
|
@@ -3211,7 +3505,7 @@ var generateUpdateMany = (db, tableName, table, updateManyInput, fieldName, filt
|
|
|
3211
3505
|
args: queryArgs
|
|
3212
3506
|
};
|
|
3213
3507
|
};
|
|
3214
|
-
var generateDelete = (db, tableName, table, filterArgs, fieldName, single, requireWhere, filterCtx) => {
|
|
3508
|
+
var generateDelete = (db, tableName, table, filterArgs, fieldName, single, requireWhere, filterCtx, txCtx) => {
|
|
3215
3509
|
const queryArgs = {
|
|
3216
3510
|
where: {
|
|
3217
3511
|
type: single || requireWhere ? new GraphQLNonNull4(filterArgs) : filterArgs
|
|
@@ -3219,21 +3513,22 @@ var generateDelete = (db, tableName, table, filterArgs, fieldName, single, requi
|
|
|
3219
3513
|
};
|
|
3220
3514
|
return {
|
|
3221
3515
|
name: fieldName,
|
|
3222
|
-
resolver: async (_source, args, context,
|
|
3516
|
+
resolver: async (_source, args, context, info) => {
|
|
3223
3517
|
try {
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3518
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
3519
|
+
const { where } = args;
|
|
3520
|
+
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
3521
|
+
const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
3522
|
+
if (single) {
|
|
3523
|
+
await assertSingleMatch(executor, table, filters, fieldName);
|
|
3524
|
+
}
|
|
3525
|
+
let query = executor.delete(table);
|
|
3526
|
+
if (filters) {
|
|
3527
|
+
query = query.where(filters);
|
|
3528
|
+
}
|
|
3529
|
+
await query;
|
|
3530
|
+
return { isSuccess: true };
|
|
3531
|
+
});
|
|
3237
3532
|
} catch (e) {
|
|
3238
3533
|
throw toGraphQLError(e);
|
|
3239
3534
|
}
|
|
@@ -3253,6 +3548,7 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3253
3548
|
"Drizzle-GraphQL Error: No tables detected in Drizzle-ORM's database instance. Did you forget to pass schema to drizzle constructor?"
|
|
3254
3549
|
);
|
|
3255
3550
|
}
|
|
3551
|
+
registerScalarOverrides(tables, options);
|
|
3256
3552
|
const namedRelations = buildNamedRelations(relations ?? {}, tableEntries);
|
|
3257
3553
|
attachTargetPrimaryKeys(namedRelations, tables, mysqlPrimaryKeyPropNames);
|
|
3258
3554
|
const eagerRelations = pruneNonEagerRelations(namedRelations, shouldEagerLoad);
|
|
@@ -3264,6 +3560,8 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3264
3560
|
relationFieldContainers: /* @__PURE__ */ new Map(),
|
|
3265
3561
|
fullyBuiltTables: /* @__PURE__ */ new Set(),
|
|
3266
3562
|
relationTypeCache: /* @__PURE__ */ new Map(),
|
|
3563
|
+
selectFieldCache: /* @__PURE__ */ new WeakMap(),
|
|
3564
|
+
filterFieldCache: /* @__PURE__ */ new WeakMap(),
|
|
3267
3565
|
orderTypeCache: /* @__PURE__ */ new WeakMap(),
|
|
3268
3566
|
filterTypeCache: /* @__PURE__ */ new WeakMap(),
|
|
3269
3567
|
listRelationFilterCache: /* @__PURE__ */ new Map(),
|
|
@@ -3273,6 +3571,7 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3273
3571
|
const relationAggregateFactory = features.relationAggregates ? createRelationAggregateFactory(db, tables, cacheCtx, typeNameMapper, filterCtx) : void 0;
|
|
3274
3572
|
const queries = {};
|
|
3275
3573
|
const mutations = {};
|
|
3574
|
+
const mutationTxCtx = createMutationTxCtx(options.transactions);
|
|
3276
3575
|
const gqlSchemaTypes = Object.fromEntries(
|
|
3277
3576
|
Object.entries(tables).map(([tableName, _table]) => [
|
|
3278
3577
|
tableName,
|
|
@@ -3348,8 +3647,22 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3348
3647
|
typeNameMapper,
|
|
3349
3648
|
filterCtx
|
|
3350
3649
|
);
|
|
3351
|
-
const insertArrGenerated = features.insert ? generateInsertArray(
|
|
3352
|
-
|
|
3650
|
+
const insertArrGenerated = features.insert ? generateInsertArray(
|
|
3651
|
+
db,
|
|
3652
|
+
tableName,
|
|
3653
|
+
schema[tableName],
|
|
3654
|
+
insertInput,
|
|
3655
|
+
createArrayFieldName,
|
|
3656
|
+
mutationTxCtx
|
|
3657
|
+
) : void 0;
|
|
3658
|
+
const insertSingleGenerated = features.insert ? generateInsertSingle(
|
|
3659
|
+
db,
|
|
3660
|
+
tableName,
|
|
3661
|
+
schema[tableName],
|
|
3662
|
+
insertInput,
|
|
3663
|
+
createSingleFieldName,
|
|
3664
|
+
mutationTxCtx
|
|
3665
|
+
) : void 0;
|
|
3353
3666
|
const onConflictInput = features.upsert ? generateOnConflictInput({
|
|
3354
3667
|
table: schema[tableName],
|
|
3355
3668
|
typeName,
|
|
@@ -3357,8 +3670,24 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3357
3670
|
tableFilters,
|
|
3358
3671
|
withTarget: false
|
|
3359
3672
|
}) : void 0;
|
|
3360
|
-
const upsertArrGenerated = onConflictInput ? generateUpsert(
|
|
3361
|
-
|
|
3673
|
+
const upsertArrGenerated = onConflictInput ? generateUpsert(
|
|
3674
|
+
db,
|
|
3675
|
+
schema[tableName],
|
|
3676
|
+
insertInput,
|
|
3677
|
+
onConflictInput,
|
|
3678
|
+
upsertArrayFieldName,
|
|
3679
|
+
false,
|
|
3680
|
+
mutationTxCtx
|
|
3681
|
+
) : void 0;
|
|
3682
|
+
const upsertSingleGenerated = onConflictInput ? generateUpsert(
|
|
3683
|
+
db,
|
|
3684
|
+
schema[tableName],
|
|
3685
|
+
insertInput,
|
|
3686
|
+
onConflictInput,
|
|
3687
|
+
upsertSingleFieldName,
|
|
3688
|
+
true,
|
|
3689
|
+
mutationTxCtx
|
|
3690
|
+
) : void 0;
|
|
3362
3691
|
const updateGenerated = features.update ? generateUpdate(
|
|
3363
3692
|
db,
|
|
3364
3693
|
tableName,
|
|
@@ -3368,7 +3697,8 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3368
3697
|
updateFieldName,
|
|
3369
3698
|
false,
|
|
3370
3699
|
features.requireWhere,
|
|
3371
|
-
filterCtx
|
|
3700
|
+
filterCtx,
|
|
3701
|
+
mutationTxCtx
|
|
3372
3702
|
) : void 0;
|
|
3373
3703
|
const updateSingleGenerated = features.update ? generateUpdate(
|
|
3374
3704
|
db,
|
|
@@ -3379,7 +3709,8 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3379
3709
|
updateSingleFieldName,
|
|
3380
3710
|
true,
|
|
3381
3711
|
features.requireWhere,
|
|
3382
|
-
filterCtx
|
|
3712
|
+
filterCtx,
|
|
3713
|
+
mutationTxCtx
|
|
3383
3714
|
) : void 0;
|
|
3384
3715
|
const updateManyInput = features.update && features.updateMany ? generateUpdateManyInput({ typeName, updatePrefix: prefixes.update, updateInput, tableFilters }) : void 0;
|
|
3385
3716
|
const updateManyGenerated = updateManyInput ? generateUpdateMany(
|
|
@@ -3388,7 +3719,8 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3388
3719
|
schema[tableName],
|
|
3389
3720
|
updateManyInput,
|
|
3390
3721
|
updateManyFieldName,
|
|
3391
|
-
filterCtx
|
|
3722
|
+
filterCtx,
|
|
3723
|
+
mutationTxCtx
|
|
3392
3724
|
) : void 0;
|
|
3393
3725
|
const deleteGenerated = features.delete ? generateDelete(
|
|
3394
3726
|
db,
|
|
@@ -3398,7 +3730,8 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3398
3730
|
deleteFieldName,
|
|
3399
3731
|
false,
|
|
3400
3732
|
features.requireWhere,
|
|
3401
|
-
filterCtx
|
|
3733
|
+
filterCtx,
|
|
3734
|
+
mutationTxCtx
|
|
3402
3735
|
) : void 0;
|
|
3403
3736
|
const deleteSingleGenerated = features.delete ? generateDelete(
|
|
3404
3737
|
db,
|
|
@@ -3408,7 +3741,8 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3408
3741
|
deleteSingleFieldName,
|
|
3409
3742
|
true,
|
|
3410
3743
|
features.requireWhere,
|
|
3411
|
-
filterCtx
|
|
3744
|
+
filterCtx,
|
|
3745
|
+
mutationTxCtx
|
|
3412
3746
|
) : void 0;
|
|
3413
3747
|
const aggregateType = features.aggregates ? generateAggregateTypes(schema[tableName], tableName, typeName, cacheCtx) : void 0;
|
|
3414
3748
|
const aggregateGenerated = features.aggregates ? generateAggregate(
|
|
@@ -3501,6 +3835,11 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3501
3835
|
inputs[havingInput.name] = havingInput;
|
|
3502
3836
|
}
|
|
3503
3837
|
}
|
|
3838
|
+
if (mutationTxCtx) {
|
|
3839
|
+
for (const name of Object.keys(mutations)) {
|
|
3840
|
+
mutationTxCtx.fieldNames.add(name);
|
|
3841
|
+
}
|
|
3842
|
+
}
|
|
3504
3843
|
const fieldResolvers = {};
|
|
3505
3844
|
for (const [tableName, tableRelations] of Object.entries(namedRelations)) {
|
|
3506
3845
|
const relResolvers = {};
|
|
@@ -3708,7 +4047,7 @@ var generateSelectSingle2 = (db, tableName, tables, relationMap, orderArgs, filt
|
|
|
3708
4047
|
};
|
|
3709
4048
|
};
|
|
3710
4049
|
var pgPrimaryKeyPropNames = (table) => getPrimaryKeyPropNamesFromConfig(table, getTableConfig2);
|
|
3711
|
-
var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false) => {
|
|
4050
|
+
var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx) => {
|
|
3712
4051
|
const queryArgs = {
|
|
3713
4052
|
values: {
|
|
3714
4053
|
type: new GraphQLNonNull5(new GraphQLList5(new GraphQLNonNull5(baseType)))
|
|
@@ -3719,31 +4058,32 @@ var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
3719
4058
|
name: fieldName,
|
|
3720
4059
|
resolver: async (_source, args, context, info) => {
|
|
3721
4060
|
try {
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
4061
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4062
|
+
const input = remapFromGraphQLArrayInput(args.values, table);
|
|
4063
|
+
if (!input.length) {
|
|
4064
|
+
throw new GraphQLError6("No values were provided!");
|
|
4065
|
+
}
|
|
4066
|
+
const parsedInfo = parseResolveInfo3(info, {
|
|
4067
|
+
deep: true
|
|
4068
|
+
});
|
|
4069
|
+
const { columns, hasRelations, withParams } = prepareMutationRelationColumns({
|
|
4070
|
+
relationMap,
|
|
4071
|
+
tables,
|
|
4072
|
+
tableName,
|
|
4073
|
+
typeName,
|
|
4074
|
+
typeNameMapper,
|
|
4075
|
+
table,
|
|
4076
|
+
pkNames,
|
|
4077
|
+
parsedInfo
|
|
4078
|
+
});
|
|
4079
|
+
let query = executor.insert(table).values(input).returning(columns);
|
|
4080
|
+
if (conflictDoNothing) {
|
|
4081
|
+
query = query.onConflictDoNothing();
|
|
4082
|
+
}
|
|
4083
|
+
const result = await query;
|
|
4084
|
+
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
4085
|
+
return remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
|
|
3738
4086
|
});
|
|
3739
|
-
const executor = resolveExecutor(db, context);
|
|
3740
|
-
let query = executor.insert(table).values(input).returning(columns);
|
|
3741
|
-
if (conflictDoNothing) {
|
|
3742
|
-
query = query.onConflictDoNothing();
|
|
3743
|
-
}
|
|
3744
|
-
const result = await query;
|
|
3745
|
-
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
3746
|
-
return remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
|
|
3747
4087
|
} catch (e) {
|
|
3748
4088
|
throw toGraphQLError(e);
|
|
3749
4089
|
}
|
|
@@ -3751,7 +4091,7 @@ var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
3751
4091
|
args: queryArgs
|
|
3752
4092
|
};
|
|
3753
4093
|
};
|
|
3754
|
-
var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false) => {
|
|
4094
|
+
var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx) => {
|
|
3755
4095
|
const queryArgs = {
|
|
3756
4096
|
values: {
|
|
3757
4097
|
type: new GraphQLNonNull5(baseType)
|
|
@@ -3762,31 +4102,32 @@ var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType
|
|
|
3762
4102
|
name: fieldName,
|
|
3763
4103
|
resolver: async (_source, args, context, info) => {
|
|
3764
4104
|
try {
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
4105
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4106
|
+
const input = remapFromGraphQLSingleInput(args.values, table);
|
|
4107
|
+
const parsedInfo = parseResolveInfo3(info, {
|
|
4108
|
+
deep: true
|
|
4109
|
+
});
|
|
4110
|
+
const { columns, hasRelations, withParams } = prepareMutationRelationColumns({
|
|
4111
|
+
relationMap,
|
|
4112
|
+
tables,
|
|
4113
|
+
tableName,
|
|
4114
|
+
typeName,
|
|
4115
|
+
typeNameMapper,
|
|
4116
|
+
table,
|
|
4117
|
+
pkNames,
|
|
4118
|
+
parsedInfo
|
|
4119
|
+
});
|
|
4120
|
+
let query = executor.insert(table).values(input).returning(columns);
|
|
4121
|
+
if (conflictDoNothing) {
|
|
4122
|
+
query = query.onConflictDoNothing();
|
|
4123
|
+
}
|
|
4124
|
+
const result = await query;
|
|
4125
|
+
if (!result[0]) {
|
|
4126
|
+
return void 0;
|
|
4127
|
+
}
|
|
4128
|
+
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
4129
|
+
return remapToGraphQLSingleOutput(enriched[0], tableName, table, relationMap);
|
|
3778
4130
|
});
|
|
3779
|
-
const executor = resolveExecutor(db, context);
|
|
3780
|
-
let query = executor.insert(table).values(input).returning(columns);
|
|
3781
|
-
if (conflictDoNothing) {
|
|
3782
|
-
query = query.onConflictDoNothing();
|
|
3783
|
-
}
|
|
3784
|
-
const result = await query;
|
|
3785
|
-
if (!result[0]) {
|
|
3786
|
-
return void 0;
|
|
3787
|
-
}
|
|
3788
|
-
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
3789
|
-
return remapToGraphQLSingleOutput(enriched[0], tableName, table, relationMap);
|
|
3790
4131
|
} catch (e) {
|
|
3791
4132
|
throw toGraphQLError(e);
|
|
3792
4133
|
}
|
|
@@ -3794,7 +4135,7 @@ var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType
|
|
|
3794
4135
|
args: queryArgs
|
|
3795
4136
|
};
|
|
3796
4137
|
};
|
|
3797
|
-
var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx) => {
|
|
4138
|
+
var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx, txCtx) => {
|
|
3798
4139
|
const queryArgs = {
|
|
3799
4140
|
values: {
|
|
3800
4141
|
type: single ? new GraphQLNonNull5(baseType) : new GraphQLNonNull5(new GraphQLList5(new GraphQLNonNull5(baseType)))
|
|
@@ -3809,40 +4150,41 @@ var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
3809
4150
|
name: fieldName,
|
|
3810
4151
|
resolver: async (_source, args, context, info) => {
|
|
3811
4152
|
try {
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
4153
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4154
|
+
const input = single ? [remapFromGraphQLSingleInput(args.values, table)] : remapFromGraphQLArrayInput(args.values, table);
|
|
4155
|
+
if (!input.length) {
|
|
4156
|
+
throw new GraphQLError6("No values were provided!");
|
|
4157
|
+
}
|
|
4158
|
+
const parsedInfo = parseResolveInfo3(info, { deep: true });
|
|
4159
|
+
const { columns, hasRelations, withParams } = prepareMutationRelationColumns({
|
|
4160
|
+
relationMap,
|
|
4161
|
+
tables,
|
|
4162
|
+
tableName,
|
|
4163
|
+
typeName,
|
|
4164
|
+
typeNameMapper,
|
|
4165
|
+
table,
|
|
4166
|
+
pkNames,
|
|
4167
|
+
parsedInfo
|
|
4168
|
+
});
|
|
4169
|
+
const plan = resolveConflictPlan({
|
|
4170
|
+
table,
|
|
4171
|
+
values: input,
|
|
4172
|
+
onConflict: args.onConflict,
|
|
4173
|
+
pkNames,
|
|
4174
|
+
uniqueSets,
|
|
4175
|
+
excludedRef: excludedColumnRef,
|
|
4176
|
+
withTarget: true,
|
|
4177
|
+
buildWhere: (where) => extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName))
|
|
4178
|
+
});
|
|
4179
|
+
let query = executor.insert(table).values(input).returning(columns);
|
|
4180
|
+
query = plan.action === "NOTHING" ? query.onConflictDoNothing(plan.target ? { target: plan.target } : void 0) : query.onConflictDoUpdate({ target: plan.target, set: plan.set, setWhere: plan.setWhere });
|
|
4181
|
+
const result = await query;
|
|
4182
|
+
if (single && !result[0]) {
|
|
4183
|
+
return void 0;
|
|
4184
|
+
}
|
|
4185
|
+
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
4186
|
+
return single ? remapToGraphQLSingleOutput(enriched[0], tableName, table, relationMap) : remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
|
|
3836
4187
|
});
|
|
3837
|
-
const executor = resolveExecutor(db, context);
|
|
3838
|
-
let query = executor.insert(table).values(input).returning(columns);
|
|
3839
|
-
query = plan.action === "NOTHING" ? query.onConflictDoNothing(plan.target ? { target: plan.target } : void 0) : query.onConflictDoUpdate({ target: plan.target, set: plan.set, setWhere: plan.setWhere });
|
|
3840
|
-
const result = await query;
|
|
3841
|
-
if (single && !result[0]) {
|
|
3842
|
-
return void 0;
|
|
3843
|
-
}
|
|
3844
|
-
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
3845
|
-
return single ? remapToGraphQLSingleOutput(enriched[0], tableName, table, relationMap) : remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
|
|
3846
4188
|
} catch (e) {
|
|
3847
4189
|
throw toGraphQLError(e);
|
|
3848
4190
|
}
|
|
@@ -3850,7 +4192,7 @@ var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
3850
4192
|
args: queryArgs
|
|
3851
4193
|
};
|
|
3852
4194
|
};
|
|
3853
|
-
var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx) => {
|
|
4195
|
+
var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx, txCtx) => {
|
|
3854
4196
|
const queryArgs = {
|
|
3855
4197
|
set: {
|
|
3856
4198
|
type: new GraphQLNonNull5(setArgs)
|
|
@@ -3861,47 +4203,48 @@ var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
3861
4203
|
};
|
|
3862
4204
|
const pkNames = pgPrimaryKeyPropNames(table);
|
|
3863
4205
|
return {
|
|
3864
|
-
name: fieldName,
|
|
3865
|
-
resolver: async (_source, args, context, info) => {
|
|
3866
|
-
try {
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
|
|
3878
|
-
|
|
3879
|
-
|
|
4206
|
+
name: fieldName,
|
|
4207
|
+
resolver: async (_source, args, context, info) => {
|
|
4208
|
+
try {
|
|
4209
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4210
|
+
const { where, set } = args;
|
|
4211
|
+
const parsedInfo = parseResolveInfo3(info, {
|
|
4212
|
+
deep: true
|
|
4213
|
+
});
|
|
4214
|
+
const { columns, hasRelations, withParams } = prepareMutationRelationColumns({
|
|
4215
|
+
relationMap,
|
|
4216
|
+
tables,
|
|
4217
|
+
tableName,
|
|
4218
|
+
typeName,
|
|
4219
|
+
typeNameMapper,
|
|
4220
|
+
table,
|
|
4221
|
+
pkNames,
|
|
4222
|
+
parsedInfo
|
|
4223
|
+
});
|
|
4224
|
+
const input = remapFromGraphQLSingleInput(set, table);
|
|
4225
|
+
if (!Object.keys(input).length) {
|
|
4226
|
+
throw new GraphQLError6("Unable to update with no values specified!");
|
|
4227
|
+
}
|
|
4228
|
+
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
4229
|
+
const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
4230
|
+
if (single) {
|
|
4231
|
+
await assertSingleMatch(executor, table, filters, fieldName);
|
|
4232
|
+
}
|
|
4233
|
+
let query = executor.update(table).set(input);
|
|
4234
|
+
if (filters) {
|
|
4235
|
+
query = query.where(filters);
|
|
4236
|
+
}
|
|
4237
|
+
query = query.returning(columns);
|
|
4238
|
+
const result = await query;
|
|
4239
|
+
if (single && result.length > 1) {
|
|
4240
|
+
throw new GraphQLError6(`${fieldName}: 'where' matched more than one row!`);
|
|
4241
|
+
}
|
|
4242
|
+
if (single && !result[0]) {
|
|
4243
|
+
return void 0;
|
|
4244
|
+
}
|
|
4245
|
+
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
4246
|
+
return single ? remapToGraphQLSingleOutput(enriched[0], tableName, table, relationMap) : remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
|
|
3880
4247
|
});
|
|
3881
|
-
const input = remapFromGraphQLSingleInput(set, table);
|
|
3882
|
-
if (!Object.keys(input).length) {
|
|
3883
|
-
throw new GraphQLError6("Unable to update with no values specified!");
|
|
3884
|
-
}
|
|
3885
|
-
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
3886
|
-
const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
3887
|
-
const executor = resolveExecutor(db, context);
|
|
3888
|
-
if (single) {
|
|
3889
|
-
await assertSingleMatch(executor, table, filters, fieldName);
|
|
3890
|
-
}
|
|
3891
|
-
let query = executor.update(table).set(input);
|
|
3892
|
-
if (filters) {
|
|
3893
|
-
query = query.where(filters);
|
|
3894
|
-
}
|
|
3895
|
-
query = query.returning(columns);
|
|
3896
|
-
const result = await query;
|
|
3897
|
-
if (single && result.length > 1) {
|
|
3898
|
-
throw new GraphQLError6(`${fieldName}: 'where' matched more than one row!`);
|
|
3899
|
-
}
|
|
3900
|
-
if (single && !result[0]) {
|
|
3901
|
-
return void 0;
|
|
3902
|
-
}
|
|
3903
|
-
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
3904
|
-
return single ? remapToGraphQLSingleOutput(enriched[0], tableName, table, relationMap) : remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
|
|
3905
4248
|
} catch (e) {
|
|
3906
4249
|
throw toGraphQLError(e);
|
|
3907
4250
|
}
|
|
@@ -3909,7 +4252,7 @@ var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
3909
4252
|
args: queryArgs
|
|
3910
4253
|
};
|
|
3911
4254
|
};
|
|
3912
|
-
var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx) => {
|
|
4255
|
+
var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx, txCtx) => {
|
|
3913
4256
|
const queryArgs = {
|
|
3914
4257
|
updates: {
|
|
3915
4258
|
type: new GraphQLNonNull5(new GraphQLList5(new GraphQLNonNull5(updateManyInput)))
|
|
@@ -3920,60 +4263,61 @@ var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
3920
4263
|
name: fieldName,
|
|
3921
4264
|
resolver: async (_source, args, context, info) => {
|
|
3922
4265
|
try {
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
const parsedInfo = parseResolveInfo3(info, {
|
|
3928
|
-
deep: true
|
|
3929
|
-
});
|
|
3930
|
-
const { columns, hasRelations, withParams } = prepareMutationRelationColumns({
|
|
3931
|
-
relationMap,
|
|
3932
|
-
tables,
|
|
3933
|
-
tableName,
|
|
3934
|
-
typeName,
|
|
3935
|
-
typeNameMapper,
|
|
3936
|
-
table,
|
|
3937
|
-
pkNames,
|
|
3938
|
-
parsedInfo
|
|
3939
|
-
});
|
|
3940
|
-
const entries = updates.map(({ where, set }) => {
|
|
3941
|
-
const input = remapFromGraphQLSingleInput(set, table);
|
|
3942
|
-
if (!Object.keys(input).length) {
|
|
3943
|
-
throw new GraphQLError6("Unable to update with no values specified!");
|
|
4266
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4267
|
+
const { updates } = args;
|
|
4268
|
+
if (!updates.length) {
|
|
4269
|
+
throw new GraphQLError6("No updates were provided!");
|
|
3944
4270
|
}
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
}
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
4271
|
+
const parsedInfo = parseResolveInfo3(info, {
|
|
4272
|
+
deep: true
|
|
4273
|
+
});
|
|
4274
|
+
const { columns, hasRelations, withParams } = prepareMutationRelationColumns({
|
|
4275
|
+
relationMap,
|
|
4276
|
+
tables,
|
|
4277
|
+
tableName,
|
|
4278
|
+
typeName,
|
|
4279
|
+
typeNameMapper,
|
|
4280
|
+
table,
|
|
4281
|
+
pkNames,
|
|
4282
|
+
parsedInfo
|
|
4283
|
+
});
|
|
4284
|
+
const entries = updates.map(({ where, set }) => {
|
|
4285
|
+
const input = remapFromGraphQLSingleInput(set, table);
|
|
4286
|
+
if (!Object.keys(input).length) {
|
|
4287
|
+
throw new GraphQLError6("Unable to update with no values specified!");
|
|
4288
|
+
}
|
|
4289
|
+
return {
|
|
4290
|
+
set: input,
|
|
4291
|
+
filters: where ? extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName)) : void 0
|
|
4292
|
+
};
|
|
4293
|
+
});
|
|
4294
|
+
const perEntry = await executor.transaction(async (tx) => {
|
|
4295
|
+
const results = [];
|
|
4296
|
+
for (const entry of entries) {
|
|
4297
|
+
let query = tx.update(table).set(entry.set);
|
|
4298
|
+
if (entry.filters) {
|
|
4299
|
+
query = query.where(entry.filters);
|
|
4300
|
+
}
|
|
4301
|
+
results.push(await query.returning(columns));
|
|
4302
|
+
}
|
|
4303
|
+
return results;
|
|
4304
|
+
});
|
|
4305
|
+
const flatRows = perEntry.flat();
|
|
4306
|
+
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, flatRows, pkNames, withParams) : flatRows;
|
|
4307
|
+
const output = [];
|
|
4308
|
+
let offset = 0;
|
|
4309
|
+
for (const rows of perEntry) {
|
|
4310
|
+
if (!rows.length) {
|
|
4311
|
+
output.push(null);
|
|
4312
|
+
continue;
|
|
4313
|
+
}
|
|
4314
|
+
for (let i = 0; i < rows.length; i++) {
|
|
4315
|
+
output.push(remapToGraphQLSingleOutput(enriched[offset + i], tableName, table, relationMap));
|
|
3957
4316
|
}
|
|
3958
|
-
|
|
4317
|
+
offset += rows.length;
|
|
3959
4318
|
}
|
|
3960
|
-
return
|
|
4319
|
+
return output;
|
|
3961
4320
|
});
|
|
3962
|
-
const flatRows = perEntry.flat();
|
|
3963
|
-
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, flatRows, pkNames, withParams) : flatRows;
|
|
3964
|
-
const output = [];
|
|
3965
|
-
let offset = 0;
|
|
3966
|
-
for (const rows of perEntry) {
|
|
3967
|
-
if (!rows.length) {
|
|
3968
|
-
output.push(null);
|
|
3969
|
-
continue;
|
|
3970
|
-
}
|
|
3971
|
-
for (let i = 0; i < rows.length; i++) {
|
|
3972
|
-
output.push(remapToGraphQLSingleOutput(enriched[offset + i], tableName, table, relationMap));
|
|
3973
|
-
}
|
|
3974
|
-
offset += rows.length;
|
|
3975
|
-
}
|
|
3976
|
-
return output;
|
|
3977
4321
|
} catch (e) {
|
|
3978
4322
|
throw toGraphQLError(e);
|
|
3979
4323
|
}
|
|
@@ -3981,7 +4325,7 @@ var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
3981
4325
|
args: queryArgs
|
|
3982
4326
|
};
|
|
3983
4327
|
};
|
|
3984
|
-
var generateDelete2 = (db, tableName, table, filterArgs, fieldName, typeName, single, requireWhere, filterCtx, selectionCtx) => {
|
|
4328
|
+
var generateDelete2 = (db, tableName, table, filterArgs, fieldName, typeName, single, requireWhere, filterCtx, selectionCtx, txCtx) => {
|
|
3985
4329
|
const queryArgs = {
|
|
3986
4330
|
where: {
|
|
3987
4331
|
type: single || requireWhere ? new GraphQLNonNull5(filterArgs) : filterArgs
|
|
@@ -3991,34 +4335,35 @@ var generateDelete2 = (db, tableName, table, filterArgs, fieldName, typeName, si
|
|
|
3991
4335
|
name: fieldName,
|
|
3992
4336
|
resolver: async (_source, args, context, info) => {
|
|
3993
4337
|
try {
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
4338
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4339
|
+
const { where } = args;
|
|
4340
|
+
const parsedInfo = parseResolveInfo3(info, {
|
|
4341
|
+
deep: true
|
|
4342
|
+
});
|
|
4343
|
+
const columns = extractSelectedColumnsFromTreeSQLFormat(
|
|
4344
|
+
parsedInfo.fieldsByTypeName[typeName],
|
|
4345
|
+
table,
|
|
4346
|
+
selectionCtx
|
|
4347
|
+
);
|
|
4348
|
+
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
4349
|
+
const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
4350
|
+
if (single) {
|
|
4351
|
+
await assertSingleMatch(executor, table, filters, fieldName);
|
|
4352
|
+
}
|
|
4353
|
+
let query = executor.delete(table);
|
|
4354
|
+
if (filters) {
|
|
4355
|
+
query = query.where(filters);
|
|
4356
|
+
}
|
|
4357
|
+
query = query.returning(columns);
|
|
4358
|
+
const result = await query;
|
|
4359
|
+
if (single && result.length > 1) {
|
|
4360
|
+
throw new GraphQLError6(`${fieldName}: 'where' matched more than one row!`);
|
|
4361
|
+
}
|
|
4362
|
+
if (single) {
|
|
4363
|
+
return result[0] ? remapToGraphQLSingleOutput(result[0], tableName, table) : void 0;
|
|
4364
|
+
}
|
|
4365
|
+
return remapToGraphQLArrayOutput(result, tableName, table);
|
|
3997
4366
|
});
|
|
3998
|
-
const columns = extractSelectedColumnsFromTreeSQLFormat(
|
|
3999
|
-
parsedInfo.fieldsByTypeName[typeName],
|
|
4000
|
-
table,
|
|
4001
|
-
selectionCtx
|
|
4002
|
-
);
|
|
4003
|
-
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
4004
|
-
const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
4005
|
-
const executor = resolveExecutor(db, context);
|
|
4006
|
-
if (single) {
|
|
4007
|
-
await assertSingleMatch(executor, table, filters, fieldName);
|
|
4008
|
-
}
|
|
4009
|
-
let query = executor.delete(table);
|
|
4010
|
-
if (filters) {
|
|
4011
|
-
query = query.where(filters);
|
|
4012
|
-
}
|
|
4013
|
-
query = query.returning(columns);
|
|
4014
|
-
const result = await query;
|
|
4015
|
-
if (single && result.length > 1) {
|
|
4016
|
-
throw new GraphQLError6(`${fieldName}: 'where' matched more than one row!`);
|
|
4017
|
-
}
|
|
4018
|
-
if (single) {
|
|
4019
|
-
return result[0] ? remapToGraphQLSingleOutput(result[0], tableName, table) : void 0;
|
|
4020
|
-
}
|
|
4021
|
-
return remapToGraphQLArrayOutput(result, tableName, table);
|
|
4022
4367
|
} catch (e) {
|
|
4023
4368
|
throw toGraphQLError(e);
|
|
4024
4369
|
}
|
|
@@ -4045,6 +4390,7 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4045
4390
|
"Drizzle-GraphQL Error: No tables detected in Drizzle-ORM's database instance. Did you forget to pass schema to drizzle constructor?"
|
|
4046
4391
|
);
|
|
4047
4392
|
}
|
|
4393
|
+
registerScalarOverrides(tables, options);
|
|
4048
4394
|
const namedRelations = buildNamedRelations(relations ?? {}, tableEntries);
|
|
4049
4395
|
attachTargetPrimaryKeys(namedRelations, tables, pgPrimaryKeyPropNames);
|
|
4050
4396
|
const eagerRelations = pruneNonEagerRelations(namedRelations, shouldEagerLoad);
|
|
@@ -4056,6 +4402,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4056
4402
|
relationFieldContainers: /* @__PURE__ */ new Map(),
|
|
4057
4403
|
fullyBuiltTables: /* @__PURE__ */ new Set(),
|
|
4058
4404
|
relationTypeCache: /* @__PURE__ */ new Map(),
|
|
4405
|
+
selectFieldCache: /* @__PURE__ */ new WeakMap(),
|
|
4406
|
+
filterFieldCache: /* @__PURE__ */ new WeakMap(),
|
|
4059
4407
|
orderTypeCache: /* @__PURE__ */ new WeakMap(),
|
|
4060
4408
|
filterTypeCache: /* @__PURE__ */ new WeakMap(),
|
|
4061
4409
|
listRelationFilterCache: /* @__PURE__ */ new Map(),
|
|
@@ -4065,6 +4413,7 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4065
4413
|
const relationAggregateFactory = features.relationAggregates ? createRelationAggregateFactory(db, tables, cacheCtx, typeNameMapper, filterCtx) : void 0;
|
|
4066
4414
|
const queries = {};
|
|
4067
4415
|
const mutations = {};
|
|
4416
|
+
const mutationTxCtx = createMutationTxCtx(options.transactions);
|
|
4068
4417
|
const gqlSchemaTypes = Object.fromEntries(
|
|
4069
4418
|
Object.entries(tables).map(([tableName, _table]) => [
|
|
4070
4419
|
tableName,
|
|
@@ -4139,7 +4488,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4139
4488
|
createArrayFieldName,
|
|
4140
4489
|
typeName,
|
|
4141
4490
|
typeNameMapper,
|
|
4142
|
-
conflictDoNothing
|
|
4491
|
+
conflictDoNothing,
|
|
4492
|
+
mutationTxCtx
|
|
4143
4493
|
) : void 0;
|
|
4144
4494
|
const insertSingleGenerated = features.insert ? generateInsertSingle2(
|
|
4145
4495
|
db,
|
|
@@ -4151,7 +4501,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4151
4501
|
createSingleFieldName,
|
|
4152
4502
|
typeName,
|
|
4153
4503
|
typeNameMapper,
|
|
4154
|
-
conflictDoNothing
|
|
4504
|
+
conflictDoNothing,
|
|
4505
|
+
mutationTxCtx
|
|
4155
4506
|
) : void 0;
|
|
4156
4507
|
const uniqueSets = features.upsert ? getUniqueColumnSets(schema[tableName], getTableConfig2) : [];
|
|
4157
4508
|
const onConflictInput = features.upsert ? generateOnConflictInput({
|
|
@@ -4174,7 +4525,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4174
4525
|
typeName,
|
|
4175
4526
|
false,
|
|
4176
4527
|
typeNameMapper,
|
|
4177
|
-
filterCtx
|
|
4528
|
+
filterCtx,
|
|
4529
|
+
mutationTxCtx
|
|
4178
4530
|
) : void 0;
|
|
4179
4531
|
const upsertSingleGenerated = onConflictInput ? generateUpsert2(
|
|
4180
4532
|
db,
|
|
@@ -4189,7 +4541,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4189
4541
|
typeName,
|
|
4190
4542
|
true,
|
|
4191
4543
|
typeNameMapper,
|
|
4192
|
-
filterCtx
|
|
4544
|
+
filterCtx,
|
|
4545
|
+
mutationTxCtx
|
|
4193
4546
|
) : void 0;
|
|
4194
4547
|
const updateGenerated = features.update ? generateUpdate2(
|
|
4195
4548
|
db,
|
|
@@ -4204,7 +4557,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4204
4557
|
false,
|
|
4205
4558
|
features.requireWhere,
|
|
4206
4559
|
typeNameMapper,
|
|
4207
|
-
filterCtx
|
|
4560
|
+
filterCtx,
|
|
4561
|
+
mutationTxCtx
|
|
4208
4562
|
) : void 0;
|
|
4209
4563
|
const updateSingleGenerated = features.update ? generateUpdate2(
|
|
4210
4564
|
db,
|
|
@@ -4219,7 +4573,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4219
4573
|
true,
|
|
4220
4574
|
features.requireWhere,
|
|
4221
4575
|
typeNameMapper,
|
|
4222
|
-
filterCtx
|
|
4576
|
+
filterCtx,
|
|
4577
|
+
mutationTxCtx
|
|
4223
4578
|
) : void 0;
|
|
4224
4579
|
const updateManyInput = features.update && features.updateMany ? generateUpdateManyInput({ typeName, updatePrefix: prefixes.update, updateInput, tableFilters }) : void 0;
|
|
4225
4580
|
const updateManyGenerated = updateManyInput ? generateUpdateMany2(
|
|
@@ -4232,7 +4587,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4232
4587
|
updateManyFieldName,
|
|
4233
4588
|
typeName,
|
|
4234
4589
|
typeNameMapper,
|
|
4235
|
-
filterCtx
|
|
4590
|
+
filterCtx,
|
|
4591
|
+
mutationTxCtx
|
|
4236
4592
|
) : void 0;
|
|
4237
4593
|
const deleteGenerated = features.delete ? generateDelete2(
|
|
4238
4594
|
db,
|
|
@@ -4244,7 +4600,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4244
4600
|
false,
|
|
4245
4601
|
features.requireWhere,
|
|
4246
4602
|
filterCtx,
|
|
4247
|
-
{ tableName, relationMap: namedRelations, tables }
|
|
4603
|
+
{ tableName, relationMap: namedRelations, tables },
|
|
4604
|
+
mutationTxCtx
|
|
4248
4605
|
) : void 0;
|
|
4249
4606
|
const deleteSingleGenerated = features.delete ? generateDelete2(
|
|
4250
4607
|
db,
|
|
@@ -4256,7 +4613,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4256
4613
|
true,
|
|
4257
4614
|
features.requireWhere,
|
|
4258
4615
|
filterCtx,
|
|
4259
|
-
{ tableName, relationMap: namedRelations, tables }
|
|
4616
|
+
{ tableName, relationMap: namedRelations, tables },
|
|
4617
|
+
mutationTxCtx
|
|
4260
4618
|
) : void 0;
|
|
4261
4619
|
const aggregateType = features.aggregates ? generateAggregateTypes(schema[tableName], tableName, typeName, cacheCtx) : void 0;
|
|
4262
4620
|
const aggregateGenerated = features.aggregates ? generateAggregate(
|
|
@@ -4395,6 +4753,11 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4395
4753
|
inputs[havingInput.name] = havingInput;
|
|
4396
4754
|
}
|
|
4397
4755
|
}
|
|
4756
|
+
if (mutationTxCtx) {
|
|
4757
|
+
for (const name of Object.keys(mutations)) {
|
|
4758
|
+
mutationTxCtx.fieldNames.add(name);
|
|
4759
|
+
}
|
|
4760
|
+
}
|
|
4398
4761
|
const fieldResolvers = {};
|
|
4399
4762
|
for (const [tableName, tableRelations] of Object.entries(namedRelations)) {
|
|
4400
4763
|
const relResolvers = {};
|
|
@@ -4504,7 +4867,7 @@ var generateSelectSingle3 = (db, tableName, tables, relationMap, orderArgs, filt
|
|
|
4504
4867
|
};
|
|
4505
4868
|
};
|
|
4506
4869
|
var sqlitePrimaryKeyPropNames = (table) => getPrimaryKeyPropNamesFromConfig(table, getTableConfig3);
|
|
4507
|
-
var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false) => {
|
|
4870
|
+
var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx) => {
|
|
4508
4871
|
const queryArgs = {
|
|
4509
4872
|
values: {
|
|
4510
4873
|
type: new GraphQLNonNull6(new GraphQLList6(new GraphQLNonNull6(baseType)))
|
|
@@ -4515,31 +4878,32 @@ var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
4515
4878
|
name: fieldName,
|
|
4516
4879
|
resolver: async (_source, args, context, info) => {
|
|
4517
4880
|
try {
|
|
4518
|
-
|
|
4519
|
-
|
|
4520
|
-
|
|
4521
|
-
|
|
4522
|
-
|
|
4523
|
-
|
|
4524
|
-
|
|
4525
|
-
|
|
4526
|
-
|
|
4527
|
-
|
|
4528
|
-
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
|
|
4532
|
-
|
|
4533
|
-
|
|
4881
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4882
|
+
const input = remapFromGraphQLArrayInput(args.values, table);
|
|
4883
|
+
if (!input.length) {
|
|
4884
|
+
throw new GraphQLError7("No values were provided!");
|
|
4885
|
+
}
|
|
4886
|
+
const parsedInfo = parseResolveInfo4(info, {
|
|
4887
|
+
deep: true
|
|
4888
|
+
});
|
|
4889
|
+
const { columns, hasRelations, withParams } = prepareMutationRelationColumns({
|
|
4890
|
+
relationMap,
|
|
4891
|
+
tables,
|
|
4892
|
+
tableName,
|
|
4893
|
+
typeName,
|
|
4894
|
+
typeNameMapper,
|
|
4895
|
+
table,
|
|
4896
|
+
pkNames,
|
|
4897
|
+
parsedInfo
|
|
4898
|
+
});
|
|
4899
|
+
let query = executor.insert(table).values(input).returning(columns);
|
|
4900
|
+
if (conflictDoNothing) {
|
|
4901
|
+
query = query.onConflictDoNothing();
|
|
4902
|
+
}
|
|
4903
|
+
const result = await query;
|
|
4904
|
+
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
4905
|
+
return remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
|
|
4534
4906
|
});
|
|
4535
|
-
const executor = resolveExecutor(db, context);
|
|
4536
|
-
let query = executor.insert(table).values(input).returning(columns);
|
|
4537
|
-
if (conflictDoNothing) {
|
|
4538
|
-
query = query.onConflictDoNothing();
|
|
4539
|
-
}
|
|
4540
|
-
const result = await query;
|
|
4541
|
-
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
4542
|
-
return remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
|
|
4543
4907
|
} catch (e) {
|
|
4544
4908
|
throw toGraphQLError(e);
|
|
4545
4909
|
}
|
|
@@ -4547,7 +4911,7 @@ var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
4547
4911
|
args: queryArgs
|
|
4548
4912
|
};
|
|
4549
4913
|
};
|
|
4550
|
-
var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false) => {
|
|
4914
|
+
var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx) => {
|
|
4551
4915
|
const queryArgs = {
|
|
4552
4916
|
values: {
|
|
4553
4917
|
type: new GraphQLNonNull6(baseType)
|
|
@@ -4558,31 +4922,32 @@ var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType
|
|
|
4558
4922
|
name: fieldName,
|
|
4559
4923
|
resolver: async (_source, args, context, info) => {
|
|
4560
4924
|
try {
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
|
|
4564
|
-
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
|
|
4572
|
-
|
|
4573
|
-
|
|
4925
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4926
|
+
const input = remapFromGraphQLSingleInput(args.values, table);
|
|
4927
|
+
const parsedInfo = parseResolveInfo4(info, {
|
|
4928
|
+
deep: true
|
|
4929
|
+
});
|
|
4930
|
+
const { columns, hasRelations, withParams } = prepareMutationRelationColumns({
|
|
4931
|
+
relationMap,
|
|
4932
|
+
tables,
|
|
4933
|
+
tableName,
|
|
4934
|
+
typeName,
|
|
4935
|
+
typeNameMapper,
|
|
4936
|
+
table,
|
|
4937
|
+
pkNames,
|
|
4938
|
+
parsedInfo
|
|
4939
|
+
});
|
|
4940
|
+
let query = executor.insert(table).values(input).returning(columns);
|
|
4941
|
+
if (conflictDoNothing) {
|
|
4942
|
+
query = query.onConflictDoNothing();
|
|
4943
|
+
}
|
|
4944
|
+
const result = await query;
|
|
4945
|
+
if (!result[0]) {
|
|
4946
|
+
return void 0;
|
|
4947
|
+
}
|
|
4948
|
+
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
4949
|
+
return remapToGraphQLSingleOutput(enriched[0], tableName, table, relationMap);
|
|
4574
4950
|
});
|
|
4575
|
-
const executor = resolveExecutor(db, context);
|
|
4576
|
-
let query = executor.insert(table).values(input).returning(columns);
|
|
4577
|
-
if (conflictDoNothing) {
|
|
4578
|
-
query = query.onConflictDoNothing();
|
|
4579
|
-
}
|
|
4580
|
-
const result = await query;
|
|
4581
|
-
if (!result[0]) {
|
|
4582
|
-
return void 0;
|
|
4583
|
-
}
|
|
4584
|
-
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
4585
|
-
return remapToGraphQLSingleOutput(enriched[0], tableName, table, relationMap);
|
|
4586
4951
|
} catch (e) {
|
|
4587
4952
|
throw toGraphQLError(e);
|
|
4588
4953
|
}
|
|
@@ -4590,7 +4955,7 @@ var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType
|
|
|
4590
4955
|
args: queryArgs
|
|
4591
4956
|
};
|
|
4592
4957
|
};
|
|
4593
|
-
var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx) => {
|
|
4958
|
+
var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx, txCtx) => {
|
|
4594
4959
|
const queryArgs = {
|
|
4595
4960
|
values: {
|
|
4596
4961
|
type: single ? new GraphQLNonNull6(baseType) : new GraphQLNonNull6(new GraphQLList6(new GraphQLNonNull6(baseType)))
|
|
@@ -4605,40 +4970,41 @@ var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
4605
4970
|
name: fieldName,
|
|
4606
4971
|
resolver: async (_source, args, context, info) => {
|
|
4607
4972
|
try {
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4973
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4974
|
+
const input = single ? [remapFromGraphQLSingleInput(args.values, table)] : remapFromGraphQLArrayInput(args.values, table);
|
|
4975
|
+
if (!input.length) {
|
|
4976
|
+
throw new GraphQLError7("No values were provided!");
|
|
4977
|
+
}
|
|
4978
|
+
const parsedInfo = parseResolveInfo4(info, { deep: true });
|
|
4979
|
+
const { columns, hasRelations, withParams } = prepareMutationRelationColumns({
|
|
4980
|
+
relationMap,
|
|
4981
|
+
tables,
|
|
4982
|
+
tableName,
|
|
4983
|
+
typeName,
|
|
4984
|
+
typeNameMapper,
|
|
4985
|
+
table,
|
|
4986
|
+
pkNames,
|
|
4987
|
+
parsedInfo
|
|
4988
|
+
});
|
|
4989
|
+
const plan = resolveConflictPlan({
|
|
4990
|
+
table,
|
|
4991
|
+
values: input,
|
|
4992
|
+
onConflict: args.onConflict,
|
|
4993
|
+
pkNames,
|
|
4994
|
+
uniqueSets,
|
|
4995
|
+
excludedRef: excludedColumnRef,
|
|
4996
|
+
withTarget: true,
|
|
4997
|
+
buildWhere: (where) => extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName))
|
|
4998
|
+
});
|
|
4999
|
+
let query = executor.insert(table).values(input).returning(columns);
|
|
5000
|
+
query = plan.action === "NOTHING" ? query.onConflictDoNothing(plan.target ? { target: plan.target } : void 0) : query.onConflictDoUpdate({ target: plan.target, set: plan.set, setWhere: plan.setWhere });
|
|
5001
|
+
const result = await query;
|
|
5002
|
+
if (single && !result[0]) {
|
|
5003
|
+
return void 0;
|
|
5004
|
+
}
|
|
5005
|
+
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
5006
|
+
return single ? remapToGraphQLSingleOutput(enriched[0], tableName, table, relationMap) : remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
|
|
4632
5007
|
});
|
|
4633
|
-
const executor = resolveExecutor(db, context);
|
|
4634
|
-
let query = executor.insert(table).values(input).returning(columns);
|
|
4635
|
-
query = plan.action === "NOTHING" ? query.onConflictDoNothing(plan.target ? { target: plan.target } : void 0) : query.onConflictDoUpdate({ target: plan.target, set: plan.set, setWhere: plan.setWhere });
|
|
4636
|
-
const result = await query;
|
|
4637
|
-
if (single && !result[0]) {
|
|
4638
|
-
return void 0;
|
|
4639
|
-
}
|
|
4640
|
-
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
4641
|
-
return single ? remapToGraphQLSingleOutput(enriched[0], tableName, table, relationMap) : remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
|
|
4642
5008
|
} catch (e) {
|
|
4643
5009
|
throw toGraphQLError(e);
|
|
4644
5010
|
}
|
|
@@ -4646,7 +5012,7 @@ var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
4646
5012
|
args: queryArgs
|
|
4647
5013
|
};
|
|
4648
5014
|
};
|
|
4649
|
-
var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx) => {
|
|
5015
|
+
var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx, txCtx) => {
|
|
4650
5016
|
const queryArgs = {
|
|
4651
5017
|
set: {
|
|
4652
5018
|
type: new GraphQLNonNull6(setArgs)
|
|
@@ -4660,44 +5026,45 @@ var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
4660
5026
|
name: fieldName,
|
|
4661
5027
|
resolver: async (_source, args, context, info) => {
|
|
4662
5028
|
try {
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
|
|
5029
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
5030
|
+
const { where, set } = args;
|
|
5031
|
+
const parsedInfo = parseResolveInfo4(info, {
|
|
5032
|
+
deep: true
|
|
5033
|
+
});
|
|
5034
|
+
const { columns, hasRelations, withParams } = prepareMutationRelationColumns({
|
|
5035
|
+
relationMap,
|
|
5036
|
+
tables,
|
|
5037
|
+
tableName,
|
|
5038
|
+
typeName,
|
|
5039
|
+
typeNameMapper,
|
|
5040
|
+
table,
|
|
5041
|
+
pkNames,
|
|
5042
|
+
parsedInfo
|
|
5043
|
+
});
|
|
5044
|
+
const input = remapFromGraphQLSingleInput(set, table);
|
|
5045
|
+
if (!Object.keys(input).length) {
|
|
5046
|
+
throw new GraphQLError7("Unable to update with no values specified!");
|
|
5047
|
+
}
|
|
5048
|
+
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
5049
|
+
const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
5050
|
+
if (single) {
|
|
5051
|
+
await assertSingleMatch(executor, table, filters, fieldName);
|
|
5052
|
+
}
|
|
5053
|
+
let query = executor.update(table).set(input);
|
|
5054
|
+
if (filters) {
|
|
5055
|
+
query = query.where(filters);
|
|
5056
|
+
}
|
|
5057
|
+
query = query.returning(columns);
|
|
5058
|
+
const result = await query;
|
|
5059
|
+
if (single && result.length > 1) {
|
|
5060
|
+
throw new GraphQLError7(`${fieldName}: 'where' matched more than one row!`);
|
|
5061
|
+
}
|
|
5062
|
+
if (single && !result[0]) {
|
|
5063
|
+
return void 0;
|
|
5064
|
+
}
|
|
5065
|
+
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
5066
|
+
return single ? remapToGraphQLSingleOutput(enriched[0], tableName, table, relationMap) : remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
|
|
4676
5067
|
});
|
|
4677
|
-
const input = remapFromGraphQLSingleInput(set, table);
|
|
4678
|
-
if (!Object.keys(input).length) {
|
|
4679
|
-
throw new GraphQLError7("Unable to update with no values specified!");
|
|
4680
|
-
}
|
|
4681
|
-
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
4682
|
-
const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
4683
|
-
const executor = resolveExecutor(db, context);
|
|
4684
|
-
if (single) {
|
|
4685
|
-
await assertSingleMatch(executor, table, filters, fieldName);
|
|
4686
|
-
}
|
|
4687
|
-
let query = executor.update(table).set(input);
|
|
4688
|
-
if (filters) {
|
|
4689
|
-
query = query.where(filters);
|
|
4690
|
-
}
|
|
4691
|
-
query = query.returning(columns);
|
|
4692
|
-
const result = await query;
|
|
4693
|
-
if (single && result.length > 1) {
|
|
4694
|
-
throw new GraphQLError7(`${fieldName}: 'where' matched more than one row!`);
|
|
4695
|
-
}
|
|
4696
|
-
if (single && !result[0]) {
|
|
4697
|
-
return void 0;
|
|
4698
|
-
}
|
|
4699
|
-
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
4700
|
-
return single ? remapToGraphQLSingleOutput(enriched[0], tableName, table, relationMap) : remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
|
|
4701
5068
|
} catch (e) {
|
|
4702
5069
|
throw toGraphQLError(e);
|
|
4703
5070
|
}
|
|
@@ -4705,7 +5072,7 @@ var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
4705
5072
|
args: queryArgs
|
|
4706
5073
|
};
|
|
4707
5074
|
};
|
|
4708
|
-
var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx) => {
|
|
5075
|
+
var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx, txCtx) => {
|
|
4709
5076
|
const queryArgs = {
|
|
4710
5077
|
updates: {
|
|
4711
5078
|
type: new GraphQLNonNull6(new GraphQLList6(new GraphQLNonNull6(updateManyInput)))
|
|
@@ -4716,73 +5083,74 @@ var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
4716
5083
|
name: fieldName,
|
|
4717
5084
|
resolver: async (_source, args, context, info) => {
|
|
4718
5085
|
try {
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
|
|
4722
|
-
|
|
4723
|
-
const parsedInfo = parseResolveInfo4(info, {
|
|
4724
|
-
deep: true
|
|
4725
|
-
});
|
|
4726
|
-
const { columns, hasRelations, withParams } = prepareMutationRelationColumns({
|
|
4727
|
-
relationMap,
|
|
4728
|
-
tables,
|
|
4729
|
-
tableName,
|
|
4730
|
-
typeName,
|
|
4731
|
-
typeNameMapper,
|
|
4732
|
-
table,
|
|
4733
|
-
pkNames,
|
|
4734
|
-
parsedInfo
|
|
4735
|
-
});
|
|
4736
|
-
const entries = updates.map(({ where, set }) => {
|
|
4737
|
-
const input = remapFromGraphQLSingleInput(set, table);
|
|
4738
|
-
if (!Object.keys(input).length) {
|
|
4739
|
-
throw new GraphQLError7("Unable to update with no values specified!");
|
|
5086
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
5087
|
+
const { updates } = args;
|
|
5088
|
+
if (!updates.length) {
|
|
5089
|
+
throw new GraphQLError7("No updates were provided!");
|
|
4740
5090
|
}
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
|
|
5091
|
+
const parsedInfo = parseResolveInfo4(info, {
|
|
5092
|
+
deep: true
|
|
5093
|
+
});
|
|
5094
|
+
const { columns, hasRelations, withParams } = prepareMutationRelationColumns({
|
|
5095
|
+
relationMap,
|
|
5096
|
+
tables,
|
|
5097
|
+
tableName,
|
|
5098
|
+
typeName,
|
|
5099
|
+
typeNameMapper,
|
|
5100
|
+
table,
|
|
5101
|
+
pkNames,
|
|
5102
|
+
parsedInfo
|
|
5103
|
+
});
|
|
5104
|
+
const entries = updates.map(({ where, set }) => {
|
|
5105
|
+
const input = remapFromGraphQLSingleInput(set, table);
|
|
5106
|
+
if (!Object.keys(input).length) {
|
|
5107
|
+
throw new GraphQLError7("Unable to update with no values specified!");
|
|
5108
|
+
}
|
|
5109
|
+
return {
|
|
5110
|
+
set: input,
|
|
5111
|
+
filters: where ? extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName)) : void 0
|
|
5112
|
+
};
|
|
5113
|
+
});
|
|
5114
|
+
const runEntry = (tx, entry) => {
|
|
5115
|
+
let query = tx.update(table).set(entry.set);
|
|
5116
|
+
if (entry.filters) {
|
|
5117
|
+
query = query.where(entry.filters);
|
|
5118
|
+
}
|
|
5119
|
+
return query.returning(columns).all();
|
|
4744
5120
|
};
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
|
|
4764
|
-
|
|
4765
|
-
|
|
4766
|
-
for (
|
|
4767
|
-
|
|
5121
|
+
const perEntry = await executor.transaction((tx) => {
|
|
5122
|
+
const first = runEntry(tx, entries[0]);
|
|
5123
|
+
if (typeof first?.then === "function") {
|
|
5124
|
+
return (async () => {
|
|
5125
|
+
const results2 = [await first];
|
|
5126
|
+
for (let i = 1; i < entries.length; i++) {
|
|
5127
|
+
results2.push(await runEntry(tx, entries[i]));
|
|
5128
|
+
}
|
|
5129
|
+
return results2;
|
|
5130
|
+
})();
|
|
5131
|
+
}
|
|
5132
|
+
const results = [first];
|
|
5133
|
+
for (let i = 1; i < entries.length; i++) {
|
|
5134
|
+
results.push(runEntry(tx, entries[i]));
|
|
5135
|
+
}
|
|
5136
|
+
return results;
|
|
5137
|
+
});
|
|
5138
|
+
const flatRows = perEntry.flat();
|
|
5139
|
+
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, flatRows, pkNames, withParams) : flatRows;
|
|
5140
|
+
const output = [];
|
|
5141
|
+
let offset = 0;
|
|
5142
|
+
for (const rows of perEntry) {
|
|
5143
|
+
if (!rows.length) {
|
|
5144
|
+
output.push(null);
|
|
5145
|
+
continue;
|
|
5146
|
+
}
|
|
5147
|
+
for (let i = 0; i < rows.length; i++) {
|
|
5148
|
+
output.push(remapToGraphQLSingleOutput(enriched[offset + i], tableName, table, relationMap));
|
|
5149
|
+
}
|
|
5150
|
+
offset += rows.length;
|
|
4768
5151
|
}
|
|
4769
|
-
return
|
|
5152
|
+
return output;
|
|
4770
5153
|
});
|
|
4771
|
-
const flatRows = perEntry.flat();
|
|
4772
|
-
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, flatRows, pkNames, withParams) : flatRows;
|
|
4773
|
-
const output = [];
|
|
4774
|
-
let offset = 0;
|
|
4775
|
-
for (const rows of perEntry) {
|
|
4776
|
-
if (!rows.length) {
|
|
4777
|
-
output.push(null);
|
|
4778
|
-
continue;
|
|
4779
|
-
}
|
|
4780
|
-
for (let i = 0; i < rows.length; i++) {
|
|
4781
|
-
output.push(remapToGraphQLSingleOutput(enriched[offset + i], tableName, table, relationMap));
|
|
4782
|
-
}
|
|
4783
|
-
offset += rows.length;
|
|
4784
|
-
}
|
|
4785
|
-
return output;
|
|
4786
5154
|
} catch (e) {
|
|
4787
5155
|
throw toGraphQLError(e);
|
|
4788
5156
|
}
|
|
@@ -4790,7 +5158,7 @@ var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
4790
5158
|
args: queryArgs
|
|
4791
5159
|
};
|
|
4792
5160
|
};
|
|
4793
|
-
var generateDelete3 = (db, tableName, table, filterArgs, fieldName, typeName, single, requireWhere, filterCtx, selectionCtx) => {
|
|
5161
|
+
var generateDelete3 = (db, tableName, table, filterArgs, fieldName, typeName, single, requireWhere, filterCtx, selectionCtx, txCtx) => {
|
|
4794
5162
|
const queryArgs = {
|
|
4795
5163
|
where: {
|
|
4796
5164
|
type: single || requireWhere ? new GraphQLNonNull6(filterArgs) : filterArgs
|
|
@@ -4800,34 +5168,35 @@ var generateDelete3 = (db, tableName, table, filterArgs, fieldName, typeName, si
|
|
|
4800
5168
|
name: fieldName,
|
|
4801
5169
|
resolver: async (_source, args, context, info) => {
|
|
4802
5170
|
try {
|
|
4803
|
-
|
|
4804
|
-
|
|
4805
|
-
|
|
5171
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
5172
|
+
const { where } = args;
|
|
5173
|
+
const parsedInfo = parseResolveInfo4(info, {
|
|
5174
|
+
deep: true
|
|
5175
|
+
});
|
|
5176
|
+
const columns = extractSelectedColumnsFromTreeSQLFormat(
|
|
5177
|
+
parsedInfo.fieldsByTypeName[typeName],
|
|
5178
|
+
table,
|
|
5179
|
+
selectionCtx
|
|
5180
|
+
);
|
|
5181
|
+
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
5182
|
+
const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
5183
|
+
if (single) {
|
|
5184
|
+
await assertSingleMatch(executor, table, filters, fieldName);
|
|
5185
|
+
}
|
|
5186
|
+
let query = executor.delete(table);
|
|
5187
|
+
if (filters) {
|
|
5188
|
+
query = query.where(filters);
|
|
5189
|
+
}
|
|
5190
|
+
query = query.returning(columns);
|
|
5191
|
+
const result = await query;
|
|
5192
|
+
if (single && result.length > 1) {
|
|
5193
|
+
throw new GraphQLError7(`${fieldName}: 'where' matched more than one row!`);
|
|
5194
|
+
}
|
|
5195
|
+
if (single) {
|
|
5196
|
+
return result[0] ? remapToGraphQLSingleOutput(result[0], tableName, table) : void 0;
|
|
5197
|
+
}
|
|
5198
|
+
return remapToGraphQLArrayOutput(result, tableName, table);
|
|
4806
5199
|
});
|
|
4807
|
-
const columns = extractSelectedColumnsFromTreeSQLFormat(
|
|
4808
|
-
parsedInfo.fieldsByTypeName[typeName],
|
|
4809
|
-
table,
|
|
4810
|
-
selectionCtx
|
|
4811
|
-
);
|
|
4812
|
-
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
4813
|
-
const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
4814
|
-
const executor = resolveExecutor(db, context);
|
|
4815
|
-
if (single) {
|
|
4816
|
-
await assertSingleMatch(executor, table, filters, fieldName);
|
|
4817
|
-
}
|
|
4818
|
-
let query = executor.delete(table);
|
|
4819
|
-
if (filters) {
|
|
4820
|
-
query = query.where(filters);
|
|
4821
|
-
}
|
|
4822
|
-
query = query.returning(columns);
|
|
4823
|
-
const result = await query;
|
|
4824
|
-
if (single && result.length > 1) {
|
|
4825
|
-
throw new GraphQLError7(`${fieldName}: 'where' matched more than one row!`);
|
|
4826
|
-
}
|
|
4827
|
-
if (single) {
|
|
4828
|
-
return result[0] ? remapToGraphQLSingleOutput(result[0], tableName, table) : void 0;
|
|
4829
|
-
}
|
|
4830
|
-
return remapToGraphQLArrayOutput(result, tableName, table);
|
|
4831
5200
|
} catch (e) {
|
|
4832
5201
|
throw toGraphQLError(e);
|
|
4833
5202
|
}
|
|
@@ -4855,6 +5224,7 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
4855
5224
|
"Drizzle-GraphQL Error: No tables detected in Drizzle-ORM's database instance. Did you forget to pass schema to drizzle constructor?"
|
|
4856
5225
|
);
|
|
4857
5226
|
}
|
|
5227
|
+
registerScalarOverrides(tables, options);
|
|
4858
5228
|
const namedRelations = buildNamedRelations(relations ?? {}, tableEntries);
|
|
4859
5229
|
attachTargetPrimaryKeys(namedRelations, tables, sqlitePrimaryKeyPropNames);
|
|
4860
5230
|
const eagerRelations = pruneNonEagerRelations(namedRelations, shouldEagerLoad);
|
|
@@ -4866,6 +5236,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
4866
5236
|
relationFieldContainers: /* @__PURE__ */ new Map(),
|
|
4867
5237
|
fullyBuiltTables: /* @__PURE__ */ new Set(),
|
|
4868
5238
|
relationTypeCache: /* @__PURE__ */ new Map(),
|
|
5239
|
+
selectFieldCache: /* @__PURE__ */ new WeakMap(),
|
|
5240
|
+
filterFieldCache: /* @__PURE__ */ new WeakMap(),
|
|
4869
5241
|
orderTypeCache: /* @__PURE__ */ new WeakMap(),
|
|
4870
5242
|
filterTypeCache: /* @__PURE__ */ new WeakMap(),
|
|
4871
5243
|
listRelationFilterCache: /* @__PURE__ */ new Map(),
|
|
@@ -4875,6 +5247,12 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
4875
5247
|
const relationAggregateFactory = features.relationAggregates ? createRelationAggregateFactory(db, tables, cacheCtx, typeNameMapper, filterCtx) : void 0;
|
|
4876
5248
|
const queries = {};
|
|
4877
5249
|
const mutations = {};
|
|
5250
|
+
if (options.transactions && db.resultKind === "sync") {
|
|
5251
|
+
throw new Error(
|
|
5252
|
+
"Drizzle-GraphQL Error: transactions: 'auto' requires an asynchronous SQLite driver (e.g. libsql). Synchronous drivers cannot hold a transaction open across resolvers."
|
|
5253
|
+
);
|
|
5254
|
+
}
|
|
5255
|
+
const mutationTxCtx = createMutationTxCtx(options.transactions);
|
|
4878
5256
|
const gqlSchemaTypes = Object.fromEntries(
|
|
4879
5257
|
Object.entries(tables).map(([tableName, _table]) => [
|
|
4880
5258
|
tableName,
|
|
@@ -4949,7 +5327,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
4949
5327
|
createArrayFieldName,
|
|
4950
5328
|
typeName,
|
|
4951
5329
|
typeNameMapper,
|
|
4952
|
-
conflictDoNothing
|
|
5330
|
+
conflictDoNothing,
|
|
5331
|
+
mutationTxCtx
|
|
4953
5332
|
) : void 0;
|
|
4954
5333
|
const insertSingleGenerated = features.insert ? generateInsertSingle3(
|
|
4955
5334
|
db,
|
|
@@ -4961,7 +5340,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
4961
5340
|
createSingleFieldName,
|
|
4962
5341
|
typeName,
|
|
4963
5342
|
typeNameMapper,
|
|
4964
|
-
conflictDoNothing
|
|
5343
|
+
conflictDoNothing,
|
|
5344
|
+
mutationTxCtx
|
|
4965
5345
|
) : void 0;
|
|
4966
5346
|
const uniqueSets = features.upsert ? getUniqueColumnSets(schema[tableName], getTableConfig3) : [];
|
|
4967
5347
|
const onConflictInput = features.upsert ? generateOnConflictInput({
|
|
@@ -4984,7 +5364,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
4984
5364
|
typeName,
|
|
4985
5365
|
false,
|
|
4986
5366
|
typeNameMapper,
|
|
4987
|
-
filterCtx
|
|
5367
|
+
filterCtx,
|
|
5368
|
+
mutationTxCtx
|
|
4988
5369
|
) : void 0;
|
|
4989
5370
|
const upsertSingleGenerated = onConflictInput ? generateUpsert3(
|
|
4990
5371
|
db,
|
|
@@ -4999,7 +5380,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
4999
5380
|
typeName,
|
|
5000
5381
|
true,
|
|
5001
5382
|
typeNameMapper,
|
|
5002
|
-
filterCtx
|
|
5383
|
+
filterCtx,
|
|
5384
|
+
mutationTxCtx
|
|
5003
5385
|
) : void 0;
|
|
5004
5386
|
const updateGenerated = features.update ? generateUpdate3(
|
|
5005
5387
|
db,
|
|
@@ -5014,7 +5396,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5014
5396
|
false,
|
|
5015
5397
|
features.requireWhere,
|
|
5016
5398
|
typeNameMapper,
|
|
5017
|
-
filterCtx
|
|
5399
|
+
filterCtx,
|
|
5400
|
+
mutationTxCtx
|
|
5018
5401
|
) : void 0;
|
|
5019
5402
|
const updateSingleGenerated = features.update ? generateUpdate3(
|
|
5020
5403
|
db,
|
|
@@ -5029,7 +5412,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5029
5412
|
true,
|
|
5030
5413
|
features.requireWhere,
|
|
5031
5414
|
typeNameMapper,
|
|
5032
|
-
filterCtx
|
|
5415
|
+
filterCtx,
|
|
5416
|
+
mutationTxCtx
|
|
5033
5417
|
) : void 0;
|
|
5034
5418
|
const updateManyInput = features.update && features.updateMany ? generateUpdateManyInput({ typeName, updatePrefix: prefixes.update, updateInput, tableFilters }) : void 0;
|
|
5035
5419
|
const updateManyGenerated = updateManyInput ? generateUpdateMany3(
|
|
@@ -5042,7 +5426,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5042
5426
|
updateManyFieldName,
|
|
5043
5427
|
typeName,
|
|
5044
5428
|
typeNameMapper,
|
|
5045
|
-
filterCtx
|
|
5429
|
+
filterCtx,
|
|
5430
|
+
mutationTxCtx
|
|
5046
5431
|
) : void 0;
|
|
5047
5432
|
const deleteGenerated = features.delete ? generateDelete3(
|
|
5048
5433
|
db,
|
|
@@ -5054,7 +5439,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5054
5439
|
false,
|
|
5055
5440
|
features.requireWhere,
|
|
5056
5441
|
filterCtx,
|
|
5057
|
-
{ tableName, relationMap: namedRelations, tables }
|
|
5442
|
+
{ tableName, relationMap: namedRelations, tables },
|
|
5443
|
+
mutationTxCtx
|
|
5058
5444
|
) : void 0;
|
|
5059
5445
|
const deleteSingleGenerated = features.delete ? generateDelete3(
|
|
5060
5446
|
db,
|
|
@@ -5066,7 +5452,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5066
5452
|
true,
|
|
5067
5453
|
features.requireWhere,
|
|
5068
5454
|
filterCtx,
|
|
5069
|
-
{ tableName, relationMap: namedRelations, tables }
|
|
5455
|
+
{ tableName, relationMap: namedRelations, tables },
|
|
5456
|
+
mutationTxCtx
|
|
5070
5457
|
) : void 0;
|
|
5071
5458
|
const aggregateType = features.aggregates ? generateAggregateTypes(schema[tableName], tableName, typeName, cacheCtx) : void 0;
|
|
5072
5459
|
const aggregateGenerated = features.aggregates ? generateAggregate(
|
|
@@ -5205,6 +5592,11 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5205
5592
|
inputs[havingInput.name] = havingInput;
|
|
5206
5593
|
}
|
|
5207
5594
|
}
|
|
5595
|
+
if (mutationTxCtx) {
|
|
5596
|
+
for (const name of Object.keys(mutations)) {
|
|
5597
|
+
mutationTxCtx.fieldNames.add(name);
|
|
5598
|
+
}
|
|
5599
|
+
}
|
|
5208
5600
|
const fieldResolvers = {};
|
|
5209
5601
|
for (const [tableName, tableRelations] of Object.entries(namedRelations)) {
|
|
5210
5602
|
const relResolvers = {};
|
|
@@ -5261,6 +5653,8 @@ var buildSchema = (db, config) => {
|
|
|
5261
5653
|
defaultListSize: (complexityConfig === true ? void 0 : complexityConfig.defaultListSize) ?? 10,
|
|
5262
5654
|
aggregateCost: (complexityConfig === true ? void 0 : complexityConfig.aggregateCost) ?? 10
|
|
5263
5655
|
};
|
|
5656
|
+
const transactionsOpt = config?.transactions;
|
|
5657
|
+
const transactions = transactionsOpt === void 0 || transactionsOpt === "none" ? void 0 : { timeoutMs: (transactionsOpt === "auto" ? void 0 : transactionsOpt.timeoutMs) ?? 3e4 };
|
|
5264
5658
|
const eagerOpt = config?.eagerLoadRelations;
|
|
5265
5659
|
const shouldEagerLoad = eagerOpt === void 0 || eagerOpt === true ? () => true : eagerOpt === false ? () => false : eagerOpt;
|
|
5266
5660
|
if (!typeNameMapper && suffixes.list === suffixes.single) {
|
|
@@ -5288,7 +5682,10 @@ var buildSchema = (db, config) => {
|
|
|
5288
5682
|
typeNameMapper,
|
|
5289
5683
|
shouldEagerLoad,
|
|
5290
5684
|
features,
|
|
5291
|
-
complexity
|
|
5685
|
+
complexity,
|
|
5686
|
+
scalars: config?.scalars,
|
|
5687
|
+
mapColumnType: config?.mapColumnType,
|
|
5688
|
+
transactions
|
|
5292
5689
|
};
|
|
5293
5690
|
let generatorOutput;
|
|
5294
5691
|
if (is7(db, MySqlDatabase)) {
|