@vantreeseba/drizzle-graphql 5.6.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1020 -768
- package/dist/README.md +1020 -768
- package/dist/index.cjs +1653 -548
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +238 -2
- package/dist/index.d.ts +238 -2
- package/dist/index.js +1578 -457
- package/dist/index.js.map +1 -1
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -45,15 +45,15 @@ __export(index_exports, {
|
|
|
45
45
|
extractRelationJoinColumns: () => extractRelationJoinColumns
|
|
46
46
|
});
|
|
47
47
|
module.exports = __toCommonJS(index_exports);
|
|
48
|
-
var
|
|
48
|
+
var import_drizzle_orm10 = require("drizzle-orm");
|
|
49
49
|
var import_mysql_core3 = require("drizzle-orm/mysql-core");
|
|
50
50
|
var import_pg_core3 = require("drizzle-orm/pg-core");
|
|
51
51
|
var import_sqlite_core3 = require("drizzle-orm/sqlite-core");
|
|
52
|
-
var
|
|
52
|
+
var import_graphql11 = require("graphql");
|
|
53
53
|
|
|
54
54
|
// src/util/builders/common.ts
|
|
55
|
-
var
|
|
56
|
-
var
|
|
55
|
+
var import_drizzle_orm4 = require("drizzle-orm");
|
|
56
|
+
var import_graphql5 = require("graphql");
|
|
57
57
|
|
|
58
58
|
// src/util/batch-loader/index.ts
|
|
59
59
|
var DRIZZLE_LOADERS_KEY = /* @__PURE__ */ Symbol("drizzle-graphql-loaders");
|
|
@@ -189,15 +189,42 @@ var GraphQLDecimalString = new import_graphql.GraphQLScalarType({
|
|
|
189
189
|
|
|
190
190
|
// src/util/type-converter/index.ts
|
|
191
191
|
var allowedNameChars = /^[a-zA-Z0-9_]+$/;
|
|
192
|
-
var
|
|
192
|
+
var declaredEnum = (column) => {
|
|
193
|
+
const declared = column.enum;
|
|
194
|
+
return typeof declared?.enumName === "string" ? { enumName: declared.enumName, schema: typeof declared.schema === "string" ? declared.schema : void 0 } : void 0;
|
|
195
|
+
};
|
|
196
|
+
var pascalize = (input) => input.split(/[^a-zA-Z0-9]+/).filter(Boolean).map((part) => capitalize(part)).join("");
|
|
197
|
+
var enumValuesKey = (values) => JSON.stringify(values);
|
|
198
|
+
var enumNamesInUse = /* @__PURE__ */ new Map();
|
|
199
|
+
var enumNameMapper;
|
|
200
|
+
var registerEnumConfig = (config) => {
|
|
201
|
+
enumNameMapper = config.enumNameMapper;
|
|
202
|
+
enumNamesInUse = /* @__PURE__ */ new Map();
|
|
203
|
+
};
|
|
193
204
|
var generateEnumCached = (column, columnName, tableName) => {
|
|
194
|
-
|
|
195
|
-
|
|
205
|
+
const declared = declaredEnum(column);
|
|
206
|
+
const values = column.enumValues;
|
|
207
|
+
const name = enumNameMapper?.({
|
|
208
|
+
enumName: declared?.enumName,
|
|
209
|
+
schema: declared?.schema,
|
|
210
|
+
tableName,
|
|
211
|
+
columnName,
|
|
212
|
+
values
|
|
213
|
+
}) ?? (declared ? `${pascalize(declared.enumName)}Enum` : `${capitalize(tableName)}${capitalize(columnName)}Enum`);
|
|
214
|
+
const valuesKey = enumValuesKey(values);
|
|
215
|
+
const claimed = enumNamesInUse.get(name);
|
|
216
|
+
if (claimed) {
|
|
217
|
+
if (claimed.valuesKey !== valuesKey) {
|
|
218
|
+
throw new Error(
|
|
219
|
+
`Drizzle-GraphQL Error: Two different enums both map to the GraphQL type name '${name}' (most recently '${tableName}.${columnName}'). Give one of them a different name via config.enumNameMapper.`
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
return claimed.type;
|
|
196
223
|
}
|
|
197
224
|
const gqlEnum = new import_graphql2.GraphQLEnumType({
|
|
198
|
-
name
|
|
225
|
+
name,
|
|
199
226
|
values: Object.fromEntries(
|
|
200
|
-
|
|
227
|
+
values.map((e, index) => [
|
|
201
228
|
allowedNameChars.test(e) ? e : `Option${index}`,
|
|
202
229
|
{
|
|
203
230
|
value: e,
|
|
@@ -206,7 +233,7 @@ var generateEnumCached = (column, columnName, tableName) => {
|
|
|
206
233
|
])
|
|
207
234
|
)
|
|
208
235
|
});
|
|
209
|
-
|
|
236
|
+
enumNamesInUse.set(name, { type: gqlEnum, valuesKey });
|
|
210
237
|
return gqlEnum;
|
|
211
238
|
};
|
|
212
239
|
var geoXyType = new import_graphql2.GraphQLObjectType({
|
|
@@ -227,14 +254,14 @@ var columnToGraphQLCore = (column, columnName, tableName, isInput) => {
|
|
|
227
254
|
const dimensions = column.dimensions;
|
|
228
255
|
if (dimensions !== void 0 && dimensions > 0) {
|
|
229
256
|
const inner = columnBaseToGraphQLCore(column, columnName, tableName, isInput);
|
|
230
|
-
const
|
|
257
|
+
const innerLabel = inner.typeLabel ?? inner.type.name;
|
|
231
258
|
let type = inner.type;
|
|
232
|
-
let
|
|
259
|
+
let typeLabel = innerLabel;
|
|
233
260
|
for (let i = 0; i < dimensions; i++) {
|
|
234
261
|
type = new import_graphql2.GraphQLList(new import_graphql2.GraphQLNonNull(type));
|
|
235
|
-
|
|
262
|
+
typeLabel = `Array<${typeLabel}>`;
|
|
236
263
|
}
|
|
237
|
-
return { type,
|
|
264
|
+
return { type, typeLabel };
|
|
238
265
|
}
|
|
239
266
|
return columnBaseToGraphQLCore(column, columnName, tableName, isInput);
|
|
240
267
|
};
|
|
@@ -242,51 +269,51 @@ var columnBaseToGraphQLCore = (column, columnName, tableName, isInput) => {
|
|
|
242
269
|
const { type: baseType, constraint } = (0, import_drizzle_orm.extractExtendedColumnType)(column);
|
|
243
270
|
switch (baseType) {
|
|
244
271
|
case "boolean":
|
|
245
|
-
return { type: import_graphql2.GraphQLBoolean,
|
|
272
|
+
return { type: import_graphql2.GraphQLBoolean, typeLabel: "Boolean" };
|
|
246
273
|
case "object":
|
|
247
274
|
if (column instanceof import_pg_core.PgTimestamp || column instanceof import_pg_core.PgDate) {
|
|
248
|
-
return { type: import_graphql_scalars.GraphQLDateTime,
|
|
275
|
+
return { type: import_graphql_scalars.GraphQLDateTime, typeLabel: "DateTime" };
|
|
249
276
|
}
|
|
250
277
|
return column.columnType === "PgGeometryObject" ? {
|
|
251
278
|
type: isInput ? geoXyInputType : geoXyType,
|
|
252
|
-
|
|
279
|
+
typeLabel: "Geometry points XY"
|
|
253
280
|
} : column.columnType === "PgBytea" ? {
|
|
254
281
|
type: new import_graphql2.GraphQLList(new import_graphql2.GraphQLNonNull(import_graphql2.GraphQLInt)),
|
|
255
|
-
|
|
256
|
-
} : { type: import_graphql_scalars.GraphQLJSON,
|
|
282
|
+
typeLabel: "Buffer"
|
|
283
|
+
} : { type: import_graphql_scalars.GraphQLJSON, typeLabel: "JSON" };
|
|
257
284
|
case "string":
|
|
258
285
|
if (column.enumValues?.length) {
|
|
259
286
|
return { type: generateEnumCached(column, columnName, tableName) };
|
|
260
287
|
}
|
|
261
288
|
if (constraint === "numeric" && !column.dimensions) {
|
|
262
|
-
return { type: GraphQLDecimalString,
|
|
289
|
+
return { type: GraphQLDecimalString, typeLabel: "Decimal" };
|
|
263
290
|
}
|
|
264
291
|
if (column instanceof import_pg_core.PgTimestamp || column instanceof import_pg_core.PgTimestampString) {
|
|
265
|
-
return { type: import_graphql_scalars.GraphQLDateTime,
|
|
292
|
+
return { type: import_graphql_scalars.GraphQLDateTime, typeLabel: "DateTime" };
|
|
266
293
|
}
|
|
267
294
|
if (column instanceof import_pg_core.PgUUID) {
|
|
268
|
-
return { type: import_graphql_scalars.GraphQLUUID,
|
|
295
|
+
return { type: import_graphql_scalars.GraphQLUUID, typeLabel: "UUID" };
|
|
269
296
|
}
|
|
270
297
|
if (column instanceof import_pg_core.PgDateString) {
|
|
271
|
-
return isInput ? { type: import_graphql2.GraphQLString,
|
|
298
|
+
return isInput ? { type: import_graphql2.GraphQLString, typeLabel: "Date" } : { type: import_graphql_scalars.GraphQLDate, typeLabel: "Date" };
|
|
272
299
|
}
|
|
273
|
-
return { type: import_graphql2.GraphQLString,
|
|
300
|
+
return { type: import_graphql2.GraphQLString, typeLabel: "String" };
|
|
274
301
|
case "bigint":
|
|
275
|
-
return { type: GraphQLBigIntString,
|
|
302
|
+
return { type: GraphQLBigIntString, typeLabel: "BigInt" };
|
|
276
303
|
case "number": {
|
|
277
|
-
return (0, import_drizzle_orm.is)(column, import_pg_core.PgInteger) || (0, import_drizzle_orm.is)(column, import_pg_core.PgSerial) || (0, import_drizzle_orm.is)(column, import_mysql_core.MySqlInt) || (0, import_drizzle_orm.is)(column, import_mysql_core.MySqlSerial) || (0, import_drizzle_orm.is)(column, import_sqlite_core.SQLiteInteger) ? { type: import_graphql2.GraphQLInt,
|
|
304
|
+
return (0, import_drizzle_orm.is)(column, import_pg_core.PgInteger) || (0, import_drizzle_orm.is)(column, import_pg_core.PgSerial) || (0, import_drizzle_orm.is)(column, import_mysql_core.MySqlInt) || (0, import_drizzle_orm.is)(column, import_mysql_core.MySqlSerial) || (0, import_drizzle_orm.is)(column, import_sqlite_core.SQLiteInteger) ? { type: import_graphql2.GraphQLInt, typeLabel: "Integer" } : { type: import_graphql2.GraphQLFloat, typeLabel: "Float" };
|
|
278
305
|
}
|
|
279
306
|
case "array": {
|
|
280
307
|
if (column.columnType === "PgVector") {
|
|
281
308
|
return {
|
|
282
309
|
type: new import_graphql2.GraphQLList(new import_graphql2.GraphQLNonNull(import_graphql2.GraphQLFloat)),
|
|
283
|
-
|
|
310
|
+
typeLabel: "Array<Float>"
|
|
284
311
|
};
|
|
285
312
|
}
|
|
286
313
|
if (column.columnType === "PgGeometry") {
|
|
287
314
|
return {
|
|
288
315
|
type: new import_graphql2.GraphQLList(new import_graphql2.GraphQLNonNull(import_graphql2.GraphQLFloat)),
|
|
289
|
-
|
|
316
|
+
typeLabel: "Tuple<[Float, Float]>"
|
|
290
317
|
};
|
|
291
318
|
}
|
|
292
319
|
const innerType = columnToGraphQLCore(
|
|
@@ -297,7 +324,7 @@ var columnBaseToGraphQLCore = (column, columnName, tableName, isInput) => {
|
|
|
297
324
|
);
|
|
298
325
|
return {
|
|
299
326
|
type: new import_graphql2.GraphQLList(new import_graphql2.GraphQLNonNull(innerType.type)),
|
|
300
|
-
|
|
327
|
+
typeLabel: `Array<${innerType.typeLabel}>`
|
|
301
328
|
};
|
|
302
329
|
}
|
|
303
330
|
default:
|
|
@@ -353,24 +380,14 @@ var registerScalarOverrides = (tables, config) => {
|
|
|
353
380
|
};
|
|
354
381
|
var drizzleColumnToGraphQLType = (column, columnName, tableName, forceNullable = false, defaultIsNullable = false, isInput = false) => {
|
|
355
382
|
const override = getColumnScalarOverride(column, isInput);
|
|
356
|
-
|
|
357
|
-
if (override) {
|
|
358
|
-
typeDesc = { type: override, description: override.name };
|
|
359
|
-
} else {
|
|
360
|
-
typeDesc = columnToGraphQLCore(column, columnName, tableName, isInput);
|
|
361
|
-
const noDesc = ["string", "boolean", "number"];
|
|
362
|
-
const { type: baseType } = (0, import_drizzle_orm.extractExtendedColumnType)(column);
|
|
363
|
-
if (noDesc.find((e) => e === baseType)) {
|
|
364
|
-
delete typeDesc.description;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
383
|
+
const typeDesc = override ? { type: override, typeLabel: override.name } : columnToGraphQLCore(column, columnName, tableName, isInput);
|
|
367
384
|
if (forceNullable) {
|
|
368
385
|
return typeDesc;
|
|
369
386
|
}
|
|
370
387
|
if (column.notNull && !(defaultIsNullable && (column.hasDefault || column.defaultFn))) {
|
|
371
388
|
return {
|
|
372
389
|
type: new import_graphql2.GraphQLNonNull(typeDesc.type),
|
|
373
|
-
|
|
390
|
+
typeLabel: typeDesc.typeLabel
|
|
374
391
|
};
|
|
375
392
|
}
|
|
376
393
|
return typeDesc;
|
|
@@ -576,6 +593,124 @@ var remapFromGraphQLArrayInput = (queryInput, table) => {
|
|
|
576
593
|
return queryInput;
|
|
577
594
|
};
|
|
578
595
|
|
|
596
|
+
// src/util/builders/field-updates.ts
|
|
597
|
+
var import_drizzle_orm3 = require("drizzle-orm");
|
|
598
|
+
var import_graphql4 = require("graphql");
|
|
599
|
+
var NUMERIC_SCALARS = /* @__PURE__ */ new Set([
|
|
600
|
+
import_graphql4.GraphQLInt,
|
|
601
|
+
import_graphql4.GraphQLFloat,
|
|
602
|
+
GraphQLBigIntString,
|
|
603
|
+
GraphQLDecimalString
|
|
604
|
+
]);
|
|
605
|
+
var NON_LIST_ARRAY_COLUMNS = /* @__PURE__ */ new Set(["PgVector", "PgGeometry", "PgBytea"]);
|
|
606
|
+
var kindCache = /* @__PURE__ */ new WeakMap();
|
|
607
|
+
var fieldUpdateKind = (column, columnName, tableName) => {
|
|
608
|
+
const cached = kindCache.get(column);
|
|
609
|
+
if (cached) {
|
|
610
|
+
return cached;
|
|
611
|
+
}
|
|
612
|
+
let kind = "none";
|
|
613
|
+
if (!getColumnScalarOverride(column, true)) {
|
|
614
|
+
const { type } = drizzleColumnToGraphQLType(column, columnName, tableName, true, false, true);
|
|
615
|
+
if (NUMERIC_SCALARS.has(type)) {
|
|
616
|
+
kind = "numeric";
|
|
617
|
+
} else if (type instanceof import_graphql4.GraphQLList && !NON_LIST_ARRAY_COLUMNS.has(column.columnType)) {
|
|
618
|
+
kind = "list";
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
kindCache.set(column, kind);
|
|
622
|
+
return kind;
|
|
623
|
+
};
|
|
624
|
+
var inputCache = /* @__PURE__ */ new Map();
|
|
625
|
+
var namedFieldUpdateInput = (name, fields, description) => {
|
|
626
|
+
const cached = inputCache.get(name);
|
|
627
|
+
if (cached) {
|
|
628
|
+
return cached;
|
|
629
|
+
}
|
|
630
|
+
const input = new import_graphql4.GraphQLInputObjectType({ name, description, fields: fields() });
|
|
631
|
+
inputCache.set(name, input);
|
|
632
|
+
return input;
|
|
633
|
+
};
|
|
634
|
+
var fieldUpdateInputType = (column, columnName, tableName) => {
|
|
635
|
+
const kind = fieldUpdateKind(column, columnName, tableName);
|
|
636
|
+
if (kind === "none") {
|
|
637
|
+
return void 0;
|
|
638
|
+
}
|
|
639
|
+
const { type } = drizzleColumnToGraphQLType(column, columnName, tableName, true, false, true);
|
|
640
|
+
if (kind === "numeric") {
|
|
641
|
+
const scalar = type;
|
|
642
|
+
return namedFieldUpdateInput(
|
|
643
|
+
`${scalar.name}FieldUpdate`,
|
|
644
|
+
() => ({
|
|
645
|
+
set: { type: scalar, description: "Replace the current value with this one" },
|
|
646
|
+
increment: { type: scalar, description: "Add this to the current value (SQL `column + value`)" },
|
|
647
|
+
decrement: { type: scalar, description: "Subtract this from the current value (SQL `column - value`)" },
|
|
648
|
+
multiply: { type: scalar, description: "Multiply the current value by this (SQL `column * value`)" },
|
|
649
|
+
divide: {
|
|
650
|
+
type: scalar,
|
|
651
|
+
description: "Divide the current value by this (SQL `column / value`), rounding as the database does"
|
|
652
|
+
}
|
|
653
|
+
}),
|
|
654
|
+
`An update to a ${scalar.name} column: exactly one of these operations`
|
|
655
|
+
);
|
|
656
|
+
}
|
|
657
|
+
const list = type;
|
|
658
|
+
const element = list.ofType;
|
|
659
|
+
const elementName = element instanceof import_graphql4.GraphQLNonNull ? String(element.ofType) : String(element);
|
|
660
|
+
return namedFieldUpdateInput(
|
|
661
|
+
`${elementName}ListFieldUpdate`,
|
|
662
|
+
() => ({
|
|
663
|
+
set: { type: list, description: "Replace the current array with this one" },
|
|
664
|
+
push: { type: list, description: "Append these elements to the current array" }
|
|
665
|
+
}),
|
|
666
|
+
`An update to a ${elementName} array column: exactly one of these operations`
|
|
667
|
+
);
|
|
668
|
+
};
|
|
669
|
+
var OPERATIONS = ["set", "increment", "decrement", "multiply", "divide", "push"];
|
|
670
|
+
var singleOperation = (value, columnName) => {
|
|
671
|
+
const given = OPERATIONS.filter((operation) => value[operation] !== void 0);
|
|
672
|
+
if (given.length === 1) {
|
|
673
|
+
return [given[0], value[given[0]]];
|
|
674
|
+
}
|
|
675
|
+
throw new import_graphql4.GraphQLError(
|
|
676
|
+
given.length ? `Field '${columnName}' takes exactly one update operation, but ${given.length} were given (${given.join(", ")}).` : `Field '${columnName}' was given no update operation. Pass exactly one of ${OPERATIONS.join(", ")}.`
|
|
677
|
+
);
|
|
678
|
+
};
|
|
679
|
+
var splitFieldUpdateOperations = (values, table, tableName) => {
|
|
680
|
+
const cols = (0, import_drizzle_orm3.getColumns)(table);
|
|
681
|
+
const columns = {};
|
|
682
|
+
const expressions = {};
|
|
683
|
+
for (const [columnName, value] of Object.entries(values)) {
|
|
684
|
+
const column = cols[columnName];
|
|
685
|
+
if (!column || value === null || value === void 0) {
|
|
686
|
+
columns[columnName] = value;
|
|
687
|
+
continue;
|
|
688
|
+
}
|
|
689
|
+
const isOperations = typeof value === "object" && !Array.isArray(value) && !(value instanceof Date);
|
|
690
|
+
if (!isOperations || fieldUpdateKind(column, columnName, tableName) === "none") {
|
|
691
|
+
columns[columnName] = value;
|
|
692
|
+
continue;
|
|
693
|
+
}
|
|
694
|
+
const [operation, operand] = singleOperation(value, columnName);
|
|
695
|
+
if (operation === "set") {
|
|
696
|
+
columns[columnName] = operand;
|
|
697
|
+
continue;
|
|
698
|
+
}
|
|
699
|
+
const param = import_drizzle_orm3.sql.param(remapFromGraphQLCore(operand, column, columnName), column);
|
|
700
|
+
expressions[columnName] = operation === "increment" ? import_drizzle_orm3.sql`${column} + ${param}` : operation === "decrement" ? import_drizzle_orm3.sql`${column} - ${param}` : operation === "multiply" ? import_drizzle_orm3.sql`${column} * ${param}` : operation === "divide" ? import_drizzle_orm3.sql`${column} / ${param}` : (
|
|
701
|
+
// `push`: array concatenation, which is the only dialect-specific operation
|
|
702
|
+
// here — and arrays are a PostgreSQL column type to begin with.
|
|
703
|
+
import_drizzle_orm3.sql`${column} || ${param}`
|
|
704
|
+
);
|
|
705
|
+
}
|
|
706
|
+
return { columns, expressions };
|
|
707
|
+
};
|
|
708
|
+
var remapUpdateInput = (values, table, tableName) => {
|
|
709
|
+
const { columns, expressions } = splitFieldUpdateOperations(values, table, tableName);
|
|
710
|
+
const remapped = remapFromGraphQLSingleInput(columns, table);
|
|
711
|
+
return Object.keys(expressions).length ? { ...remapped, ...expressions } : remapped;
|
|
712
|
+
};
|
|
713
|
+
|
|
579
714
|
// src/util/builders/common.ts
|
|
580
715
|
var rqbCrashTypes = ["SQLiteBigInt", "SQLiteBlobJson", "SQLiteBlobBuffer"];
|
|
581
716
|
var resolveTypeName = (name, typeNameMapper) => {
|
|
@@ -638,9 +773,9 @@ var extractRelationJoinColumns = (relEntry, parentTable, targetTable) => {
|
|
|
638
773
|
}
|
|
639
774
|
const sourceCol = sourceColumns[0];
|
|
640
775
|
const targetCol = targetColumns[0];
|
|
641
|
-
const parentCols = (0,
|
|
776
|
+
const parentCols = (0, import_drizzle_orm4.getColumns)(parentTable);
|
|
642
777
|
const localColPropName = Object.entries(parentCols).find(([, c]) => c === sourceCol)?.[0];
|
|
643
|
-
const targetCols = (0,
|
|
778
|
+
const targetCols = (0, import_drizzle_orm4.getColumns)(targetTable);
|
|
644
779
|
const foreignColPropName = Object.entries(targetCols).find(([, c]) => c === targetCol)?.[0];
|
|
645
780
|
if (!localColPropName || !foreignColPropName) {
|
|
646
781
|
return void 0;
|
|
@@ -722,7 +857,7 @@ var collectRootMutationKeys = (selectionSet, fragments, variables, known, keys,
|
|
|
722
857
|
}
|
|
723
858
|
return true;
|
|
724
859
|
};
|
|
725
|
-
var abortedBatchError = () => new
|
|
860
|
+
var abortedBatchError = () => new import_graphql5.GraphQLError(
|
|
726
861
|
"Drizzle-GraphQL Error: Mutation was not executed because an earlier mutation in the same request failed and the shared transaction was rolled back."
|
|
727
862
|
);
|
|
728
863
|
var openSharedTx = (db, context, txCtx, stateKey, expected) => {
|
|
@@ -780,7 +915,7 @@ var openSharedTx = (db, context, txCtx, stateKey, expected) => {
|
|
|
780
915
|
}
|
|
781
916
|
timer = setTimeout(() => {
|
|
782
917
|
state.abort(
|
|
783
|
-
new
|
|
918
|
+
new import_graphql5.GraphQLError(
|
|
784
919
|
`Drizzle-GraphQL Error: Shared mutation transaction timed out after ${txCtx.timeoutMs}ms waiting for the remaining mutation fields; rolling back.`
|
|
785
920
|
)
|
|
786
921
|
);
|
|
@@ -862,27 +997,27 @@ var runMutation = async (db, context, info, txCtx, body) => {
|
|
|
862
997
|
return runOnSharedTx(state, body);
|
|
863
998
|
};
|
|
864
999
|
var batchedPaginatedRelationQuery = async (db, targetTable, foreignCol, whereCondition, orderByArg, limit, offset, pkNames, orderCtx) => {
|
|
865
|
-
const cols = (0,
|
|
1000
|
+
const cols = (0, import_drizzle_orm4.getColumns)(targetTable);
|
|
866
1001
|
const orderExprs = [
|
|
867
1002
|
...orderByArg ? extractOrderBy(targetTable, orderByArg, orderCtx) : [],
|
|
868
1003
|
...primaryKeyOrderExprs(targetTable, pkNames)
|
|
869
1004
|
];
|
|
870
|
-
const orderClause = orderExprs.length ?
|
|
1005
|
+
const orderClause = orderExprs.length ? import_drizzle_orm4.sql` order by ${import_drizzle_orm4.sql.join(orderExprs, import_drizzle_orm4.sql`, `)}` : import_drizzle_orm4.sql``;
|
|
871
1006
|
const RN = "__drizzle_graphql_rn";
|
|
872
|
-
const rowNumber =
|
|
1007
|
+
const rowNumber = import_drizzle_orm4.sql`row_number() over (partition by ${foreignCol}${orderClause})`.as(RN);
|
|
873
1008
|
const sub = db.select({ ...cols, [RN]: rowNumber }).from(targetTable).where(whereCondition).as("__paginated");
|
|
874
1009
|
const lower = offset ?? 0;
|
|
875
|
-
const windowConds = [(0,
|
|
1010
|
+
const windowConds = [(0, import_drizzle_orm4.gt)(sub[RN], lower)];
|
|
876
1011
|
if (limit != null) {
|
|
877
|
-
windowConds.push((0,
|
|
1012
|
+
windowConds.push((0, import_drizzle_orm4.lte)(sub[RN], lower + limit));
|
|
878
1013
|
}
|
|
879
|
-
const rows = await db.select().from(sub).where((0,
|
|
1014
|
+
const rows = await db.select().from(sub).where((0, import_drizzle_orm4.and)(...windowConds)).orderBy(sub[RN]);
|
|
880
1015
|
for (const row of rows) {
|
|
881
1016
|
delete row[RN];
|
|
882
1017
|
}
|
|
883
1018
|
return rows;
|
|
884
1019
|
};
|
|
885
|
-
var createRelationResolverFactory = (db, tables, filterCtx) => ({ tableName, relationName, relEntry, isOne }) => {
|
|
1020
|
+
var createRelationResolverFactory = (db, tables, nullOrdering, filterCtx) => ({ tableName, relationName, relEntry, isOne }) => {
|
|
886
1021
|
const parentTable = tables[tableName];
|
|
887
1022
|
const targetTableName = relEntry.targetTableName;
|
|
888
1023
|
const targetTable = tables[targetTableName];
|
|
@@ -895,7 +1030,7 @@ var createRelationResolverFactory = (db, tables, filterCtx) => ({ tableName, rel
|
|
|
895
1030
|
}
|
|
896
1031
|
const { localColPropName, foreignCol, foreignColPropName } = joinCols;
|
|
897
1032
|
const targetPkNames = relEntry.targetPkNames ?? [];
|
|
898
|
-
return async (parent, args, context) => {
|
|
1033
|
+
return async (parent, args, context, info) => {
|
|
899
1034
|
if (parent[relationName] !== void 0) {
|
|
900
1035
|
return parent[relationName];
|
|
901
1036
|
}
|
|
@@ -903,21 +1038,65 @@ var createRelationResolverFactory = (db, tables, filterCtx) => ({ tableName, rel
|
|
|
903
1038
|
if (localValue == null) {
|
|
904
1039
|
return isOne ? null : [];
|
|
905
1040
|
}
|
|
906
|
-
const { where: whereArg, orderBy: orderByArg, limit, offset } = args ?? {};
|
|
1041
|
+
const { where: whereArg, orderBy: orderByArg, limit, offset, after } = args ?? {};
|
|
1042
|
+
const distinct = (args ?? {}).distinct?.length ? (args ?? {}).distinct : void 0;
|
|
1043
|
+
const cursorSelected = !isOne && !!info && selectsCursorField(info, targetTable);
|
|
1044
|
+
let cursorEntries;
|
|
1045
|
+
if (!isOne && (after != null || cursorSelected)) {
|
|
1046
|
+
if (after != null && distinct) {
|
|
1047
|
+
throw new import_graphql5.GraphQLError("'after' cannot be combined with 'distinct'.");
|
|
1048
|
+
}
|
|
1049
|
+
if (orderByHasRelationEntry(orderByArg)) {
|
|
1050
|
+
if (after != null) {
|
|
1051
|
+
throw new import_graphql5.GraphQLError(
|
|
1052
|
+
"'after' cannot be combined with an orderBy that orders through a relation \u2014 a related row's value cannot be encoded into a cursor."
|
|
1053
|
+
);
|
|
1054
|
+
}
|
|
1055
|
+
} else if (!targetPkNames.length) {
|
|
1056
|
+
if (after != null) {
|
|
1057
|
+
throw new import_graphql5.GraphQLError(
|
|
1058
|
+
`Table ${targetTableName} has no primary key, so cursor pagination cannot be used on it.`
|
|
1059
|
+
);
|
|
1060
|
+
}
|
|
1061
|
+
} else {
|
|
1062
|
+
cursorEntries = cursorOrderingEntries(orderByArg, targetPkNames);
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
const cursorValues = after != null && cursorEntries ? decodeCursor(after, cursorEntries) : void 0;
|
|
907
1066
|
const argsKey = JSON.stringify({
|
|
908
1067
|
where: whereArg ?? null,
|
|
909
1068
|
orderBy: orderByArg ?? null,
|
|
910
1069
|
limit: limit ?? null,
|
|
911
|
-
offset: offset ?? null
|
|
1070
|
+
offset: offset ?? null,
|
|
1071
|
+
after: after ?? null,
|
|
1072
|
+
distinct: distinct ?? null,
|
|
1073
|
+
cursor: cursorEntries ? 1 : 0
|
|
912
1074
|
});
|
|
913
1075
|
const loaderKey = `${tableName}::${relationName}::${argsKey}`;
|
|
914
1076
|
const loader = getOrCreateLoader(context, loaderKey, async (parentIds) => {
|
|
915
1077
|
const executor = resolveExecutor(db, context);
|
|
916
1078
|
const uniqueIds = [...new Set(parentIds)];
|
|
917
|
-
|
|
918
|
-
(0,
|
|
919
|
-
whereArg ? extractFilters(targetTable, targetTableName, whereArg, relationFilterCtx(filterCtx, targetTableName)) : void 0
|
|
1079
|
+
let whereCondition = (0, import_drizzle_orm4.and)(
|
|
1080
|
+
(0, import_drizzle_orm4.inArray)(foreignCol, uniqueIds),
|
|
1081
|
+
whereArg ? extractFilters(targetTable, targetTableName, whereArg, relationFilterCtx(filterCtx, targetTableName)) : void 0,
|
|
1082
|
+
cursorValues ? buildCursorCondition(targetTable, cursorEntries, cursorValues, nullOrdering) : void 0
|
|
920
1083
|
);
|
|
1084
|
+
if (distinct) {
|
|
1085
|
+
const keys = await selectDistinctKeys({
|
|
1086
|
+
db: executor,
|
|
1087
|
+
table: targetTable,
|
|
1088
|
+
tableName: targetTableName,
|
|
1089
|
+
distinct,
|
|
1090
|
+
pkNames: targetPkNames,
|
|
1091
|
+
where: whereCondition,
|
|
1092
|
+
orderBy: orderByArg,
|
|
1093
|
+
partitionBy: [foreignCol]
|
|
1094
|
+
});
|
|
1095
|
+
if (!keys.length) {
|
|
1096
|
+
return parentIds.map(() => isOne ? null : []);
|
|
1097
|
+
}
|
|
1098
|
+
whereCondition = (0, import_drizzle_orm4.and)(whereCondition, primaryKeyRestriction(targetTable, targetPkNames, keys));
|
|
1099
|
+
}
|
|
921
1100
|
let rows;
|
|
922
1101
|
if (limit != null || offset != null) {
|
|
923
1102
|
rows = await batchedPaginatedRelationQuery(
|
|
@@ -933,11 +1112,15 @@ var createRelationResolverFactory = (db, tables, filterCtx) => ({ tableName, rel
|
|
|
933
1112
|
);
|
|
934
1113
|
} else {
|
|
935
1114
|
let q = executor.select().from(targetTable).where(whereCondition);
|
|
936
|
-
|
|
937
|
-
|
|
1115
|
+
const orderExprs = cursorEntries ? cursorOrderExprs(targetTable, cursorEntries) : orderByArg ? extractOrderBy(targetTable, orderByArg, relationFilterCtx(filterCtx, targetTableName)) : [];
|
|
1116
|
+
if (orderExprs.length) {
|
|
1117
|
+
q = q.orderBy(...orderExprs);
|
|
938
1118
|
}
|
|
939
1119
|
rows = await q;
|
|
940
1120
|
}
|
|
1121
|
+
if (cursorEntries) {
|
|
1122
|
+
attachRowCursors(rows, cursorEntries);
|
|
1123
|
+
}
|
|
941
1124
|
if (isOne) {
|
|
942
1125
|
const byKey = new Map(rows.map((row) => [String(row[foreignColPropName]), row]));
|
|
943
1126
|
remapToGraphQLArrayOutput(rows, targetTableName, targetTable);
|
|
@@ -953,6 +1136,22 @@ var createRelationResolverFactory = (db, tables, filterCtx) => ({ tableName, rel
|
|
|
953
1136
|
return loader.load(localValue);
|
|
954
1137
|
};
|
|
955
1138
|
};
|
|
1139
|
+
var columnDocs = (docs, column, tableName, columnName) => {
|
|
1140
|
+
const description = docs.describeColumn?.(column, { tableName, columnName });
|
|
1141
|
+
const deprecationReason = docs.deprecateColumn?.(column, { tableName, columnName });
|
|
1142
|
+
return {
|
|
1143
|
+
...description !== void 0 ? { description } : {},
|
|
1144
|
+
...deprecationReason !== void 0 ? { deprecationReason } : {}
|
|
1145
|
+
};
|
|
1146
|
+
};
|
|
1147
|
+
var inputFieldDocs = (docs, column, tableName, columnName, fieldType) => {
|
|
1148
|
+
const resolved = columnDocs(docs, column, tableName, columnName);
|
|
1149
|
+
if (resolved.deprecationReason !== void 0 && fieldType instanceof import_graphql5.GraphQLNonNull) {
|
|
1150
|
+
const { deprecationReason: _dropped, ...rest } = resolved;
|
|
1151
|
+
return rest;
|
|
1152
|
+
}
|
|
1153
|
+
return resolved;
|
|
1154
|
+
};
|
|
956
1155
|
var listFieldComplexity = (options) => ({ args, childComplexity }) => {
|
|
957
1156
|
const limit = args["limit"];
|
|
958
1157
|
const rows = typeof limit === "number" && limit > 0 ? limit : options.defaultListSize;
|
|
@@ -960,18 +1159,21 @@ var listFieldComplexity = (options) => ({ args, childComplexity }) => {
|
|
|
960
1159
|
};
|
|
961
1160
|
var aggregateFieldComplexity = (options) => ({ childComplexity }) => options.aggregateCost + childComplexity;
|
|
962
1161
|
var AGGREGATE_FIELD_SUFFIX = "Aggregate";
|
|
963
|
-
var
|
|
964
|
-
|
|
965
|
-
|
|
1162
|
+
var relationJoinColumns = (tree, table, selectionCtx) => {
|
|
1163
|
+
if (!selectionCtx) {
|
|
1164
|
+
return [];
|
|
1165
|
+
}
|
|
1166
|
+
const relations = (selectionCtx.allRelations ?? selectionCtx.relationMap)[selectionCtx.tableName] ?? selectionCtx.relationMap[selectionCtx.tableName];
|
|
1167
|
+
if (!relations) {
|
|
966
1168
|
return [];
|
|
967
1169
|
}
|
|
968
|
-
const tableColumns = (0,
|
|
1170
|
+
const tableColumns = (0, import_drizzle_orm4.getColumns)(table);
|
|
969
1171
|
const needed = [];
|
|
970
1172
|
for (const fieldData of Object.values(tree)) {
|
|
971
|
-
if (tableColumns[fieldData.name]
|
|
1173
|
+
if (tableColumns[fieldData.name]) {
|
|
972
1174
|
continue;
|
|
973
1175
|
}
|
|
974
|
-
const relEntry = relations[fieldData.name.slice(0, -AGGREGATE_FIELD_SUFFIX.length)];
|
|
1176
|
+
const relEntry = fieldData.name.endsWith(AGGREGATE_FIELD_SUFFIX) ? relations[fieldData.name.slice(0, -AGGREGATE_FIELD_SUFFIX.length)] : relations[fieldData.name];
|
|
975
1177
|
const targetTable = relEntry ? selectionCtx.tables[relEntry.targetTableName] : void 0;
|
|
976
1178
|
if (!relEntry || !targetTable) {
|
|
977
1179
|
continue;
|
|
@@ -984,7 +1186,7 @@ var relationAggregateJoinColumns = (tree, table, selectionCtx) => {
|
|
|
984
1186
|
return needed;
|
|
985
1187
|
};
|
|
986
1188
|
var extractSelectedColumnsFromTree = (tree, table, selectionCtx) => {
|
|
987
|
-
const tableColumns = (0,
|
|
1189
|
+
const tableColumns = (0, import_drizzle_orm4.getColumns)(table);
|
|
988
1190
|
const treeEntries = Object.entries(tree);
|
|
989
1191
|
const selectedColumns = [];
|
|
990
1192
|
for (const [_fieldName, fieldData] of treeEntries) {
|
|
@@ -993,7 +1195,7 @@ var extractSelectedColumnsFromTree = (tree, table, selectionCtx) => {
|
|
|
993
1195
|
}
|
|
994
1196
|
selectedColumns.push([fieldData.name, true]);
|
|
995
1197
|
}
|
|
996
|
-
for (const columnName of
|
|
1198
|
+
for (const columnName of relationJoinColumns(tree, table, selectionCtx)) {
|
|
997
1199
|
selectedColumns.push([columnName, true]);
|
|
998
1200
|
}
|
|
999
1201
|
if (!selectedColumns.length) {
|
|
@@ -1004,7 +1206,7 @@ var extractSelectedColumnsFromTree = (tree, table, selectionCtx) => {
|
|
|
1004
1206
|
return Object.fromEntries(selectedColumns);
|
|
1005
1207
|
};
|
|
1006
1208
|
var extractSelectedColumnsFromTreeSQLFormat = (tree, table, selectionCtx) => {
|
|
1007
|
-
const tableColumns = (0,
|
|
1209
|
+
const tableColumns = (0, import_drizzle_orm4.getColumns)(table);
|
|
1008
1210
|
const treeEntries = Object.entries(tree);
|
|
1009
1211
|
const selectedColumns = [];
|
|
1010
1212
|
for (const [_fieldName, fieldData] of treeEntries) {
|
|
@@ -1013,7 +1215,7 @@ var extractSelectedColumnsFromTreeSQLFormat = (tree, table, selectionCtx) => {
|
|
|
1013
1215
|
}
|
|
1014
1216
|
selectedColumns.push([fieldData.name, tableColumns[fieldData.name]]);
|
|
1015
1217
|
}
|
|
1016
|
-
for (const columnName of
|
|
1218
|
+
for (const columnName of relationJoinColumns(tree, table, selectionCtx)) {
|
|
1017
1219
|
selectedColumns.push([columnName, tableColumns[columnName]]);
|
|
1018
1220
|
}
|
|
1019
1221
|
if (!selectedColumns.length) {
|
|
@@ -1023,7 +1225,7 @@ var extractSelectedColumnsFromTreeSQLFormat = (tree, table, selectionCtx) => {
|
|
|
1023
1225
|
}
|
|
1024
1226
|
return Object.fromEntries(selectedColumns);
|
|
1025
1227
|
};
|
|
1026
|
-
var orderNulls = new
|
|
1228
|
+
var orderNulls = new import_graphql5.GraphQLEnumType({
|
|
1027
1229
|
name: "OrderNulls",
|
|
1028
1230
|
description: "Where NULL values sort relative to non-NULL values",
|
|
1029
1231
|
values: {
|
|
@@ -1037,12 +1239,12 @@ var orderNulls = new import_graphql4.GraphQLEnumType({
|
|
|
1037
1239
|
}
|
|
1038
1240
|
}
|
|
1039
1241
|
});
|
|
1040
|
-
var innerOrder = new
|
|
1242
|
+
var innerOrder = new import_graphql5.GraphQLInputObjectType({
|
|
1041
1243
|
name: "InnerOrder",
|
|
1042
1244
|
fields: {
|
|
1043
1245
|
direction: {
|
|
1044
|
-
type: new
|
|
1045
|
-
new
|
|
1246
|
+
type: new import_graphql5.GraphQLNonNull(
|
|
1247
|
+
new import_graphql5.GraphQLEnumType({
|
|
1046
1248
|
name: "OrderDirection",
|
|
1047
1249
|
description: "Order by direction",
|
|
1048
1250
|
values: {
|
|
@@ -1059,7 +1261,7 @@ var innerOrder = new import_graphql4.GraphQLInputObjectType({
|
|
|
1059
1261
|
)
|
|
1060
1262
|
},
|
|
1061
1263
|
priority: {
|
|
1062
|
-
type: new
|
|
1264
|
+
type: new import_graphql5.GraphQLNonNull(import_graphql5.GraphQLInt),
|
|
1063
1265
|
description: "Priority of current field"
|
|
1064
1266
|
},
|
|
1065
1267
|
nulls: {
|
|
@@ -1085,9 +1287,9 @@ var resolveGenericFilterDescriptor = (column, columnGraphQLType) => {
|
|
|
1085
1287
|
if (columnGraphQLType.type === import_graphql_scalars.GraphQLJSON) {
|
|
1086
1288
|
return { name: "JSON", kind: "json" };
|
|
1087
1289
|
}
|
|
1088
|
-
if (columnGraphQLType.type instanceof
|
|
1290
|
+
if (columnGraphQLType.type instanceof import_graphql5.GraphQLList) {
|
|
1089
1291
|
let element = columnGraphQLType.type.ofType;
|
|
1090
|
-
if (element instanceof
|
|
1292
|
+
if (element instanceof import_graphql5.GraphQLNonNull) {
|
|
1091
1293
|
element = element.ofType;
|
|
1092
1294
|
}
|
|
1093
1295
|
return { name: `${element.name}Array`, kind: "array" };
|
|
@@ -1095,10 +1297,10 @@ var resolveGenericFilterDescriptor = (column, columnGraphQLType) => {
|
|
|
1095
1297
|
if (columnGraphQLType.type === import_graphql_scalars.GraphQLUUID) {
|
|
1096
1298
|
return { name: "Id", kind: "scalar" };
|
|
1097
1299
|
}
|
|
1098
|
-
if (columnGraphQLType.type ===
|
|
1300
|
+
if (columnGraphQLType.type === import_graphql5.GraphQLBoolean) {
|
|
1099
1301
|
return { name: "Boolean", kind: "scalar" };
|
|
1100
1302
|
}
|
|
1101
|
-
if (columnGraphQLType.type instanceof
|
|
1303
|
+
if (columnGraphQLType.type instanceof import_graphql5.GraphQLEnumType) {
|
|
1102
1304
|
return { name: columnGraphQLType.type.name, kind: "scalar" };
|
|
1103
1305
|
}
|
|
1104
1306
|
if (columnGraphQLType.type === GraphQLBigIntString) {
|
|
@@ -1111,10 +1313,10 @@ var resolveGenericFilterDescriptor = (column, columnGraphQLType) => {
|
|
|
1111
1313
|
if (ct === "PgTimestamp" || ct === "PgTimestampString" || ct === "PgDate") {
|
|
1112
1314
|
return { name: "DateTime", kind: "scalar" };
|
|
1113
1315
|
}
|
|
1114
|
-
if (columnGraphQLType.type ===
|
|
1316
|
+
if (columnGraphQLType.type === import_graphql5.GraphQLInt) {
|
|
1115
1317
|
return { name: "Int", kind: "scalar" };
|
|
1116
1318
|
}
|
|
1117
|
-
if (columnGraphQLType.type ===
|
|
1319
|
+
if (columnGraphQLType.type === import_graphql5.GraphQLFloat) {
|
|
1118
1320
|
return { name: "Float", kind: "scalar" };
|
|
1119
1321
|
}
|
|
1120
1322
|
return { name: "String", kind: "scalar" };
|
|
@@ -1130,35 +1332,37 @@ var jsonFilterFields = (column, colType) => {
|
|
|
1130
1332
|
description: "Value structurally contains this JSON (Postgres `@>` / MySQL JSON_CONTAINS)"
|
|
1131
1333
|
}
|
|
1132
1334
|
} : {},
|
|
1133
|
-
isNull: { type:
|
|
1134
|
-
isNotNull: { type:
|
|
1335
|
+
isNull: { type: import_graphql5.GraphQLBoolean },
|
|
1336
|
+
isNotNull: { type: import_graphql5.GraphQLBoolean }
|
|
1135
1337
|
};
|
|
1136
1338
|
};
|
|
1137
|
-
var
|
|
1339
|
+
var IN_ARRAY_DESCRIPTION = "Matches any one of these values (SQL `IN`)";
|
|
1340
|
+
var NOT_IN_ARRAY_DESCRIPTION = "Matches none of these values (SQL `NOT IN`)";
|
|
1341
|
+
var arrayFilterFields = (colType, colArr) => {
|
|
1138
1342
|
let element = colType.ofType;
|
|
1139
|
-
if (element instanceof
|
|
1343
|
+
if (element instanceof import_graphql5.GraphQLNonNull) {
|
|
1140
1344
|
element = element.ofType;
|
|
1141
1345
|
}
|
|
1142
|
-
const elementList = new
|
|
1346
|
+
const elementList = new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(element));
|
|
1143
1347
|
return {
|
|
1144
|
-
eq: { type: colType, description:
|
|
1145
|
-
ne: { type: colType, description:
|
|
1348
|
+
eq: { type: colType, description: "The whole array equals this array" },
|
|
1349
|
+
ne: { type: colType, description: "The whole array differs from this array" },
|
|
1146
1350
|
has: { type: element, description: "Array contains this element" },
|
|
1147
1351
|
hasSome: { type: elementList, description: "Array contains at least one of these elements (overlap, `&&`)" },
|
|
1148
1352
|
hasEvery: { type: elementList, description: "Array contains every one of these elements (containment, `@>`)" },
|
|
1149
|
-
isEmpty: { type:
|
|
1150
|
-
inArray: { type: colArr, description:
|
|
1151
|
-
notInArray: { type: colArr, description:
|
|
1152
|
-
isNull: { type:
|
|
1153
|
-
isNotNull: { type:
|
|
1353
|
+
isEmpty: { type: import_graphql5.GraphQLBoolean, description: "When true, matches arrays with no elements" },
|
|
1354
|
+
inArray: { type: colArr, description: IN_ARRAY_DESCRIPTION },
|
|
1355
|
+
notInArray: { type: colArr, description: NOT_IN_ARRAY_DESCRIPTION },
|
|
1356
|
+
isNull: { type: import_graphql5.GraphQLBoolean },
|
|
1357
|
+
isNotNull: { type: import_graphql5.GraphQLBoolean }
|
|
1154
1358
|
};
|
|
1155
1359
|
};
|
|
1156
1360
|
var FILTERS_WITHOUT_STRING_OPS = /* @__PURE__ */ new Set(["Id", "Int", "Float", "BigInt", "Decimal"]);
|
|
1157
1361
|
var BUILTIN_FILTER_SCALARS = /* @__PURE__ */ new Set([
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1362
|
+
import_graphql5.GraphQLString,
|
|
1363
|
+
import_graphql5.GraphQLInt,
|
|
1364
|
+
import_graphql5.GraphQLFloat,
|
|
1365
|
+
import_graphql5.GraphQLBoolean,
|
|
1162
1366
|
GraphQLBigIntString,
|
|
1163
1367
|
GraphQLDecimalString,
|
|
1164
1368
|
import_graphql_scalars.GraphQLUUID,
|
|
@@ -1184,63 +1388,62 @@ var generateColumnFilterValues = (column, tableName, columnName, cacheCtx) => {
|
|
|
1184
1388
|
return cached;
|
|
1185
1389
|
}
|
|
1186
1390
|
const colType = columnGraphQLType.type;
|
|
1187
|
-
const
|
|
1188
|
-
const colArr = new import_graphql4.GraphQLList(new import_graphql4.GraphQLNonNull(colType));
|
|
1391
|
+
const colArr = new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(colType));
|
|
1189
1392
|
const customOverrideFilter = inputOverride !== void 0 && !BUILTIN_FILTER_SCALARS.has(inputOverride);
|
|
1190
|
-
const underlying = (0,
|
|
1393
|
+
const underlying = (0, import_drizzle_orm4.extractExtendedColumnType)(column);
|
|
1191
1394
|
const omitStringOps = customOverrideFilter ? underlying.type !== "string" || underlying.constraint === "numeric" : FILTERS_WITHOUT_STRING_OPS.has(genericName);
|
|
1192
|
-
const baseFields = kind === "json" ? jsonFilterFields(column, colType) : kind === "array" ? arrayFilterFields(colType, colArr
|
|
1193
|
-
eq: { type: colType, description:
|
|
1194
|
-
ne: { type: colType, description:
|
|
1195
|
-
lt: { type: colType, description:
|
|
1196
|
-
lte: { type: colType, description:
|
|
1197
|
-
gt: { type: colType, description:
|
|
1198
|
-
gte: { type: colType, description:
|
|
1395
|
+
const baseFields = kind === "json" ? jsonFilterFields(column, colType) : kind === "array" ? arrayFilterFields(colType, colArr) : {
|
|
1396
|
+
eq: { type: colType, description: "Equal to" },
|
|
1397
|
+
ne: { type: colType, description: "Not equal to" },
|
|
1398
|
+
lt: { type: colType, description: "Less than" },
|
|
1399
|
+
lte: { type: colType, description: "Less than or equal to" },
|
|
1400
|
+
gt: { type: colType, description: "Greater than" },
|
|
1401
|
+
gte: { type: colType, description: "Greater than or equal to" },
|
|
1199
1402
|
...omitStringOps ? {} : {
|
|
1200
|
-
like: { type:
|
|
1201
|
-
notLike: { type:
|
|
1202
|
-
ilike: { type:
|
|
1203
|
-
notIlike: { type:
|
|
1403
|
+
like: { type: import_graphql5.GraphQLString },
|
|
1404
|
+
notLike: { type: import_graphql5.GraphQLString },
|
|
1405
|
+
ilike: { type: import_graphql5.GraphQLString },
|
|
1406
|
+
notIlike: { type: import_graphql5.GraphQLString },
|
|
1204
1407
|
startsWith: {
|
|
1205
|
-
type:
|
|
1408
|
+
type: import_graphql5.GraphQLString,
|
|
1206
1409
|
description: "Matches values starting with the given string. `%`, `_` and `\\` are matched literally."
|
|
1207
1410
|
},
|
|
1208
1411
|
endsWith: {
|
|
1209
|
-
type:
|
|
1412
|
+
type: import_graphql5.GraphQLString,
|
|
1210
1413
|
description: "Matches values ending with the given string. `%`, `_` and `\\` are matched literally."
|
|
1211
1414
|
},
|
|
1212
1415
|
contains: {
|
|
1213
|
-
type:
|
|
1416
|
+
type: import_graphql5.GraphQLString,
|
|
1214
1417
|
description: "Matches values containing the given string. `%`, `_` and `\\` are matched literally."
|
|
1215
1418
|
},
|
|
1216
1419
|
iStartsWith: {
|
|
1217
|
-
type:
|
|
1420
|
+
type: import_graphql5.GraphQLString,
|
|
1218
1421
|
description: "Case-insensitive `startsWith`."
|
|
1219
1422
|
},
|
|
1220
1423
|
iEndsWith: {
|
|
1221
|
-
type:
|
|
1424
|
+
type: import_graphql5.GraphQLString,
|
|
1222
1425
|
description: "Case-insensitive `endsWith`."
|
|
1223
1426
|
},
|
|
1224
1427
|
iContains: {
|
|
1225
|
-
type:
|
|
1428
|
+
type: import_graphql5.GraphQLString,
|
|
1226
1429
|
description: "Case-insensitive `contains`."
|
|
1227
1430
|
}
|
|
1228
1431
|
},
|
|
1229
|
-
inArray: { type: colArr, description:
|
|
1230
|
-
notInArray: { type: colArr, description:
|
|
1231
|
-
isNull: { type:
|
|
1232
|
-
isNotNull: { type:
|
|
1432
|
+
inArray: { type: colArr, description: IN_ARRAY_DESCRIPTION },
|
|
1433
|
+
notInArray: { type: colArr, description: NOT_IN_ARRAY_DESCRIPTION },
|
|
1434
|
+
isNull: { type: import_graphql5.GraphQLBoolean, description: "When true, matches rows where the column is NULL" },
|
|
1435
|
+
isNotNull: { type: import_graphql5.GraphQLBoolean, description: "When true, matches rows where the column is not NULL" }
|
|
1233
1436
|
};
|
|
1234
|
-
const mainType = new
|
|
1437
|
+
const mainType = new import_graphql5.GraphQLInputObjectType({
|
|
1235
1438
|
name: `${genericName}Filter`,
|
|
1236
1439
|
fields: () => ({
|
|
1237
1440
|
...baseFields,
|
|
1238
1441
|
OR: {
|
|
1239
|
-
type: new
|
|
1442
|
+
type: new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(mainType)),
|
|
1240
1443
|
description: "At least one branch matches; ANDed with any sibling operators"
|
|
1241
1444
|
},
|
|
1242
1445
|
AND: {
|
|
1243
|
-
type: new
|
|
1446
|
+
type: new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(mainType)),
|
|
1244
1447
|
description: "Every branch matches"
|
|
1245
1448
|
},
|
|
1246
1449
|
NOT: {
|
|
@@ -1259,7 +1462,7 @@ var generateTableOrderCached = (table) => {
|
|
|
1259
1462
|
}
|
|
1260
1463
|
let remapped = {};
|
|
1261
1464
|
try {
|
|
1262
|
-
const columns = (0,
|
|
1465
|
+
const columns = (0, import_drizzle_orm4.getColumns)(table);
|
|
1263
1466
|
const columnEntries = Object.entries(columns);
|
|
1264
1467
|
remapped = Object.fromEntries(
|
|
1265
1468
|
columnEntries.map(([columnName, _columnDescription]) => [columnName, { type: innerOrder }])
|
|
@@ -1273,13 +1476,17 @@ var generateTableFilterValuesCached = (table, tableName, cacheCtx) => {
|
|
|
1273
1476
|
if (cacheCtx.filterFieldCache.has(table)) {
|
|
1274
1477
|
return cacheCtx.filterFieldCache.get(table);
|
|
1275
1478
|
}
|
|
1276
|
-
const columns = (0,
|
|
1479
|
+
const columns = (0, import_drizzle_orm4.getColumns)(table);
|
|
1277
1480
|
const columnEntries = Object.entries(columns);
|
|
1278
1481
|
const remapped = Object.fromEntries(
|
|
1279
|
-
columnEntries.map(([columnName,
|
|
1482
|
+
columnEntries.map(([columnName, column]) => [
|
|
1280
1483
|
columnName,
|
|
1281
1484
|
{
|
|
1282
|
-
type: generateColumnFilterValues(
|
|
1485
|
+
type: generateColumnFilterValues(column, tableName, columnName, cacheCtx),
|
|
1486
|
+
// A filter field is the same column, so it carries the same documentation. Deprecation
|
|
1487
|
+
// is not propagated: filtering on a deprecated column is how a caller finds the rows
|
|
1488
|
+
// that still use it.
|
|
1489
|
+
...cacheCtx.docs.describeColumn ? { description: cacheCtx.docs.describeColumn(column, { tableName, columnName }) } : {}
|
|
1283
1490
|
}
|
|
1284
1491
|
])
|
|
1285
1492
|
);
|
|
@@ -1290,17 +1497,20 @@ var generateTableSelectTypeFieldsCached = (table, tableName, cacheCtx) => {
|
|
|
1290
1497
|
if (cacheCtx.selectFieldCache.has(table)) {
|
|
1291
1498
|
return cacheCtx.selectFieldCache.get(table);
|
|
1292
1499
|
}
|
|
1293
|
-
const columns = (0,
|
|
1500
|
+
const columns = (0, import_drizzle_orm4.getColumns)(table);
|
|
1294
1501
|
const columnEntries = Object.entries(columns);
|
|
1295
1502
|
const remapped = Object.fromEntries(
|
|
1296
|
-
columnEntries.map(([columnName,
|
|
1503
|
+
columnEntries.map(([columnName, column]) => [
|
|
1297
1504
|
columnName,
|
|
1298
|
-
|
|
1505
|
+
{
|
|
1506
|
+
...drizzleColumnToGraphQLType(column, columnName, tableName),
|
|
1507
|
+
...columnDocs(cacheCtx.docs, column, tableName, columnName)
|
|
1508
|
+
}
|
|
1299
1509
|
])
|
|
1300
1510
|
);
|
|
1301
1511
|
if (!remapped[CURSOR_FIELD_NAME]) {
|
|
1302
1512
|
remapped[CURSOR_FIELD_NAME] = {
|
|
1303
|
-
type:
|
|
1513
|
+
type: import_graphql5.GraphQLString,
|
|
1304
1514
|
description: "Opaque cursor of this row's position in the query's ordering. Pass it as `after` to resume from here. Only set on rows returned by a list query.",
|
|
1305
1515
|
resolve: rowCursorResolver
|
|
1306
1516
|
};
|
|
@@ -1321,7 +1531,7 @@ var generateRelationOrderFields = (tableName, cacheCtx, typeNameMapper, columnFi
|
|
|
1321
1531
|
}
|
|
1322
1532
|
const targetTable = tables[relEntry.targetTableName];
|
|
1323
1533
|
const relation = relEntry.relation ?? relEntry;
|
|
1324
|
-
if (!targetTable || !(0,
|
|
1534
|
+
if (!targetTable || !(0, import_drizzle_orm4.is)(relation, import_drizzle_orm4.One) || !isFilterableRelation(relation)) {
|
|
1325
1535
|
continue;
|
|
1326
1536
|
}
|
|
1327
1537
|
fields[relationName] = {
|
|
@@ -1342,7 +1552,7 @@ var generateTableOrderTypeCached = (table, tableName, typeNameMapper, cacheCtx,
|
|
|
1342
1552
|
if (cacheCtx.orderTypeCache.has(table)) {
|
|
1343
1553
|
return cacheCtx.orderTypeCache.get(table);
|
|
1344
1554
|
}
|
|
1345
|
-
const order = new
|
|
1555
|
+
const order = new import_graphql5.GraphQLInputObjectType({
|
|
1346
1556
|
name: `${resolveTypeName(tableName, typeNameMapper)}OrderBy`,
|
|
1347
1557
|
fields: () => {
|
|
1348
1558
|
const orderColumns = generateTableOrderCached(table);
|
|
@@ -1360,7 +1570,7 @@ var generateListRelationFilterCached = (targetTable, targetTableName, cacheCtx,
|
|
|
1360
1570
|
if (cached) {
|
|
1361
1571
|
return cached;
|
|
1362
1572
|
}
|
|
1363
|
-
const listFilter = new
|
|
1573
|
+
const listFilter = new import_graphql5.GraphQLInputObjectType({
|
|
1364
1574
|
name: `${resolveTypeName(targetTableName, typeNameMapper)}ListRelationFilter`,
|
|
1365
1575
|
fields: () => {
|
|
1366
1576
|
const targetFilters = generateTableFilterTypeCached(
|
|
@@ -1396,7 +1606,7 @@ var generateRelationFilterFields = (tableName, cacheCtx, typeNameMapper, columnF
|
|
|
1396
1606
|
if (!targetTable) {
|
|
1397
1607
|
continue;
|
|
1398
1608
|
}
|
|
1399
|
-
fields[relationName] = (0,
|
|
1609
|
+
fields[relationName] = (0, import_drizzle_orm4.is)(relation, import_drizzle_orm4.One) ? {
|
|
1400
1610
|
type: generateTableFilterTypeCached(
|
|
1401
1611
|
targetTable,
|
|
1402
1612
|
relEntry.targetTableName,
|
|
@@ -1430,16 +1640,16 @@ var generateTableFilterTypeCached = (table, tableName, cacheCtx, typeNameMapper,
|
|
|
1430
1640
|
...generateRelationFilterFields(tableName, cacheCtx, typeNameMapper, filterColumns, relationMap, tables)
|
|
1431
1641
|
};
|
|
1432
1642
|
};
|
|
1433
|
-
const filters = new
|
|
1643
|
+
const filters = new import_graphql5.GraphQLInputObjectType({
|
|
1434
1644
|
name: `${resolveTypeName(tableName, typeNameMapper)}Filters`,
|
|
1435
1645
|
fields: () => ({
|
|
1436
1646
|
...buildFields(),
|
|
1437
1647
|
OR: {
|
|
1438
|
-
type: new
|
|
1648
|
+
type: new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(filters)),
|
|
1439
1649
|
description: "At least one branch matches; ANDed with any sibling fields"
|
|
1440
1650
|
},
|
|
1441
1651
|
AND: {
|
|
1442
|
-
type: new
|
|
1652
|
+
type: new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(filters)),
|
|
1443
1653
|
description: "Every branch matches"
|
|
1444
1654
|
},
|
|
1445
1655
|
NOT: {
|
|
@@ -1490,8 +1700,9 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
|
|
|
1490
1700
|
}
|
|
1491
1701
|
if (isRootCall && !cacheCtx.objectTypeCache.has(tableName)) {
|
|
1492
1702
|
const typeName = resolveTypeName(tableName, typeNameMapper);
|
|
1493
|
-
const shell = new
|
|
1703
|
+
const shell = new import_graphql5.GraphQLObjectType({
|
|
1494
1704
|
name: typeName,
|
|
1705
|
+
description: cacheCtx.docs.describeTable?.(tableName),
|
|
1495
1706
|
fields: () => ({ ...tableFields, ...container.fields })
|
|
1496
1707
|
});
|
|
1497
1708
|
cacheCtx.objectTypeCache.set(tableName, shell);
|
|
@@ -1503,7 +1714,7 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
|
|
|
1503
1714
|
for (const [relationName, relEntry] of relationEntries) {
|
|
1504
1715
|
const { targetTableName } = relEntry;
|
|
1505
1716
|
const relation = relEntry.relation ?? relEntry;
|
|
1506
|
-
const isOne = (0,
|
|
1717
|
+
const isOne = (0, import_drizzle_orm4.is)(relation, import_drizzle_orm4.One);
|
|
1507
1718
|
const relSelectData = generateSelectFields(
|
|
1508
1719
|
tables,
|
|
1509
1720
|
targetTableName,
|
|
@@ -1531,38 +1742,49 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
|
|
|
1531
1742
|
cacheCtx.relationFieldContainers.set(targetTableName, targetContainer);
|
|
1532
1743
|
}
|
|
1533
1744
|
const capturedTargetContainer = targetContainer;
|
|
1534
|
-
relType = new
|
|
1745
|
+
relType = new import_graphql5.GraphQLObjectType({
|
|
1535
1746
|
name: resolveTypeName(targetTableName, typeNameMapper),
|
|
1747
|
+
description: cacheCtx.docs.describeTable?.(targetTableName),
|
|
1536
1748
|
fields: () => ({ ...targetTableFields, ...capturedTargetContainer.fields })
|
|
1537
1749
|
});
|
|
1538
1750
|
cacheCtx.objectTypeCache.set(targetTableName, relType);
|
|
1539
1751
|
}
|
|
1540
1752
|
const resolve = resolverFactory?.({ tableName, relationName, relEntry, isOne });
|
|
1753
|
+
const relationDescription = cacheCtx.docs.describeRelation?.(tableName, relationName);
|
|
1754
|
+
const relationDocs = relationDescription !== void 0 ? { description: relationDescription } : {};
|
|
1541
1755
|
if (isOne) {
|
|
1542
1756
|
const isRequired = relation.optional === false;
|
|
1543
1757
|
rawRelationFields.push([
|
|
1544
1758
|
relationName,
|
|
1545
1759
|
{
|
|
1546
|
-
type: isRequired ? new
|
|
1760
|
+
type: isRequired ? new import_graphql5.GraphQLNonNull(relType) : relType,
|
|
1547
1761
|
args: {
|
|
1548
1762
|
where: { type: relSelectData.filters }
|
|
1549
1763
|
},
|
|
1550
|
-
resolve
|
|
1764
|
+
resolve,
|
|
1765
|
+
...relationDocs
|
|
1551
1766
|
}
|
|
1552
1767
|
]);
|
|
1553
1768
|
continue;
|
|
1554
1769
|
}
|
|
1770
|
+
const targetDistinctEnum = cacheCtx.features.distinct ? generateDistinctEnum(tables[targetTableName], resolveTypeName(targetTableName, typeNameMapper)) : void 0;
|
|
1555
1771
|
rawRelationFields.push([
|
|
1556
1772
|
relationName,
|
|
1557
1773
|
{
|
|
1558
|
-
type: new
|
|
1774
|
+
type: new import_graphql5.GraphQLNonNull(new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(relType))),
|
|
1559
1775
|
args: {
|
|
1560
1776
|
where: { type: relSelectData.filters },
|
|
1561
1777
|
orderBy: { type: relSelectData.order },
|
|
1562
|
-
offset: { type:
|
|
1563
|
-
limit: { type:
|
|
1778
|
+
offset: { type: import_graphql5.GraphQLInt },
|
|
1779
|
+
limit: { type: import_graphql5.GraphQLInt },
|
|
1780
|
+
after: {
|
|
1781
|
+
type: import_graphql5.GraphQLString,
|
|
1782
|
+
description: "Keyset pagination: only return related rows strictly after this cursor (a row's `cursor` field from a previous page of this relation, under the same orderBy)."
|
|
1783
|
+
},
|
|
1784
|
+
...targetDistinctEnum ? { distinct: { type: new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(targetDistinctEnum)) } } : {}
|
|
1564
1785
|
},
|
|
1565
1786
|
resolve,
|
|
1787
|
+
...relationDocs,
|
|
1566
1788
|
...cacheCtx.complexity ? { extensions: { complexity: listFieldComplexity(cacheCtx.complexity) } } : {}
|
|
1567
1789
|
}
|
|
1568
1790
|
]);
|
|
@@ -1577,7 +1799,7 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
|
|
|
1577
1799
|
rawRelationFields.push([
|
|
1578
1800
|
aggregateFieldName,
|
|
1579
1801
|
{
|
|
1580
|
-
type: new
|
|
1802
|
+
type: new import_graphql5.GraphQLNonNull(relationAggregate.type),
|
|
1581
1803
|
args: {
|
|
1582
1804
|
where: { type: relSelectData.filters }
|
|
1583
1805
|
},
|
|
@@ -1610,7 +1832,7 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
|
|
|
1610
1832
|
relationFields: {}
|
|
1611
1833
|
};
|
|
1612
1834
|
};
|
|
1613
|
-
var generateTableTypes = (tableName, tables, relationMap, withReturning, relationsDepthLimit, cacheCtx, typeNameMapper = void 0, insertPrefix = "create", updatePrefix = "update", resolverFactory, relationAggregateFactory) => {
|
|
1835
|
+
var generateTableTypes = (tableName, tables, relationMap, withReturning, relationsDepthLimit, cacheCtx, typeNameMapper = void 0, insertPrefix = "create", updatePrefix = "update", resolverFactory, relationAggregateFactory, nestedWrites) => {
|
|
1614
1836
|
const { tableFields, relationFields, filters, order } = generateSelectFields(
|
|
1615
1837
|
tables,
|
|
1616
1838
|
tableName,
|
|
@@ -1629,36 +1851,51 @@ var generateTableTypes = (tableName, tables, relationMap, withReturning, relatio
|
|
|
1629
1851
|
relationAggregateFactory
|
|
1630
1852
|
);
|
|
1631
1853
|
const table = tables[tableName];
|
|
1632
|
-
const columns = (0,
|
|
1854
|
+
const columns = (0, import_drizzle_orm4.getColumns)(table);
|
|
1633
1855
|
const columnEntries = Object.entries(columns);
|
|
1856
|
+
const relaxedColumns = nestedWrites?.relaxedColumns(tableName);
|
|
1634
1857
|
const insertFields = Object.fromEntries(
|
|
1635
|
-
columnEntries.map(([columnName,
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1858
|
+
columnEntries.map(([columnName, column]) => {
|
|
1859
|
+
const converted = drizzleColumnToGraphQLType(
|
|
1860
|
+
column,
|
|
1861
|
+
columnName,
|
|
1862
|
+
tableName,
|
|
1863
|
+
!!relaxedColumns?.has(columnName),
|
|
1864
|
+
true,
|
|
1865
|
+
true
|
|
1866
|
+
);
|
|
1867
|
+
return [
|
|
1868
|
+
columnName,
|
|
1869
|
+
{ ...converted, ...inputFieldDocs(cacheCtx.docs, column, tableName, columnName, converted.type) }
|
|
1870
|
+
];
|
|
1871
|
+
})
|
|
1639
1872
|
);
|
|
1640
1873
|
const updateFields = Object.fromEntries(
|
|
1641
|
-
columnEntries.map(([columnName,
|
|
1642
|
-
columnName,
|
|
1643
|
-
|
|
1644
|
-
|
|
1874
|
+
columnEntries.map(([columnName, column]) => {
|
|
1875
|
+
const converted = drizzleColumnToGraphQLType(column, columnName, tableName, true, false, true);
|
|
1876
|
+
const operations = cacheCtx.features.fieldUpdateOperations ? fieldUpdateInputType(column, columnName, tableName) : void 0;
|
|
1877
|
+
const field = operations ? { ...converted, type: operations } : converted;
|
|
1878
|
+
return [columnName, { ...field, ...inputFieldDocs(cacheCtx.docs, column, tableName, columnName, field.type) }];
|
|
1879
|
+
})
|
|
1645
1880
|
);
|
|
1646
|
-
const
|
|
1647
|
-
|
|
1648
|
-
|
|
1881
|
+
const typeName = resolveTypeName(tableName, typeNameMapper);
|
|
1882
|
+
const insertInput = new import_graphql5.GraphQLInputObjectType({
|
|
1883
|
+
name: `${capitalize(insertPrefix)}${typeName}Input`,
|
|
1884
|
+
fields: nestedWrites ? () => ({ ...insertFields, ...nestedWrites.createFields(tableName, typeName) }) : insertFields
|
|
1649
1885
|
});
|
|
1650
|
-
const updateInput = new
|
|
1651
|
-
name: `${capitalize(updatePrefix)}${
|
|
1652
|
-
fields: updateFields
|
|
1886
|
+
const updateInput = new import_graphql5.GraphQLInputObjectType({
|
|
1887
|
+
name: `${capitalize(updatePrefix)}${typeName}Input`,
|
|
1888
|
+
fields: nestedWrites ? () => ({ ...updateFields, ...nestedWrites.updateFields(tableName, typeName) }) : updateFields
|
|
1653
1889
|
});
|
|
1654
|
-
const selectSingleOutput = cacheCtx.objectTypeCache.get(tableName) ?? new
|
|
1890
|
+
const selectSingleOutput = cacheCtx.objectTypeCache.get(tableName) ?? new import_graphql5.GraphQLObjectType({
|
|
1655
1891
|
name: resolveTypeName(tableName, typeNameMapper),
|
|
1892
|
+
description: cacheCtx.docs.describeTable?.(tableName),
|
|
1656
1893
|
fields: { ...tableFields, ...relationFields }
|
|
1657
1894
|
});
|
|
1658
|
-
const selectArrOutput = new
|
|
1895
|
+
const selectArrOutput = new import_graphql5.GraphQLNonNull(new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(selectSingleOutput)));
|
|
1659
1896
|
const arrTableItemOutput = withReturning ? (
|
|
1660
1897
|
// ? new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(singleTableItemOutput!)))
|
|
1661
|
-
new
|
|
1898
|
+
new import_graphql5.GraphQLNonNull(new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(selectSingleOutput)))
|
|
1662
1899
|
) : void 0;
|
|
1663
1900
|
const inputs = {
|
|
1664
1901
|
insertInput,
|
|
@@ -1683,34 +1920,34 @@ var generateTableTypes = (tableName, tables, relationMap, withReturning, relatio
|
|
|
1683
1920
|
};
|
|
1684
1921
|
var orderByEntries = (orderArgs) => Object.entries(orderArgs).sort((a, b) => (b[1]?.priority ?? 0) - (a[1]?.priority ?? 0)).filter(([, config]) => config).map(([column, config]) => {
|
|
1685
1922
|
if (typeof config === "object" && config.direction === void 0) {
|
|
1686
|
-
throw new
|
|
1923
|
+
throw new import_graphql5.GraphQLError(`ORDER BY ${column}: ordering through a relation is not supported in this query`);
|
|
1687
1924
|
}
|
|
1688
1925
|
return [column, config.direction, config.nulls ?? void 0];
|
|
1689
1926
|
});
|
|
1690
1927
|
var orderExpressions = (expr, direction, nulls, dialectColumn) => {
|
|
1691
|
-
const directed = direction === "asc" ? (0,
|
|
1928
|
+
const directed = direction === "asc" ? (0, import_drizzle_orm4.asc)(expr) : (0, import_drizzle_orm4.desc)(expr);
|
|
1692
1929
|
if (!nulls) {
|
|
1693
1930
|
return [directed];
|
|
1694
1931
|
}
|
|
1695
1932
|
const isMySql = (dialectColumn.columnType ?? "").startsWith("MySql");
|
|
1696
1933
|
if (isMySql) {
|
|
1697
|
-
const nullsKey = nulls === "first" ? (0,
|
|
1934
|
+
const nullsKey = nulls === "first" ? (0, import_drizzle_orm4.desc)(import_drizzle_orm4.sql`(${expr} is null)`) : (0, import_drizzle_orm4.asc)(import_drizzle_orm4.sql`(${expr} is null)`);
|
|
1698
1935
|
return [nullsKey, directed];
|
|
1699
1936
|
}
|
|
1700
|
-
return [nulls === "first" ?
|
|
1937
|
+
return [nulls === "first" ? import_drizzle_orm4.sql`${directed} nulls first` : import_drizzle_orm4.sql`${directed} nulls last`];
|
|
1701
1938
|
};
|
|
1702
1939
|
var extendRelationOrderChain = (parentTable, relationName, relEntry, ctx, chain) => {
|
|
1703
1940
|
const targetTable = ctx.tables[relEntry.targetTableName];
|
|
1704
1941
|
const relation = relEntry.relation ?? relEntry;
|
|
1705
|
-
if (!targetTable || !(0,
|
|
1706
|
-
throw new
|
|
1942
|
+
if (!targetTable || !(0, import_drizzle_orm4.is)(relation, import_drizzle_orm4.One) || !isFilterableRelation(relation)) {
|
|
1943
|
+
throw new import_graphql5.GraphQLError(`ORDER BY ${relationName}: Relation cannot be used for ordering`);
|
|
1707
1944
|
}
|
|
1708
1945
|
ctx.aliases ??= { n: 0 };
|
|
1709
|
-
const aliasedTarget = (0,
|
|
1946
|
+
const aliasedTarget = (0, import_drizzle_orm4.aliasedTable)(targetTable, `dgql_ord_${ctx.aliases.n++}`);
|
|
1710
1947
|
const joinCondition = buildRelationJoinCondition(parentTable, relation, aliasedTarget, relationName);
|
|
1711
|
-
const relationWhere = relation.where ? (0,
|
|
1948
|
+
const relationWhere = relation.where ? (0, import_drizzle_orm4.relationsFilterToSQL)(relation.isReversed ? parentTable : aliasedTarget, relation.where) : void 0;
|
|
1712
1949
|
return {
|
|
1713
|
-
fromParts: [...chain?.fromParts ?? [], (0,
|
|
1950
|
+
fromParts: [...chain?.fromParts ?? [], (0, import_drizzle_orm4.getTableAsAliasSQL)(aliasedTarget)],
|
|
1714
1951
|
conditions: [
|
|
1715
1952
|
...chain?.conditions ?? [],
|
|
1716
1953
|
...joinCondition ? [joinCondition] : [],
|
|
@@ -1720,7 +1957,7 @@ var extendRelationOrderChain = (parentTable, relationName, relEntry, ctx, chain)
|
|
|
1720
1957
|
};
|
|
1721
1958
|
};
|
|
1722
1959
|
var collectOrderEntries = (table, tableKey, orderArgs, ctx, chain, out) => {
|
|
1723
|
-
const columns = (0,
|
|
1960
|
+
const columns = (0, import_drizzle_orm4.getColumns)(table);
|
|
1724
1961
|
const relations = ctx?.relationMap[tableKey];
|
|
1725
1962
|
for (const [key, config] of Object.entries(orderArgs)) {
|
|
1726
1963
|
if (config === null || config === void 0) {
|
|
@@ -1729,7 +1966,7 @@ var collectOrderEntries = (table, tableKey, orderArgs, ctx, chain, out) => {
|
|
|
1729
1966
|
const column = columns[key];
|
|
1730
1967
|
if (column) {
|
|
1731
1968
|
out.push({
|
|
1732
|
-
expression: chain ?
|
|
1969
|
+
expression: chain ? import_drizzle_orm4.sql`(select ${column} from ${import_drizzle_orm4.sql.join(chain.fromParts, import_drizzle_orm4.sql`, `)} where ${(0, import_drizzle_orm4.and)(...chain.conditions)})` : column,
|
|
1733
1970
|
column,
|
|
1734
1971
|
direction: config.direction,
|
|
1735
1972
|
nulls: config.nulls ?? void 0,
|
|
@@ -1739,7 +1976,7 @@ var collectOrderEntries = (table, tableKey, orderArgs, ctx, chain, out) => {
|
|
|
1739
1976
|
}
|
|
1740
1977
|
const relEntry = relations?.[key];
|
|
1741
1978
|
if (!relEntry || !ctx) {
|
|
1742
|
-
throw new
|
|
1979
|
+
throw new import_graphql5.GraphQLError(`ORDER BY ${key}: Unknown column or relation`);
|
|
1743
1980
|
}
|
|
1744
1981
|
const nextChain = extendRelationOrderChain(chain?.table ?? table, key, relEntry, ctx, chain);
|
|
1745
1982
|
collectOrderEntries(nextChain.table, relEntry.targetTableName, config, ctx, nextChain, out);
|
|
@@ -1762,34 +1999,34 @@ var safeLikeOps = {
|
|
|
1762
1999
|
};
|
|
1763
2000
|
var safeLikeCondition = (column, pattern, insensitive) => {
|
|
1764
2001
|
if (!insensitive) {
|
|
1765
|
-
return
|
|
2002
|
+
return import_drizzle_orm4.sql`${column} like ${pattern} escape ${LIKE_ESCAPE_CHAR}`;
|
|
1766
2003
|
}
|
|
1767
2004
|
const isPg = (column.columnType ?? "").startsWith("Pg");
|
|
1768
|
-
return isPg ?
|
|
2005
|
+
return isPg ? import_drizzle_orm4.sql`${column} ilike ${pattern} escape ${LIKE_ESCAPE_CHAR}` : import_drizzle_orm4.sql`lower(${column}) like ${pattern.toLowerCase()} escape ${LIKE_ESCAPE_CHAR}`;
|
|
1769
2006
|
};
|
|
1770
2007
|
var isJsonColumn2 = (column) => (column.columnType ?? "").includes("Json");
|
|
1771
2008
|
var jsonContains = (column, columnName, value) => {
|
|
1772
2009
|
const serialized = JSON.stringify(value);
|
|
1773
2010
|
switch (columnDialect(column)) {
|
|
1774
2011
|
case "pg":
|
|
1775
|
-
return column.columnType === "PgJson" ?
|
|
2012
|
+
return column.columnType === "PgJson" ? import_drizzle_orm4.sql`${column}::jsonb @> ${serialized}::jsonb` : import_drizzle_orm4.sql`${column} @> ${serialized}::jsonb`;
|
|
1776
2013
|
case "mysql":
|
|
1777
|
-
return
|
|
2014
|
+
return import_drizzle_orm4.sql`json_contains(${column}, ${serialized})`;
|
|
1778
2015
|
default:
|
|
1779
|
-
throw new
|
|
2016
|
+
throw new import_graphql5.GraphQLError(`WHERE ${columnName}: Operator 'contains' is not supported for this dialect!`);
|
|
1780
2017
|
}
|
|
1781
2018
|
};
|
|
1782
2019
|
var extractFiltersColumn = (column, columnName, operators) => {
|
|
1783
2020
|
const { OR, AND, NOT, ...restOperators } = operators;
|
|
1784
2021
|
const entries = Object.entries(restOperators);
|
|
1785
|
-
const singleValueOps = { eq:
|
|
1786
|
-
const stringValueOps = { like:
|
|
1787
|
-
const arrayValueOps = { inArray:
|
|
2022
|
+
const singleValueOps = { eq: import_drizzle_orm4.eq, ne: import_drizzle_orm4.ne, gt: import_drizzle_orm4.gt, gte: import_drizzle_orm4.gte, lt: import_drizzle_orm4.lt, lte: import_drizzle_orm4.lte };
|
|
2023
|
+
const stringValueOps = { like: import_drizzle_orm4.like, notLike: import_drizzle_orm4.notLike, ilike: import_drizzle_orm4.ilike, notIlike: import_drizzle_orm4.notIlike };
|
|
2024
|
+
const arrayValueOps = { inArray: import_drizzle_orm4.inArray, notInArray: import_drizzle_orm4.notInArray };
|
|
1788
2025
|
const arrayMembershipOps = {
|
|
1789
|
-
hasSome:
|
|
1790
|
-
hasEvery:
|
|
2026
|
+
hasSome: import_drizzle_orm4.arrayOverlaps,
|
|
2027
|
+
hasEvery: import_drizzle_orm4.arrayContains
|
|
1791
2028
|
};
|
|
1792
|
-
const nullableOps = { isNull:
|
|
2029
|
+
const nullableOps = { isNull: import_drizzle_orm4.isNull, isNotNull: import_drizzle_orm4.isNotNull };
|
|
1793
2030
|
const variants = [];
|
|
1794
2031
|
for (const [operatorName, operatorValue] of entries) {
|
|
1795
2032
|
if (operatorValue === null || operatorValue === false) {
|
|
@@ -1807,23 +2044,23 @@ var extractFiltersColumn = (column, columnName, operators) => {
|
|
|
1807
2044
|
variants.push(safeLikeCondition(column, buildPattern(operatorValue), insensitive));
|
|
1808
2045
|
} else if (operatorName in arrayValueOps) {
|
|
1809
2046
|
if (!operatorValue.length) {
|
|
1810
|
-
throw new
|
|
2047
|
+
throw new import_graphql5.GraphQLError(`WHERE ${columnName}: Unable to use operator ${operatorName} with an empty array!`);
|
|
1811
2048
|
}
|
|
1812
2049
|
const arrayValue = operatorValue.map((val) => remapFromGraphQLCore(val, column, columnName));
|
|
1813
2050
|
variants.push(arrayValueOps[operatorName](column, arrayValue));
|
|
1814
2051
|
} else if (operatorName === "has") {
|
|
1815
|
-
variants.push((0,
|
|
2052
|
+
variants.push((0, import_drizzle_orm4.arrayContains)(column, [operatorValue]));
|
|
1816
2053
|
} else if (operatorName in arrayMembershipOps) {
|
|
1817
2054
|
if (!operatorValue.length) {
|
|
1818
|
-
throw new
|
|
2055
|
+
throw new import_graphql5.GraphQLError(`WHERE ${columnName}: Unable to use operator ${operatorName} with an empty array!`);
|
|
1819
2056
|
}
|
|
1820
2057
|
variants.push(arrayMembershipOps[operatorName](column, operatorValue));
|
|
1821
2058
|
} else if (operatorName === "isEmpty") {
|
|
1822
|
-
variants.push(
|
|
2059
|
+
variants.push(import_drizzle_orm4.sql`cardinality(${column}) = 0`);
|
|
1823
2060
|
} else if (operatorName in nullableOps) {
|
|
1824
2061
|
variants.push(nullableOps[operatorName](column));
|
|
1825
2062
|
} else {
|
|
1826
|
-
throw new
|
|
2063
|
+
throw new import_graphql5.GraphQLError(`WHERE ${columnName}: Unknown operator: ${operatorName}`);
|
|
1827
2064
|
}
|
|
1828
2065
|
}
|
|
1829
2066
|
if (AND?.length) {
|
|
@@ -1837,7 +2074,7 @@ var extractFiltersColumn = (column, columnName, operators) => {
|
|
|
1837
2074
|
if (NOT) {
|
|
1838
2075
|
const extracted = extractFiltersColumn(column, columnName, NOT);
|
|
1839
2076
|
if (extracted) {
|
|
1840
|
-
variants.push((0,
|
|
2077
|
+
variants.push((0, import_drizzle_orm4.not)(extracted));
|
|
1841
2078
|
}
|
|
1842
2079
|
}
|
|
1843
2080
|
if (OR?.length) {
|
|
@@ -1849,33 +2086,33 @@ var extractFiltersColumn = (column, columnName, operators) => {
|
|
|
1849
2086
|
}
|
|
1850
2087
|
}
|
|
1851
2088
|
if (orVariants.length) {
|
|
1852
|
-
variants.push(orVariants.length > 1 ? (0,
|
|
2089
|
+
variants.push(orVariants.length > 1 ? (0, import_drizzle_orm4.or)(...orVariants) : orVariants[0]);
|
|
1853
2090
|
}
|
|
1854
2091
|
}
|
|
1855
|
-
return variants.length ? variants.length > 1 ? (0,
|
|
2092
|
+
return variants.length ? variants.length > 1 ? (0, import_drizzle_orm4.and)(...variants) : variants[0] : void 0;
|
|
1856
2093
|
};
|
|
1857
2094
|
var relationFilterCtx = (base, tableKey) => base ? { ...base, tableKey } : void 0;
|
|
1858
2095
|
var buildRelationJoinCondition = (parentTable, relation, aliasedTarget, relationName) => {
|
|
1859
2096
|
const sourceColumns = relation.sourceColumns;
|
|
1860
2097
|
const targetColumns = relation.targetColumns;
|
|
1861
2098
|
if (!sourceColumns?.length || sourceColumns.length !== targetColumns?.length) {
|
|
1862
|
-
throw new
|
|
2099
|
+
throw new import_graphql5.GraphQLError(`WHERE ${relationName}: Relation cannot be used as a filter`);
|
|
1863
2100
|
}
|
|
1864
|
-
const parentColumns = Object.values((0,
|
|
1865
|
-
const targetColumnsByName = Object.values((0,
|
|
2101
|
+
const parentColumns = Object.values((0, import_drizzle_orm4.getColumns)(parentTable));
|
|
2102
|
+
const targetColumnsByName = Object.values((0, import_drizzle_orm4.getColumns)(aliasedTarget));
|
|
1866
2103
|
const conditions = [];
|
|
1867
2104
|
for (let i = 0; i < sourceColumns.length; i++) {
|
|
1868
2105
|
const localColumn = parentColumns.find((c) => c.name === sourceColumns[i].name);
|
|
1869
2106
|
const foreignColumn = targetColumnsByName.find((c) => c.name === targetColumns[i].name);
|
|
1870
2107
|
if (!localColumn || !foreignColumn) {
|
|
1871
|
-
throw new
|
|
2108
|
+
throw new import_graphql5.GraphQLError(`WHERE ${relationName}: Relation cannot be used as a filter`);
|
|
1872
2109
|
}
|
|
1873
|
-
conditions.push((0,
|
|
2110
|
+
conditions.push((0, import_drizzle_orm4.eq)(localColumn, foreignColumn));
|
|
1874
2111
|
}
|
|
1875
|
-
return conditions.length > 1 ? (0,
|
|
2112
|
+
return conditions.length > 1 ? (0, import_drizzle_orm4.and)(...conditions) : conditions[0];
|
|
1876
2113
|
};
|
|
1877
2114
|
var resolveJunctionColumn = (aliasedThrough, junctionRef, relationName) => {
|
|
1878
|
-
const throughColumns = (0,
|
|
2115
|
+
const throughColumns = (0, import_drizzle_orm4.getColumns)(aliasedThrough);
|
|
1879
2116
|
const key = junctionRef?._?.key;
|
|
1880
2117
|
const byKey = key ? throughColumns[key] : void 0;
|
|
1881
2118
|
if (byKey) {
|
|
@@ -1884,7 +2121,7 @@ var resolveJunctionColumn = (aliasedThrough, junctionRef, relationName) => {
|
|
|
1884
2121
|
const columnName = junctionRef?._?.column?.name;
|
|
1885
2122
|
const byName = columnName ? Object.values(throughColumns).find((c) => c.name === columnName) : void 0;
|
|
1886
2123
|
if (!byName) {
|
|
1887
|
-
throw new
|
|
2124
|
+
throw new import_graphql5.GraphQLError(`WHERE ${relationName}: Relation cannot be used as a filter`);
|
|
1888
2125
|
}
|
|
1889
2126
|
return byName;
|
|
1890
2127
|
};
|
|
@@ -1893,31 +2130,31 @@ var buildThroughJoinConditions = (parentTable, relation, aliasedThrough, aliased
|
|
|
1893
2130
|
const targetColumns = relation.targetColumns;
|
|
1894
2131
|
const through = relation.through;
|
|
1895
2132
|
if (!sourceColumns?.length || !targetColumns?.length || through?.source.length !== sourceColumns.length || through.target.length !== targetColumns.length) {
|
|
1896
|
-
throw new
|
|
2133
|
+
throw new import_graphql5.GraphQLError(`WHERE ${relationName}: Relation cannot be used as a filter`);
|
|
1897
2134
|
}
|
|
1898
|
-
const parentColumns = Object.values((0,
|
|
1899
|
-
const targetTableColumns = Object.values((0,
|
|
2135
|
+
const parentColumns = Object.values((0, import_drizzle_orm4.getColumns)(parentTable));
|
|
2136
|
+
const targetTableColumns = Object.values((0, import_drizzle_orm4.getColumns)(aliasedTarget));
|
|
1900
2137
|
const correlationConditions = [];
|
|
1901
2138
|
for (let i = 0; i < sourceColumns.length; i++) {
|
|
1902
2139
|
const localColumn = parentColumns.find((c) => c.name === sourceColumns[i].name);
|
|
1903
2140
|
if (!localColumn) {
|
|
1904
|
-
throw new
|
|
2141
|
+
throw new import_graphql5.GraphQLError(`WHERE ${relationName}: Relation cannot be used as a filter`);
|
|
1905
2142
|
}
|
|
1906
|
-
correlationConditions.push((0,
|
|
2143
|
+
correlationConditions.push((0, import_drizzle_orm4.eq)(localColumn, resolveJunctionColumn(aliasedThrough, through.source[i], relationName)));
|
|
1907
2144
|
}
|
|
1908
2145
|
const junctionJoinConditions = [];
|
|
1909
2146
|
for (let i = 0; i < targetColumns.length; i++) {
|
|
1910
2147
|
const foreignColumn = targetTableColumns.find((c) => c.name === targetColumns[i].name);
|
|
1911
2148
|
if (!foreignColumn) {
|
|
1912
|
-
throw new
|
|
2149
|
+
throw new import_graphql5.GraphQLError(`WHERE ${relationName}: Relation cannot be used as a filter`);
|
|
1913
2150
|
}
|
|
1914
2151
|
junctionJoinConditions.push(
|
|
1915
|
-
(0,
|
|
2152
|
+
(0, import_drizzle_orm4.eq)(resolveJunctionColumn(aliasedThrough, through.target[i], relationName), foreignColumn)
|
|
1916
2153
|
);
|
|
1917
2154
|
}
|
|
1918
2155
|
return {
|
|
1919
|
-
correlation: correlationConditions.length > 1 ? (0,
|
|
1920
|
-
junctionJoin: junctionJoinConditions.length > 1 ? (0,
|
|
2156
|
+
correlation: correlationConditions.length > 1 ? (0, import_drizzle_orm4.and)(...correlationConditions) : correlationConditions[0],
|
|
2157
|
+
junctionJoin: junctionJoinConditions.length > 1 ? (0, import_drizzle_orm4.and)(...junctionJoinConditions) : junctionJoinConditions[0]
|
|
1921
2158
|
};
|
|
1922
2159
|
};
|
|
1923
2160
|
var buildRelationExists = (parentTable, relationName, relEntry, innerFilters, mode, ctx) => {
|
|
@@ -1925,16 +2162,16 @@ var buildRelationExists = (parentTable, relationName, relEntry, innerFilters, mo
|
|
|
1925
2162
|
const targetTable = ctx.tables[targetTableName];
|
|
1926
2163
|
const relation = relEntry.relation ?? relEntry;
|
|
1927
2164
|
if (!targetTable) {
|
|
1928
|
-
throw new
|
|
2165
|
+
throw new import_graphql5.GraphQLError(`WHERE ${relationName}: Relation cannot be used as a filter`);
|
|
1929
2166
|
}
|
|
1930
2167
|
ctx.aliases ??= { n: 0 };
|
|
1931
2168
|
const aliases = ctx.aliases;
|
|
1932
|
-
const aliasedTarget = (0,
|
|
2169
|
+
const aliasedTarget = (0, import_drizzle_orm4.aliasedTable)(targetTable, `dgql_rel_${aliases.n++}`);
|
|
1933
2170
|
const throughTable = relation.throughTable;
|
|
1934
2171
|
let fromClause;
|
|
1935
2172
|
let joinCondition;
|
|
1936
2173
|
if (throughTable) {
|
|
1937
|
-
const aliasedThrough = (0,
|
|
2174
|
+
const aliasedThrough = (0, import_drizzle_orm4.aliasedTable)(throughTable, `dgql_rel_${aliases.n++}`);
|
|
1938
2175
|
const { correlation, junctionJoin } = buildThroughJoinConditions(
|
|
1939
2176
|
parentTable,
|
|
1940
2177
|
relation,
|
|
@@ -1942,26 +2179,26 @@ var buildRelationExists = (parentTable, relationName, relEntry, innerFilters, mo
|
|
|
1942
2179
|
aliasedTarget,
|
|
1943
2180
|
relationName
|
|
1944
2181
|
);
|
|
1945
|
-
fromClause =
|
|
2182
|
+
fromClause = import_drizzle_orm4.sql`${(0, import_drizzle_orm4.getTableAsAliasSQL)(aliasedTarget)} inner join ${(0, import_drizzle_orm4.getTableAsAliasSQL)(aliasedThrough)} on ${junctionJoin}`;
|
|
1946
2183
|
joinCondition = correlation;
|
|
1947
2184
|
} else {
|
|
1948
|
-
fromClause = (0,
|
|
2185
|
+
fromClause = (0, import_drizzle_orm4.getTableAsAliasSQL)(aliasedTarget);
|
|
1949
2186
|
joinCondition = buildRelationJoinCondition(parentTable, relation, aliasedTarget, relationName);
|
|
1950
2187
|
}
|
|
1951
|
-
const relationWhere = relation.where ? (0,
|
|
2188
|
+
const relationWhere = relation.where ? (0, import_drizzle_orm4.relationsFilterToSQL)(relation.isReversed ? parentTable : aliasedTarget, relation.where) : void 0;
|
|
1952
2189
|
const inner = innerFilters ? extractFilters(aliasedTarget, targetTableName, innerFilters, { ...ctx, tableKey: targetTableName, aliases }) : void 0;
|
|
1953
2190
|
if (mode === "every") {
|
|
1954
2191
|
if (!inner) {
|
|
1955
2192
|
return void 0;
|
|
1956
2193
|
}
|
|
1957
|
-
return
|
|
2194
|
+
return import_drizzle_orm4.sql`not exists (select 1 from ${fromClause} where ${(0, import_drizzle_orm4.and)(joinCondition, relationWhere, (0, import_drizzle_orm4.not)(inner))})`;
|
|
1958
2195
|
}
|
|
1959
|
-
const condition = (0,
|
|
1960
|
-
return mode === "none" ?
|
|
2196
|
+
const condition = (0, import_drizzle_orm4.and)(joinCondition, relationWhere, inner);
|
|
2197
|
+
return mode === "none" ? import_drizzle_orm4.sql`not exists (select 1 from ${fromClause} where ${condition})` : import_drizzle_orm4.sql`exists (select 1 from ${fromClause} where ${condition})`;
|
|
1961
2198
|
};
|
|
1962
2199
|
var extractRelationFilter = (parentTable, relationName, relEntry, value, ctx) => {
|
|
1963
2200
|
const relation = relEntry.relation ?? relEntry;
|
|
1964
|
-
if ((0,
|
|
2201
|
+
if ((0, import_drizzle_orm4.is)(relation, import_drizzle_orm4.One)) {
|
|
1965
2202
|
return buildRelationExists(parentTable, relationName, relEntry, value, "some", ctx);
|
|
1966
2203
|
}
|
|
1967
2204
|
const relationMatchModes = ["some", "none", "every"];
|
|
@@ -1971,19 +2208,19 @@ var extractRelationFilter = (parentTable, relationName, relEntry, value, ctx) =>
|
|
|
1971
2208
|
continue;
|
|
1972
2209
|
}
|
|
1973
2210
|
if (!relationMatchModes.includes(mode)) {
|
|
1974
|
-
throw new
|
|
2211
|
+
throw new import_graphql5.GraphQLError(`WHERE ${relationName}: Unknown relation filter key: ${mode}`);
|
|
1975
2212
|
}
|
|
1976
2213
|
const extracted = buildRelationExists(parentTable, relationName, relEntry, inner, mode, ctx);
|
|
1977
2214
|
if (extracted) {
|
|
1978
2215
|
variants.push(extracted);
|
|
1979
2216
|
}
|
|
1980
2217
|
}
|
|
1981
|
-
return variants.length ? variants.length > 1 ? (0,
|
|
2218
|
+
return variants.length ? variants.length > 1 ? (0, import_drizzle_orm4.and)(...variants) : variants[0] : void 0;
|
|
1982
2219
|
};
|
|
1983
2220
|
var extractFilters = (table, tableName, filters, relationCtx) => {
|
|
1984
2221
|
const { OR, AND, NOT, ...fieldFilters } = filters;
|
|
1985
2222
|
const entries = Object.entries(fieldFilters);
|
|
1986
|
-
const columns = (0,
|
|
2223
|
+
const columns = (0, import_drizzle_orm4.getColumns)(table);
|
|
1987
2224
|
const relations = relationCtx?.relationMap[relationCtx.tableKey];
|
|
1988
2225
|
const variants = [];
|
|
1989
2226
|
for (const [fieldName, operators] of entries) {
|
|
@@ -1992,7 +2229,7 @@ var extractFilters = (table, tableName, filters, relationCtx) => {
|
|
|
1992
2229
|
}
|
|
1993
2230
|
const column = columns[fieldName];
|
|
1994
2231
|
if (!column && !(relations?.[fieldName] && relationCtx)) {
|
|
1995
|
-
throw new
|
|
2232
|
+
throw new import_graphql5.GraphQLError(`WHERE ${tableName}: Unknown filter key: ${fieldName}`);
|
|
1996
2233
|
}
|
|
1997
2234
|
const extracted = column ? extractFiltersColumn(column, fieldName, operators) : extractRelationFilter(table, fieldName, relations[fieldName], operators, relationCtx);
|
|
1998
2235
|
if (extracted) {
|
|
@@ -2010,7 +2247,7 @@ var extractFilters = (table, tableName, filters, relationCtx) => {
|
|
|
2010
2247
|
if (NOT) {
|
|
2011
2248
|
const extracted = extractFilters(table, tableName, NOT, relationCtx);
|
|
2012
2249
|
if (extracted) {
|
|
2013
|
-
variants.push((0,
|
|
2250
|
+
variants.push((0, import_drizzle_orm4.not)(extracted));
|
|
2014
2251
|
}
|
|
2015
2252
|
}
|
|
2016
2253
|
if (OR?.length) {
|
|
@@ -2022,10 +2259,10 @@ var extractFilters = (table, tableName, filters, relationCtx) => {
|
|
|
2022
2259
|
}
|
|
2023
2260
|
}
|
|
2024
2261
|
if (orVariants.length) {
|
|
2025
|
-
variants.push(orVariants.length > 1 ? (0,
|
|
2262
|
+
variants.push(orVariants.length > 1 ? (0, import_drizzle_orm4.or)(...orVariants) : orVariants[0]);
|
|
2026
2263
|
}
|
|
2027
2264
|
}
|
|
2028
|
-
return variants.length ? variants.length > 1 ? (0,
|
|
2265
|
+
return variants.length ? variants.length > 1 ? (0, import_drizzle_orm4.and)(...variants) : variants[0] : void 0;
|
|
2029
2266
|
};
|
|
2030
2267
|
var extractRelationsParamsInner = (relationMap, tables, tableName, typeName, originField, typeNameMapper, _isInitial = false, filterCtx) => {
|
|
2031
2268
|
const relationsForTable = relationMap[tableName];
|
|
@@ -2044,15 +2281,27 @@ var extractRelationsParamsInner = (relationMap, tables, tableName, typeName, ori
|
|
|
2044
2281
|
if (!field) {
|
|
2045
2282
|
continue;
|
|
2046
2283
|
}
|
|
2284
|
+
const selectionCount = Object.values(baseField).reduce(
|
|
2285
|
+
(n, f) => n + (f.name === relName ? 1 : 0),
|
|
2286
|
+
0
|
|
2287
|
+
);
|
|
2288
|
+
if (selectionCount > 1) {
|
|
2289
|
+
continue;
|
|
2290
|
+
}
|
|
2047
2291
|
const relField = field?.fieldsByTypeName;
|
|
2048
2292
|
const relFieldSelection = relField?.[relTypeName];
|
|
2049
2293
|
if (!relFieldSelection) {
|
|
2050
2294
|
continue;
|
|
2051
2295
|
}
|
|
2296
|
+
const eagerArgs = field.args;
|
|
2297
|
+
if (!(0, import_drizzle_orm4.is)(relEntry.relation ?? relEntry, import_drizzle_orm4.One) && (eagerArgs?.after != null || !!eagerArgs?.distinct?.length || isCursorFieldSelected(relFieldSelection, tables[targetTableName]))) {
|
|
2298
|
+
continue;
|
|
2299
|
+
}
|
|
2052
2300
|
const columns = extractSelectedColumnsFromTree(relFieldSelection, tables[targetTableName], {
|
|
2053
2301
|
tableName: targetTableName,
|
|
2054
2302
|
relationMap,
|
|
2055
|
-
tables
|
|
2303
|
+
tables,
|
|
2304
|
+
allRelations: filterCtx?.relationMap
|
|
2056
2305
|
});
|
|
2057
2306
|
const thisRecord = {};
|
|
2058
2307
|
thisRecord.columns = columns;
|
|
@@ -2100,7 +2349,7 @@ var pruneNonEagerRelations = (relationMap, shouldEagerLoad) => {
|
|
|
2100
2349
|
return out;
|
|
2101
2350
|
};
|
|
2102
2351
|
var getPrimaryKeyPropNames = (table, compositePkColumnNames) => {
|
|
2103
|
-
const cols = (0,
|
|
2352
|
+
const cols = (0, import_drizzle_orm4.getColumns)(table);
|
|
2104
2353
|
const entries = Object.entries(cols);
|
|
2105
2354
|
const inlinePks = entries.filter(([, c]) => c.primary).map(([k]) => k);
|
|
2106
2355
|
if (inlinePks.length) {
|
|
@@ -2116,7 +2365,7 @@ var getPrimaryKeyPropNames = (table, compositePkColumnNames) => {
|
|
|
2116
2365
|
return [];
|
|
2117
2366
|
};
|
|
2118
2367
|
var withPrimaryKeyColumns = (columns, table, pkNames) => {
|
|
2119
|
-
const allCols = (0,
|
|
2368
|
+
const allCols = (0, import_drizzle_orm4.getColumns)(table);
|
|
2120
2369
|
for (const pk of pkNames) {
|
|
2121
2370
|
if (!(pk in columns) && allCols[pk]) {
|
|
2122
2371
|
columns[pk] = allCols[pk];
|
|
@@ -2129,8 +2378,8 @@ var getPrimaryKeyPropNamesFromConfig = (table, getTableConfig4) => {
|
|
|
2129
2378
|
return getPrimaryKeyPropNames(table, compositePkColumnNames);
|
|
2130
2379
|
};
|
|
2131
2380
|
var primaryKeyOrderExprs = (table, pkNames) => {
|
|
2132
|
-
const cols = (0,
|
|
2133
|
-
return pkNames.map((n) => cols[n]).filter(Boolean).map((col) => (0,
|
|
2381
|
+
const cols = (0, import_drizzle_orm4.getColumns)(table);
|
|
2382
|
+
return pkNames.map((n) => cols[n]).filter(Boolean).map((col) => (0, import_drizzle_orm4.asc)(col));
|
|
2134
2383
|
};
|
|
2135
2384
|
var CURSOR_FIELD_NAME = "cursor";
|
|
2136
2385
|
var ROW_CURSOR_PROP = "__drizzle_graphql_cursor";
|
|
@@ -2146,7 +2395,7 @@ var cursorOrderingEntries = (orderBy, pkNames) => {
|
|
|
2146
2395
|
return entries;
|
|
2147
2396
|
};
|
|
2148
2397
|
var cursorOrderExprs = (table, entries) => {
|
|
2149
|
-
const cols = (0,
|
|
2398
|
+
const cols = (0, import_drizzle_orm4.getColumns)(table);
|
|
2150
2399
|
return entries.flatMap(
|
|
2151
2400
|
([column, direction, nulls]) => orderExpressions(cols[column], direction, nulls ?? void 0, cols[column])
|
|
2152
2401
|
);
|
|
@@ -2183,10 +2432,10 @@ var decodeCursor = (after, entries) => {
|
|
|
2183
2432
|
try {
|
|
2184
2433
|
payload = JSON.parse(Buffer.from(after, "base64url").toString("utf8"));
|
|
2185
2434
|
} catch (_e) {
|
|
2186
|
-
throw new
|
|
2435
|
+
throw new import_graphql5.GraphQLError("Invalid cursor: unable to decode it. Pass a cursor returned by a previous page.");
|
|
2187
2436
|
}
|
|
2188
2437
|
if (!payload || typeof payload !== "object" || !Array.isArray(payload.o) || !Array.isArray(payload.v) || payload.o.length !== payload.v.length) {
|
|
2189
|
-
throw new
|
|
2438
|
+
throw new import_graphql5.GraphQLError("Invalid cursor: malformed payload. Pass a cursor returned by a previous page.");
|
|
2190
2439
|
}
|
|
2191
2440
|
const matchesOrdering = payload.o.length === entries.length && payload.o.every(
|
|
2192
2441
|
(entry, i) => Array.isArray(entry) && entry[0] === entries[i][0] && entry[1] === entries[i][1] && // The nulls override changes where NULLs sort, so it is part of the ordering identity.
|
|
@@ -2194,49 +2443,71 @@ var decodeCursor = (after, entries) => {
|
|
|
2194
2443
|
(entry[2] ?? null) === (entries[i][2] ?? null)
|
|
2195
2444
|
);
|
|
2196
2445
|
if (!matchesOrdering) {
|
|
2197
|
-
throw new
|
|
2446
|
+
throw new import_graphql5.GraphQLError(
|
|
2198
2447
|
"Invalid cursor: it was issued for a different ordering. Pass the same orderBy the cursor's page used."
|
|
2199
2448
|
);
|
|
2200
2449
|
}
|
|
2201
2450
|
return payload.v.map(decodeCursorValue);
|
|
2202
2451
|
};
|
|
2203
2452
|
var buildCursorCondition = (table, entries, values, nullOrdering) => {
|
|
2204
|
-
const cols = (0,
|
|
2453
|
+
const cols = (0, import_drizzle_orm4.getColumns)(table);
|
|
2205
2454
|
const disjuncts = [];
|
|
2206
2455
|
const equalities = [];
|
|
2207
2456
|
entries.forEach(([column, direction, nulls], i) => {
|
|
2208
2457
|
const col = cols[column];
|
|
2209
2458
|
if (!col) {
|
|
2210
|
-
throw new
|
|
2459
|
+
throw new import_graphql5.GraphQLError(`Invalid cursor: unknown column '${column}'.`);
|
|
2211
2460
|
}
|
|
2212
2461
|
const value = values[i];
|
|
2213
2462
|
const nullsSortLast = nulls != null ? nulls === "last" : direction === "asc" === (nullOrdering === "nulls-largest");
|
|
2214
2463
|
let strictlyAfter;
|
|
2215
2464
|
if (value === null || value === void 0) {
|
|
2216
|
-
strictlyAfter = nullsSortLast ? void 0 : (0,
|
|
2465
|
+
strictlyAfter = nullsSortLast ? void 0 : (0, import_drizzle_orm4.isNotNull)(col);
|
|
2217
2466
|
} else {
|
|
2218
|
-
const comparison = direction === "asc" ? (0,
|
|
2219
|
-
strictlyAfter = nullsSortLast ? (0,
|
|
2467
|
+
const comparison = direction === "asc" ? (0, import_drizzle_orm4.gt)(col, value) : (0, import_drizzle_orm4.lt)(col, value);
|
|
2468
|
+
strictlyAfter = nullsSortLast ? (0, import_drizzle_orm4.or)(comparison, (0, import_drizzle_orm4.isNull)(col)) : comparison;
|
|
2220
2469
|
}
|
|
2221
2470
|
if (strictlyAfter) {
|
|
2222
|
-
disjuncts.push(equalities.length ? (0,
|
|
2471
|
+
disjuncts.push(equalities.length ? (0, import_drizzle_orm4.and)(...equalities, strictlyAfter) : strictlyAfter);
|
|
2223
2472
|
}
|
|
2224
|
-
equalities.push(value === null || value === void 0 ? (0,
|
|
2473
|
+
equalities.push(value === null || value === void 0 ? (0, import_drizzle_orm4.isNull)(col) : (0, import_drizzle_orm4.eq)(col, value));
|
|
2225
2474
|
});
|
|
2226
2475
|
if (!disjuncts.length) {
|
|
2227
|
-
return
|
|
2476
|
+
return import_drizzle_orm4.sql`1 = 0`;
|
|
2228
2477
|
}
|
|
2229
|
-
return disjuncts.length > 1 ? (0,
|
|
2478
|
+
return disjuncts.length > 1 ? (0, import_drizzle_orm4.or)(...disjuncts) : disjuncts[0];
|
|
2230
2479
|
};
|
|
2231
2480
|
var isCursorFieldSelected = (tree, table) => {
|
|
2232
2481
|
if (!tree) {
|
|
2233
2482
|
return false;
|
|
2234
2483
|
}
|
|
2235
|
-
if ((0,
|
|
2484
|
+
if ((0, import_drizzle_orm4.getColumns)(table)[CURSOR_FIELD_NAME]) {
|
|
2236
2485
|
return false;
|
|
2237
2486
|
}
|
|
2238
2487
|
return Object.values(tree).some((field) => field.name === CURSOR_FIELD_NAME);
|
|
2239
2488
|
};
|
|
2489
|
+
var selectsCursorField = (info, table) => {
|
|
2490
|
+
if ((0, import_drizzle_orm4.getColumns)(table)[CURSOR_FIELD_NAME]) {
|
|
2491
|
+
return false;
|
|
2492
|
+
}
|
|
2493
|
+
const visited = /* @__PURE__ */ new Set();
|
|
2494
|
+
const walk = (selections) => selections.some((selection) => {
|
|
2495
|
+
if (selection.kind === "Field") {
|
|
2496
|
+
return selection.name.value === CURSOR_FIELD_NAME;
|
|
2497
|
+
}
|
|
2498
|
+
if (selection.kind === "InlineFragment") {
|
|
2499
|
+
return walk(selection.selectionSet.selections);
|
|
2500
|
+
}
|
|
2501
|
+
const name = selection.name?.value;
|
|
2502
|
+
if (!name || visited.has(name)) {
|
|
2503
|
+
return false;
|
|
2504
|
+
}
|
|
2505
|
+
visited.add(name);
|
|
2506
|
+
const fragment = info.fragments?.[name];
|
|
2507
|
+
return fragment ? walk(fragment.selectionSet.selections) : false;
|
|
2508
|
+
});
|
|
2509
|
+
return (info.fieldNodes ?? []).some((node) => !!node.selectionSet && walk(node.selectionSet.selections));
|
|
2510
|
+
};
|
|
2240
2511
|
var attachRowCursors = (rows, entries) => {
|
|
2241
2512
|
for (const row of rows) {
|
|
2242
2513
|
row[ROW_CURSOR_PROP] = encodeCursor(entries, row);
|
|
@@ -2244,7 +2515,7 @@ var attachRowCursors = (rows, entries) => {
|
|
|
2244
2515
|
};
|
|
2245
2516
|
var rowCursorResolver = (source) => source?.[ROW_CURSOR_PROP] ?? null;
|
|
2246
2517
|
var getUniqueColumnSets = (table, getTableConfig4) => {
|
|
2247
|
-
const cols = (0,
|
|
2518
|
+
const cols = (0, import_drizzle_orm4.getColumns)(table);
|
|
2248
2519
|
const propNameByColumnName = new Map(Object.entries(cols).map(([propName, col]) => [col.name, propName]));
|
|
2249
2520
|
const toPropNames = (columnNames) => {
|
|
2250
2521
|
const propNames = [];
|
|
@@ -2289,11 +2560,11 @@ var generateColumnEnum = (table, enumName, description, predicate = () => true)
|
|
|
2289
2560
|
if (cached) {
|
|
2290
2561
|
return cached;
|
|
2291
2562
|
}
|
|
2292
|
-
const columnNames = Object.entries((0,
|
|
2563
|
+
const columnNames = Object.entries((0, import_drizzle_orm4.getColumns)(table)).filter(([columnName, column]) => predicate(column, columnName)).map(([columnName]) => columnName);
|
|
2293
2564
|
if (!columnNames.length) {
|
|
2294
2565
|
return void 0;
|
|
2295
2566
|
}
|
|
2296
|
-
const enumType = new
|
|
2567
|
+
const enumType = new import_graphql5.GraphQLEnumType({
|
|
2297
2568
|
name: enumName,
|
|
2298
2569
|
description,
|
|
2299
2570
|
values: Object.fromEntries(columnNames.map((columnName) => [columnName, { value: columnName }]))
|
|
@@ -2306,7 +2577,7 @@ var generateColumnEnum = (table, enumName, description, predicate = () => true)
|
|
|
2306
2577
|
return enumType;
|
|
2307
2578
|
};
|
|
2308
2579
|
var generateDistinctEnum = (table, typeName) => generateColumnEnum(table, `${typeName}DistinctColumn`, `Columns of ${typeName} that a query can be made distinct on`);
|
|
2309
|
-
var conflictActionEnum = new
|
|
2580
|
+
var conflictActionEnum = new import_graphql5.GraphQLEnumType({
|
|
2310
2581
|
name: "ConflictAction",
|
|
2311
2582
|
description: "What an upsert does when a row with the same unique key already exists",
|
|
2312
2583
|
values: {
|
|
@@ -2331,7 +2602,7 @@ var generateOnConflictInput = (params) => {
|
|
|
2331
2602
|
description: "Whether a conflicting row is overwritten or left alone. Defaults to UPDATE."
|
|
2332
2603
|
},
|
|
2333
2604
|
update: {
|
|
2334
|
-
type: new
|
|
2605
|
+
type: new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(updateEnum)),
|
|
2335
2606
|
description: "Columns to overwrite on conflict. Defaults to every column the request supplied, minus the conflict target. Columns the request did not supply cannot be listed here \u2014 there would be no value to write."
|
|
2336
2607
|
}
|
|
2337
2608
|
};
|
|
@@ -2347,7 +2618,7 @@ var generateOnConflictInput = (params) => {
|
|
|
2347
2618
|
return void 0;
|
|
2348
2619
|
}
|
|
2349
2620
|
fields["target"] = {
|
|
2350
|
-
type: new
|
|
2621
|
+
type: new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(targetEnum)),
|
|
2351
2622
|
description: "The unique column set a conflict is detected on. Must match one of the table\u2019s unique constraints exactly. Defaults to the primary key."
|
|
2352
2623
|
};
|
|
2353
2624
|
fields["where"] = {
|
|
@@ -2355,7 +2626,7 @@ var generateOnConflictInput = (params) => {
|
|
|
2355
2626
|
description: "Only overwrite conflicting rows that match this filter. Others are left alone."
|
|
2356
2627
|
};
|
|
2357
2628
|
}
|
|
2358
|
-
return new
|
|
2629
|
+
return new import_graphql5.GraphQLInputObjectType({
|
|
2359
2630
|
name: `${typeName}OnConflict`,
|
|
2360
2631
|
description: `Conflict handling for an upsert of ${typeName}`,
|
|
2361
2632
|
fields
|
|
@@ -2363,18 +2634,18 @@ var generateOnConflictInput = (params) => {
|
|
|
2363
2634
|
};
|
|
2364
2635
|
var resolveConflictPlan = (params) => {
|
|
2365
2636
|
const { table, values, onConflict, pkNames, uniqueSets, excludedRef, withTarget, buildWhere } = params;
|
|
2366
|
-
const columns = (0,
|
|
2637
|
+
const columns = (0, import_drizzle_orm4.getColumns)(table);
|
|
2367
2638
|
let target;
|
|
2368
2639
|
if (withTarget) {
|
|
2369
2640
|
const targetNames2 = onConflict?.target?.length ? onConflict.target : [...pkNames];
|
|
2370
2641
|
if (!targetNames2.length) {
|
|
2371
|
-
throw new
|
|
2642
|
+
throw new import_graphql5.GraphQLError(
|
|
2372
2643
|
"Unable to upsert: no conflict target was given and this table has no primary key. Pass onConflict.target."
|
|
2373
2644
|
);
|
|
2374
2645
|
}
|
|
2375
2646
|
const requested = [...targetNames2].sort().join(",");
|
|
2376
2647
|
if (!uniqueSets.some((set2) => [...set2].sort().join(",") === requested)) {
|
|
2377
|
-
throw new
|
|
2648
|
+
throw new import_graphql5.GraphQLError(
|
|
2378
2649
|
`Unable to upsert: [${targetNames2.join(", ")}] is not a unique constraint on this table. Valid conflict targets: ${uniqueSets.map((set2) => `[${set2.join(", ")}]`).join(", ")}.`
|
|
2379
2650
|
);
|
|
2380
2651
|
}
|
|
@@ -2389,7 +2660,7 @@ var resolveConflictPlan = (params) => {
|
|
|
2389
2660
|
if (onConflict?.update?.length) {
|
|
2390
2661
|
const unsupplied = onConflict.update.filter((name) => !supplied.has(name));
|
|
2391
2662
|
if (unsupplied.length) {
|
|
2392
|
-
throw new
|
|
2663
|
+
throw new import_graphql5.GraphQLError(
|
|
2393
2664
|
`Unable to upsert: onConflict.update lists ${unsupplied.join(", ")}, which the values do not supply.`
|
|
2394
2665
|
);
|
|
2395
2666
|
}
|
|
@@ -2404,18 +2675,19 @@ var resolveConflictPlan = (params) => {
|
|
|
2404
2675
|
const setWhere = onConflict?.where && buildWhere ? buildWhere(onConflict.where) : void 0;
|
|
2405
2676
|
return { action: "UPDATE", target, set, setWhere };
|
|
2406
2677
|
};
|
|
2407
|
-
var excludedColumnRef = (columnName) =>
|
|
2408
|
-
var mysqlValuesColumnRef = (columnName) =>
|
|
2678
|
+
var excludedColumnRef = (columnName) => import_drizzle_orm4.sql`excluded.${import_drizzle_orm4.sql.identifier(columnName)}`;
|
|
2679
|
+
var mysqlValuesColumnRef = (columnName) => import_drizzle_orm4.sql`values(${import_drizzle_orm4.sql.identifier(columnName)})`;
|
|
2409
2680
|
var selectDistinctKeys = async (params) => {
|
|
2410
|
-
const { db, table, tableName, distinct, pkNames, where, orderBy, limit, offset } = params;
|
|
2411
|
-
const cols = (0,
|
|
2681
|
+
const { db, table, tableName, distinct, pkNames, where, orderBy, limit, offset, partitionBy } = params;
|
|
2682
|
+
const cols = (0, import_drizzle_orm4.getColumns)(table);
|
|
2412
2683
|
if (!pkNames.length) {
|
|
2413
|
-
throw new
|
|
2684
|
+
throw new import_graphql5.GraphQLError(`Table ${tableName} has no primary key, so 'distinct' cannot be applied to it.`);
|
|
2414
2685
|
}
|
|
2415
|
-
const
|
|
2416
|
-
if (!
|
|
2417
|
-
throw new
|
|
2686
|
+
const requestedCols = distinct.map((name) => cols[name]).filter(Boolean);
|
|
2687
|
+
if (!requestedCols.length) {
|
|
2688
|
+
throw new import_graphql5.GraphQLError(`No known columns were given to 'distinct' on ${tableName}.`);
|
|
2418
2689
|
}
|
|
2690
|
+
const partitionCols = [...partitionBy ?? [], ...requestedCols];
|
|
2419
2691
|
const orderEntries = orderBy ? orderByEntries(orderBy) : [];
|
|
2420
2692
|
const windowOrder = [
|
|
2421
2693
|
...orderEntries.flatMap(
|
|
@@ -2423,18 +2695,18 @@ var selectDistinctKeys = async (params) => {
|
|
|
2423
2695
|
),
|
|
2424
2696
|
...primaryKeyOrderExprs(table, pkNames)
|
|
2425
2697
|
];
|
|
2426
|
-
const rowNumber =
|
|
2698
|
+
const rowNumber = import_drizzle_orm4.sql`row_number() over (partition by ${import_drizzle_orm4.sql.join(partitionCols, import_drizzle_orm4.sql`, `)} order by ${import_drizzle_orm4.sql.join(
|
|
2427
2699
|
windowOrder,
|
|
2428
|
-
|
|
2700
|
+
import_drizzle_orm4.sql`, `
|
|
2429
2701
|
)})`.as(DISTINCT_RN);
|
|
2430
2702
|
const sub = db.select({ ...cols, [DISTINCT_RN]: rowNumber }).from(table).where(where).as("__dgql_distinct");
|
|
2431
2703
|
const outerOrder = [
|
|
2432
2704
|
...orderEntries.flatMap(
|
|
2433
2705
|
([column, direction, nulls]) => orderExpressions(sub[column], direction, nulls, cols[column])
|
|
2434
2706
|
),
|
|
2435
|
-
...pkNames.filter((name) => sub[name]).map((name) => (0,
|
|
2707
|
+
...pkNames.filter((name) => sub[name]).map((name) => (0, import_drizzle_orm4.asc)(sub[name]))
|
|
2436
2708
|
];
|
|
2437
|
-
let query = db.select(Object.fromEntries(pkNames.map((name) => [name, sub[name]]))).from(sub).where((0,
|
|
2709
|
+
let query = db.select(Object.fromEntries(pkNames.map((name) => [name, sub[name]]))).from(sub).where((0, import_drizzle_orm4.eq)(sub[DISTINCT_RN], 1)).orderBy(...outerOrder);
|
|
2438
2710
|
if (offset) {
|
|
2439
2711
|
query = query.offset(offset);
|
|
2440
2712
|
}
|
|
@@ -2444,15 +2716,15 @@ var selectDistinctKeys = async (params) => {
|
|
|
2444
2716
|
return await query;
|
|
2445
2717
|
};
|
|
2446
2718
|
var primaryKeyRestriction = (table, pkNames, keys) => {
|
|
2447
|
-
const cols = (0,
|
|
2719
|
+
const cols = (0, import_drizzle_orm4.getColumns)(table);
|
|
2448
2720
|
if (pkNames.length === 1) {
|
|
2449
2721
|
const name = pkNames[0];
|
|
2450
|
-
return (0,
|
|
2722
|
+
return (0, import_drizzle_orm4.inArray)(
|
|
2451
2723
|
cols[name],
|
|
2452
2724
|
keys.map((key) => key[name])
|
|
2453
2725
|
);
|
|
2454
2726
|
}
|
|
2455
|
-
return (0,
|
|
2727
|
+
return (0, import_drizzle_orm4.or)(...keys.map((key) => (0, import_drizzle_orm4.and)(...pkNames.map((name) => (0, import_drizzle_orm4.eq)(cols[name], key[name])))));
|
|
2456
2728
|
};
|
|
2457
2729
|
var prepareMutationRelationColumns = (params) => {
|
|
2458
2730
|
const { relationMap, tables, tableName, typeName, typeNameMapper, table, pkNames, parsedInfo } = params;
|
|
@@ -2467,17 +2739,17 @@ var prepareMutationRelationColumns = (params) => {
|
|
|
2467
2739
|
return { columns, hasRelations, withParams };
|
|
2468
2740
|
};
|
|
2469
2741
|
var toGraphQLError = (e) => {
|
|
2470
|
-
if (e instanceof
|
|
2742
|
+
if (e instanceof import_graphql5.GraphQLError) {
|
|
2471
2743
|
return e;
|
|
2472
2744
|
}
|
|
2473
|
-
return e instanceof Error ? new
|
|
2745
|
+
return e instanceof Error ? new import_graphql5.GraphQLError(e.message, { originalError: e }) : e;
|
|
2474
2746
|
};
|
|
2475
2747
|
var defaultErrorMapper = (error) => {
|
|
2476
|
-
if (error instanceof
|
|
2748
|
+
if (error instanceof import_graphql5.GraphQLError && !error.originalError) {
|
|
2477
2749
|
return error;
|
|
2478
2750
|
}
|
|
2479
|
-
return new
|
|
2480
|
-
originalError: error instanceof
|
|
2751
|
+
return new import_graphql5.GraphQLError("Internal server error", {
|
|
2752
|
+
originalError: error instanceof import_graphql5.GraphQLError ? error.originalError ?? error : error instanceof Error ? error : null,
|
|
2481
2753
|
extensions: { code: "INTERNAL_SERVER_ERROR" }
|
|
2482
2754
|
});
|
|
2483
2755
|
};
|
|
@@ -2534,6 +2806,9 @@ var computeResolverFieldNames = (tableName, typeNameMapper, prefixes, suffixes)
|
|
|
2534
2806
|
const writeSingleSuffix = suffixes.single === "" ? "Single" : suffixes.single;
|
|
2535
2807
|
const updateSingleFieldName = `${updateFieldName}${writeSingleSuffix}`;
|
|
2536
2808
|
const deleteSingleFieldName = `${deleteFieldName}${writeSingleSuffix}`;
|
|
2809
|
+
const pluralNoun = mapped ? capitalize(mapped.plural) : capitalize(tableName);
|
|
2810
|
+
const updateCountFieldName = `${prefixes.update}${pluralNoun}Count`;
|
|
2811
|
+
const deleteCountFieldName = `${prefixes.delete}${pluralNoun}Count`;
|
|
2537
2812
|
return {
|
|
2538
2813
|
typeName,
|
|
2539
2814
|
listFieldName,
|
|
@@ -2547,13 +2822,15 @@ var computeResolverFieldNames = (tableName, typeNameMapper, prefixes, suffixes)
|
|
|
2547
2822
|
updateFieldName,
|
|
2548
2823
|
updateManyFieldName,
|
|
2549
2824
|
updateSingleFieldName,
|
|
2825
|
+
updateCountFieldName,
|
|
2550
2826
|
deleteFieldName,
|
|
2551
|
-
deleteSingleFieldName
|
|
2827
|
+
deleteSingleFieldName,
|
|
2828
|
+
deleteCountFieldName
|
|
2552
2829
|
};
|
|
2553
2830
|
};
|
|
2554
2831
|
var generateUpdateManyInput = (params) => {
|
|
2555
2832
|
const { typeName, updatePrefix, updateInput, tableFilters } = params;
|
|
2556
|
-
return new
|
|
2833
|
+
return new import_graphql5.GraphQLInputObjectType({
|
|
2557
2834
|
name: `${capitalize(updatePrefix)}${typeName}ManyInput`,
|
|
2558
2835
|
description: `One entry of a batch update of ${typeName}: the rows \`where\` matches get this entry's \`set\` applied.`,
|
|
2559
2836
|
fields: {
|
|
@@ -2562,7 +2839,7 @@ var generateUpdateManyInput = (params) => {
|
|
|
2562
2839
|
description: "Rows this entry updates. An omitted filter updates every row."
|
|
2563
2840
|
},
|
|
2564
2841
|
set: {
|
|
2565
|
-
type: new
|
|
2842
|
+
type: new import_graphql5.GraphQLNonNull(updateInput)
|
|
2566
2843
|
}
|
|
2567
2844
|
}
|
|
2568
2845
|
});
|
|
@@ -2570,29 +2847,101 @@ var generateUpdateManyInput = (params) => {
|
|
|
2570
2847
|
var extractRequiredFilters = (table, tableName, where, fieldName, relationCtx) => {
|
|
2571
2848
|
const filters = where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
2572
2849
|
if (!filters) {
|
|
2573
|
-
throw new
|
|
2850
|
+
throw new import_graphql5.GraphQLError(`${fieldName} requires a 'where' argument with at least one filter!`);
|
|
2574
2851
|
}
|
|
2575
2852
|
return filters;
|
|
2576
2853
|
};
|
|
2854
|
+
var rowsAffected = (result, fieldName) => {
|
|
2855
|
+
const asNumber = (value) => typeof value === "number" ? value : typeof value === "bigint" ? Number(value) : void 0;
|
|
2856
|
+
if (result && typeof result === "object") {
|
|
2857
|
+
for (const key of ["rowCount", "affectedRows", "rowsAffected", "changes", "count"]) {
|
|
2858
|
+
const value = asNumber(result[key]);
|
|
2859
|
+
if (value !== void 0) {
|
|
2860
|
+
return value;
|
|
2861
|
+
}
|
|
2862
|
+
}
|
|
2863
|
+
const header = Array.isArray(result) ? result[0] : void 0;
|
|
2864
|
+
const affected = header && typeof header === "object" ? asNumber(header.affectedRows) : void 0;
|
|
2865
|
+
if (affected !== void 0) {
|
|
2866
|
+
return affected;
|
|
2867
|
+
}
|
|
2868
|
+
}
|
|
2869
|
+
throw new import_graphql5.GraphQLError(`${fieldName}: the driver did not report how many rows the write affected.`);
|
|
2870
|
+
};
|
|
2577
2871
|
var assertSingleMatch = async (executor, table, filters, fieldName) => {
|
|
2578
|
-
const matched = await executor.select({ found:
|
|
2872
|
+
const matched = await executor.select({ found: import_drizzle_orm4.sql`1` }).from(table).where(filters).limit(2);
|
|
2579
2873
|
if (matched.length > 1) {
|
|
2580
|
-
throw new
|
|
2581
|
-
}
|
|
2874
|
+
throw new import_graphql5.GraphQLError(`${fieldName}: 'where' matched more than one row \u2014 nothing was written!`);
|
|
2875
|
+
}
|
|
2876
|
+
};
|
|
2877
|
+
var generateWriteCount = ({
|
|
2878
|
+
db,
|
|
2879
|
+
tableName,
|
|
2880
|
+
table,
|
|
2881
|
+
kind,
|
|
2882
|
+
setArgs,
|
|
2883
|
+
filterArgs,
|
|
2884
|
+
fieldName,
|
|
2885
|
+
requireWhere,
|
|
2886
|
+
filterCtx,
|
|
2887
|
+
txCtx,
|
|
2888
|
+
nested
|
|
2889
|
+
}) => {
|
|
2890
|
+
const queryArgs = {
|
|
2891
|
+
...setArgs ? { set: { type: new import_graphql5.GraphQLNonNull(setArgs) } } : {},
|
|
2892
|
+
where: {
|
|
2893
|
+
type: requireWhere ? new import_graphql5.GraphQLNonNull(filterArgs) : filterArgs
|
|
2894
|
+
}
|
|
2895
|
+
};
|
|
2896
|
+
return {
|
|
2897
|
+
name: fieldName,
|
|
2898
|
+
resolver: async (_source, args, context, info) => {
|
|
2899
|
+
try {
|
|
2900
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
2901
|
+
const { where, set } = args;
|
|
2902
|
+
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
2903
|
+
const filters = requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
2904
|
+
let query;
|
|
2905
|
+
if (kind === "delete") {
|
|
2906
|
+
query = executor.delete(table);
|
|
2907
|
+
} else {
|
|
2908
|
+
const entry = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
|
|
2909
|
+
if (entry && nested.hasOps(entry.ops)) {
|
|
2910
|
+
throw new import_graphql5.GraphQLError(
|
|
2911
|
+
`${fieldName} does not support nested writes \u2014 use ${fieldName.slice(0, -"Count".length)} instead.`
|
|
2912
|
+
);
|
|
2913
|
+
}
|
|
2914
|
+
const values = remapUpdateInput(entry ? entry.columns : set, table, tableName);
|
|
2915
|
+
if (!Object.keys(values).length) {
|
|
2916
|
+
throw new import_graphql5.GraphQLError("Unable to update with no values specified!");
|
|
2917
|
+
}
|
|
2918
|
+
query = executor.update(table).set(values);
|
|
2919
|
+
}
|
|
2920
|
+
if (filters) {
|
|
2921
|
+
query = query.where(filters);
|
|
2922
|
+
}
|
|
2923
|
+
return rowsAffected(await query, fieldName);
|
|
2924
|
+
});
|
|
2925
|
+
} catch (e) {
|
|
2926
|
+
throw toGraphQLError(e);
|
|
2927
|
+
}
|
|
2928
|
+
},
|
|
2929
|
+
args: queryArgs
|
|
2930
|
+
};
|
|
2582
2931
|
};
|
|
2583
2932
|
var selectArrayArgs = (orderArgs, filterArgs, distinctEnum) => ({
|
|
2584
|
-
offset: { type:
|
|
2585
|
-
limit: { type:
|
|
2933
|
+
offset: { type: import_graphql5.GraphQLInt },
|
|
2934
|
+
limit: { type: import_graphql5.GraphQLInt },
|
|
2586
2935
|
orderBy: { type: orderArgs },
|
|
2587
2936
|
where: { type: filterArgs },
|
|
2588
2937
|
after: {
|
|
2589
|
-
type:
|
|
2938
|
+
type: import_graphql5.GraphQLString,
|
|
2590
2939
|
description: "Keyset pagination: only return rows strictly after this cursor (a row's `cursor` field from a previous page, under the same orderBy)."
|
|
2591
2940
|
},
|
|
2592
|
-
...distinctEnum ? { distinct: { type: new
|
|
2941
|
+
...distinctEnum ? { distinct: { type: new import_graphql5.GraphQLList(new import_graphql5.GraphQLNonNull(distinctEnum)) } } : {}
|
|
2593
2942
|
});
|
|
2594
2943
|
var selectSingleArgs = (orderArgs, filterArgs) => ({
|
|
2595
|
-
offset: { type:
|
|
2944
|
+
offset: { type: import_graphql5.GraphQLInt },
|
|
2596
2945
|
orderBy: { type: orderArgs },
|
|
2597
2946
|
where: { type: filterArgs }
|
|
2598
2947
|
});
|
|
@@ -2619,17 +2968,17 @@ var runRelationalSelect = async (opts) => {
|
|
|
2619
2968
|
let cursorEntries;
|
|
2620
2969
|
if (!single && (after != null || cursorSelected)) {
|
|
2621
2970
|
if (after != null && distinct) {
|
|
2622
|
-
throw new
|
|
2971
|
+
throw new import_graphql5.GraphQLError("'after' cannot be combined with 'distinct'.");
|
|
2623
2972
|
}
|
|
2624
2973
|
if (orderByHasRelationEntry(orderBy)) {
|
|
2625
2974
|
if (after != null) {
|
|
2626
|
-
throw new
|
|
2975
|
+
throw new import_graphql5.GraphQLError(
|
|
2627
2976
|
"'after' cannot be combined with an orderBy that orders through a relation \u2014 a related row's value cannot be encoded into a cursor."
|
|
2628
2977
|
);
|
|
2629
2978
|
}
|
|
2630
2979
|
} else if (!pkNames?.length) {
|
|
2631
2980
|
if (after != null) {
|
|
2632
|
-
throw new
|
|
2981
|
+
throw new import_graphql5.GraphQLError(`Table ${tableName} has no primary key, so cursor pagination cannot be used on it.`);
|
|
2633
2982
|
}
|
|
2634
2983
|
} else {
|
|
2635
2984
|
cursorEntries = cursorOrderingEntries(orderBy, pkNames);
|
|
@@ -2658,7 +3007,8 @@ var runRelationalSelect = async (opts) => {
|
|
|
2658
3007
|
columns: extractSelectedColumnsFromTree(parsedInfo.fieldsByTypeName[typeName], table, {
|
|
2659
3008
|
tableName,
|
|
2660
3009
|
relationMap,
|
|
2661
|
-
tables
|
|
3010
|
+
tables,
|
|
3011
|
+
allRelations: filterCtx?.relationMap
|
|
2662
3012
|
}),
|
|
2663
3013
|
offset: distinctKeys ? void 0 : offset,
|
|
2664
3014
|
// drizzle-orm v1 RQB calls orderBy/where with the aliased table proxy — use it
|
|
@@ -2672,7 +3022,7 @@ var runRelationalSelect = async (opts) => {
|
|
|
2672
3022
|
(aliasedTable2) => cursorOrderExprs(aliasedTable2, cursorEntries)
|
|
2673
3023
|
) : orderBy ? (aliasedTable2) => extractOrderBy(aliasedTable2, orderBy, relationFilterCtx(filterCtx, tableName)) : needsDefaultOrder && pkNames?.length ? (aliasedTable2) => primaryKeyOrderExprs(aliasedTable2, pkNames) : void 0,
|
|
2674
3024
|
where: distinctKeys ? { RAW: (aliasedTable2) => primaryKeyRestriction(aliasedTable2, pkNames, distinctKeys) } : where || cursorValues ? {
|
|
2675
|
-
RAW: (aliasedTable2) => (0,
|
|
3025
|
+
RAW: (aliasedTable2) => (0, import_drizzle_orm4.and)(
|
|
2676
3026
|
where ? extractFilters(aliasedTable2, tableName, where, relationFilterCtx(filterCtx, tableName)) : void 0,
|
|
2677
3027
|
cursorValues ? buildCursorCondition(
|
|
2678
3028
|
aliasedTable2,
|
|
@@ -2722,23 +3072,23 @@ var eagerLoadMutationRelations = async (db, tableName, rows, pkNames, withParams
|
|
|
2722
3072
|
if (pkNames.length === 1) {
|
|
2723
3073
|
const pkName = pkNames[0];
|
|
2724
3074
|
const ids = keyableRows.map((r) => r[pkName]);
|
|
2725
|
-
whereRaw = (aliased) => (0,
|
|
3075
|
+
whereRaw = (aliased) => (0, import_drizzle_orm4.inArray)(aliased[pkName], ids);
|
|
2726
3076
|
} else {
|
|
2727
3077
|
whereRaw = (aliased) => {
|
|
2728
|
-
const lhs =
|
|
2729
|
-
pkNames.map((n) =>
|
|
2730
|
-
|
|
3078
|
+
const lhs = import_drizzle_orm4.sql.join(
|
|
3079
|
+
pkNames.map((n) => import_drizzle_orm4.sql`${aliased[n]}`),
|
|
3080
|
+
import_drizzle_orm4.sql`, `
|
|
2731
3081
|
);
|
|
2732
|
-
const tuples =
|
|
3082
|
+
const tuples = import_drizzle_orm4.sql.join(
|
|
2733
3083
|
keyableRows.map(
|
|
2734
|
-
(row) =>
|
|
2735
|
-
pkNames.map((n) =>
|
|
2736
|
-
|
|
3084
|
+
(row) => import_drizzle_orm4.sql`(${import_drizzle_orm4.sql.join(
|
|
3085
|
+
pkNames.map((n) => import_drizzle_orm4.sql`${row[n]}`),
|
|
3086
|
+
import_drizzle_orm4.sql`, `
|
|
2737
3087
|
)})`
|
|
2738
3088
|
),
|
|
2739
|
-
|
|
3089
|
+
import_drizzle_orm4.sql`, `
|
|
2740
3090
|
);
|
|
2741
|
-
return
|
|
3091
|
+
return import_drizzle_orm4.sql`(${lhs}) in (${tuples})`;
|
|
2742
3092
|
};
|
|
2743
3093
|
}
|
|
2744
3094
|
let enriched;
|
|
@@ -2769,38 +3119,38 @@ var eagerLoadMutationRelations = async (db, tableName, rows, pkNames, withParams
|
|
|
2769
3119
|
};
|
|
2770
3120
|
|
|
2771
3121
|
// src/util/builders/mysql.ts
|
|
2772
|
-
var
|
|
3122
|
+
var import_drizzle_orm6 = require("drizzle-orm");
|
|
2773
3123
|
var import_mysql_core2 = require("drizzle-orm/mysql-core");
|
|
2774
|
-
var
|
|
3124
|
+
var import_graphql7 = require("graphql");
|
|
2775
3125
|
var import_graphql_parse_resolve_info2 = require("graphql-parse-resolve-info");
|
|
2776
3126
|
|
|
2777
3127
|
// src/util/builders/aggregates.ts
|
|
2778
|
-
var
|
|
2779
|
-
var
|
|
3128
|
+
var import_drizzle_orm5 = require("drizzle-orm");
|
|
3129
|
+
var import_graphql6 = require("graphql");
|
|
2780
3130
|
var import_graphql_parse_resolve_info = require("graphql-parse-resolve-info");
|
|
2781
3131
|
var AGGREGATE_OPS = ["avg", "sum", "min", "max", "countNonNull", "countDistinct"];
|
|
2782
3132
|
var COUNT_OPS = /* @__PURE__ */ new Set(["countNonNull", "countDistinct"]);
|
|
2783
3133
|
var OP_FNS = {
|
|
2784
|
-
avg:
|
|
2785
|
-
sum:
|
|
2786
|
-
min:
|
|
2787
|
-
max:
|
|
2788
|
-
countNonNull:
|
|
2789
|
-
countDistinct:
|
|
3134
|
+
avg: import_drizzle_orm5.avg,
|
|
3135
|
+
sum: import_drizzle_orm5.sum,
|
|
3136
|
+
min: import_drizzle_orm5.min,
|
|
3137
|
+
max: import_drizzle_orm5.max,
|
|
3138
|
+
countNonNull: import_drizzle_orm5.count,
|
|
3139
|
+
countDistinct: import_drizzle_orm5.countDistinct
|
|
2790
3140
|
};
|
|
2791
3141
|
var SEP = "__";
|
|
2792
3142
|
var classifyAggregateColumns = (table, tableName) => {
|
|
2793
3143
|
const numeric = {};
|
|
2794
3144
|
const orderable = {};
|
|
2795
3145
|
const all = {};
|
|
2796
|
-
for (const [columnName, column] of Object.entries((0,
|
|
3146
|
+
for (const [columnName, column] of Object.entries((0, import_drizzle_orm5.getColumns)(table))) {
|
|
2797
3147
|
all[columnName] = column;
|
|
2798
3148
|
const converted = drizzleColumnToGraphQLType(column, columnName, tableName, true, false, false);
|
|
2799
3149
|
const gqlType = converted.type;
|
|
2800
|
-
if (gqlType instanceof
|
|
3150
|
+
if (gqlType instanceof import_graphql6.GraphQLList || gqlType instanceof import_graphql6.GraphQLObjectType) {
|
|
2801
3151
|
continue;
|
|
2802
3152
|
}
|
|
2803
|
-
const { type: dataType, constraint } = (0,
|
|
3153
|
+
const { type: dataType, constraint } = (0, import_drizzle_orm5.extractExtendedColumnType)(column);
|
|
2804
3154
|
if (dataType === "boolean" || dataType === "array" || dataType === "custom") {
|
|
2805
3155
|
continue;
|
|
2806
3156
|
}
|
|
@@ -2821,14 +3171,14 @@ var generateAggregateTypes = (table, tableName, typeName, cacheCtx) => {
|
|
|
2821
3171
|
}
|
|
2822
3172
|
const { numeric, orderable, all } = classifyAggregateColumns(table, tableName);
|
|
2823
3173
|
const fields = {
|
|
2824
|
-
count: { type: new
|
|
3174
|
+
count: { type: new import_graphql6.GraphQLNonNull(import_graphql6.GraphQLInt) }
|
|
2825
3175
|
};
|
|
2826
3176
|
if (Object.keys(numeric).length) {
|
|
2827
3177
|
for (const op of ["avg", "sum"]) {
|
|
2828
3178
|
fields[op] = {
|
|
2829
|
-
type: new
|
|
3179
|
+
type: new import_graphql6.GraphQLObjectType({
|
|
2830
3180
|
name: `${typeName}${capitalize(op)}Aggregate`,
|
|
2831
|
-
fields: Object.fromEntries(Object.keys(numeric).map((columnName) => [columnName, { type:
|
|
3181
|
+
fields: Object.fromEntries(Object.keys(numeric).map((columnName) => [columnName, { type: import_graphql6.GraphQLFloat }]))
|
|
2832
3182
|
})
|
|
2833
3183
|
};
|
|
2834
3184
|
}
|
|
@@ -2836,12 +3186,12 @@ var generateAggregateTypes = (table, tableName, typeName, cacheCtx) => {
|
|
|
2836
3186
|
if (Object.keys(orderable).length) {
|
|
2837
3187
|
for (const op of ["min", "max"]) {
|
|
2838
3188
|
fields[op] = {
|
|
2839
|
-
type: new
|
|
3189
|
+
type: new import_graphql6.GraphQLObjectType({
|
|
2840
3190
|
name: `${typeName}${capitalize(op)}Aggregate`,
|
|
2841
3191
|
fields: Object.fromEntries(
|
|
2842
|
-
Object.entries(orderable).map(([columnName, { converted }]) => [
|
|
3192
|
+
Object.entries(orderable).map(([columnName, { column, converted }]) => [
|
|
2843
3193
|
columnName,
|
|
2844
|
-
{ type: converted.type,
|
|
3194
|
+
{ type: converted.type, ...columnDocs(cacheCtx?.docs ?? {}, column, tableName, columnName) }
|
|
2845
3195
|
])
|
|
2846
3196
|
)
|
|
2847
3197
|
})
|
|
@@ -2855,15 +3205,15 @@ var generateAggregateTypes = (table, tableName, typeName, cacheCtx) => {
|
|
|
2855
3205
|
continue;
|
|
2856
3206
|
}
|
|
2857
3207
|
fields[op] = {
|
|
2858
|
-
type: new
|
|
3208
|
+
type: new import_graphql6.GraphQLObjectType({
|
|
2859
3209
|
name: `${typeName}${capitalize(op)}Aggregate`,
|
|
2860
3210
|
fields: Object.fromEntries(
|
|
2861
|
-
columnNames.map((columnName) => [columnName, { type: new
|
|
3211
|
+
columnNames.map((columnName) => [columnName, { type: new import_graphql6.GraphQLNonNull(import_graphql6.GraphQLInt) }])
|
|
2862
3212
|
)
|
|
2863
3213
|
})
|
|
2864
3214
|
};
|
|
2865
3215
|
}
|
|
2866
|
-
const aggregateType = new
|
|
3216
|
+
const aggregateType = new import_graphql6.GraphQLObjectType({
|
|
2867
3217
|
name: `${typeName}Aggregate`,
|
|
2868
3218
|
fields
|
|
2869
3219
|
});
|
|
@@ -2886,9 +3236,9 @@ var aggregateTarget = (table, tableName, typeName) => {
|
|
|
2886
3236
|
return {
|
|
2887
3237
|
tableName,
|
|
2888
3238
|
typeName,
|
|
2889
|
-
columns: (0,
|
|
3239
|
+
columns: (0, import_drizzle_orm5.getColumns)(table),
|
|
2890
3240
|
dateTimeColumns: new Set(
|
|
2891
|
-
Object.entries(orderable).filter(([, { converted }]) => converted.
|
|
3241
|
+
Object.entries(orderable).filter(([, { converted }]) => converted.typeLabel === "DateTime").map(([columnName]) => columnName)
|
|
2892
3242
|
)
|
|
2893
3243
|
};
|
|
2894
3244
|
};
|
|
@@ -2903,7 +3253,7 @@ var parseAggregateRequest = (info, target, rootTypeName = `${target.typeName}Agg
|
|
|
2903
3253
|
for (const field of Object.values(selectionTree)) {
|
|
2904
3254
|
if (field.name === "count") {
|
|
2905
3255
|
request.count = true;
|
|
2906
|
-
request.selection.count = (0,
|
|
3256
|
+
request.selection.count = (0, import_drizzle_orm5.count)();
|
|
2907
3257
|
continue;
|
|
2908
3258
|
}
|
|
2909
3259
|
if (!AGGREGATE_OPS.includes(field.name)) {
|
|
@@ -3016,8 +3366,8 @@ var createRelationAggregateFactory = (db, tables, cacheCtx, typeNameMapper, filt
|
|
|
3016
3366
|
const loader = getOrCreateLoader(context, loaderKey, async (parentIds) => {
|
|
3017
3367
|
const executor = resolveExecutor(db, context);
|
|
3018
3368
|
const uniqueIds = [...new Set(parentIds)];
|
|
3019
|
-
const whereCondition = (0,
|
|
3020
|
-
(0,
|
|
3369
|
+
const whereCondition = (0, import_drizzle_orm5.and)(
|
|
3370
|
+
(0, import_drizzle_orm5.inArray)(foreignCol, uniqueIds),
|
|
3021
3371
|
whereArg ? extractFilters(targetTable, targetTableName, whereArg, relationFilterCtx(filterCtx, targetTableName)) : void 0
|
|
3022
3372
|
);
|
|
3023
3373
|
const rows = await executor.select({ [GROUP_KEY]: foreignCol, ...request.selection }).from(targetTable).where(whereCondition).groupBy(foreignCol);
|
|
@@ -3033,15 +3383,15 @@ var createRelationAggregateFactory = (db, tables, cacheCtx, typeNameMapper, filt
|
|
|
3033
3383
|
};
|
|
3034
3384
|
};
|
|
3035
3385
|
var GROUP_COL = `group${SEP}`;
|
|
3036
|
-
var HAVING_OPS = { eq:
|
|
3386
|
+
var HAVING_OPS = { eq: import_drizzle_orm5.eq, ne: import_drizzle_orm5.ne, gt: import_drizzle_orm5.gt, gte: import_drizzle_orm5.gte, lt: import_drizzle_orm5.lt, lte: import_drizzle_orm5.lte };
|
|
3037
3387
|
var groupableColumns = (table, tableName) => {
|
|
3038
3388
|
const { orderable } = classifyAggregateColumns(table, tableName);
|
|
3039
3389
|
const groupable = { ...orderable };
|
|
3040
|
-
for (const [columnName, column] of Object.entries((0,
|
|
3390
|
+
for (const [columnName, column] of Object.entries((0, import_drizzle_orm5.getColumns)(table))) {
|
|
3041
3391
|
if (groupable[columnName]) {
|
|
3042
3392
|
continue;
|
|
3043
3393
|
}
|
|
3044
|
-
const { type: dataType } = (0,
|
|
3394
|
+
const { type: dataType } = (0, import_drizzle_orm5.extractExtendedColumnType)(column);
|
|
3045
3395
|
if (dataType !== "boolean") {
|
|
3046
3396
|
continue;
|
|
3047
3397
|
}
|
|
@@ -3061,10 +3411,10 @@ var generateGroupByEnum = (table, tableName, typeName) => {
|
|
|
3061
3411
|
(_column, columnName) => Boolean(groupable[columnName])
|
|
3062
3412
|
);
|
|
3063
3413
|
};
|
|
3064
|
-
var aggregateNumberFilter = new
|
|
3414
|
+
var aggregateNumberFilter = new import_graphql6.GraphQLInputObjectType({
|
|
3065
3415
|
name: "AggregateNumberFilter",
|
|
3066
3416
|
description: "Compares an aggregated value. Several operators in one filter are ANDed together.",
|
|
3067
|
-
fields: Object.fromEntries(Object.keys(HAVING_OPS).map((op) => [op, { type:
|
|
3417
|
+
fields: Object.fromEntries(Object.keys(HAVING_OPS).map((op) => [op, { type: import_graphql6.GraphQLFloat }]))
|
|
3068
3418
|
});
|
|
3069
3419
|
var generateHavingInput = (table, tableName, typeName) => {
|
|
3070
3420
|
const { numeric, orderable, all } = classifyAggregateColumns(table, tableName);
|
|
@@ -3085,13 +3435,13 @@ var generateHavingInput = (table, tableName, typeName) => {
|
|
|
3085
3435
|
continue;
|
|
3086
3436
|
}
|
|
3087
3437
|
fields[op] = {
|
|
3088
|
-
type: new
|
|
3438
|
+
type: new import_graphql6.GraphQLInputObjectType({
|
|
3089
3439
|
name: `${typeName}${capitalize(op)}Having`,
|
|
3090
3440
|
fields: Object.fromEntries(columnNames.map((columnName) => [columnName, { type: aggregateNumberFilter }]))
|
|
3091
3441
|
})
|
|
3092
3442
|
};
|
|
3093
3443
|
}
|
|
3094
|
-
return new
|
|
3444
|
+
return new import_graphql6.GraphQLInputObjectType({
|
|
3095
3445
|
name: `${typeName}Having`,
|
|
3096
3446
|
description: `Filters ${typeName} groups by their aggregated values`,
|
|
3097
3447
|
fields
|
|
@@ -3102,13 +3452,13 @@ var generateGroupByType = (table, tableName, typeName, cacheCtx) => {
|
|
|
3102
3452
|
if (!Object.keys(groupable).length) {
|
|
3103
3453
|
return void 0;
|
|
3104
3454
|
}
|
|
3105
|
-
const keysType = new
|
|
3455
|
+
const keysType = new import_graphql6.GraphQLObjectType({
|
|
3106
3456
|
name: `${typeName}GroupKeys`,
|
|
3107
3457
|
description: `The grouped column values of one ${typeName} group. A column the query did not group by is null.`,
|
|
3108
3458
|
fields: Object.fromEntries(
|
|
3109
|
-
Object.entries(groupable).map(([columnName, { converted }]) => [
|
|
3459
|
+
Object.entries(groupable).map(([columnName, { column, converted }]) => [
|
|
3110
3460
|
columnName,
|
|
3111
|
-
{ type: converted.type,
|
|
3461
|
+
{ type: converted.type, ...columnDocs(cacheCtx?.docs ?? {}, column, tableName, columnName) }
|
|
3112
3462
|
])
|
|
3113
3463
|
)
|
|
3114
3464
|
});
|
|
@@ -3119,9 +3469,9 @@ var generateGroupByType = (table, tableName, typeName, cacheCtx) => {
|
|
|
3119
3469
|
{ type: field.type, description: field.description ?? void 0 }
|
|
3120
3470
|
])
|
|
3121
3471
|
);
|
|
3122
|
-
return new
|
|
3472
|
+
return new import_graphql6.GraphQLObjectType({
|
|
3123
3473
|
name: `${typeName}GroupBy`,
|
|
3124
|
-
fields: { group: { type: new
|
|
3474
|
+
fields: { group: { type: new import_graphql6.GraphQLNonNull(keysType) }, ...aggregateFields }
|
|
3125
3475
|
});
|
|
3126
3476
|
};
|
|
3127
3477
|
var havingComparisons = (expression, filter) => Object.entries(filter).filter(([op, value]) => value != null && op in HAVING_OPS).map(([op, value]) => HAVING_OPS[op](expression, value));
|
|
@@ -3135,7 +3485,7 @@ var buildHavingCondition = (having, columns) => {
|
|
|
3135
3485
|
continue;
|
|
3136
3486
|
}
|
|
3137
3487
|
if (key === "count") {
|
|
3138
|
-
conditions.push(...havingComparisons((0,
|
|
3488
|
+
conditions.push(...havingComparisons((0, import_drizzle_orm5.count)(), value));
|
|
3139
3489
|
continue;
|
|
3140
3490
|
}
|
|
3141
3491
|
if (!AGGREGATE_OPS.includes(key)) {
|
|
@@ -3149,16 +3499,16 @@ var buildHavingCondition = (having, columns) => {
|
|
|
3149
3499
|
conditions.push(...havingComparisons(OP_FNS[key](column), filter));
|
|
3150
3500
|
}
|
|
3151
3501
|
}
|
|
3152
|
-
return conditions.length ? (0,
|
|
3502
|
+
return conditions.length ? (0, import_drizzle_orm5.and)(...conditions) : void 0;
|
|
3153
3503
|
};
|
|
3154
3504
|
var generateGroupBy = (db, tableName, table, typeName, fieldName, filterArgs, groupByEnum, havingInput, filterCtx) => {
|
|
3155
3505
|
const target = aggregateTarget(table, tableName, typeName);
|
|
3156
3506
|
const groupable = groupableColumns(table, tableName);
|
|
3157
|
-
const columns = (0,
|
|
3507
|
+
const columns = (0, import_drizzle_orm5.getColumns)(table);
|
|
3158
3508
|
const rootTypeName = `${typeName}GroupBy`;
|
|
3159
3509
|
const queryArgs = {
|
|
3160
3510
|
groupBy: {
|
|
3161
|
-
type: new
|
|
3511
|
+
type: new import_graphql6.GraphQLNonNull(new import_graphql6.GraphQLList(new import_graphql6.GraphQLNonNull(groupByEnum))),
|
|
3162
3512
|
description: "Columns to group by. One result row per distinct combination of their values."
|
|
3163
3513
|
},
|
|
3164
3514
|
where: { type: filterArgs, description: "Filters the rows before they are grouped." },
|
|
@@ -3170,12 +3520,12 @@ var generateGroupBy = (db, tableName, table, typeName, fieldName, filterArgs, gr
|
|
|
3170
3520
|
try {
|
|
3171
3521
|
const requestedKeys = [...new Set(args.groupBy ?? [])];
|
|
3172
3522
|
if (!requestedKeys.length) {
|
|
3173
|
-
throw new
|
|
3523
|
+
throw new import_graphql6.GraphQLError("At least one column to group by is required!");
|
|
3174
3524
|
}
|
|
3175
3525
|
const keyColumns = requestedKeys.map((columnName) => {
|
|
3176
3526
|
const groupableColumn = groupable[columnName];
|
|
3177
3527
|
if (!groupableColumn) {
|
|
3178
|
-
throw new
|
|
3528
|
+
throw new import_graphql6.GraphQLError(`Cannot group ${typeName} by ${columnName}!`);
|
|
3179
3529
|
}
|
|
3180
3530
|
return [columnName, groupableColumn.column];
|
|
3181
3531
|
});
|
|
@@ -3297,7 +3647,7 @@ var generateSelectSingle = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
3297
3647
|
var generateInsertArray = (db, _tableName, table, baseType, fieldName, txCtx) => {
|
|
3298
3648
|
const queryArgs = {
|
|
3299
3649
|
values: {
|
|
3300
|
-
type: new
|
|
3650
|
+
type: new import_graphql7.GraphQLNonNull(new import_graphql7.GraphQLList(new import_graphql7.GraphQLNonNull(baseType)))
|
|
3301
3651
|
}
|
|
3302
3652
|
};
|
|
3303
3653
|
return {
|
|
@@ -3307,7 +3657,7 @@ var generateInsertArray = (db, _tableName, table, baseType, fieldName, txCtx) =>
|
|
|
3307
3657
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
3308
3658
|
const input = remapFromGraphQLArrayInput(args.values, table);
|
|
3309
3659
|
if (!input.length) {
|
|
3310
|
-
throw new
|
|
3660
|
+
throw new import_graphql7.GraphQLError("No values were provided!");
|
|
3311
3661
|
}
|
|
3312
3662
|
await executor.insert(table).values(input);
|
|
3313
3663
|
return { isSuccess: true };
|
|
@@ -3322,7 +3672,7 @@ var generateInsertArray = (db, _tableName, table, baseType, fieldName, txCtx) =>
|
|
|
3322
3672
|
var generateInsertSingle = (db, _tableName, table, baseType, fieldName, txCtx) => {
|
|
3323
3673
|
const queryArgs = {
|
|
3324
3674
|
values: {
|
|
3325
|
-
type: new
|
|
3675
|
+
type: new import_graphql7.GraphQLNonNull(baseType)
|
|
3326
3676
|
}
|
|
3327
3677
|
};
|
|
3328
3678
|
return {
|
|
@@ -3344,7 +3694,7 @@ var generateInsertSingle = (db, _tableName, table, baseType, fieldName, txCtx) =
|
|
|
3344
3694
|
var generateUpsert = (db, table, baseType, onConflictType, fieldName, single, txCtx) => {
|
|
3345
3695
|
const queryArgs = {
|
|
3346
3696
|
values: {
|
|
3347
|
-
type: single ? new
|
|
3697
|
+
type: single ? new import_graphql7.GraphQLNonNull(baseType) : new import_graphql7.GraphQLNonNull(new import_graphql7.GraphQLList(new import_graphql7.GraphQLNonNull(baseType)))
|
|
3348
3698
|
},
|
|
3349
3699
|
onConflict: {
|
|
3350
3700
|
type: onConflictType,
|
|
@@ -3359,7 +3709,7 @@ var generateUpsert = (db, table, baseType, onConflictType, fieldName, single, tx
|
|
|
3359
3709
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
3360
3710
|
const input = single ? [remapFromGraphQLSingleInput(args.values, table)] : remapFromGraphQLArrayInput(args.values, table);
|
|
3361
3711
|
if (!input.length) {
|
|
3362
|
-
throw new
|
|
3712
|
+
throw new import_graphql7.GraphQLError("No values were provided!");
|
|
3363
3713
|
}
|
|
3364
3714
|
const plan = resolveConflictPlan({
|
|
3365
3715
|
table,
|
|
@@ -3387,10 +3737,10 @@ var generateUpsert = (db, table, baseType, onConflictType, fieldName, single, tx
|
|
|
3387
3737
|
var generateUpdate = (db, tableName, table, setArgs, filterArgs, fieldName, single, requireWhere, filterCtx, txCtx) => {
|
|
3388
3738
|
const queryArgs = {
|
|
3389
3739
|
set: {
|
|
3390
|
-
type: new
|
|
3740
|
+
type: new import_graphql7.GraphQLNonNull(setArgs)
|
|
3391
3741
|
},
|
|
3392
3742
|
where: {
|
|
3393
|
-
type: single || requireWhere ? new
|
|
3743
|
+
type: single || requireWhere ? new import_graphql7.GraphQLNonNull(filterArgs) : filterArgs
|
|
3394
3744
|
}
|
|
3395
3745
|
};
|
|
3396
3746
|
return {
|
|
@@ -3399,9 +3749,9 @@ var generateUpdate = (db, tableName, table, setArgs, filterArgs, fieldName, sing
|
|
|
3399
3749
|
try {
|
|
3400
3750
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
3401
3751
|
const { where, set } = args;
|
|
3402
|
-
const input =
|
|
3752
|
+
const input = remapUpdateInput(set, table, tableName);
|
|
3403
3753
|
if (!Object.keys(input).length) {
|
|
3404
|
-
throw new
|
|
3754
|
+
throw new import_graphql7.GraphQLError("Unable to update with no values specified!");
|
|
3405
3755
|
}
|
|
3406
3756
|
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
3407
3757
|
const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
@@ -3425,7 +3775,7 @@ var generateUpdate = (db, tableName, table, setArgs, filterArgs, fieldName, sing
|
|
|
3425
3775
|
var generateUpdateMany = (db, tableName, table, updateManyInput, fieldName, filterCtx, txCtx) => {
|
|
3426
3776
|
const queryArgs = {
|
|
3427
3777
|
updates: {
|
|
3428
|
-
type: new
|
|
3778
|
+
type: new import_graphql7.GraphQLNonNull(new import_graphql7.GraphQLList(new import_graphql7.GraphQLNonNull(updateManyInput)))
|
|
3429
3779
|
}
|
|
3430
3780
|
};
|
|
3431
3781
|
return {
|
|
@@ -3435,12 +3785,12 @@ var generateUpdateMany = (db, tableName, table, updateManyInput, fieldName, filt
|
|
|
3435
3785
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
3436
3786
|
const { updates } = args;
|
|
3437
3787
|
if (!updates.length) {
|
|
3438
|
-
throw new
|
|
3788
|
+
throw new import_graphql7.GraphQLError("No updates were provided!");
|
|
3439
3789
|
}
|
|
3440
3790
|
const entries = updates.map(({ where, set }) => {
|
|
3441
|
-
const input =
|
|
3791
|
+
const input = remapUpdateInput(set, table, tableName);
|
|
3442
3792
|
if (!Object.keys(input).length) {
|
|
3443
|
-
throw new
|
|
3793
|
+
throw new import_graphql7.GraphQLError("Unable to update with no values specified!");
|
|
3444
3794
|
}
|
|
3445
3795
|
return {
|
|
3446
3796
|
set: input,
|
|
@@ -3468,7 +3818,7 @@ var generateUpdateMany = (db, tableName, table, updateManyInput, fieldName, filt
|
|
|
3468
3818
|
var generateDelete = (db, tableName, table, filterArgs, fieldName, single, requireWhere, filterCtx, txCtx) => {
|
|
3469
3819
|
const queryArgs = {
|
|
3470
3820
|
where: {
|
|
3471
|
-
type: single || requireWhere ? new
|
|
3821
|
+
type: single || requireWhere ? new import_graphql7.GraphQLNonNull(filterArgs) : filterArgs
|
|
3472
3822
|
}
|
|
3473
3823
|
};
|
|
3474
3824
|
return {
|
|
@@ -3501,19 +3851,30 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3501
3851
|
const { relationsDepthLimit, prefixes, suffixes, typeNameMapper, shouldEagerLoad, features, complexity } = options;
|
|
3502
3852
|
const rawSchema = schema;
|
|
3503
3853
|
const schemaEntries = Object.entries(rawSchema);
|
|
3504
|
-
const tableEntries = schemaEntries.filter(([_key, value]) => (0,
|
|
3854
|
+
const tableEntries = schemaEntries.filter(([_key, value]) => (0, import_drizzle_orm6.is)(value, import_mysql_core2.MySqlTable));
|
|
3505
3855
|
const tables = Object.fromEntries(tableEntries);
|
|
3506
3856
|
if (!tableEntries.length) {
|
|
3507
3857
|
throw new Error(
|
|
3508
3858
|
"Drizzle-GraphQL Error: No tables detected in Drizzle-ORM's database instance. Did you forget to pass schema to drizzle constructor?"
|
|
3509
3859
|
);
|
|
3510
3860
|
}
|
|
3861
|
+
if (features.nestedWrites) {
|
|
3862
|
+
throw new Error(
|
|
3863
|
+
"Drizzle-GraphQL Error: features.nestedWrites is not supported on MySQL \u2014 a nested write needs the parent row it just inserted returned to it, and MySQL has no RETURNING clause."
|
|
3864
|
+
);
|
|
3865
|
+
}
|
|
3511
3866
|
registerScalarOverrides(tables, options);
|
|
3867
|
+
registerEnumConfig(options);
|
|
3512
3868
|
const namedRelations = buildNamedRelations(relations ?? {}, tableEntries);
|
|
3513
3869
|
attachTargetPrimaryKeys(namedRelations, tables, mysqlPrimaryKeyPropNames);
|
|
3514
3870
|
const eagerRelations = pruneNonEagerRelations(namedRelations, shouldEagerLoad);
|
|
3515
3871
|
const filterCtx = { tables, relationMap: namedRelations };
|
|
3516
|
-
const resolverFactory = createRelationResolverFactory(
|
|
3872
|
+
const resolverFactory = createRelationResolverFactory(
|
|
3873
|
+
db,
|
|
3874
|
+
tables,
|
|
3875
|
+
"nulls-smallest",
|
|
3876
|
+
filterCtx
|
|
3877
|
+
);
|
|
3517
3878
|
const cacheCtx = {
|
|
3518
3879
|
genericFilterCache: /* @__PURE__ */ new Map(),
|
|
3519
3880
|
objectTypeCache: /* @__PURE__ */ new Map(),
|
|
@@ -3526,7 +3887,9 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3526
3887
|
filterTypeCache: /* @__PURE__ */ new WeakMap(),
|
|
3527
3888
|
listRelationFilterCache: /* @__PURE__ */ new Map(),
|
|
3528
3889
|
aggregateTypeCache: /* @__PURE__ */ new Map(),
|
|
3529
|
-
complexity
|
|
3890
|
+
complexity,
|
|
3891
|
+
docs: options.docs ?? {},
|
|
3892
|
+
features
|
|
3530
3893
|
};
|
|
3531
3894
|
const relationAggregateFactory = features.relationAggregates ? createRelationAggregateFactory(db, tables, cacheCtx, typeNameMapper, filterCtx) : void 0;
|
|
3532
3895
|
const queries = {};
|
|
@@ -3550,11 +3913,11 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3550
3913
|
)
|
|
3551
3914
|
])
|
|
3552
3915
|
);
|
|
3553
|
-
const mutationReturnType = new
|
|
3916
|
+
const mutationReturnType = new import_graphql7.GraphQLObjectType({
|
|
3554
3917
|
name: "MutationReturn",
|
|
3555
3918
|
fields: {
|
|
3556
3919
|
isSuccess: {
|
|
3557
|
-
type: new
|
|
3920
|
+
type: new import_graphql7.GraphQLNonNull(import_graphql7.GraphQLBoolean)
|
|
3558
3921
|
}
|
|
3559
3922
|
}
|
|
3560
3923
|
});
|
|
@@ -3579,8 +3942,10 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3579
3942
|
updateFieldName,
|
|
3580
3943
|
updateManyFieldName,
|
|
3581
3944
|
updateSingleFieldName,
|
|
3945
|
+
updateCountFieldName,
|
|
3582
3946
|
deleteFieldName,
|
|
3583
|
-
deleteSingleFieldName
|
|
3947
|
+
deleteSingleFieldName,
|
|
3948
|
+
deleteCountFieldName
|
|
3584
3949
|
} = computeResolverFieldNames(tableName, typeNameMapper, prefixes, suffixes);
|
|
3585
3950
|
const selectArrGenerated = generateSelectArray(
|
|
3586
3951
|
db,
|
|
@@ -3704,6 +4069,29 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3704
4069
|
filterCtx,
|
|
3705
4070
|
mutationTxCtx
|
|
3706
4071
|
) : void 0;
|
|
4072
|
+
const updateCountGenerated = features.update && features.countMutations ? generateWriteCount({
|
|
4073
|
+
db,
|
|
4074
|
+
tableName,
|
|
4075
|
+
table: schema[tableName],
|
|
4076
|
+
kind: "update",
|
|
4077
|
+
setArgs: updateInput,
|
|
4078
|
+
filterArgs: tableFilters,
|
|
4079
|
+
fieldName: updateCountFieldName,
|
|
4080
|
+
requireWhere: features.requireWhere,
|
|
4081
|
+
filterCtx,
|
|
4082
|
+
txCtx: mutationTxCtx
|
|
4083
|
+
}) : void 0;
|
|
4084
|
+
const deleteCountGenerated = features.delete && features.countMutations ? generateWriteCount({
|
|
4085
|
+
db,
|
|
4086
|
+
tableName,
|
|
4087
|
+
table: schema[tableName],
|
|
4088
|
+
kind: "delete",
|
|
4089
|
+
filterArgs: tableFilters,
|
|
4090
|
+
fieldName: deleteCountFieldName,
|
|
4091
|
+
requireWhere: features.requireWhere,
|
|
4092
|
+
filterCtx,
|
|
4093
|
+
txCtx: mutationTxCtx
|
|
4094
|
+
}) : void 0;
|
|
3707
4095
|
const aggregateType = features.aggregates ? generateAggregateTypes(schema[tableName], tableName, typeName, cacheCtx) : void 0;
|
|
3708
4096
|
const aggregateGenerated = features.aggregates ? generateAggregate(
|
|
3709
4097
|
db,
|
|
@@ -3741,7 +4129,7 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3741
4129
|
};
|
|
3742
4130
|
if (aggregateGenerated && aggregateType) {
|
|
3743
4131
|
queries[aggregateGenerated.name] = {
|
|
3744
|
-
type: new
|
|
4132
|
+
type: new import_graphql7.GraphQLNonNull(aggregateType),
|
|
3745
4133
|
args: aggregateGenerated.args,
|
|
3746
4134
|
resolve: aggregateGenerated.resolver,
|
|
3747
4135
|
...complexity ? { extensions: { complexity: aggregateFieldComplexity(complexity) } } : {}
|
|
@@ -3749,7 +4137,7 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3749
4137
|
}
|
|
3750
4138
|
if (groupByGenerated && groupByType) {
|
|
3751
4139
|
queries[groupByGenerated.name] = {
|
|
3752
|
-
type: new
|
|
4140
|
+
type: new import_graphql7.GraphQLNonNull(new import_graphql7.GraphQLList(new import_graphql7.GraphQLNonNull(groupByType))),
|
|
3753
4141
|
args: groupByGenerated.args,
|
|
3754
4142
|
resolve: groupByGenerated.resolver,
|
|
3755
4143
|
...complexity ? { extensions: { complexity: aggregateFieldComplexity(complexity) } } : {}
|
|
@@ -3774,6 +4162,22 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3774
4162
|
};
|
|
3775
4163
|
}
|
|
3776
4164
|
}
|
|
4165
|
+
if (updateCountGenerated) {
|
|
4166
|
+
mutations[updateCountGenerated.name] = {
|
|
4167
|
+
type: new import_graphql7.GraphQLNonNull(import_graphql7.GraphQLInt),
|
|
4168
|
+
args: updateCountGenerated.args,
|
|
4169
|
+
resolve: updateCountGenerated.resolver,
|
|
4170
|
+
description: "How many rows the update touched. The rows themselves are not read back, which is the point of this mutation."
|
|
4171
|
+
};
|
|
4172
|
+
}
|
|
4173
|
+
if (deleteCountGenerated) {
|
|
4174
|
+
mutations[deleteCountGenerated.name] = {
|
|
4175
|
+
type: new import_graphql7.GraphQLNonNull(import_graphql7.GraphQLInt),
|
|
4176
|
+
args: deleteCountGenerated.args,
|
|
4177
|
+
resolve: deleteCountGenerated.resolver,
|
|
4178
|
+
description: "How many rows the delete removed. The rows themselves are not read back, which is the point of this mutation."
|
|
4179
|
+
};
|
|
4180
|
+
}
|
|
3777
4181
|
const activeInputs = [
|
|
3778
4182
|
// The insert input types the upsert mutations too, so either feature keeps it.
|
|
3779
4183
|
...features.insert || onConflictInput ? [insertInput] : [],
|
|
@@ -3804,7 +4208,7 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3804
4208
|
for (const [tableName, tableRelations] of Object.entries(namedRelations)) {
|
|
3805
4209
|
const relResolvers = {};
|
|
3806
4210
|
for (const [relName, relEntry] of Object.entries(tableRelations)) {
|
|
3807
|
-
const isOne = (0,
|
|
4211
|
+
const isOne = (0, import_drizzle_orm6.is)(relEntry.relation ?? relEntry, import_drizzle_orm6.One);
|
|
3808
4212
|
const resolver = resolverFactory({ tableName, relationName: relName, relEntry, isOne });
|
|
3809
4213
|
if (resolver) {
|
|
3810
4214
|
relResolvers[relName] = resolver;
|
|
@@ -3818,10 +4222,389 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3818
4222
|
};
|
|
3819
4223
|
|
|
3820
4224
|
// src/util/builders/pg.ts
|
|
3821
|
-
var
|
|
4225
|
+
var import_drizzle_orm8 = require("drizzle-orm");
|
|
3822
4226
|
var import_pg_core2 = require("drizzle-orm/pg-core");
|
|
3823
|
-
var
|
|
4227
|
+
var import_graphql9 = require("graphql");
|
|
3824
4228
|
var import_graphql_parse_resolve_info3 = require("graphql-parse-resolve-info");
|
|
4229
|
+
|
|
4230
|
+
// src/util/builders/nested-writes.ts
|
|
4231
|
+
var import_drizzle_orm7 = require("drizzle-orm");
|
|
4232
|
+
var import_graphql8 = require("graphql");
|
|
4233
|
+
var isOptionalOnInsert = (column) => !column.notNull || !!column.hasDefault || !!column.defaultFn;
|
|
4234
|
+
var buildNestedWritePlans = (tables, relationMap, resolveUniqueSets, resolvePrimaryKeys, extractJoinColumns) => {
|
|
4235
|
+
const uniqueCache = /* @__PURE__ */ new Map();
|
|
4236
|
+
const singleColumnUniques = (tableName, table) => {
|
|
4237
|
+
let cached = uniqueCache.get(tableName);
|
|
4238
|
+
if (!cached) {
|
|
4239
|
+
cached = new Set(
|
|
4240
|
+
resolveUniqueSets(table).filter((set) => set.length === 1).map((set) => set[0])
|
|
4241
|
+
);
|
|
4242
|
+
uniqueCache.set(tableName, cached);
|
|
4243
|
+
}
|
|
4244
|
+
return cached;
|
|
4245
|
+
};
|
|
4246
|
+
const pkCache = /* @__PURE__ */ new Map();
|
|
4247
|
+
const singleColumnPk = (tableName, table) => {
|
|
4248
|
+
if (!pkCache.has(tableName)) {
|
|
4249
|
+
const pk = resolvePrimaryKeys(table);
|
|
4250
|
+
pkCache.set(tableName, pk.length === 1 ? pk[0] : void 0);
|
|
4251
|
+
}
|
|
4252
|
+
return pkCache.get(tableName);
|
|
4253
|
+
};
|
|
4254
|
+
const plans = {};
|
|
4255
|
+
for (const [tableName, relations] of Object.entries(relationMap)) {
|
|
4256
|
+
const table = tables[tableName];
|
|
4257
|
+
if (!table) {
|
|
4258
|
+
continue;
|
|
4259
|
+
}
|
|
4260
|
+
const tablePlans = {};
|
|
4261
|
+
for (const [relationName, relEntry] of Object.entries(relations)) {
|
|
4262
|
+
const relation = relEntry.relation;
|
|
4263
|
+
if (relation.through) {
|
|
4264
|
+
continue;
|
|
4265
|
+
}
|
|
4266
|
+
const targetTableName = relEntry.targetTableName;
|
|
4267
|
+
const targetTable = tables[targetTableName];
|
|
4268
|
+
if (!targetTable) {
|
|
4269
|
+
continue;
|
|
4270
|
+
}
|
|
4271
|
+
const joinColumns = extractJoinColumns(relEntry, table, targetTable);
|
|
4272
|
+
if (!joinColumns) {
|
|
4273
|
+
continue;
|
|
4274
|
+
}
|
|
4275
|
+
const { localColPropName, foreignCol, foreignColPropName } = joinColumns;
|
|
4276
|
+
const localCol = (0, import_drizzle_orm7.getColumns)(table)[localColPropName];
|
|
4277
|
+
if (!localCol) {
|
|
4278
|
+
continue;
|
|
4279
|
+
}
|
|
4280
|
+
const isOne = (0, import_drizzle_orm7.is)(relation, import_drizzle_orm7.One);
|
|
4281
|
+
const localIsPk = singleColumnPk(tableName, table) === localColPropName;
|
|
4282
|
+
const foreignIsPk = singleColumnPk(targetTableName, targetTable) === foreignColPropName;
|
|
4283
|
+
const localIsUnique = singleColumnUniques(tableName, table).has(localColPropName);
|
|
4284
|
+
const foreignIsUnique = singleColumnUniques(targetTableName, targetTable).has(foreignColPropName);
|
|
4285
|
+
let fkSide;
|
|
4286
|
+
if (!isOne) {
|
|
4287
|
+
fkSide = "child";
|
|
4288
|
+
} else if (foreignIsPk && !localIsPk) {
|
|
4289
|
+
fkSide = "parent";
|
|
4290
|
+
} else if (localIsPk) {
|
|
4291
|
+
fkSide = "child";
|
|
4292
|
+
} else if (foreignIsUnique) {
|
|
4293
|
+
fkSide = "parent";
|
|
4294
|
+
} else if (localIsUnique) {
|
|
4295
|
+
fkSide = "child";
|
|
4296
|
+
} else {
|
|
4297
|
+
continue;
|
|
4298
|
+
}
|
|
4299
|
+
const fkColumn = fkSide === "child" ? foreignCol : localCol;
|
|
4300
|
+
tablePlans[relationName] = {
|
|
4301
|
+
relationName,
|
|
4302
|
+
targetTableName,
|
|
4303
|
+
targetTable,
|
|
4304
|
+
localColPropName,
|
|
4305
|
+
foreignColPropName,
|
|
4306
|
+
foreignCol,
|
|
4307
|
+
localCol,
|
|
4308
|
+
isOne,
|
|
4309
|
+
fkSide,
|
|
4310
|
+
canDetach: !fkColumn.notNull
|
|
4311
|
+
};
|
|
4312
|
+
}
|
|
4313
|
+
if (Object.keys(tablePlans).length) {
|
|
4314
|
+
plans[tableName] = tablePlans;
|
|
4315
|
+
}
|
|
4316
|
+
}
|
|
4317
|
+
return plans;
|
|
4318
|
+
};
|
|
4319
|
+
var NO_COLUMNS = /* @__PURE__ */ new Set();
|
|
4320
|
+
var createNestedWriteTypes = (params) => {
|
|
4321
|
+
const { plans, cacheCtx, typeNameMapper, insertPrefix } = params;
|
|
4322
|
+
const wrapperCache = /* @__PURE__ */ new Map();
|
|
4323
|
+
const payloadCache = /* @__PURE__ */ new Map();
|
|
4324
|
+
const payloadType = (tableName, typeName, plan) => {
|
|
4325
|
+
const key = `${tableName}.${plan.relationName}`;
|
|
4326
|
+
const cached = payloadCache.get(key);
|
|
4327
|
+
if (cached) {
|
|
4328
|
+
return cached;
|
|
4329
|
+
}
|
|
4330
|
+
const omitted = plan.fkSide === "child" ? plan.foreignColPropName : void 0;
|
|
4331
|
+
const fields = Object.fromEntries(
|
|
4332
|
+
Object.entries((0, import_drizzle_orm7.getColumns)(plan.targetTable)).filter(([columnName]) => columnName !== omitted).map(([columnName, column]) => [
|
|
4333
|
+
columnName,
|
|
4334
|
+
drizzleColumnToGraphQLType(column, columnName, plan.targetTableName, false, true, true)
|
|
4335
|
+
])
|
|
4336
|
+
);
|
|
4337
|
+
const type = new import_graphql8.GraphQLInputObjectType({
|
|
4338
|
+
name: `${capitalize(insertPrefix)}${typeName}${capitalize(plan.relationName)}Input`,
|
|
4339
|
+
description: omitted === void 0 ? `A new ${resolveTypeName(plan.targetTableName, typeNameMapper)} row for ${typeName}.${plan.relationName}` : `A new ${resolveTypeName(plan.targetTableName, typeNameMapper)} row for ${typeName}.${plan.relationName}. \`${omitted}\` is set from the ${typeName} row this is written with.`,
|
|
4340
|
+
fields
|
|
4341
|
+
});
|
|
4342
|
+
payloadCache.set(key, type);
|
|
4343
|
+
return type;
|
|
4344
|
+
};
|
|
4345
|
+
const targetFilters = (plan) => cacheCtx.filterTypeCache.get(plan.targetTable);
|
|
4346
|
+
const listOf = (type) => new import_graphql8.GraphQLList(new import_graphql8.GraphQLNonNull(type));
|
|
4347
|
+
const wrapperType = (tableName, typeName, plan, forUpdate) => {
|
|
4348
|
+
const key = `${tableName}.${plan.relationName}.${forUpdate ? "update" : "create"}`;
|
|
4349
|
+
const cached = wrapperCache.get(key);
|
|
4350
|
+
if (cached) {
|
|
4351
|
+
return cached;
|
|
4352
|
+
}
|
|
4353
|
+
const filters = targetFilters(plan);
|
|
4354
|
+
const payload = payloadType(tableName, typeName, plan);
|
|
4355
|
+
const targetTypeName = resolveTypeName(plan.targetTableName, typeNameMapper);
|
|
4356
|
+
const fields = {};
|
|
4357
|
+
if (plan.isOne) {
|
|
4358
|
+
fields["create"] = { type: payload, description: `Insert a ${targetTypeName} row and attach it` };
|
|
4359
|
+
if (filters) {
|
|
4360
|
+
fields["connect"] = {
|
|
4361
|
+
type: filters,
|
|
4362
|
+
description: `Attach the existing ${targetTypeName} row this matches. Must match exactly one row.`
|
|
4363
|
+
};
|
|
4364
|
+
}
|
|
4365
|
+
if (forUpdate && plan.canDetach) {
|
|
4366
|
+
fields["disconnect"] = {
|
|
4367
|
+
type: import_graphql8.GraphQLBoolean,
|
|
4368
|
+
description: `Detach the currently attached ${targetTypeName} row, leaving it in place`
|
|
4369
|
+
};
|
|
4370
|
+
}
|
|
4371
|
+
} else {
|
|
4372
|
+
fields["create"] = { type: listOf(payload), description: `Insert these ${targetTypeName} rows and attach them` };
|
|
4373
|
+
if (filters) {
|
|
4374
|
+
fields["connect"] = {
|
|
4375
|
+
type: listOf(filters),
|
|
4376
|
+
description: `Attach every existing ${targetTypeName} row these match`
|
|
4377
|
+
};
|
|
4378
|
+
if (forUpdate && plan.canDetach) {
|
|
4379
|
+
fields["disconnect"] = {
|
|
4380
|
+
type: listOf(filters),
|
|
4381
|
+
description: `Detach every attached ${targetTypeName} row these match, leaving the rows in place`
|
|
4382
|
+
};
|
|
4383
|
+
fields["set"] = {
|
|
4384
|
+
type: listOf(filters),
|
|
4385
|
+
description: `Replace the whole set: detach everything attached, then attach every ${targetTypeName} row these match. Applied before \`disconnect\`, \`connect\` and \`create\`.`
|
|
4386
|
+
};
|
|
4387
|
+
}
|
|
4388
|
+
}
|
|
4389
|
+
}
|
|
4390
|
+
const type = new import_graphql8.GraphQLInputObjectType({
|
|
4391
|
+
name: `${typeName}${capitalize(plan.relationName)}Nested${forUpdate ? "Update" : "Create"}Input`,
|
|
4392
|
+
description: `Writes through ${typeName}.${plan.relationName}`,
|
|
4393
|
+
fields
|
|
4394
|
+
});
|
|
4395
|
+
wrapperCache.set(key, type);
|
|
4396
|
+
return type;
|
|
4397
|
+
};
|
|
4398
|
+
const relationFields = (tableName, typeName, forUpdate) => {
|
|
4399
|
+
const tablePlans = plans[tableName];
|
|
4400
|
+
if (!tablePlans) {
|
|
4401
|
+
return {};
|
|
4402
|
+
}
|
|
4403
|
+
return Object.fromEntries(
|
|
4404
|
+
Object.values(tablePlans).flatMap((plan) => {
|
|
4405
|
+
const wrapper = wrapperType(tableName, typeName, plan, forUpdate);
|
|
4406
|
+
return wrapper ? [[plan.relationName, { type: wrapper, description: `Writes through ${typeName}.${plan.relationName}` }]] : [];
|
|
4407
|
+
})
|
|
4408
|
+
);
|
|
4409
|
+
};
|
|
4410
|
+
return {
|
|
4411
|
+
createFields: (tableName, typeName) => relationFields(tableName, typeName, false),
|
|
4412
|
+
updateFields: (tableName, typeName) => relationFields(tableName, typeName, true),
|
|
4413
|
+
relaxedColumns: (tableName) => {
|
|
4414
|
+
const tablePlans = plans[tableName];
|
|
4415
|
+
if (!tablePlans) {
|
|
4416
|
+
return NO_COLUMNS;
|
|
4417
|
+
}
|
|
4418
|
+
const relaxed = /* @__PURE__ */ new Set();
|
|
4419
|
+
for (const plan of Object.values(tablePlans)) {
|
|
4420
|
+
if (plan.fkSide === "parent" && !isOptionalOnInsert(plan.localCol)) {
|
|
4421
|
+
relaxed.add(plan.localColPropName);
|
|
4422
|
+
}
|
|
4423
|
+
}
|
|
4424
|
+
return relaxed.size ? relaxed : NO_COLUMNS;
|
|
4425
|
+
}
|
|
4426
|
+
};
|
|
4427
|
+
};
|
|
4428
|
+
var mergedOps = (entries) => Object.assign({}, ...entries.map((entry) => entry.ops));
|
|
4429
|
+
var asArray = (value) => Array.isArray(value) ? value : value === void 0 ? [] : [value];
|
|
4430
|
+
var createNestedWriteRuntime = (params) => {
|
|
4431
|
+
const { plans, filterCtx } = params;
|
|
4432
|
+
const conditionOf = (plan, filter, operation) => {
|
|
4433
|
+
const condition = extractFilters(
|
|
4434
|
+
plan.targetTable,
|
|
4435
|
+
plan.targetTableName,
|
|
4436
|
+
filter,
|
|
4437
|
+
relationFilterCtx(filterCtx, plan.targetTableName)
|
|
4438
|
+
);
|
|
4439
|
+
if (!condition) {
|
|
4440
|
+
throw new import_graphql8.GraphQLError(
|
|
4441
|
+
`Drizzle-GraphQL Error: '${operation}' on '${plan.relationName}' needs a filter that selects rows \u2014 it was given one that matches everything.`
|
|
4442
|
+
);
|
|
4443
|
+
}
|
|
4444
|
+
return condition;
|
|
4445
|
+
};
|
|
4446
|
+
const assertSingleOperation = (plan, op) => {
|
|
4447
|
+
const supplied = ["create", "connect", "disconnect"].filter((key) => op[key] !== void 0 && op[key] !== null);
|
|
4448
|
+
if (supplied.length > 1) {
|
|
4449
|
+
throw new import_graphql8.GraphQLError(
|
|
4450
|
+
`Drizzle-GraphQL Error: '${plan.relationName}' takes one of ${supplied.join(", ")} at a time \u2014 it holds a single row.`
|
|
4451
|
+
);
|
|
4452
|
+
}
|
|
4453
|
+
};
|
|
4454
|
+
const detachAll = async (executor, plan, key) => executor.update(plan.targetTable).set({ [plan.foreignColPropName]: null }).where((0, import_drizzle_orm7.eq)(plan.foreignCol, key));
|
|
4455
|
+
return {
|
|
4456
|
+
enabled: (tableName) => !!plans[tableName],
|
|
4457
|
+
split: (tableName, values) => {
|
|
4458
|
+
const tablePlans = plans[tableName];
|
|
4459
|
+
if (!tablePlans) {
|
|
4460
|
+
return { columns: values, ops: {} };
|
|
4461
|
+
}
|
|
4462
|
+
const columns = {};
|
|
4463
|
+
const ops = {};
|
|
4464
|
+
for (const [key, value] of Object.entries(values)) {
|
|
4465
|
+
if (tablePlans[key] && value !== void 0 && value !== null) {
|
|
4466
|
+
ops[key] = value;
|
|
4467
|
+
} else if (!tablePlans[key]) {
|
|
4468
|
+
columns[key] = value;
|
|
4469
|
+
}
|
|
4470
|
+
}
|
|
4471
|
+
return { columns, ops };
|
|
4472
|
+
},
|
|
4473
|
+
hasOps: (ops) => Object.keys(ops).length > 0,
|
|
4474
|
+
withJoinColumns: (tableName, ops, columns, table) => {
|
|
4475
|
+
const tablePlans = plans[tableName];
|
|
4476
|
+
if (!tablePlans) {
|
|
4477
|
+
return columns;
|
|
4478
|
+
}
|
|
4479
|
+
const allColumns = (0, import_drizzle_orm7.getColumns)(table);
|
|
4480
|
+
for (const relationName of Object.keys(ops)) {
|
|
4481
|
+
const plan = tablePlans[relationName];
|
|
4482
|
+
if (plan?.fkSide === "child" && !(plan.localColPropName in columns) && allColumns[plan.localColPropName]) {
|
|
4483
|
+
columns[plan.localColPropName] = allColumns[plan.localColPropName];
|
|
4484
|
+
}
|
|
4485
|
+
}
|
|
4486
|
+
return columns;
|
|
4487
|
+
},
|
|
4488
|
+
applyParentSide: async (executor, tableName, ops) => {
|
|
4489
|
+
const tablePlans = plans[tableName];
|
|
4490
|
+
const patch = {};
|
|
4491
|
+
if (!tablePlans) {
|
|
4492
|
+
return patch;
|
|
4493
|
+
}
|
|
4494
|
+
for (const [relationName, op] of Object.entries(ops)) {
|
|
4495
|
+
const plan = tablePlans[relationName];
|
|
4496
|
+
if (!plan || plan.fkSide !== "parent") {
|
|
4497
|
+
continue;
|
|
4498
|
+
}
|
|
4499
|
+
assertSingleOperation(plan, op);
|
|
4500
|
+
if (op["create"] !== void 0) {
|
|
4501
|
+
const values = remapFromGraphQLSingleInput({ ...op["create"] }, plan.targetTable);
|
|
4502
|
+
const inserted = await executor.insert(plan.targetTable).values(values).returning();
|
|
4503
|
+
const created = inserted[0];
|
|
4504
|
+
if (!created) {
|
|
4505
|
+
throw new import_graphql8.GraphQLError(
|
|
4506
|
+
`Drizzle-GraphQL Error: 'create' on '${relationName}' inserted no row, so there is nothing to attach.`
|
|
4507
|
+
);
|
|
4508
|
+
}
|
|
4509
|
+
patch[plan.localColPropName] = created[plan.foreignColPropName];
|
|
4510
|
+
} else if (op["connect"] !== void 0) {
|
|
4511
|
+
const rows = await executor.select().from(plan.targetTable).where(conditionOf(plan, op["connect"], "connect"));
|
|
4512
|
+
if (rows.length !== 1) {
|
|
4513
|
+
throw new import_graphql8.GraphQLError(
|
|
4514
|
+
`Drizzle-GraphQL Error: 'connect' on '${relationName}' matched ${rows.length} rows \u2014 it attaches a single row, so its filter must match exactly one.`
|
|
4515
|
+
);
|
|
4516
|
+
}
|
|
4517
|
+
patch[plan.localColPropName] = rows[0][plan.foreignColPropName];
|
|
4518
|
+
} else if (op["disconnect"] === true) {
|
|
4519
|
+
patch[plan.localColPropName] = null;
|
|
4520
|
+
}
|
|
4521
|
+
}
|
|
4522
|
+
return patch;
|
|
4523
|
+
},
|
|
4524
|
+
applyChildSide: async (executor, tableName, ops, parentRows) => {
|
|
4525
|
+
const tablePlans = plans[tableName];
|
|
4526
|
+
if (!tablePlans) {
|
|
4527
|
+
return;
|
|
4528
|
+
}
|
|
4529
|
+
for (const [relationName, op] of Object.entries(ops)) {
|
|
4530
|
+
const plan = tablePlans[relationName];
|
|
4531
|
+
if (!plan || plan.fkSide !== "child") {
|
|
4532
|
+
continue;
|
|
4533
|
+
}
|
|
4534
|
+
if (plan.isOne) {
|
|
4535
|
+
assertSingleOperation(plan, op);
|
|
4536
|
+
}
|
|
4537
|
+
for (const parentRow of parentRows) {
|
|
4538
|
+
const key = parentRow?.[plan.localColPropName];
|
|
4539
|
+
if (key === void 0 || key === null) {
|
|
4540
|
+
throw new import_graphql8.GraphQLError(
|
|
4541
|
+
`Drizzle-GraphQL Error: cannot write through '${relationName}': the ${tableName} row has no '${plan.localColPropName}' value to attach to.`
|
|
4542
|
+
);
|
|
4543
|
+
}
|
|
4544
|
+
if (op["set"] !== void 0) {
|
|
4545
|
+
await detachAll(executor, plan, key);
|
|
4546
|
+
for (const filter of asArray(op["set"])) {
|
|
4547
|
+
await executor.update(plan.targetTable).set({ [plan.foreignColPropName]: key }).where(conditionOf(plan, filter, "set"));
|
|
4548
|
+
}
|
|
4549
|
+
}
|
|
4550
|
+
if (op["disconnect"] !== void 0) {
|
|
4551
|
+
if (plan.isOne) {
|
|
4552
|
+
if (op["disconnect"] === true) {
|
|
4553
|
+
await detachAll(executor, plan, key);
|
|
4554
|
+
}
|
|
4555
|
+
} else {
|
|
4556
|
+
for (const filter of asArray(op["disconnect"])) {
|
|
4557
|
+
await executor.update(plan.targetTable).set({ [plan.foreignColPropName]: null }).where((0, import_drizzle_orm7.and)((0, import_drizzle_orm7.eq)(plan.foreignCol, key), conditionOf(plan, filter, "disconnect")));
|
|
4558
|
+
}
|
|
4559
|
+
}
|
|
4560
|
+
}
|
|
4561
|
+
const attaches = op["connect"] !== void 0 || op["create"] !== void 0;
|
|
4562
|
+
if (plan.isOne && attaches && plan.canDetach && op["set"] === void 0) {
|
|
4563
|
+
await detachAll(executor, plan, key);
|
|
4564
|
+
}
|
|
4565
|
+
if (op["connect"] !== void 0) {
|
|
4566
|
+
for (const filter of asArray(op["connect"])) {
|
|
4567
|
+
await executor.update(plan.targetTable).set({ [plan.foreignColPropName]: key }).where(conditionOf(plan, filter, "connect"));
|
|
4568
|
+
}
|
|
4569
|
+
}
|
|
4570
|
+
if (op["create"] !== void 0) {
|
|
4571
|
+
const rows = asArray(op["create"]).map((row) => ({
|
|
4572
|
+
...remapFromGraphQLSingleInput({ ...row }, plan.targetTable),
|
|
4573
|
+
[plan.foreignColPropName]: key
|
|
4574
|
+
}));
|
|
4575
|
+
if (rows.length) {
|
|
4576
|
+
await executor.insert(plan.targetTable).values(rows);
|
|
4577
|
+
}
|
|
4578
|
+
}
|
|
4579
|
+
}
|
|
4580
|
+
}
|
|
4581
|
+
}
|
|
4582
|
+
};
|
|
4583
|
+
};
|
|
4584
|
+
var writeWithNestedOps = async (params) => {
|
|
4585
|
+
const { executor, runtime, tableName, entries, remapValues, write } = params;
|
|
4586
|
+
return executor.transaction(async (tx) => {
|
|
4587
|
+
const rows = [];
|
|
4588
|
+
for (const entry of entries) {
|
|
4589
|
+
const patch = await runtime.applyParentSide(tx, tableName, entry.ops);
|
|
4590
|
+
const written = await write(tx, { ...remapValues(entry.columns), ...patch });
|
|
4591
|
+
await runtime.applyChildSide(tx, tableName, entry.ops, written);
|
|
4592
|
+
rows.push(...written);
|
|
4593
|
+
}
|
|
4594
|
+
return rows;
|
|
4595
|
+
});
|
|
4596
|
+
};
|
|
4597
|
+
var updateWithNestedOps = async (params) => {
|
|
4598
|
+
const { executor, runtime, tableName, columns, ops, remapValues, write } = params;
|
|
4599
|
+
return executor.transaction(async (tx) => {
|
|
4600
|
+
const patch = await runtime.applyParentSide(tx, tableName, ops);
|
|
4601
|
+
const rows = await write(tx, { ...remapValues(columns), ...patch });
|
|
4602
|
+
await runtime.applyChildSide(tx, tableName, ops, rows);
|
|
4603
|
+
return rows;
|
|
4604
|
+
});
|
|
4605
|
+
};
|
|
4606
|
+
|
|
4607
|
+
// src/util/builders/pg.ts
|
|
3825
4608
|
var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, distinctEnabled = true) => {
|
|
3826
4609
|
const queryBase = db.query[tableName];
|
|
3827
4610
|
const table = tables[tableName];
|
|
@@ -3866,24 +4649,24 @@ var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
3866
4649
|
let cursorEntries;
|
|
3867
4650
|
if (after != null || cursorSelected) {
|
|
3868
4651
|
if (after != null && distinct?.length) {
|
|
3869
|
-
throw new
|
|
4652
|
+
throw new import_graphql9.GraphQLError("'after' cannot be combined with 'distinct'.");
|
|
3870
4653
|
}
|
|
3871
4654
|
if (orderByHasRelationEntry(orderBy)) {
|
|
3872
4655
|
if (after != null) {
|
|
3873
|
-
throw new
|
|
4656
|
+
throw new import_graphql9.GraphQLError(
|
|
3874
4657
|
"'after' cannot be combined with an orderBy that orders through a relation \u2014 a related row's value cannot be encoded into a cursor."
|
|
3875
4658
|
);
|
|
3876
4659
|
}
|
|
3877
4660
|
} else if (!pkNames.length) {
|
|
3878
4661
|
if (after != null) {
|
|
3879
|
-
throw new
|
|
4662
|
+
throw new import_graphql9.GraphQLError(
|
|
3880
4663
|
`Table ${tableName} has no primary key, so cursor pagination cannot be used on it.`
|
|
3881
4664
|
);
|
|
3882
4665
|
}
|
|
3883
4666
|
} else {
|
|
3884
4667
|
cursorEntries = cursorOrderingEntries(orderBy, pkNames);
|
|
3885
4668
|
if (cursorSelected) {
|
|
3886
|
-
const allColumns = (0,
|
|
4669
|
+
const allColumns = (0, import_drizzle_orm8.getColumns)(table);
|
|
3887
4670
|
for (const [column] of cursorEntries) {
|
|
3888
4671
|
selectedColumnsSql[column] ??= allColumns[column];
|
|
3889
4672
|
}
|
|
@@ -3892,7 +4675,7 @@ var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
3892
4675
|
}
|
|
3893
4676
|
const cursorCondition = after != null && cursorEntries ? buildCursorCondition(table, cursorEntries, decodeCursor(after, cursorEntries), "nulls-largest") : void 0;
|
|
3894
4677
|
const baseWhereSql = where ? extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName)) : void 0;
|
|
3895
|
-
const whereSql = cursorCondition ? (0,
|
|
4678
|
+
const whereSql = cursorCondition ? (0, import_drizzle_orm8.and)(baseWhereSql, cursorCondition) : baseWhereSql;
|
|
3896
4679
|
let distinctKeys;
|
|
3897
4680
|
if (distinct?.length) {
|
|
3898
4681
|
distinctKeys = await selectDistinctKeys({
|
|
@@ -4003,10 +4786,10 @@ var generateSelectSingle2 = (db, tableName, tables, relationMap, orderArgs, filt
|
|
|
4003
4786
|
};
|
|
4004
4787
|
};
|
|
4005
4788
|
var pgPrimaryKeyPropNames = (table) => getPrimaryKeyPropNamesFromConfig(table, import_pg_core2.getTableConfig);
|
|
4006
|
-
var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx) => {
|
|
4789
|
+
var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested) => {
|
|
4007
4790
|
const queryArgs = {
|
|
4008
4791
|
values: {
|
|
4009
|
-
type: new
|
|
4792
|
+
type: new import_graphql9.GraphQLNonNull(new import_graphql9.GraphQLList(new import_graphql9.GraphQLNonNull(baseType)))
|
|
4010
4793
|
}
|
|
4011
4794
|
};
|
|
4012
4795
|
const pkNames = pgPrimaryKeyPropNames(table);
|
|
@@ -4015,10 +4798,12 @@ var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
4015
4798
|
resolver: async (_source, args, context, info) => {
|
|
4016
4799
|
try {
|
|
4017
4800
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
throw new import_graphql7.GraphQLError("No values were provided!");
|
|
4801
|
+
if (!args.values.length) {
|
|
4802
|
+
throw new import_graphql9.GraphQLError("No values were provided!");
|
|
4021
4803
|
}
|
|
4804
|
+
const entries = nested?.enabled(tableName) ? args.values.map((values) => nested.split(tableName, values)) : void 0;
|
|
4805
|
+
const nestedEntries = entries?.some((entry) => nested.hasOps(entry.ops)) ? entries : void 0;
|
|
4806
|
+
const input = nestedEntries ? [] : remapFromGraphQLArrayInput(entries ? entries.map((entry) => entry.columns) : args.values, table);
|
|
4022
4807
|
const parsedInfo = (0, import_graphql_parse_resolve_info3.parseResolveInfo)(info, {
|
|
4023
4808
|
deep: true
|
|
4024
4809
|
});
|
|
@@ -4032,11 +4817,22 @@ var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
4032
4817
|
pkNames,
|
|
4033
4818
|
parsedInfo
|
|
4034
4819
|
});
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
query =
|
|
4038
|
-
|
|
4039
|
-
|
|
4820
|
+
const returning = nestedEntries ? nested.withJoinColumns(tableName, mergedOps(nestedEntries), { ...columns }, table) : columns;
|
|
4821
|
+
const runInsert = async (target, values) => {
|
|
4822
|
+
let query = target.insert(table).values(values).returning(returning);
|
|
4823
|
+
if (conflictDoNothing) {
|
|
4824
|
+
query = query.onConflictDoNothing();
|
|
4825
|
+
}
|
|
4826
|
+
return await query;
|
|
4827
|
+
};
|
|
4828
|
+
const result = nestedEntries ? await writeWithNestedOps({
|
|
4829
|
+
executor,
|
|
4830
|
+
runtime: nested,
|
|
4831
|
+
tableName,
|
|
4832
|
+
entries: nestedEntries,
|
|
4833
|
+
remapValues: (values) => remapFromGraphQLSingleInput(values, table),
|
|
4834
|
+
write: (tx, values) => runInsert(tx, [values])
|
|
4835
|
+
}) : await runInsert(executor, input);
|
|
4040
4836
|
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
4041
4837
|
return remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
|
|
4042
4838
|
});
|
|
@@ -4047,10 +4843,10 @@ var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
4047
4843
|
args: queryArgs
|
|
4048
4844
|
};
|
|
4049
4845
|
};
|
|
4050
|
-
var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx) => {
|
|
4846
|
+
var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested) => {
|
|
4051
4847
|
const queryArgs = {
|
|
4052
4848
|
values: {
|
|
4053
|
-
type: new
|
|
4849
|
+
type: new import_graphql9.GraphQLNonNull(baseType)
|
|
4054
4850
|
}
|
|
4055
4851
|
};
|
|
4056
4852
|
const pkNames = pgPrimaryKeyPropNames(table);
|
|
@@ -4059,7 +4855,9 @@ var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType
|
|
|
4059
4855
|
resolver: async (_source, args, context, info) => {
|
|
4060
4856
|
try {
|
|
4061
4857
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4062
|
-
const
|
|
4858
|
+
const entry = nested?.enabled(tableName) ? nested.split(tableName, args.values) : void 0;
|
|
4859
|
+
const nestedEntry = entry && nested.hasOps(entry.ops) ? entry : void 0;
|
|
4860
|
+
const input = nestedEntry ? {} : remapFromGraphQLSingleInput(entry ? entry.columns : args.values, table);
|
|
4063
4861
|
const parsedInfo = (0, import_graphql_parse_resolve_info3.parseResolveInfo)(info, {
|
|
4064
4862
|
deep: true
|
|
4065
4863
|
});
|
|
@@ -4073,12 +4871,26 @@ var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType
|
|
|
4073
4871
|
pkNames,
|
|
4074
4872
|
parsedInfo
|
|
4075
4873
|
});
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
query =
|
|
4079
|
-
|
|
4080
|
-
|
|
4874
|
+
const returning = nestedEntry ? nested.withJoinColumns(tableName, nestedEntry.ops, { ...columns }, table) : columns;
|
|
4875
|
+
const runInsert = async (target, values) => {
|
|
4876
|
+
let query = target.insert(table).values(values).returning(returning);
|
|
4877
|
+
if (conflictDoNothing) {
|
|
4878
|
+
query = query.onConflictDoNothing();
|
|
4879
|
+
}
|
|
4880
|
+
return await query;
|
|
4881
|
+
};
|
|
4882
|
+
const result = nestedEntry ? await writeWithNestedOps({
|
|
4883
|
+
executor,
|
|
4884
|
+
runtime: nested,
|
|
4885
|
+
tableName,
|
|
4886
|
+
entries: [nestedEntry],
|
|
4887
|
+
remapValues: (values) => remapFromGraphQLSingleInput(values, table),
|
|
4888
|
+
write: runInsert
|
|
4889
|
+
}) : await runInsert(executor, input);
|
|
4081
4890
|
if (!result[0]) {
|
|
4891
|
+
if (!conflictDoNothing) {
|
|
4892
|
+
throw new import_graphql9.GraphQLError(`${fieldName}: the insert returned no row.`);
|
|
4893
|
+
}
|
|
4082
4894
|
return void 0;
|
|
4083
4895
|
}
|
|
4084
4896
|
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
@@ -4091,10 +4903,10 @@ var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType
|
|
|
4091
4903
|
args: queryArgs
|
|
4092
4904
|
};
|
|
4093
4905
|
};
|
|
4094
|
-
var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx, txCtx) => {
|
|
4906
|
+
var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx, txCtx, nested) => {
|
|
4095
4907
|
const queryArgs = {
|
|
4096
4908
|
values: {
|
|
4097
|
-
type: single ? new
|
|
4909
|
+
type: single ? new import_graphql9.GraphQLNonNull(baseType) : new import_graphql9.GraphQLNonNull(new import_graphql9.GraphQLList(new import_graphql9.GraphQLNonNull(baseType)))
|
|
4098
4910
|
},
|
|
4099
4911
|
onConflict: {
|
|
4100
4912
|
type: onConflictType,
|
|
@@ -4107,10 +4919,13 @@ var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
4107
4919
|
resolver: async (_source, args, context, info) => {
|
|
4108
4920
|
try {
|
|
4109
4921
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4110
|
-
const
|
|
4111
|
-
if (!
|
|
4112
|
-
throw new
|
|
4922
|
+
const supplied = single ? [args.values] : args.values;
|
|
4923
|
+
if (!supplied.length) {
|
|
4924
|
+
throw new import_graphql9.GraphQLError("No values were provided!");
|
|
4113
4925
|
}
|
|
4926
|
+
const entries = nested?.enabled(tableName) ? supplied.map((values) => nested.split(tableName, values)) : void 0;
|
|
4927
|
+
const nestedEntries = entries?.some((entry) => nested.hasOps(entry.ops)) ? entries : void 0;
|
|
4928
|
+
const input = nestedEntries ? [] : remapFromGraphQLArrayInput(entries ? entries.map((entry) => entry.columns) : supplied, table);
|
|
4114
4929
|
const parsedInfo = (0, import_graphql_parse_resolve_info3.parseResolveInfo)(info, { deep: true });
|
|
4115
4930
|
const { columns, hasRelations, withParams } = prepareMutationRelationColumns({
|
|
4116
4931
|
relationMap,
|
|
@@ -4122,19 +4937,30 @@ var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
4122
4937
|
pkNames,
|
|
4123
4938
|
parsedInfo
|
|
4124
4939
|
});
|
|
4125
|
-
const
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4940
|
+
const returning = nestedEntries ? nested.withJoinColumns(tableName, mergedOps(nestedEntries), { ...columns }, table) : columns;
|
|
4941
|
+
const runUpsert = async (target, values) => {
|
|
4942
|
+
const plan = resolveConflictPlan({
|
|
4943
|
+
table,
|
|
4944
|
+
values,
|
|
4945
|
+
onConflict: args.onConflict,
|
|
4946
|
+
pkNames,
|
|
4947
|
+
uniqueSets,
|
|
4948
|
+
excludedRef: excludedColumnRef,
|
|
4949
|
+
withTarget: true,
|
|
4950
|
+
buildWhere: (where) => extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName))
|
|
4951
|
+
});
|
|
4952
|
+
let query = target.insert(table).values(values).returning(returning);
|
|
4953
|
+
query = plan.action === "NOTHING" ? query.onConflictDoNothing(plan.target ? { target: plan.target } : void 0) : query.onConflictDoUpdate({ target: plan.target, set: plan.set, setWhere: plan.setWhere });
|
|
4954
|
+
return await query;
|
|
4955
|
+
};
|
|
4956
|
+
const result = nestedEntries ? await writeWithNestedOps({
|
|
4957
|
+
executor,
|
|
4958
|
+
runtime: nested,
|
|
4959
|
+
tableName,
|
|
4960
|
+
entries: nestedEntries,
|
|
4961
|
+
remapValues: (values) => remapFromGraphQLSingleInput(values, table),
|
|
4962
|
+
write: (tx, values) => runUpsert(tx, [values])
|
|
4963
|
+
}) : await runUpsert(executor, input);
|
|
4138
4964
|
if (single && !result[0]) {
|
|
4139
4965
|
return void 0;
|
|
4140
4966
|
}
|
|
@@ -4148,13 +4974,13 @@ var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
4148
4974
|
args: queryArgs
|
|
4149
4975
|
};
|
|
4150
4976
|
};
|
|
4151
|
-
var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx, txCtx) => {
|
|
4977
|
+
var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx, txCtx, nested) => {
|
|
4152
4978
|
const queryArgs = {
|
|
4153
4979
|
set: {
|
|
4154
|
-
type: new
|
|
4980
|
+
type: new import_graphql9.GraphQLNonNull(setArgs)
|
|
4155
4981
|
},
|
|
4156
4982
|
where: {
|
|
4157
|
-
type: single || requireWhere ? new
|
|
4983
|
+
type: single || requireWhere ? new import_graphql9.GraphQLNonNull(filterArgs) : filterArgs
|
|
4158
4984
|
}
|
|
4159
4985
|
};
|
|
4160
4986
|
const pkNames = pgPrimaryKeyPropNames(table);
|
|
@@ -4177,23 +5003,37 @@ var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
4177
5003
|
pkNames,
|
|
4178
5004
|
parsedInfo
|
|
4179
5005
|
});
|
|
4180
|
-
const
|
|
4181
|
-
|
|
4182
|
-
|
|
5006
|
+
const entry = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
|
|
5007
|
+
const nestedOps = entry && nested.hasOps(entry.ops) ? entry.ops : void 0;
|
|
5008
|
+
const input = remapUpdateInput(entry ? entry.columns : set, table, tableName);
|
|
5009
|
+
if (!Object.keys(input).length && !nestedOps) {
|
|
5010
|
+
throw new import_graphql9.GraphQLError("Unable to update with no values specified!");
|
|
4183
5011
|
}
|
|
4184
5012
|
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
4185
5013
|
const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
4186
5014
|
if (single) {
|
|
4187
5015
|
await assertSingleMatch(executor, table, filters, fieldName);
|
|
4188
5016
|
}
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
5017
|
+
const returning = nestedOps ? nested.withJoinColumns(tableName, nestedOps, { ...columns }, table) : columns;
|
|
5018
|
+
const runUpdate = async (target, values) => {
|
|
5019
|
+
const writes = Object.keys(values).length > 0;
|
|
5020
|
+
let query = writes ? target.update(table).set(values) : target.select(returning).from(table);
|
|
5021
|
+
if (filters) {
|
|
5022
|
+
query = query.where(filters);
|
|
5023
|
+
}
|
|
5024
|
+
return await (writes ? query.returning(returning) : query);
|
|
5025
|
+
};
|
|
5026
|
+
const result = nestedOps ? await updateWithNestedOps({
|
|
5027
|
+
executor,
|
|
5028
|
+
runtime: nested,
|
|
5029
|
+
tableName,
|
|
5030
|
+
columns: input,
|
|
5031
|
+
ops: nestedOps,
|
|
5032
|
+
remapValues: (values) => values,
|
|
5033
|
+
write: runUpdate
|
|
5034
|
+
}) : await runUpdate(executor, input);
|
|
4195
5035
|
if (single && result.length > 1) {
|
|
4196
|
-
throw new
|
|
5036
|
+
throw new import_graphql9.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
|
|
4197
5037
|
}
|
|
4198
5038
|
if (single && !result[0]) {
|
|
4199
5039
|
return void 0;
|
|
@@ -4208,10 +5048,10 @@ var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
4208
5048
|
args: queryArgs
|
|
4209
5049
|
};
|
|
4210
5050
|
};
|
|
4211
|
-
var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx, txCtx) => {
|
|
5051
|
+
var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx, txCtx, nested) => {
|
|
4212
5052
|
const queryArgs = {
|
|
4213
5053
|
updates: {
|
|
4214
|
-
type: new
|
|
5054
|
+
type: new import_graphql9.GraphQLNonNull(new import_graphql9.GraphQLList(new import_graphql9.GraphQLNonNull(updateManyInput)))
|
|
4215
5055
|
}
|
|
4216
5056
|
};
|
|
4217
5057
|
const pkNames = pgPrimaryKeyPropNames(table);
|
|
@@ -4222,7 +5062,7 @@ var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
4222
5062
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4223
5063
|
const { updates } = args;
|
|
4224
5064
|
if (!updates.length) {
|
|
4225
|
-
throw new
|
|
5065
|
+
throw new import_graphql9.GraphQLError("No updates were provided!");
|
|
4226
5066
|
}
|
|
4227
5067
|
const parsedInfo = (0, import_graphql_parse_resolve_info3.parseResolveInfo)(info, {
|
|
4228
5068
|
deep: true
|
|
@@ -4238,23 +5078,40 @@ var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
4238
5078
|
parsedInfo
|
|
4239
5079
|
});
|
|
4240
5080
|
const entries = updates.map(({ where, set }) => {
|
|
4241
|
-
const
|
|
4242
|
-
|
|
4243
|
-
|
|
5081
|
+
const split = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
|
|
5082
|
+
const ops = split && nested.hasOps(split.ops) ? split.ops : void 0;
|
|
5083
|
+
const input = remapUpdateInput(split ? split.columns : set, table, tableName);
|
|
5084
|
+
if (!Object.keys(input).length && !ops) {
|
|
5085
|
+
throw new import_graphql9.GraphQLError("Unable to update with no values specified!");
|
|
4244
5086
|
}
|
|
4245
5087
|
return {
|
|
4246
5088
|
set: input,
|
|
5089
|
+
ops,
|
|
4247
5090
|
filters: where ? extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName)) : void 0
|
|
4248
5091
|
};
|
|
4249
5092
|
});
|
|
5093
|
+
const returning = entries.some((entry) => entry.ops) ? nested.withJoinColumns(
|
|
5094
|
+
tableName,
|
|
5095
|
+
mergedOps(entries.map((entry) => ({ ops: entry.ops ?? {} }))),
|
|
5096
|
+
{
|
|
5097
|
+
...columns
|
|
5098
|
+
},
|
|
5099
|
+
table
|
|
5100
|
+
) : columns;
|
|
4250
5101
|
const perEntry = await executor.transaction(async (tx) => {
|
|
4251
5102
|
const results = [];
|
|
4252
5103
|
for (const entry of entries) {
|
|
4253
|
-
|
|
5104
|
+
const values = entry.ops ? { ...entry.set, ...await nested.applyParentSide(tx, tableName, entry.ops) } : entry.set;
|
|
5105
|
+
const writes = Object.keys(values).length > 0;
|
|
5106
|
+
let query = writes ? tx.update(table).set(values) : tx.select(returning).from(table);
|
|
4254
5107
|
if (entry.filters) {
|
|
4255
5108
|
query = query.where(entry.filters);
|
|
4256
5109
|
}
|
|
4257
|
-
|
|
5110
|
+
const rows = await (writes ? query.returning(returning) : query);
|
|
5111
|
+
if (entry.ops) {
|
|
5112
|
+
await nested.applyChildSide(tx, tableName, entry.ops, rows);
|
|
5113
|
+
}
|
|
5114
|
+
results.push(rows);
|
|
4258
5115
|
}
|
|
4259
5116
|
return results;
|
|
4260
5117
|
});
|
|
@@ -4284,7 +5141,7 @@ var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
4284
5141
|
var generateDelete2 = (db, tableName, table, filterArgs, fieldName, typeName, single, requireWhere, filterCtx, selectionCtx, txCtx) => {
|
|
4285
5142
|
const queryArgs = {
|
|
4286
5143
|
where: {
|
|
4287
|
-
type: single || requireWhere ? new
|
|
5144
|
+
type: single || requireWhere ? new import_graphql9.GraphQLNonNull(filterArgs) : filterArgs
|
|
4288
5145
|
}
|
|
4289
5146
|
};
|
|
4290
5147
|
return {
|
|
@@ -4313,7 +5170,7 @@ var generateDelete2 = (db, tableName, table, filterArgs, fieldName, typeName, si
|
|
|
4313
5170
|
query = query.returning(columns);
|
|
4314
5171
|
const result = await query;
|
|
4315
5172
|
if (single && result.length > 1) {
|
|
4316
|
-
throw new
|
|
5173
|
+
throw new import_graphql9.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
|
|
4317
5174
|
}
|
|
4318
5175
|
if (single) {
|
|
4319
5176
|
return result[0] ? remapToGraphQLSingleOutput(result[0], tableName, table) : void 0;
|
|
@@ -4339,7 +5196,7 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4339
5196
|
complexity
|
|
4340
5197
|
} = options;
|
|
4341
5198
|
const schemaEntries = Object.entries(schema);
|
|
4342
|
-
const tableEntries = schemaEntries.filter(([_key, value]) => (0,
|
|
5199
|
+
const tableEntries = schemaEntries.filter(([_key, value]) => (0, import_drizzle_orm8.is)(value, import_pg_core2.PgTable));
|
|
4343
5200
|
const tables = Object.fromEntries(tableEntries);
|
|
4344
5201
|
if (!tableEntries.length) {
|
|
4345
5202
|
throw new Error(
|
|
@@ -4347,11 +5204,17 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4347
5204
|
);
|
|
4348
5205
|
}
|
|
4349
5206
|
registerScalarOverrides(tables, options);
|
|
5207
|
+
registerEnumConfig(options);
|
|
4350
5208
|
const namedRelations = buildNamedRelations(relations ?? {}, tableEntries);
|
|
4351
5209
|
attachTargetPrimaryKeys(namedRelations, tables, pgPrimaryKeyPropNames);
|
|
4352
5210
|
const eagerRelations = pruneNonEagerRelations(namedRelations, shouldEagerLoad);
|
|
4353
5211
|
const filterCtx = { tables, relationMap: namedRelations };
|
|
4354
|
-
const resolverFactory = createRelationResolverFactory(
|
|
5212
|
+
const resolverFactory = createRelationResolverFactory(
|
|
5213
|
+
db,
|
|
5214
|
+
tables,
|
|
5215
|
+
"nulls-largest",
|
|
5216
|
+
filterCtx
|
|
5217
|
+
);
|
|
4355
5218
|
const cacheCtx = {
|
|
4356
5219
|
genericFilterCache: /* @__PURE__ */ new Map(),
|
|
4357
5220
|
objectTypeCache: /* @__PURE__ */ new Map(),
|
|
@@ -4364,8 +5227,19 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4364
5227
|
filterTypeCache: /* @__PURE__ */ new WeakMap(),
|
|
4365
5228
|
listRelationFilterCache: /* @__PURE__ */ new Map(),
|
|
4366
5229
|
aggregateTypeCache: /* @__PURE__ */ new Map(),
|
|
4367
|
-
complexity
|
|
5230
|
+
complexity,
|
|
5231
|
+
docs: options.docs ?? {},
|
|
5232
|
+
features
|
|
4368
5233
|
};
|
|
5234
|
+
const nestedPlans = features.nestedWrites ? buildNestedWritePlans(
|
|
5235
|
+
tables,
|
|
5236
|
+
namedRelations,
|
|
5237
|
+
(target) => getUniqueColumnSets(target, import_pg_core2.getTableConfig),
|
|
5238
|
+
(target) => pgPrimaryKeyPropNames(target),
|
|
5239
|
+
extractRelationJoinColumns
|
|
5240
|
+
) : void 0;
|
|
5241
|
+
const nestedTypes = nestedPlans ? createNestedWriteTypes({ plans: nestedPlans, cacheCtx, typeNameMapper, insertPrefix: prefixes.insert }) : void 0;
|
|
5242
|
+
const nestedRuntime = nestedPlans ? createNestedWriteRuntime({ plans: nestedPlans, filterCtx }) : void 0;
|
|
4369
5243
|
const relationAggregateFactory = features.relationAggregates ? createRelationAggregateFactory(db, tables, cacheCtx, typeNameMapper, filterCtx) : void 0;
|
|
4370
5244
|
const queries = {};
|
|
4371
5245
|
const mutations = {};
|
|
@@ -4384,7 +5258,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4384
5258
|
prefixes.insert,
|
|
4385
5259
|
prefixes.update,
|
|
4386
5260
|
resolverFactory,
|
|
4387
|
-
relationAggregateFactory
|
|
5261
|
+
relationAggregateFactory,
|
|
5262
|
+
nestedTypes
|
|
4388
5263
|
)
|
|
4389
5264
|
])
|
|
4390
5265
|
);
|
|
@@ -4406,8 +5281,10 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4406
5281
|
updateFieldName,
|
|
4407
5282
|
updateManyFieldName,
|
|
4408
5283
|
updateSingleFieldName,
|
|
5284
|
+
updateCountFieldName,
|
|
4409
5285
|
deleteFieldName,
|
|
4410
|
-
deleteSingleFieldName
|
|
5286
|
+
deleteSingleFieldName,
|
|
5287
|
+
deleteCountFieldName
|
|
4411
5288
|
} = computeResolverFieldNames(tableName, typeNameMapper, prefixes, suffixes);
|
|
4412
5289
|
const selectArrGenerated = generateSelectArray2(
|
|
4413
5290
|
db,
|
|
@@ -4445,7 +5322,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4445
5322
|
typeName,
|
|
4446
5323
|
typeNameMapper,
|
|
4447
5324
|
conflictDoNothing,
|
|
4448
|
-
mutationTxCtx
|
|
5325
|
+
mutationTxCtx,
|
|
5326
|
+
nestedRuntime
|
|
4449
5327
|
) : void 0;
|
|
4450
5328
|
const insertSingleGenerated = features.insert ? generateInsertSingle2(
|
|
4451
5329
|
db,
|
|
@@ -4458,7 +5336,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4458
5336
|
typeName,
|
|
4459
5337
|
typeNameMapper,
|
|
4460
5338
|
conflictDoNothing,
|
|
4461
|
-
mutationTxCtx
|
|
5339
|
+
mutationTxCtx,
|
|
5340
|
+
nestedRuntime
|
|
4462
5341
|
) : void 0;
|
|
4463
5342
|
const uniqueSets = features.upsert ? getUniqueColumnSets(schema[tableName], import_pg_core2.getTableConfig) : [];
|
|
4464
5343
|
const onConflictInput = features.upsert ? generateOnConflictInput({
|
|
@@ -4482,7 +5361,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4482
5361
|
false,
|
|
4483
5362
|
typeNameMapper,
|
|
4484
5363
|
filterCtx,
|
|
4485
|
-
mutationTxCtx
|
|
5364
|
+
mutationTxCtx,
|
|
5365
|
+
nestedRuntime
|
|
4486
5366
|
) : void 0;
|
|
4487
5367
|
const upsertSingleGenerated = onConflictInput ? generateUpsert2(
|
|
4488
5368
|
db,
|
|
@@ -4498,7 +5378,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4498
5378
|
true,
|
|
4499
5379
|
typeNameMapper,
|
|
4500
5380
|
filterCtx,
|
|
4501
|
-
mutationTxCtx
|
|
5381
|
+
mutationTxCtx,
|
|
5382
|
+
nestedRuntime
|
|
4502
5383
|
) : void 0;
|
|
4503
5384
|
const updateGenerated = features.update ? generateUpdate2(
|
|
4504
5385
|
db,
|
|
@@ -4514,7 +5395,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4514
5395
|
features.requireWhere,
|
|
4515
5396
|
typeNameMapper,
|
|
4516
5397
|
filterCtx,
|
|
4517
|
-
mutationTxCtx
|
|
5398
|
+
mutationTxCtx,
|
|
5399
|
+
nestedRuntime
|
|
4518
5400
|
) : void 0;
|
|
4519
5401
|
const updateSingleGenerated = features.update ? generateUpdate2(
|
|
4520
5402
|
db,
|
|
@@ -4530,7 +5412,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4530
5412
|
features.requireWhere,
|
|
4531
5413
|
typeNameMapper,
|
|
4532
5414
|
filterCtx,
|
|
4533
|
-
mutationTxCtx
|
|
5415
|
+
mutationTxCtx,
|
|
5416
|
+
nestedRuntime
|
|
4534
5417
|
) : void 0;
|
|
4535
5418
|
const updateManyInput = features.update && features.updateMany ? generateUpdateManyInput({ typeName, updatePrefix: prefixes.update, updateInput, tableFilters }) : void 0;
|
|
4536
5419
|
const updateManyGenerated = updateManyInput ? generateUpdateMany2(
|
|
@@ -4544,7 +5427,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4544
5427
|
typeName,
|
|
4545
5428
|
typeNameMapper,
|
|
4546
5429
|
filterCtx,
|
|
4547
|
-
mutationTxCtx
|
|
5430
|
+
mutationTxCtx,
|
|
5431
|
+
nestedRuntime
|
|
4548
5432
|
) : void 0;
|
|
4549
5433
|
const deleteGenerated = features.delete ? generateDelete2(
|
|
4550
5434
|
db,
|
|
@@ -4572,6 +5456,30 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4572
5456
|
{ tableName, relationMap: namedRelations, tables },
|
|
4573
5457
|
mutationTxCtx
|
|
4574
5458
|
) : void 0;
|
|
5459
|
+
const updateCountGenerated = features.update && features.countMutations ? generateWriteCount({
|
|
5460
|
+
db,
|
|
5461
|
+
tableName,
|
|
5462
|
+
table: schema[tableName],
|
|
5463
|
+
kind: "update",
|
|
5464
|
+
setArgs: updateInput,
|
|
5465
|
+
filterArgs: tableFilters,
|
|
5466
|
+
fieldName: updateCountFieldName,
|
|
5467
|
+
requireWhere: features.requireWhere,
|
|
5468
|
+
filterCtx,
|
|
5469
|
+
txCtx: mutationTxCtx,
|
|
5470
|
+
nested: nestedRuntime
|
|
5471
|
+
}) : void 0;
|
|
5472
|
+
const deleteCountGenerated = features.delete && features.countMutations ? generateWriteCount({
|
|
5473
|
+
db,
|
|
5474
|
+
tableName,
|
|
5475
|
+
table: schema[tableName],
|
|
5476
|
+
kind: "delete",
|
|
5477
|
+
filterArgs: tableFilters,
|
|
5478
|
+
fieldName: deleteCountFieldName,
|
|
5479
|
+
requireWhere: features.requireWhere,
|
|
5480
|
+
filterCtx,
|
|
5481
|
+
txCtx: mutationTxCtx
|
|
5482
|
+
}) : void 0;
|
|
4575
5483
|
const aggregateType = features.aggregates ? generateAggregateTypes(schema[tableName], tableName, typeName, cacheCtx) : void 0;
|
|
4576
5484
|
const aggregateGenerated = features.aggregates ? generateAggregate(
|
|
4577
5485
|
db,
|
|
@@ -4609,7 +5517,7 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4609
5517
|
};
|
|
4610
5518
|
if (aggregateGenerated && aggregateType) {
|
|
4611
5519
|
queries[aggregateGenerated.name] = {
|
|
4612
|
-
type: new
|
|
5520
|
+
type: new import_graphql9.GraphQLNonNull(aggregateType),
|
|
4613
5521
|
args: aggregateGenerated.args,
|
|
4614
5522
|
resolve: aggregateGenerated.resolver,
|
|
4615
5523
|
...complexity ? { extensions: { complexity: aggregateFieldComplexity(complexity) } } : {}
|
|
@@ -4617,7 +5525,7 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4617
5525
|
}
|
|
4618
5526
|
if (groupByGenerated && groupByType) {
|
|
4619
5527
|
queries[groupByGenerated.name] = {
|
|
4620
|
-
type: new
|
|
5528
|
+
type: new import_graphql9.GraphQLNonNull(new import_graphql9.GraphQLList(new import_graphql9.GraphQLNonNull(groupByType))),
|
|
4621
5529
|
args: groupByGenerated.args,
|
|
4622
5530
|
resolve: groupByGenerated.resolver,
|
|
4623
5531
|
...complexity ? { extensions: { complexity: aggregateFieldComplexity(complexity) } } : {}
|
|
@@ -4632,7 +5540,9 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4632
5540
|
}
|
|
4633
5541
|
if (insertSingleGenerated) {
|
|
4634
5542
|
mutations[insertSingleGenerated.name] = {
|
|
4635
|
-
|
|
5543
|
+
// An insert either returns the row it inserted or throws — the one path to `null` is
|
|
5544
|
+
// `conflictDoNothing` swallowing the insert, so the field is nullable only there.
|
|
5545
|
+
type: conflictDoNothing ? singleTableItemOutput : new import_graphql9.GraphQLNonNull(singleTableItemOutput),
|
|
4636
5546
|
args: insertSingleGenerated.args,
|
|
4637
5547
|
resolve: insertSingleGenerated.resolver
|
|
4638
5548
|
};
|
|
@@ -4660,10 +5570,13 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4660
5570
|
}
|
|
4661
5571
|
if (updateManyGenerated) {
|
|
4662
5572
|
mutations[updateManyGenerated.name] = {
|
|
4663
|
-
|
|
4664
|
-
type: new import_graphql7.GraphQLNonNull(new import_graphql7.GraphQLList(singleTableItemOutput)),
|
|
5573
|
+
type: new import_graphql9.GraphQLNonNull(new import_graphql9.GraphQLList(singleTableItemOutput)),
|
|
4665
5574
|
args: updateManyGenerated.args,
|
|
4666
|
-
resolve: updateManyGenerated.resolver
|
|
5575
|
+
resolve: updateManyGenerated.resolver,
|
|
5576
|
+
// The nullable element is deliberate, and the reason this mutation's return type
|
|
5577
|
+
// differs from every sibling's: the result is aligned with the input, one slot per
|
|
5578
|
+
// entry, so an entry that matched nothing has to be able to say so.
|
|
5579
|
+
description: "Each entry's updated rows, in entry order. An entry whose `where` matched no rows contributes `null` in its slot; an entry that matched several contributes each of its rows."
|
|
4667
5580
|
};
|
|
4668
5581
|
}
|
|
4669
5582
|
if (updateSingleGenerated) {
|
|
@@ -4687,6 +5600,22 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4687
5600
|
resolve: deleteSingleGenerated.resolver
|
|
4688
5601
|
};
|
|
4689
5602
|
}
|
|
5603
|
+
if (updateCountGenerated) {
|
|
5604
|
+
mutations[updateCountGenerated.name] = {
|
|
5605
|
+
type: new import_graphql9.GraphQLNonNull(import_graphql9.GraphQLInt),
|
|
5606
|
+
args: updateCountGenerated.args,
|
|
5607
|
+
resolve: updateCountGenerated.resolver,
|
|
5608
|
+
description: "How many rows the update touched. The rows themselves are not read back, which is the point of this mutation."
|
|
5609
|
+
};
|
|
5610
|
+
}
|
|
5611
|
+
if (deleteCountGenerated) {
|
|
5612
|
+
mutations[deleteCountGenerated.name] = {
|
|
5613
|
+
type: new import_graphql9.GraphQLNonNull(import_graphql9.GraphQLInt),
|
|
5614
|
+
args: deleteCountGenerated.args,
|
|
5615
|
+
resolve: deleteCountGenerated.resolver,
|
|
5616
|
+
description: "How many rows the delete removed. The rows themselves are not read back, which is the point of this mutation."
|
|
5617
|
+
};
|
|
5618
|
+
}
|
|
4690
5619
|
const activeInputs = [
|
|
4691
5620
|
// The insert input types the upsert mutations too, so either feature keeps it.
|
|
4692
5621
|
...features.insert || onConflictInput ? [insertInput] : [],
|
|
@@ -4718,7 +5647,7 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4718
5647
|
for (const [tableName, tableRelations] of Object.entries(namedRelations)) {
|
|
4719
5648
|
const relResolvers = {};
|
|
4720
5649
|
for (const [relName, relEntry] of Object.entries(tableRelations)) {
|
|
4721
|
-
const isOne = (0,
|
|
5650
|
+
const isOne = (0, import_drizzle_orm8.is)(relEntry.relation ?? relEntry, import_drizzle_orm8.One);
|
|
4722
5651
|
const resolver = resolverFactory({ tableName, relationName: relName, relEntry, isOne });
|
|
4723
5652
|
if (resolver) {
|
|
4724
5653
|
relResolvers[relName] = resolver;
|
|
@@ -4732,9 +5661,9 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4732
5661
|
}
|
|
4733
5662
|
|
|
4734
5663
|
// src/util/builders/sqlite.ts
|
|
4735
|
-
var
|
|
5664
|
+
var import_drizzle_orm9 = require("drizzle-orm");
|
|
4736
5665
|
var import_sqlite_core2 = require("drizzle-orm/sqlite-core");
|
|
4737
|
-
var
|
|
5666
|
+
var import_graphql10 = require("graphql");
|
|
4738
5667
|
var import_graphql_parse_resolve_info4 = require("graphql-parse-resolve-info");
|
|
4739
5668
|
var generateSelectArray3 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, distinctEnabled = true) => {
|
|
4740
5669
|
const queryBase = db.query[tableName];
|
|
@@ -4819,10 +5748,10 @@ var generateSelectSingle3 = (db, tableName, tables, relationMap, orderArgs, filt
|
|
|
4819
5748
|
};
|
|
4820
5749
|
};
|
|
4821
5750
|
var sqlitePrimaryKeyPropNames = (table) => getPrimaryKeyPropNamesFromConfig(table, import_sqlite_core2.getTableConfig);
|
|
4822
|
-
var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx) => {
|
|
5751
|
+
var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested) => {
|
|
4823
5752
|
const queryArgs = {
|
|
4824
5753
|
values: {
|
|
4825
|
-
type: new
|
|
5754
|
+
type: new import_graphql10.GraphQLNonNull(new import_graphql10.GraphQLList(new import_graphql10.GraphQLNonNull(baseType)))
|
|
4826
5755
|
}
|
|
4827
5756
|
};
|
|
4828
5757
|
const pkNames = sqlitePrimaryKeyPropNames(table);
|
|
@@ -4831,10 +5760,12 @@ var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
4831
5760
|
resolver: async (_source, args, context, info) => {
|
|
4832
5761
|
try {
|
|
4833
5762
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
throw new import_graphql8.GraphQLError("No values were provided!");
|
|
5763
|
+
if (!args.values.length) {
|
|
5764
|
+
throw new import_graphql10.GraphQLError("No values were provided!");
|
|
4837
5765
|
}
|
|
5766
|
+
const entries = nested?.enabled(tableName) ? args.values.map((values) => nested.split(tableName, values)) : void 0;
|
|
5767
|
+
const nestedEntries = entries?.some((entry) => nested.hasOps(entry.ops)) ? entries : void 0;
|
|
5768
|
+
const input = nestedEntries ? [] : remapFromGraphQLArrayInput(entries ? entries.map((entry) => entry.columns) : args.values, table);
|
|
4838
5769
|
const parsedInfo = (0, import_graphql_parse_resolve_info4.parseResolveInfo)(info, {
|
|
4839
5770
|
deep: true
|
|
4840
5771
|
});
|
|
@@ -4848,11 +5779,22 @@ var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
4848
5779
|
pkNames,
|
|
4849
5780
|
parsedInfo
|
|
4850
5781
|
});
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
query =
|
|
4854
|
-
|
|
4855
|
-
|
|
5782
|
+
const returning = nestedEntries ? nested.withJoinColumns(tableName, mergedOps(nestedEntries), { ...columns }, table) : columns;
|
|
5783
|
+
const runInsert = async (target, values) => {
|
|
5784
|
+
let query = target.insert(table).values(values).returning(returning);
|
|
5785
|
+
if (conflictDoNothing) {
|
|
5786
|
+
query = query.onConflictDoNothing();
|
|
5787
|
+
}
|
|
5788
|
+
return await query;
|
|
5789
|
+
};
|
|
5790
|
+
const result = nestedEntries ? await writeWithNestedOps({
|
|
5791
|
+
executor,
|
|
5792
|
+
runtime: nested,
|
|
5793
|
+
tableName,
|
|
5794
|
+
entries: nestedEntries,
|
|
5795
|
+
remapValues: (values) => remapFromGraphQLSingleInput(values, table),
|
|
5796
|
+
write: (tx, values) => runInsert(tx, [values])
|
|
5797
|
+
}) : await runInsert(executor, input);
|
|
4856
5798
|
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
4857
5799
|
return remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
|
|
4858
5800
|
});
|
|
@@ -4863,10 +5805,10 @@ var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
4863
5805
|
args: queryArgs
|
|
4864
5806
|
};
|
|
4865
5807
|
};
|
|
4866
|
-
var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx) => {
|
|
5808
|
+
var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested) => {
|
|
4867
5809
|
const queryArgs = {
|
|
4868
5810
|
values: {
|
|
4869
|
-
type: new
|
|
5811
|
+
type: new import_graphql10.GraphQLNonNull(baseType)
|
|
4870
5812
|
}
|
|
4871
5813
|
};
|
|
4872
5814
|
const pkNames = sqlitePrimaryKeyPropNames(table);
|
|
@@ -4875,7 +5817,9 @@ var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType
|
|
|
4875
5817
|
resolver: async (_source, args, context, info) => {
|
|
4876
5818
|
try {
|
|
4877
5819
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4878
|
-
const
|
|
5820
|
+
const entry = nested?.enabled(tableName) ? nested.split(tableName, args.values) : void 0;
|
|
5821
|
+
const nestedEntry = entry && nested.hasOps(entry.ops) ? entry : void 0;
|
|
5822
|
+
const input = nestedEntry ? {} : remapFromGraphQLSingleInput(entry ? entry.columns : args.values, table);
|
|
4879
5823
|
const parsedInfo = (0, import_graphql_parse_resolve_info4.parseResolveInfo)(info, {
|
|
4880
5824
|
deep: true
|
|
4881
5825
|
});
|
|
@@ -4889,12 +5833,26 @@ var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType
|
|
|
4889
5833
|
pkNames,
|
|
4890
5834
|
parsedInfo
|
|
4891
5835
|
});
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
query =
|
|
4895
|
-
|
|
4896
|
-
|
|
5836
|
+
const returning = nestedEntry ? nested.withJoinColumns(tableName, nestedEntry.ops, { ...columns }, table) : columns;
|
|
5837
|
+
const runInsert = async (target, values) => {
|
|
5838
|
+
let query = target.insert(table).values(values).returning(returning);
|
|
5839
|
+
if (conflictDoNothing) {
|
|
5840
|
+
query = query.onConflictDoNothing();
|
|
5841
|
+
}
|
|
5842
|
+
return await query;
|
|
5843
|
+
};
|
|
5844
|
+
const result = nestedEntry ? await writeWithNestedOps({
|
|
5845
|
+
executor,
|
|
5846
|
+
runtime: nested,
|
|
5847
|
+
tableName,
|
|
5848
|
+
entries: [nestedEntry],
|
|
5849
|
+
remapValues: (values) => remapFromGraphQLSingleInput(values, table),
|
|
5850
|
+
write: runInsert
|
|
5851
|
+
}) : await runInsert(executor, input);
|
|
4897
5852
|
if (!result[0]) {
|
|
5853
|
+
if (!conflictDoNothing) {
|
|
5854
|
+
throw new import_graphql10.GraphQLError(`${fieldName}: the insert returned no row.`);
|
|
5855
|
+
}
|
|
4898
5856
|
return void 0;
|
|
4899
5857
|
}
|
|
4900
5858
|
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
@@ -4907,10 +5865,10 @@ var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType
|
|
|
4907
5865
|
args: queryArgs
|
|
4908
5866
|
};
|
|
4909
5867
|
};
|
|
4910
|
-
var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx, txCtx) => {
|
|
5868
|
+
var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx, txCtx, nested) => {
|
|
4911
5869
|
const queryArgs = {
|
|
4912
5870
|
values: {
|
|
4913
|
-
type: single ? new
|
|
5871
|
+
type: single ? new import_graphql10.GraphQLNonNull(baseType) : new import_graphql10.GraphQLNonNull(new import_graphql10.GraphQLList(new import_graphql10.GraphQLNonNull(baseType)))
|
|
4914
5872
|
},
|
|
4915
5873
|
onConflict: {
|
|
4916
5874
|
type: onConflictType,
|
|
@@ -4923,10 +5881,13 @@ var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
4923
5881
|
resolver: async (_source, args, context, info) => {
|
|
4924
5882
|
try {
|
|
4925
5883
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4926
|
-
const
|
|
4927
|
-
if (!
|
|
4928
|
-
throw new
|
|
5884
|
+
const supplied = single ? [args.values] : args.values;
|
|
5885
|
+
if (!supplied.length) {
|
|
5886
|
+
throw new import_graphql10.GraphQLError("No values were provided!");
|
|
4929
5887
|
}
|
|
5888
|
+
const entries = nested?.enabled(tableName) ? supplied.map((values) => nested.split(tableName, values)) : void 0;
|
|
5889
|
+
const nestedEntries = entries?.some((entry) => nested.hasOps(entry.ops)) ? entries : void 0;
|
|
5890
|
+
const input = nestedEntries ? [] : remapFromGraphQLArrayInput(entries ? entries.map((entry) => entry.columns) : supplied, table);
|
|
4930
5891
|
const parsedInfo = (0, import_graphql_parse_resolve_info4.parseResolveInfo)(info, { deep: true });
|
|
4931
5892
|
const { columns, hasRelations, withParams } = prepareMutationRelationColumns({
|
|
4932
5893
|
relationMap,
|
|
@@ -4938,19 +5899,30 @@ var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
4938
5899
|
pkNames,
|
|
4939
5900
|
parsedInfo
|
|
4940
5901
|
});
|
|
4941
|
-
const
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
|
|
4945
|
-
|
|
4946
|
-
|
|
4947
|
-
|
|
4948
|
-
|
|
4949
|
-
|
|
4950
|
-
|
|
4951
|
-
|
|
4952
|
-
|
|
4953
|
-
|
|
5902
|
+
const returning = nestedEntries ? nested.withJoinColumns(tableName, mergedOps(nestedEntries), { ...columns }, table) : columns;
|
|
5903
|
+
const runUpsert = async (target, values) => {
|
|
5904
|
+
const plan = resolveConflictPlan({
|
|
5905
|
+
table,
|
|
5906
|
+
values,
|
|
5907
|
+
onConflict: args.onConflict,
|
|
5908
|
+
pkNames,
|
|
5909
|
+
uniqueSets,
|
|
5910
|
+
excludedRef: excludedColumnRef,
|
|
5911
|
+
withTarget: true,
|
|
5912
|
+
buildWhere: (where) => extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName))
|
|
5913
|
+
});
|
|
5914
|
+
let query = target.insert(table).values(values).returning(returning);
|
|
5915
|
+
query = plan.action === "NOTHING" ? query.onConflictDoNothing(plan.target ? { target: plan.target } : void 0) : query.onConflictDoUpdate({ target: plan.target, set: plan.set, setWhere: plan.setWhere });
|
|
5916
|
+
return await query;
|
|
5917
|
+
};
|
|
5918
|
+
const result = nestedEntries ? await writeWithNestedOps({
|
|
5919
|
+
executor,
|
|
5920
|
+
runtime: nested,
|
|
5921
|
+
tableName,
|
|
5922
|
+
entries: nestedEntries,
|
|
5923
|
+
remapValues: (values) => remapFromGraphQLSingleInput(values, table),
|
|
5924
|
+
write: (tx, values) => runUpsert(tx, [values])
|
|
5925
|
+
}) : await runUpsert(executor, input);
|
|
4954
5926
|
if (single && !result[0]) {
|
|
4955
5927
|
return void 0;
|
|
4956
5928
|
}
|
|
@@ -4964,13 +5936,13 @@ var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
4964
5936
|
args: queryArgs
|
|
4965
5937
|
};
|
|
4966
5938
|
};
|
|
4967
|
-
var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx, txCtx) => {
|
|
5939
|
+
var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx, txCtx, nested) => {
|
|
4968
5940
|
const queryArgs = {
|
|
4969
5941
|
set: {
|
|
4970
|
-
type: new
|
|
5942
|
+
type: new import_graphql10.GraphQLNonNull(setArgs)
|
|
4971
5943
|
},
|
|
4972
5944
|
where: {
|
|
4973
|
-
type: single || requireWhere ? new
|
|
5945
|
+
type: single || requireWhere ? new import_graphql10.GraphQLNonNull(filterArgs) : filterArgs
|
|
4974
5946
|
}
|
|
4975
5947
|
};
|
|
4976
5948
|
const pkNames = sqlitePrimaryKeyPropNames(table);
|
|
@@ -4993,23 +5965,37 @@ var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
4993
5965
|
pkNames,
|
|
4994
5966
|
parsedInfo
|
|
4995
5967
|
});
|
|
4996
|
-
const
|
|
4997
|
-
|
|
4998
|
-
|
|
5968
|
+
const entry = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
|
|
5969
|
+
const nestedOps = entry && nested.hasOps(entry.ops) ? entry.ops : void 0;
|
|
5970
|
+
const input = remapUpdateInput(entry ? entry.columns : set, table, tableName);
|
|
5971
|
+
if (!Object.keys(input).length && !nestedOps) {
|
|
5972
|
+
throw new import_graphql10.GraphQLError("Unable to update with no values specified!");
|
|
4999
5973
|
}
|
|
5000
5974
|
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
5001
5975
|
const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
5002
5976
|
if (single) {
|
|
5003
5977
|
await assertSingleMatch(executor, table, filters, fieldName);
|
|
5004
5978
|
}
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
5009
|
-
|
|
5010
|
-
|
|
5979
|
+
const returning = nestedOps ? nested.withJoinColumns(tableName, nestedOps, { ...columns }, table) : columns;
|
|
5980
|
+
const runUpdate = async (target, values) => {
|
|
5981
|
+
const writes = Object.keys(values).length > 0;
|
|
5982
|
+
let query = writes ? target.update(table).set(values) : target.select(returning).from(table);
|
|
5983
|
+
if (filters) {
|
|
5984
|
+
query = query.where(filters);
|
|
5985
|
+
}
|
|
5986
|
+
return await (writes ? query.returning(returning) : query);
|
|
5987
|
+
};
|
|
5988
|
+
const result = nestedOps ? await updateWithNestedOps({
|
|
5989
|
+
executor,
|
|
5990
|
+
runtime: nested,
|
|
5991
|
+
tableName,
|
|
5992
|
+
columns: input,
|
|
5993
|
+
ops: nestedOps,
|
|
5994
|
+
remapValues: (values) => values,
|
|
5995
|
+
write: runUpdate
|
|
5996
|
+
}) : await runUpdate(executor, input);
|
|
5011
5997
|
if (single && result.length > 1) {
|
|
5012
|
-
throw new
|
|
5998
|
+
throw new import_graphql10.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
|
|
5013
5999
|
}
|
|
5014
6000
|
if (single && !result[0]) {
|
|
5015
6001
|
return void 0;
|
|
@@ -5024,10 +6010,10 @@ var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
5024
6010
|
args: queryArgs
|
|
5025
6011
|
};
|
|
5026
6012
|
};
|
|
5027
|
-
var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx, txCtx) => {
|
|
6013
|
+
var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx, txCtx, nested) => {
|
|
5028
6014
|
const queryArgs = {
|
|
5029
6015
|
updates: {
|
|
5030
|
-
type: new
|
|
6016
|
+
type: new import_graphql10.GraphQLNonNull(new import_graphql10.GraphQLList(new import_graphql10.GraphQLNonNull(updateManyInput)))
|
|
5031
6017
|
}
|
|
5032
6018
|
};
|
|
5033
6019
|
const pkNames = sqlitePrimaryKeyPropNames(table);
|
|
@@ -5038,7 +6024,7 @@ var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
5038
6024
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
5039
6025
|
const { updates } = args;
|
|
5040
6026
|
if (!updates.length) {
|
|
5041
|
-
throw new
|
|
6027
|
+
throw new import_graphql10.GraphQLError("No updates were provided!");
|
|
5042
6028
|
}
|
|
5043
6029
|
const parsedInfo = (0, import_graphql_parse_resolve_info4.parseResolveInfo)(info, {
|
|
5044
6030
|
deep: true
|
|
@@ -5054,23 +6040,55 @@ var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
5054
6040
|
parsedInfo
|
|
5055
6041
|
});
|
|
5056
6042
|
const entries = updates.map(({ where, set }) => {
|
|
5057
|
-
const
|
|
5058
|
-
|
|
5059
|
-
|
|
6043
|
+
const split = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
|
|
6044
|
+
const ops = split && nested.hasOps(split.ops) ? split.ops : void 0;
|
|
6045
|
+
const input = remapUpdateInput(split ? split.columns : set, table, tableName);
|
|
6046
|
+
if (!Object.keys(input).length && !ops) {
|
|
6047
|
+
throw new import_graphql10.GraphQLError("Unable to update with no values specified!");
|
|
5060
6048
|
}
|
|
5061
6049
|
return {
|
|
5062
6050
|
set: input,
|
|
6051
|
+
ops,
|
|
5063
6052
|
filters: where ? extractFilters(table, tableName, where, relationFilterCtx(filterCtx, tableName)) : void 0
|
|
5064
6053
|
};
|
|
5065
6054
|
});
|
|
6055
|
+
const anyNested = entries.some((entry) => entry.ops);
|
|
6056
|
+
const returning = anyNested ? nested.withJoinColumns(
|
|
6057
|
+
tableName,
|
|
6058
|
+
mergedOps(entries.map((entry) => ({ ops: entry.ops ?? {} }))),
|
|
6059
|
+
{ ...columns },
|
|
6060
|
+
table
|
|
6061
|
+
) : columns;
|
|
5066
6062
|
const runEntry = (tx, entry) => {
|
|
5067
6063
|
let query = tx.update(table).set(entry.set);
|
|
5068
6064
|
if (entry.filters) {
|
|
5069
6065
|
query = query.where(entry.filters);
|
|
5070
6066
|
}
|
|
5071
|
-
return query.returning(
|
|
6067
|
+
return query.returning(returning).all();
|
|
6068
|
+
};
|
|
6069
|
+
const runNestedEntry = async (tx, entry) => {
|
|
6070
|
+
const values = entry.ops ? { ...entry.set, ...await nested.applyParentSide(tx, tableName, entry.ops) } : entry.set;
|
|
6071
|
+
const writes = Object.keys(values).length > 0;
|
|
6072
|
+
let query = writes ? tx.update(table).set(values) : tx.select(returning).from(table);
|
|
6073
|
+
if (entry.filters) {
|
|
6074
|
+
query = query.where(entry.filters);
|
|
6075
|
+
}
|
|
6076
|
+
const rows = await (writes ? query.returning(returning) : query);
|
|
6077
|
+
if (entry.ops) {
|
|
6078
|
+
await nested.applyChildSide(tx, tableName, entry.ops, rows);
|
|
6079
|
+
}
|
|
6080
|
+
return rows;
|
|
5072
6081
|
};
|
|
5073
6082
|
const perEntry = await executor.transaction((tx) => {
|
|
6083
|
+
if (anyNested) {
|
|
6084
|
+
return (async () => {
|
|
6085
|
+
const results2 = [];
|
|
6086
|
+
for (const entry of entries) {
|
|
6087
|
+
results2.push(await runNestedEntry(tx, entry));
|
|
6088
|
+
}
|
|
6089
|
+
return results2;
|
|
6090
|
+
})();
|
|
6091
|
+
}
|
|
5074
6092
|
const first = runEntry(tx, entries[0]);
|
|
5075
6093
|
if (typeof first?.then === "function") {
|
|
5076
6094
|
return (async () => {
|
|
@@ -5113,7 +6131,7 @@ var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
5113
6131
|
var generateDelete3 = (db, tableName, table, filterArgs, fieldName, typeName, single, requireWhere, filterCtx, selectionCtx, txCtx) => {
|
|
5114
6132
|
const queryArgs = {
|
|
5115
6133
|
where: {
|
|
5116
|
-
type: single || requireWhere ? new
|
|
6134
|
+
type: single || requireWhere ? new import_graphql10.GraphQLNonNull(filterArgs) : filterArgs
|
|
5117
6135
|
}
|
|
5118
6136
|
};
|
|
5119
6137
|
return {
|
|
@@ -5142,7 +6160,7 @@ var generateDelete3 = (db, tableName, table, filterArgs, fieldName, typeName, si
|
|
|
5142
6160
|
query = query.returning(columns);
|
|
5143
6161
|
const result = await query;
|
|
5144
6162
|
if (single && result.length > 1) {
|
|
5145
|
-
throw new
|
|
6163
|
+
throw new import_graphql10.GraphQLError(`${fieldName}: 'where' matched more than one row!`);
|
|
5146
6164
|
}
|
|
5147
6165
|
if (single) {
|
|
5148
6166
|
return result[0] ? remapToGraphQLSingleOutput(result[0], tableName, table) : void 0;
|
|
@@ -5169,7 +6187,7 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5169
6187
|
} = options;
|
|
5170
6188
|
const rawSchema = schema;
|
|
5171
6189
|
const schemaEntries = Object.entries(rawSchema);
|
|
5172
|
-
const tableEntries = schemaEntries.filter(([_key, value]) => (0,
|
|
6190
|
+
const tableEntries = schemaEntries.filter(([_key, value]) => (0, import_drizzle_orm9.is)(value, import_sqlite_core2.SQLiteTable));
|
|
5173
6191
|
const tables = Object.fromEntries(tableEntries);
|
|
5174
6192
|
if (!tableEntries.length) {
|
|
5175
6193
|
throw new Error(
|
|
@@ -5177,11 +6195,17 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5177
6195
|
);
|
|
5178
6196
|
}
|
|
5179
6197
|
registerScalarOverrides(tables, options);
|
|
6198
|
+
registerEnumConfig(options);
|
|
5180
6199
|
const namedRelations = buildNamedRelations(relations ?? {}, tableEntries);
|
|
5181
6200
|
attachTargetPrimaryKeys(namedRelations, tables, sqlitePrimaryKeyPropNames);
|
|
5182
6201
|
const eagerRelations = pruneNonEagerRelations(namedRelations, shouldEagerLoad);
|
|
5183
6202
|
const filterCtx = { tables, relationMap: namedRelations };
|
|
5184
|
-
const resolverFactory = createRelationResolverFactory(
|
|
6203
|
+
const resolverFactory = createRelationResolverFactory(
|
|
6204
|
+
db,
|
|
6205
|
+
tables,
|
|
6206
|
+
"nulls-smallest",
|
|
6207
|
+
filterCtx
|
|
6208
|
+
);
|
|
5185
6209
|
const cacheCtx = {
|
|
5186
6210
|
genericFilterCache: /* @__PURE__ */ new Map(),
|
|
5187
6211
|
objectTypeCache: /* @__PURE__ */ new Map(),
|
|
@@ -5194,8 +6218,24 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5194
6218
|
filterTypeCache: /* @__PURE__ */ new WeakMap(),
|
|
5195
6219
|
listRelationFilterCache: /* @__PURE__ */ new Map(),
|
|
5196
6220
|
aggregateTypeCache: /* @__PURE__ */ new Map(),
|
|
5197
|
-
complexity
|
|
6221
|
+
complexity,
|
|
6222
|
+
docs: options.docs ?? {},
|
|
6223
|
+
features
|
|
5198
6224
|
};
|
|
6225
|
+
if (features.nestedWrites && db.resultKind === "sync") {
|
|
6226
|
+
throw new Error(
|
|
6227
|
+
"Drizzle-GraphQL Error: features.nestedWrites requires an asynchronous SQLite driver (e.g. libsql). Synchronous drivers cannot run the multi-statement transaction a nested write needs."
|
|
6228
|
+
);
|
|
6229
|
+
}
|
|
6230
|
+
const nestedPlans = features.nestedWrites ? buildNestedWritePlans(
|
|
6231
|
+
tables,
|
|
6232
|
+
namedRelations,
|
|
6233
|
+
(target) => getUniqueColumnSets(target, import_sqlite_core2.getTableConfig),
|
|
6234
|
+
(target) => sqlitePrimaryKeyPropNames(target),
|
|
6235
|
+
extractRelationJoinColumns
|
|
6236
|
+
) : void 0;
|
|
6237
|
+
const nestedTypes = nestedPlans ? createNestedWriteTypes({ plans: nestedPlans, cacheCtx, typeNameMapper, insertPrefix: prefixes.insert }) : void 0;
|
|
6238
|
+
const nestedRuntime = nestedPlans ? createNestedWriteRuntime({ plans: nestedPlans, filterCtx }) : void 0;
|
|
5199
6239
|
const relationAggregateFactory = features.relationAggregates ? createRelationAggregateFactory(db, tables, cacheCtx, typeNameMapper, filterCtx) : void 0;
|
|
5200
6240
|
const queries = {};
|
|
5201
6241
|
const mutations = {};
|
|
@@ -5219,7 +6259,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5219
6259
|
prefixes.insert,
|
|
5220
6260
|
prefixes.update,
|
|
5221
6261
|
resolverFactory,
|
|
5222
|
-
relationAggregateFactory
|
|
6262
|
+
relationAggregateFactory,
|
|
6263
|
+
nestedTypes
|
|
5223
6264
|
)
|
|
5224
6265
|
])
|
|
5225
6266
|
);
|
|
@@ -5241,8 +6282,10 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5241
6282
|
updateFieldName,
|
|
5242
6283
|
updateManyFieldName,
|
|
5243
6284
|
updateSingleFieldName,
|
|
6285
|
+
updateCountFieldName,
|
|
5244
6286
|
deleteFieldName,
|
|
5245
|
-
deleteSingleFieldName
|
|
6287
|
+
deleteSingleFieldName,
|
|
6288
|
+
deleteCountFieldName
|
|
5246
6289
|
} = computeResolverFieldNames(tableName, typeNameMapper, prefixes, suffixes);
|
|
5247
6290
|
const selectArrGenerated = generateSelectArray3(
|
|
5248
6291
|
db,
|
|
@@ -5280,7 +6323,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5280
6323
|
typeName,
|
|
5281
6324
|
typeNameMapper,
|
|
5282
6325
|
conflictDoNothing,
|
|
5283
|
-
mutationTxCtx
|
|
6326
|
+
mutationTxCtx,
|
|
6327
|
+
nestedRuntime
|
|
5284
6328
|
) : void 0;
|
|
5285
6329
|
const insertSingleGenerated = features.insert ? generateInsertSingle3(
|
|
5286
6330
|
db,
|
|
@@ -5293,7 +6337,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5293
6337
|
typeName,
|
|
5294
6338
|
typeNameMapper,
|
|
5295
6339
|
conflictDoNothing,
|
|
5296
|
-
mutationTxCtx
|
|
6340
|
+
mutationTxCtx,
|
|
6341
|
+
nestedRuntime
|
|
5297
6342
|
) : void 0;
|
|
5298
6343
|
const uniqueSets = features.upsert ? getUniqueColumnSets(schema[tableName], import_sqlite_core2.getTableConfig) : [];
|
|
5299
6344
|
const onConflictInput = features.upsert ? generateOnConflictInput({
|
|
@@ -5317,7 +6362,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5317
6362
|
false,
|
|
5318
6363
|
typeNameMapper,
|
|
5319
6364
|
filterCtx,
|
|
5320
|
-
mutationTxCtx
|
|
6365
|
+
mutationTxCtx,
|
|
6366
|
+
nestedRuntime
|
|
5321
6367
|
) : void 0;
|
|
5322
6368
|
const upsertSingleGenerated = onConflictInput ? generateUpsert3(
|
|
5323
6369
|
db,
|
|
@@ -5333,7 +6379,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5333
6379
|
true,
|
|
5334
6380
|
typeNameMapper,
|
|
5335
6381
|
filterCtx,
|
|
5336
|
-
mutationTxCtx
|
|
6382
|
+
mutationTxCtx,
|
|
6383
|
+
nestedRuntime
|
|
5337
6384
|
) : void 0;
|
|
5338
6385
|
const updateGenerated = features.update ? generateUpdate3(
|
|
5339
6386
|
db,
|
|
@@ -5349,7 +6396,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5349
6396
|
features.requireWhere,
|
|
5350
6397
|
typeNameMapper,
|
|
5351
6398
|
filterCtx,
|
|
5352
|
-
mutationTxCtx
|
|
6399
|
+
mutationTxCtx,
|
|
6400
|
+
nestedRuntime
|
|
5353
6401
|
) : void 0;
|
|
5354
6402
|
const updateSingleGenerated = features.update ? generateUpdate3(
|
|
5355
6403
|
db,
|
|
@@ -5365,7 +6413,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5365
6413
|
features.requireWhere,
|
|
5366
6414
|
typeNameMapper,
|
|
5367
6415
|
filterCtx,
|
|
5368
|
-
mutationTxCtx
|
|
6416
|
+
mutationTxCtx,
|
|
6417
|
+
nestedRuntime
|
|
5369
6418
|
) : void 0;
|
|
5370
6419
|
const updateManyInput = features.update && features.updateMany ? generateUpdateManyInput({ typeName, updatePrefix: prefixes.update, updateInput, tableFilters }) : void 0;
|
|
5371
6420
|
const updateManyGenerated = updateManyInput ? generateUpdateMany3(
|
|
@@ -5379,7 +6428,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5379
6428
|
typeName,
|
|
5380
6429
|
typeNameMapper,
|
|
5381
6430
|
filterCtx,
|
|
5382
|
-
mutationTxCtx
|
|
6431
|
+
mutationTxCtx,
|
|
6432
|
+
nestedRuntime
|
|
5383
6433
|
) : void 0;
|
|
5384
6434
|
const deleteGenerated = features.delete ? generateDelete3(
|
|
5385
6435
|
db,
|
|
@@ -5407,6 +6457,30 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5407
6457
|
{ tableName, relationMap: namedRelations, tables },
|
|
5408
6458
|
mutationTxCtx
|
|
5409
6459
|
) : void 0;
|
|
6460
|
+
const updateCountGenerated = features.update && features.countMutations ? generateWriteCount({
|
|
6461
|
+
db,
|
|
6462
|
+
tableName,
|
|
6463
|
+
table: schema[tableName],
|
|
6464
|
+
kind: "update",
|
|
6465
|
+
setArgs: updateInput,
|
|
6466
|
+
filterArgs: tableFilters,
|
|
6467
|
+
fieldName: updateCountFieldName,
|
|
6468
|
+
requireWhere: features.requireWhere,
|
|
6469
|
+
filterCtx,
|
|
6470
|
+
txCtx: mutationTxCtx,
|
|
6471
|
+
nested: nestedRuntime
|
|
6472
|
+
}) : void 0;
|
|
6473
|
+
const deleteCountGenerated = features.delete && features.countMutations ? generateWriteCount({
|
|
6474
|
+
db,
|
|
6475
|
+
tableName,
|
|
6476
|
+
table: schema[tableName],
|
|
6477
|
+
kind: "delete",
|
|
6478
|
+
filterArgs: tableFilters,
|
|
6479
|
+
fieldName: deleteCountFieldName,
|
|
6480
|
+
requireWhere: features.requireWhere,
|
|
6481
|
+
filterCtx,
|
|
6482
|
+
txCtx: mutationTxCtx
|
|
6483
|
+
}) : void 0;
|
|
5410
6484
|
const aggregateType = features.aggregates ? generateAggregateTypes(schema[tableName], tableName, typeName, cacheCtx) : void 0;
|
|
5411
6485
|
const aggregateGenerated = features.aggregates ? generateAggregate(
|
|
5412
6486
|
db,
|
|
@@ -5444,7 +6518,7 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5444
6518
|
};
|
|
5445
6519
|
if (aggregateGenerated && aggregateType) {
|
|
5446
6520
|
queries[aggregateGenerated.name] = {
|
|
5447
|
-
type: new
|
|
6521
|
+
type: new import_graphql10.GraphQLNonNull(aggregateType),
|
|
5448
6522
|
args: aggregateGenerated.args,
|
|
5449
6523
|
resolve: aggregateGenerated.resolver,
|
|
5450
6524
|
...complexity ? { extensions: { complexity: aggregateFieldComplexity(complexity) } } : {}
|
|
@@ -5452,7 +6526,7 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5452
6526
|
}
|
|
5453
6527
|
if (groupByGenerated && groupByType) {
|
|
5454
6528
|
queries[groupByGenerated.name] = {
|
|
5455
|
-
type: new
|
|
6529
|
+
type: new import_graphql10.GraphQLNonNull(new import_graphql10.GraphQLList(new import_graphql10.GraphQLNonNull(groupByType))),
|
|
5456
6530
|
args: groupByGenerated.args,
|
|
5457
6531
|
resolve: groupByGenerated.resolver,
|
|
5458
6532
|
...complexity ? { extensions: { complexity: aggregateFieldComplexity(complexity) } } : {}
|
|
@@ -5467,7 +6541,9 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5467
6541
|
}
|
|
5468
6542
|
if (insertSingleGenerated) {
|
|
5469
6543
|
mutations[insertSingleGenerated.name] = {
|
|
5470
|
-
|
|
6544
|
+
// An insert either returns the row it inserted or throws — the one path to `null` is
|
|
6545
|
+
// `conflictDoNothing` swallowing the insert, so the field is nullable only there.
|
|
6546
|
+
type: conflictDoNothing ? singleTableItemOutput : new import_graphql10.GraphQLNonNull(singleTableItemOutput),
|
|
5471
6547
|
args: insertSingleGenerated.args,
|
|
5472
6548
|
resolve: insertSingleGenerated.resolver
|
|
5473
6549
|
};
|
|
@@ -5495,10 +6571,13 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5495
6571
|
}
|
|
5496
6572
|
if (updateManyGenerated) {
|
|
5497
6573
|
mutations[updateManyGenerated.name] = {
|
|
5498
|
-
|
|
5499
|
-
type: new import_graphql8.GraphQLNonNull(new import_graphql8.GraphQLList(singleTableItemOutput)),
|
|
6574
|
+
type: new import_graphql10.GraphQLNonNull(new import_graphql10.GraphQLList(singleTableItemOutput)),
|
|
5500
6575
|
args: updateManyGenerated.args,
|
|
5501
|
-
resolve: updateManyGenerated.resolver
|
|
6576
|
+
resolve: updateManyGenerated.resolver,
|
|
6577
|
+
// The nullable element is deliberate, and the reason this mutation's return type
|
|
6578
|
+
// differs from every sibling's: the result is aligned with the input, one slot per
|
|
6579
|
+
// entry, so an entry that matched nothing has to be able to say so.
|
|
6580
|
+
description: "Each entry's updated rows, in entry order. An entry whose `where` matched no rows contributes `null` in its slot; an entry that matched several contributes each of its rows."
|
|
5502
6581
|
};
|
|
5503
6582
|
}
|
|
5504
6583
|
if (updateSingleGenerated) {
|
|
@@ -5522,6 +6601,22 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5522
6601
|
resolve: deleteSingleGenerated.resolver
|
|
5523
6602
|
};
|
|
5524
6603
|
}
|
|
6604
|
+
if (updateCountGenerated) {
|
|
6605
|
+
mutations[updateCountGenerated.name] = {
|
|
6606
|
+
type: new import_graphql10.GraphQLNonNull(import_graphql10.GraphQLInt),
|
|
6607
|
+
args: updateCountGenerated.args,
|
|
6608
|
+
resolve: updateCountGenerated.resolver,
|
|
6609
|
+
description: "How many rows the update touched. The rows themselves are not read back, which is the point of this mutation."
|
|
6610
|
+
};
|
|
6611
|
+
}
|
|
6612
|
+
if (deleteCountGenerated) {
|
|
6613
|
+
mutations[deleteCountGenerated.name] = {
|
|
6614
|
+
type: new import_graphql10.GraphQLNonNull(import_graphql10.GraphQLInt),
|
|
6615
|
+
args: deleteCountGenerated.args,
|
|
6616
|
+
resolve: deleteCountGenerated.resolver,
|
|
6617
|
+
description: "How many rows the delete removed. The rows themselves are not read back, which is the point of this mutation."
|
|
6618
|
+
};
|
|
6619
|
+
}
|
|
5525
6620
|
const activeInputs = [
|
|
5526
6621
|
// The insert input types the upsert mutations too, so either feature keeps it.
|
|
5527
6622
|
...features.insert || onConflictInput ? [insertInput] : [],
|
|
@@ -5553,7 +6648,7 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5553
6648
|
for (const [tableName, tableRelations] of Object.entries(namedRelations)) {
|
|
5554
6649
|
const relResolvers = {};
|
|
5555
6650
|
for (const [relName, relEntry] of Object.entries(tableRelations)) {
|
|
5556
|
-
const isOne = (0,
|
|
6651
|
+
const isOne = (0, import_drizzle_orm9.is)(relEntry.relation ?? relEntry, import_drizzle_orm9.One);
|
|
5557
6652
|
const resolver = resolverFactory({ tableName, relationName: relName, relEntry, isOne });
|
|
5558
6653
|
if (resolver) {
|
|
5559
6654
|
relResolvers[relName] = resolver;
|
|
@@ -5598,6 +6693,9 @@ var buildSchema = (db, config) => {
|
|
|
5598
6693
|
updateMany: config?.features?.updateMany ?? true,
|
|
5599
6694
|
delete: config?.features?.delete ?? true,
|
|
5600
6695
|
upsert: config?.features?.upsert ?? false,
|
|
6696
|
+
nestedWrites: config?.features?.nestedWrites ?? false,
|
|
6697
|
+
fieldUpdateOperations: config?.features?.fieldUpdateOperations ?? false,
|
|
6698
|
+
countMutations: config?.features?.countMutations ?? false,
|
|
5601
6699
|
requireWhere: config?.features?.requireWhere ?? false
|
|
5602
6700
|
};
|
|
5603
6701
|
const complexityConfig = config?.complexity ?? true;
|
|
@@ -5637,14 +6735,21 @@ var buildSchema = (db, config) => {
|
|
|
5637
6735
|
complexity,
|
|
5638
6736
|
scalars: config?.scalars,
|
|
5639
6737
|
mapColumnType: config?.mapColumnType,
|
|
5640
|
-
|
|
6738
|
+
enumNameMapper: config?.enumNameMapper,
|
|
6739
|
+
transactions,
|
|
6740
|
+
docs: {
|
|
6741
|
+
describeColumn: config?.describeColumn,
|
|
6742
|
+
describeTable: config?.describeTable,
|
|
6743
|
+
describeRelation: config?.describeRelation,
|
|
6744
|
+
deprecateColumn: config?.deprecateColumn
|
|
6745
|
+
}
|
|
5641
6746
|
};
|
|
5642
6747
|
let generatorOutput;
|
|
5643
|
-
if ((0,
|
|
6748
|
+
if ((0, import_drizzle_orm10.is)(db, import_mysql_core3.MySqlDatabase)) {
|
|
5644
6749
|
generatorOutput = generateSchemaData(db, schema, relations, generatorOptions);
|
|
5645
|
-
} else if ((0,
|
|
6750
|
+
} else if ((0, import_drizzle_orm10.is)(db, import_pg_core3.PgAsyncDatabase)) {
|
|
5646
6751
|
generatorOutput = generateSchemaData2(db, schema, relations, generatorOptions);
|
|
5647
|
-
} else if ((0,
|
|
6752
|
+
} else if ((0, import_drizzle_orm10.is)(db, import_sqlite_core3.BaseSQLiteDatabase)) {
|
|
5648
6753
|
generatorOutput = generateSchemaData3(db, schema, relations, generatorOptions);
|
|
5649
6754
|
} else {
|
|
5650
6755
|
throw new Error("Drizzle-GraphQL Error: Unknown database instance type");
|
|
@@ -5657,19 +6762,19 @@ var buildSchema = (db, config) => {
|
|
|
5657
6762
|
const { queries, mutations, inputs, types } = generatorOutput;
|
|
5658
6763
|
const graphQLSchemaConfig = {
|
|
5659
6764
|
types: [...Object.values(inputs), ...Object.values(types)],
|
|
5660
|
-
query: new
|
|
6765
|
+
query: new import_graphql11.GraphQLObjectType({
|
|
5661
6766
|
name: "Query",
|
|
5662
6767
|
fields: queries
|
|
5663
6768
|
})
|
|
5664
6769
|
};
|
|
5665
6770
|
if (config?.mutations !== false && Object.keys(mutations).length) {
|
|
5666
|
-
const mutation = new
|
|
6771
|
+
const mutation = new import_graphql11.GraphQLObjectType({
|
|
5667
6772
|
name: "Mutation",
|
|
5668
6773
|
fields: mutations
|
|
5669
6774
|
});
|
|
5670
6775
|
graphQLSchemaConfig.mutation = mutation;
|
|
5671
6776
|
}
|
|
5672
|
-
const outputSchema = new
|
|
6777
|
+
const outputSchema = new import_graphql11.GraphQLSchema(graphQLSchemaConfig);
|
|
5673
6778
|
return { schema: outputSchema, entities: generatorOutput };
|
|
5674
6779
|
};
|
|
5675
6780
|
// Annotate the CommonJS export names for ESM import in node:
|