@vantreeseba/drizzle-graphql 6.0.0 → 7.1.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 +372 -10
- package/dist/README.md +372 -10
- package/dist/index.cjs +1029 -447
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +132 -2
- package/dist/index.d.ts +132 -2
- package/dist/index.js +935 -343
- package/dist/index.js.map +1 -1
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
desc,
|
|
19
19
|
eq,
|
|
20
20
|
extractExtendedColumnType as extractExtendedColumnType2,
|
|
21
|
-
getColumns,
|
|
21
|
+
getColumns as getColumns2,
|
|
22
22
|
getTableAsAliasSQL,
|
|
23
23
|
gt,
|
|
24
24
|
gte,
|
|
@@ -38,17 +38,17 @@ import {
|
|
|
38
38
|
One as One2,
|
|
39
39
|
or,
|
|
40
40
|
relationsFilterToSQL,
|
|
41
|
-
sql
|
|
41
|
+
sql as sql2
|
|
42
42
|
} from "drizzle-orm";
|
|
43
43
|
import {
|
|
44
44
|
GraphQLBoolean as GraphQLBoolean2,
|
|
45
45
|
GraphQLEnumType as GraphQLEnumType2,
|
|
46
|
-
GraphQLError as
|
|
47
|
-
GraphQLFloat as
|
|
48
|
-
GraphQLInputObjectType as
|
|
49
|
-
GraphQLInt as
|
|
50
|
-
GraphQLList as
|
|
51
|
-
GraphQLNonNull as
|
|
46
|
+
GraphQLError as GraphQLError4,
|
|
47
|
+
GraphQLFloat as GraphQLFloat3,
|
|
48
|
+
GraphQLInputObjectType as GraphQLInputObjectType3,
|
|
49
|
+
GraphQLInt as GraphQLInt3,
|
|
50
|
+
GraphQLList as GraphQLList3,
|
|
51
|
+
GraphQLNonNull as GraphQLNonNull3,
|
|
52
52
|
GraphQLObjectType as GraphQLObjectType2,
|
|
53
53
|
GraphQLString as GraphQLString2
|
|
54
54
|
} from "graphql";
|
|
@@ -602,6 +602,131 @@ var remapFromGraphQLArrayInput = (queryInput, table) => {
|
|
|
602
602
|
return queryInput;
|
|
603
603
|
};
|
|
604
604
|
|
|
605
|
+
// src/util/builders/field-updates.ts
|
|
606
|
+
import { getColumns, sql } from "drizzle-orm";
|
|
607
|
+
import {
|
|
608
|
+
GraphQLError as GraphQLError3,
|
|
609
|
+
GraphQLFloat as GraphQLFloat2,
|
|
610
|
+
GraphQLInputObjectType as GraphQLInputObjectType2,
|
|
611
|
+
GraphQLInt as GraphQLInt2,
|
|
612
|
+
GraphQLList as GraphQLList2,
|
|
613
|
+
GraphQLNonNull as GraphQLNonNull2
|
|
614
|
+
} from "graphql";
|
|
615
|
+
var NUMERIC_SCALARS = /* @__PURE__ */ new Set([
|
|
616
|
+
GraphQLInt2,
|
|
617
|
+
GraphQLFloat2,
|
|
618
|
+
GraphQLBigIntString,
|
|
619
|
+
GraphQLDecimalString
|
|
620
|
+
]);
|
|
621
|
+
var NON_LIST_ARRAY_COLUMNS = /* @__PURE__ */ new Set(["PgVector", "PgGeometry", "PgBytea"]);
|
|
622
|
+
var kindCache = /* @__PURE__ */ new WeakMap();
|
|
623
|
+
var fieldUpdateKind = (column, columnName, tableName) => {
|
|
624
|
+
const cached = kindCache.get(column);
|
|
625
|
+
if (cached) {
|
|
626
|
+
return cached;
|
|
627
|
+
}
|
|
628
|
+
let kind = "none";
|
|
629
|
+
if (!getColumnScalarOverride(column, true)) {
|
|
630
|
+
const { type } = drizzleColumnToGraphQLType(column, columnName, tableName, true, false, true);
|
|
631
|
+
if (NUMERIC_SCALARS.has(type)) {
|
|
632
|
+
kind = "numeric";
|
|
633
|
+
} else if (type instanceof GraphQLList2 && !NON_LIST_ARRAY_COLUMNS.has(column.columnType)) {
|
|
634
|
+
kind = "list";
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
kindCache.set(column, kind);
|
|
638
|
+
return kind;
|
|
639
|
+
};
|
|
640
|
+
var inputCache = /* @__PURE__ */ new Map();
|
|
641
|
+
var namedFieldUpdateInput = (name, fields, description) => {
|
|
642
|
+
const cached = inputCache.get(name);
|
|
643
|
+
if (cached) {
|
|
644
|
+
return cached;
|
|
645
|
+
}
|
|
646
|
+
const input = new GraphQLInputObjectType2({ name, description, fields: fields() });
|
|
647
|
+
inputCache.set(name, input);
|
|
648
|
+
return input;
|
|
649
|
+
};
|
|
650
|
+
var fieldUpdateInputType = (column, columnName, tableName) => {
|
|
651
|
+
const kind = fieldUpdateKind(column, columnName, tableName);
|
|
652
|
+
if (kind === "none") {
|
|
653
|
+
return void 0;
|
|
654
|
+
}
|
|
655
|
+
const { type } = drizzleColumnToGraphQLType(column, columnName, tableName, true, false, true);
|
|
656
|
+
if (kind === "numeric") {
|
|
657
|
+
const scalar = type;
|
|
658
|
+
return namedFieldUpdateInput(
|
|
659
|
+
`${scalar.name}FieldUpdate`,
|
|
660
|
+
() => ({
|
|
661
|
+
set: { type: scalar, description: "Replace the current value with this one" },
|
|
662
|
+
increment: { type: scalar, description: "Add this to the current value (SQL `column + value`)" },
|
|
663
|
+
decrement: { type: scalar, description: "Subtract this from the current value (SQL `column - value`)" },
|
|
664
|
+
multiply: { type: scalar, description: "Multiply the current value by this (SQL `column * value`)" },
|
|
665
|
+
divide: {
|
|
666
|
+
type: scalar,
|
|
667
|
+
description: "Divide the current value by this (SQL `column / value`), rounding as the database does"
|
|
668
|
+
}
|
|
669
|
+
}),
|
|
670
|
+
`An update to a ${scalar.name} column: exactly one of these operations`
|
|
671
|
+
);
|
|
672
|
+
}
|
|
673
|
+
const list = type;
|
|
674
|
+
const element = list.ofType;
|
|
675
|
+
const elementName = element instanceof GraphQLNonNull2 ? String(element.ofType) : String(element);
|
|
676
|
+
return namedFieldUpdateInput(
|
|
677
|
+
`${elementName}ListFieldUpdate`,
|
|
678
|
+
() => ({
|
|
679
|
+
set: { type: list, description: "Replace the current array with this one" },
|
|
680
|
+
push: { type: list, description: "Append these elements to the current array" }
|
|
681
|
+
}),
|
|
682
|
+
`An update to a ${elementName} array column: exactly one of these operations`
|
|
683
|
+
);
|
|
684
|
+
};
|
|
685
|
+
var OPERATIONS = ["set", "increment", "decrement", "multiply", "divide", "push"];
|
|
686
|
+
var singleOperation = (value, columnName) => {
|
|
687
|
+
const given = OPERATIONS.filter((operation) => value[operation] !== void 0);
|
|
688
|
+
if (given.length === 1) {
|
|
689
|
+
return [given[0], value[given[0]]];
|
|
690
|
+
}
|
|
691
|
+
throw new GraphQLError3(
|
|
692
|
+
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(", ")}.`
|
|
693
|
+
);
|
|
694
|
+
};
|
|
695
|
+
var splitFieldUpdateOperations = (values, table, tableName) => {
|
|
696
|
+
const cols = getColumns(table);
|
|
697
|
+
const columns = {};
|
|
698
|
+
const expressions = {};
|
|
699
|
+
for (const [columnName, value] of Object.entries(values)) {
|
|
700
|
+
const column = cols[columnName];
|
|
701
|
+
if (!column || value === null || value === void 0) {
|
|
702
|
+
columns[columnName] = value;
|
|
703
|
+
continue;
|
|
704
|
+
}
|
|
705
|
+
const isOperations = typeof value === "object" && !Array.isArray(value) && !(value instanceof Date);
|
|
706
|
+
if (!isOperations || fieldUpdateKind(column, columnName, tableName) === "none") {
|
|
707
|
+
columns[columnName] = value;
|
|
708
|
+
continue;
|
|
709
|
+
}
|
|
710
|
+
const [operation, operand] = singleOperation(value, columnName);
|
|
711
|
+
if (operation === "set") {
|
|
712
|
+
columns[columnName] = operand;
|
|
713
|
+
continue;
|
|
714
|
+
}
|
|
715
|
+
const param = sql.param(remapFromGraphQLCore(operand, column, columnName), column);
|
|
716
|
+
expressions[columnName] = operation === "increment" ? sql`${column} + ${param}` : operation === "decrement" ? sql`${column} - ${param}` : operation === "multiply" ? sql`${column} * ${param}` : operation === "divide" ? sql`${column} / ${param}` : (
|
|
717
|
+
// `push`: array concatenation, which is the only dialect-specific operation
|
|
718
|
+
// here — and arrays are a PostgreSQL column type to begin with.
|
|
719
|
+
sql`${column} || ${param}`
|
|
720
|
+
);
|
|
721
|
+
}
|
|
722
|
+
return { columns, expressions };
|
|
723
|
+
};
|
|
724
|
+
var remapUpdateInput = (values, table, tableName) => {
|
|
725
|
+
const { columns, expressions } = splitFieldUpdateOperations(values, table, tableName);
|
|
726
|
+
const remapped = remapFromGraphQLSingleInput(columns, table);
|
|
727
|
+
return Object.keys(expressions).length ? { ...remapped, ...expressions } : remapped;
|
|
728
|
+
};
|
|
729
|
+
|
|
605
730
|
// src/util/builders/common.ts
|
|
606
731
|
var rqbCrashTypes = ["SQLiteBigInt", "SQLiteBlobJson", "SQLiteBlobBuffer"];
|
|
607
732
|
var resolveTypeName = (name, typeNameMapper) => {
|
|
@@ -664,9 +789,9 @@ var extractRelationJoinColumns = (relEntry, parentTable, targetTable) => {
|
|
|
664
789
|
}
|
|
665
790
|
const sourceCol = sourceColumns[0];
|
|
666
791
|
const targetCol = targetColumns[0];
|
|
667
|
-
const parentCols =
|
|
792
|
+
const parentCols = getColumns2(parentTable);
|
|
668
793
|
const localColPropName = Object.entries(parentCols).find(([, c]) => c === sourceCol)?.[0];
|
|
669
|
-
const targetCols =
|
|
794
|
+
const targetCols = getColumns2(targetTable);
|
|
670
795
|
const foreignColPropName = Object.entries(targetCols).find(([, c]) => c === targetCol)?.[0];
|
|
671
796
|
if (!localColPropName || !foreignColPropName) {
|
|
672
797
|
return void 0;
|
|
@@ -748,7 +873,7 @@ var collectRootMutationKeys = (selectionSet, fragments, variables, known, keys,
|
|
|
748
873
|
}
|
|
749
874
|
return true;
|
|
750
875
|
};
|
|
751
|
-
var abortedBatchError = () => new
|
|
876
|
+
var abortedBatchError = () => new GraphQLError4(
|
|
752
877
|
"Drizzle-GraphQL Error: Mutation was not executed because an earlier mutation in the same request failed and the shared transaction was rolled back."
|
|
753
878
|
);
|
|
754
879
|
var openSharedTx = (db, context, txCtx, stateKey, expected) => {
|
|
@@ -806,7 +931,7 @@ var openSharedTx = (db, context, txCtx, stateKey, expected) => {
|
|
|
806
931
|
}
|
|
807
932
|
timer = setTimeout(() => {
|
|
808
933
|
state.abort(
|
|
809
|
-
new
|
|
934
|
+
new GraphQLError4(
|
|
810
935
|
`Drizzle-GraphQL Error: Shared mutation transaction timed out after ${txCtx.timeoutMs}ms waiting for the remaining mutation fields; rolling back.`
|
|
811
936
|
)
|
|
812
937
|
);
|
|
@@ -888,14 +1013,14 @@ var runMutation = async (db, context, info, txCtx, body) => {
|
|
|
888
1013
|
return runOnSharedTx(state, body);
|
|
889
1014
|
};
|
|
890
1015
|
var batchedPaginatedRelationQuery = async (db, targetTable, foreignCol, whereCondition, orderByArg, limit, offset, pkNames, orderCtx) => {
|
|
891
|
-
const cols =
|
|
1016
|
+
const cols = getColumns2(targetTable);
|
|
892
1017
|
const orderExprs = [
|
|
893
1018
|
...orderByArg ? extractOrderBy(targetTable, orderByArg, orderCtx) : [],
|
|
894
1019
|
...primaryKeyOrderExprs(targetTable, pkNames)
|
|
895
1020
|
];
|
|
896
|
-
const orderClause = orderExprs.length ?
|
|
1021
|
+
const orderClause = orderExprs.length ? sql2` order by ${sql2.join(orderExprs, sql2`, `)}` : sql2``;
|
|
897
1022
|
const RN = "__drizzle_graphql_rn";
|
|
898
|
-
const rowNumber =
|
|
1023
|
+
const rowNumber = sql2`row_number() over (partition by ${foreignCol}${orderClause})`.as(RN);
|
|
899
1024
|
const sub = db.select({ ...cols, [RN]: rowNumber }).from(targetTable).where(whereCondition).as("__paginated");
|
|
900
1025
|
const lower = offset ?? 0;
|
|
901
1026
|
const windowConds = [gt(sub[RN], lower)];
|
|
@@ -908,7 +1033,7 @@ var batchedPaginatedRelationQuery = async (db, targetTable, foreignCol, whereCon
|
|
|
908
1033
|
}
|
|
909
1034
|
return rows;
|
|
910
1035
|
};
|
|
911
|
-
var createRelationResolverFactory = (db, tables, filterCtx) => ({ tableName, relationName, relEntry, isOne }) => {
|
|
1036
|
+
var createRelationResolverFactory = (db, tables, nullOrdering, filterCtx, limits) => ({ tableName, relationName, relEntry, isOne }) => {
|
|
912
1037
|
const parentTable = tables[tableName];
|
|
913
1038
|
const targetTableName = relEntry.targetTableName;
|
|
914
1039
|
const targetTable = tables[targetTableName];
|
|
@@ -920,8 +1045,9 @@ var createRelationResolverFactory = (db, tables, filterCtx) => ({ tableName, rel
|
|
|
920
1045
|
return void 0;
|
|
921
1046
|
}
|
|
922
1047
|
const { localColPropName, foreignCol, foreignColPropName } = joinCols;
|
|
1048
|
+
const limitPolicy = isOne ? void 0 : limits?.(targetTableName);
|
|
923
1049
|
const targetPkNames = relEntry.targetPkNames ?? [];
|
|
924
|
-
return async (parent, args, context) => {
|
|
1050
|
+
return async (parent, args, context, info) => {
|
|
925
1051
|
if (parent[relationName] !== void 0) {
|
|
926
1052
|
return parent[relationName];
|
|
927
1053
|
}
|
|
@@ -929,21 +1055,66 @@ var createRelationResolverFactory = (db, tables, filterCtx) => ({ tableName, rel
|
|
|
929
1055
|
if (localValue == null) {
|
|
930
1056
|
return isOne ? null : [];
|
|
931
1057
|
}
|
|
932
|
-
const { where: whereArg, orderBy: orderByArg, limit, offset } = args ?? {};
|
|
1058
|
+
const { where: whereArg, orderBy: orderByArg, limit: requestedLimit, offset, after } = args ?? {};
|
|
1059
|
+
const limit = applyLimitPolicy(requestedLimit, limitPolicy, `${tableName}.${relationName}`);
|
|
1060
|
+
const distinct = (args ?? {}).distinct?.length ? (args ?? {}).distinct : void 0;
|
|
1061
|
+
const cursorSelected = !isOne && !!info && selectsCursorField(info, targetTable);
|
|
1062
|
+
let cursorEntries;
|
|
1063
|
+
if (!isOne && (after != null || cursorSelected)) {
|
|
1064
|
+
if (after != null && distinct) {
|
|
1065
|
+
throw new GraphQLError4("'after' cannot be combined with 'distinct'.");
|
|
1066
|
+
}
|
|
1067
|
+
if (orderByHasRelationEntry(orderByArg)) {
|
|
1068
|
+
if (after != null) {
|
|
1069
|
+
throw new GraphQLError4(
|
|
1070
|
+
"'after' cannot be combined with an orderBy that orders through a relation \u2014 a related row's value cannot be encoded into a cursor."
|
|
1071
|
+
);
|
|
1072
|
+
}
|
|
1073
|
+
} else if (!targetPkNames.length) {
|
|
1074
|
+
if (after != null) {
|
|
1075
|
+
throw new GraphQLError4(
|
|
1076
|
+
`Table ${targetTableName} has no primary key, so cursor pagination cannot be used on it.`
|
|
1077
|
+
);
|
|
1078
|
+
}
|
|
1079
|
+
} else {
|
|
1080
|
+
cursorEntries = cursorOrderingEntries(orderByArg, targetPkNames);
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
const cursorValues = after != null && cursorEntries ? decodeCursor(after, cursorEntries) : void 0;
|
|
933
1084
|
const argsKey = JSON.stringify({
|
|
934
1085
|
where: whereArg ?? null,
|
|
935
1086
|
orderBy: orderByArg ?? null,
|
|
936
1087
|
limit: limit ?? null,
|
|
937
|
-
offset: offset ?? null
|
|
1088
|
+
offset: offset ?? null,
|
|
1089
|
+
after: after ?? null,
|
|
1090
|
+
distinct: distinct ?? null,
|
|
1091
|
+
cursor: cursorEntries ? 1 : 0
|
|
938
1092
|
});
|
|
939
1093
|
const loaderKey = `${tableName}::${relationName}::${argsKey}`;
|
|
940
1094
|
const loader = getOrCreateLoader(context, loaderKey, async (parentIds) => {
|
|
941
1095
|
const executor = resolveExecutor(db, context);
|
|
942
1096
|
const uniqueIds = [...new Set(parentIds)];
|
|
943
|
-
|
|
1097
|
+
let whereCondition = and(
|
|
944
1098
|
inArray(foreignCol, uniqueIds),
|
|
945
|
-
whereArg ? extractFilters(targetTable, targetTableName, whereArg, relationFilterCtx(filterCtx, targetTableName)) : void 0
|
|
1099
|
+
whereArg ? extractFilters(targetTable, targetTableName, whereArg, relationFilterCtx(filterCtx, targetTableName)) : void 0,
|
|
1100
|
+
cursorValues ? buildCursorCondition(targetTable, cursorEntries, cursorValues, nullOrdering) : void 0
|
|
946
1101
|
);
|
|
1102
|
+
if (distinct) {
|
|
1103
|
+
const keys = await selectDistinctKeys({
|
|
1104
|
+
db: executor,
|
|
1105
|
+
table: targetTable,
|
|
1106
|
+
tableName: targetTableName,
|
|
1107
|
+
distinct,
|
|
1108
|
+
pkNames: targetPkNames,
|
|
1109
|
+
where: whereCondition,
|
|
1110
|
+
orderBy: orderByArg,
|
|
1111
|
+
partitionBy: [foreignCol]
|
|
1112
|
+
});
|
|
1113
|
+
if (!keys.length) {
|
|
1114
|
+
return parentIds.map(() => isOne ? null : []);
|
|
1115
|
+
}
|
|
1116
|
+
whereCondition = and(whereCondition, primaryKeyRestriction(targetTable, targetPkNames, keys));
|
|
1117
|
+
}
|
|
947
1118
|
let rows;
|
|
948
1119
|
if (limit != null || offset != null) {
|
|
949
1120
|
rows = await batchedPaginatedRelationQuery(
|
|
@@ -959,11 +1130,15 @@ var createRelationResolverFactory = (db, tables, filterCtx) => ({ tableName, rel
|
|
|
959
1130
|
);
|
|
960
1131
|
} else {
|
|
961
1132
|
let q = executor.select().from(targetTable).where(whereCondition);
|
|
962
|
-
|
|
963
|
-
|
|
1133
|
+
const orderExprs = cursorEntries ? cursorOrderExprs(targetTable, cursorEntries) : orderByArg ? extractOrderBy(targetTable, orderByArg, relationFilterCtx(filterCtx, targetTableName)) : [];
|
|
1134
|
+
if (orderExprs.length) {
|
|
1135
|
+
q = q.orderBy(...orderExprs);
|
|
964
1136
|
}
|
|
965
1137
|
rows = await q;
|
|
966
1138
|
}
|
|
1139
|
+
if (cursorEntries) {
|
|
1140
|
+
attachRowCursors(rows, cursorEntries);
|
|
1141
|
+
}
|
|
967
1142
|
if (isOne) {
|
|
968
1143
|
const byKey = new Map(rows.map((row) => [String(row[foreignColPropName]), row]));
|
|
969
1144
|
remapToGraphQLArrayOutput(rows, targetTableName, targetTable);
|
|
@@ -989,15 +1164,47 @@ var columnDocs = (docs, column, tableName, columnName) => {
|
|
|
989
1164
|
};
|
|
990
1165
|
var inputFieldDocs = (docs, column, tableName, columnName, fieldType) => {
|
|
991
1166
|
const resolved = columnDocs(docs, column, tableName, columnName);
|
|
992
|
-
if (resolved.deprecationReason !== void 0 && fieldType instanceof
|
|
1167
|
+
if (resolved.deprecationReason !== void 0 && fieldType instanceof GraphQLNonNull3) {
|
|
993
1168
|
const { deprecationReason: _dropped, ...rest } = resolved;
|
|
994
1169
|
return rest;
|
|
995
1170
|
}
|
|
996
1171
|
return resolved;
|
|
997
1172
|
};
|
|
998
|
-
var
|
|
1173
|
+
var applyLimitPolicy = (limit, policy, fieldName) => {
|
|
1174
|
+
if (!policy) {
|
|
1175
|
+
return limit ?? void 0;
|
|
1176
|
+
}
|
|
1177
|
+
const { defaultLimit, maxLimit, clampToMax } = policy;
|
|
1178
|
+
if (limit == null) {
|
|
1179
|
+
const fallback = defaultLimit ?? maxLimit;
|
|
1180
|
+
if (fallback === void 0) {
|
|
1181
|
+
return void 0;
|
|
1182
|
+
}
|
|
1183
|
+
return maxLimit === void 0 ? fallback : Math.min(fallback, maxLimit);
|
|
1184
|
+
}
|
|
1185
|
+
if (maxLimit !== void 0 && limit > maxLimit) {
|
|
1186
|
+
if (clampToMax) {
|
|
1187
|
+
return maxLimit;
|
|
1188
|
+
}
|
|
1189
|
+
throw new GraphQLError4(`${fieldName}: 'limit' of ${limit} exceeds the maximum of ${maxLimit}.`);
|
|
1190
|
+
}
|
|
1191
|
+
return limit;
|
|
1192
|
+
};
|
|
1193
|
+
var resolveLimitPolicy = (global, table) => {
|
|
1194
|
+
const defaultLimit = table?.defaultLimit ?? global?.defaultLimit;
|
|
1195
|
+
const maxLimit = table?.maxLimit ?? global?.maxLimit;
|
|
1196
|
+
if (defaultLimit === void 0 && maxLimit === void 0) {
|
|
1197
|
+
return void 0;
|
|
1198
|
+
}
|
|
1199
|
+
return { defaultLimit, maxLimit, clampToMax: table?.clampToMax ?? global?.clampToMax ?? false };
|
|
1200
|
+
};
|
|
1201
|
+
var listFieldComplexity = (options, policy) => ({ args, childComplexity }) => {
|
|
999
1202
|
const limit = args["limit"];
|
|
1000
|
-
const
|
|
1203
|
+
const requested = typeof limit === "number" && limit > 0 ? limit : void 0;
|
|
1204
|
+
let rows = requested ?? policy?.defaultLimit ?? options.defaultListSize;
|
|
1205
|
+
if (policy?.maxLimit !== void 0) {
|
|
1206
|
+
rows = Math.min(rows, policy.maxLimit);
|
|
1207
|
+
}
|
|
1001
1208
|
return rows * Math.max(childComplexity, 1);
|
|
1002
1209
|
};
|
|
1003
1210
|
var aggregateFieldComplexity = (options) => ({ childComplexity }) => options.aggregateCost + childComplexity;
|
|
@@ -1010,7 +1217,7 @@ var relationJoinColumns = (tree, table, selectionCtx) => {
|
|
|
1010
1217
|
if (!relations) {
|
|
1011
1218
|
return [];
|
|
1012
1219
|
}
|
|
1013
|
-
const tableColumns =
|
|
1220
|
+
const tableColumns = getColumns2(table);
|
|
1014
1221
|
const needed = [];
|
|
1015
1222
|
for (const fieldData of Object.values(tree)) {
|
|
1016
1223
|
if (tableColumns[fieldData.name]) {
|
|
@@ -1029,7 +1236,7 @@ var relationJoinColumns = (tree, table, selectionCtx) => {
|
|
|
1029
1236
|
return needed;
|
|
1030
1237
|
};
|
|
1031
1238
|
var extractSelectedColumnsFromTree = (tree, table, selectionCtx) => {
|
|
1032
|
-
const tableColumns =
|
|
1239
|
+
const tableColumns = getColumns2(table);
|
|
1033
1240
|
const treeEntries = Object.entries(tree);
|
|
1034
1241
|
const selectedColumns = [];
|
|
1035
1242
|
for (const [_fieldName, fieldData] of treeEntries) {
|
|
@@ -1049,7 +1256,7 @@ var extractSelectedColumnsFromTree = (tree, table, selectionCtx) => {
|
|
|
1049
1256
|
return Object.fromEntries(selectedColumns);
|
|
1050
1257
|
};
|
|
1051
1258
|
var extractSelectedColumnsFromTreeSQLFormat = (tree, table, selectionCtx) => {
|
|
1052
|
-
const tableColumns =
|
|
1259
|
+
const tableColumns = getColumns2(table);
|
|
1053
1260
|
const treeEntries = Object.entries(tree);
|
|
1054
1261
|
const selectedColumns = [];
|
|
1055
1262
|
for (const [_fieldName, fieldData] of treeEntries) {
|
|
@@ -1082,11 +1289,11 @@ var orderNulls = new GraphQLEnumType2({
|
|
|
1082
1289
|
}
|
|
1083
1290
|
}
|
|
1084
1291
|
});
|
|
1085
|
-
var innerOrder = new
|
|
1292
|
+
var innerOrder = new GraphQLInputObjectType3({
|
|
1086
1293
|
name: "InnerOrder",
|
|
1087
1294
|
fields: {
|
|
1088
1295
|
direction: {
|
|
1089
|
-
type: new
|
|
1296
|
+
type: new GraphQLNonNull3(
|
|
1090
1297
|
new GraphQLEnumType2({
|
|
1091
1298
|
name: "OrderDirection",
|
|
1092
1299
|
description: "Order by direction",
|
|
@@ -1104,7 +1311,7 @@ var innerOrder = new GraphQLInputObjectType2({
|
|
|
1104
1311
|
)
|
|
1105
1312
|
},
|
|
1106
1313
|
priority: {
|
|
1107
|
-
type: new
|
|
1314
|
+
type: new GraphQLNonNull3(GraphQLInt3),
|
|
1108
1315
|
description: "Priority of current field"
|
|
1109
1316
|
},
|
|
1110
1317
|
nulls: {
|
|
@@ -1130,9 +1337,9 @@ var resolveGenericFilterDescriptor = (column, columnGraphQLType) => {
|
|
|
1130
1337
|
if (columnGraphQLType.type === GraphQLJSON) {
|
|
1131
1338
|
return { name: "JSON", kind: "json" };
|
|
1132
1339
|
}
|
|
1133
|
-
if (columnGraphQLType.type instanceof
|
|
1340
|
+
if (columnGraphQLType.type instanceof GraphQLList3) {
|
|
1134
1341
|
let element = columnGraphQLType.type.ofType;
|
|
1135
|
-
if (element instanceof
|
|
1342
|
+
if (element instanceof GraphQLNonNull3) {
|
|
1136
1343
|
element = element.ofType;
|
|
1137
1344
|
}
|
|
1138
1345
|
return { name: `${element.name}Array`, kind: "array" };
|
|
@@ -1156,10 +1363,10 @@ var resolveGenericFilterDescriptor = (column, columnGraphQLType) => {
|
|
|
1156
1363
|
if (ct === "PgTimestamp" || ct === "PgTimestampString" || ct === "PgDate") {
|
|
1157
1364
|
return { name: "DateTime", kind: "scalar" };
|
|
1158
1365
|
}
|
|
1159
|
-
if (columnGraphQLType.type ===
|
|
1366
|
+
if (columnGraphQLType.type === GraphQLInt3) {
|
|
1160
1367
|
return { name: "Int", kind: "scalar" };
|
|
1161
1368
|
}
|
|
1162
|
-
if (columnGraphQLType.type ===
|
|
1369
|
+
if (columnGraphQLType.type === GraphQLFloat3) {
|
|
1163
1370
|
return { name: "Float", kind: "scalar" };
|
|
1164
1371
|
}
|
|
1165
1372
|
return { name: "String", kind: "scalar" };
|
|
@@ -1183,10 +1390,10 @@ var IN_ARRAY_DESCRIPTION = "Matches any one of these values (SQL `IN`)";
|
|
|
1183
1390
|
var NOT_IN_ARRAY_DESCRIPTION = "Matches none of these values (SQL `NOT IN`)";
|
|
1184
1391
|
var arrayFilterFields = (colType, colArr) => {
|
|
1185
1392
|
let element = colType.ofType;
|
|
1186
|
-
if (element instanceof
|
|
1393
|
+
if (element instanceof GraphQLNonNull3) {
|
|
1187
1394
|
element = element.ofType;
|
|
1188
1395
|
}
|
|
1189
|
-
const elementList = new
|
|
1396
|
+
const elementList = new GraphQLList3(new GraphQLNonNull3(element));
|
|
1190
1397
|
return {
|
|
1191
1398
|
eq: { type: colType, description: "The whole array equals this array" },
|
|
1192
1399
|
ne: { type: colType, description: "The whole array differs from this array" },
|
|
@@ -1203,8 +1410,8 @@ var arrayFilterFields = (colType, colArr) => {
|
|
|
1203
1410
|
var FILTERS_WITHOUT_STRING_OPS = /* @__PURE__ */ new Set(["Id", "Int", "Float", "BigInt", "Decimal"]);
|
|
1204
1411
|
var BUILTIN_FILTER_SCALARS = /* @__PURE__ */ new Set([
|
|
1205
1412
|
GraphQLString2,
|
|
1206
|
-
|
|
1207
|
-
|
|
1413
|
+
GraphQLInt3,
|
|
1414
|
+
GraphQLFloat3,
|
|
1208
1415
|
GraphQLBoolean2,
|
|
1209
1416
|
GraphQLBigIntString,
|
|
1210
1417
|
GraphQLDecimalString,
|
|
@@ -1231,7 +1438,7 @@ var generateColumnFilterValues = (column, tableName, columnName, cacheCtx) => {
|
|
|
1231
1438
|
return cached;
|
|
1232
1439
|
}
|
|
1233
1440
|
const colType = columnGraphQLType.type;
|
|
1234
|
-
const colArr = new
|
|
1441
|
+
const colArr = new GraphQLList3(new GraphQLNonNull3(colType));
|
|
1235
1442
|
const customOverrideFilter = inputOverride !== void 0 && !BUILTIN_FILTER_SCALARS.has(inputOverride);
|
|
1236
1443
|
const underlying = extractExtendedColumnType2(column);
|
|
1237
1444
|
const omitStringOps = customOverrideFilter ? underlying.type !== "string" || underlying.constraint === "numeric" : FILTERS_WITHOUT_STRING_OPS.has(genericName);
|
|
@@ -1277,16 +1484,16 @@ var generateColumnFilterValues = (column, tableName, columnName, cacheCtx) => {
|
|
|
1277
1484
|
isNull: { type: GraphQLBoolean2, description: "When true, matches rows where the column is NULL" },
|
|
1278
1485
|
isNotNull: { type: GraphQLBoolean2, description: "When true, matches rows where the column is not NULL" }
|
|
1279
1486
|
};
|
|
1280
|
-
const mainType = new
|
|
1487
|
+
const mainType = new GraphQLInputObjectType3({
|
|
1281
1488
|
name: `${genericName}Filter`,
|
|
1282
1489
|
fields: () => ({
|
|
1283
1490
|
...baseFields,
|
|
1284
1491
|
OR: {
|
|
1285
|
-
type: new
|
|
1492
|
+
type: new GraphQLList3(new GraphQLNonNull3(mainType)),
|
|
1286
1493
|
description: "At least one branch matches; ANDed with any sibling operators"
|
|
1287
1494
|
},
|
|
1288
1495
|
AND: {
|
|
1289
|
-
type: new
|
|
1496
|
+
type: new GraphQLList3(new GraphQLNonNull3(mainType)),
|
|
1290
1497
|
description: "Every branch matches"
|
|
1291
1498
|
},
|
|
1292
1499
|
NOT: {
|
|
@@ -1305,7 +1512,7 @@ var generateTableOrderCached = (table) => {
|
|
|
1305
1512
|
}
|
|
1306
1513
|
let remapped = {};
|
|
1307
1514
|
try {
|
|
1308
|
-
const columns =
|
|
1515
|
+
const columns = getColumns2(table);
|
|
1309
1516
|
const columnEntries = Object.entries(columns);
|
|
1310
1517
|
remapped = Object.fromEntries(
|
|
1311
1518
|
columnEntries.map(([columnName, _columnDescription]) => [columnName, { type: innerOrder }])
|
|
@@ -1319,7 +1526,7 @@ var generateTableFilterValuesCached = (table, tableName, cacheCtx) => {
|
|
|
1319
1526
|
if (cacheCtx.filterFieldCache.has(table)) {
|
|
1320
1527
|
return cacheCtx.filterFieldCache.get(table);
|
|
1321
1528
|
}
|
|
1322
|
-
const columns =
|
|
1529
|
+
const columns = getColumns2(table);
|
|
1323
1530
|
const columnEntries = Object.entries(columns);
|
|
1324
1531
|
const remapped = Object.fromEntries(
|
|
1325
1532
|
columnEntries.map(([columnName, column]) => [
|
|
@@ -1340,7 +1547,7 @@ var generateTableSelectTypeFieldsCached = (table, tableName, cacheCtx) => {
|
|
|
1340
1547
|
if (cacheCtx.selectFieldCache.has(table)) {
|
|
1341
1548
|
return cacheCtx.selectFieldCache.get(table);
|
|
1342
1549
|
}
|
|
1343
|
-
const columns =
|
|
1550
|
+
const columns = getColumns2(table);
|
|
1344
1551
|
const columnEntries = Object.entries(columns);
|
|
1345
1552
|
const remapped = Object.fromEntries(
|
|
1346
1553
|
columnEntries.map(([columnName, column]) => [
|
|
@@ -1395,7 +1602,7 @@ var generateTableOrderTypeCached = (table, tableName, typeNameMapper, cacheCtx,
|
|
|
1395
1602
|
if (cacheCtx.orderTypeCache.has(table)) {
|
|
1396
1603
|
return cacheCtx.orderTypeCache.get(table);
|
|
1397
1604
|
}
|
|
1398
|
-
const order = new
|
|
1605
|
+
const order = new GraphQLInputObjectType3({
|
|
1399
1606
|
name: `${resolveTypeName(tableName, typeNameMapper)}OrderBy`,
|
|
1400
1607
|
fields: () => {
|
|
1401
1608
|
const orderColumns = generateTableOrderCached(table);
|
|
@@ -1413,7 +1620,7 @@ var generateListRelationFilterCached = (targetTable, targetTableName, cacheCtx,
|
|
|
1413
1620
|
if (cached) {
|
|
1414
1621
|
return cached;
|
|
1415
1622
|
}
|
|
1416
|
-
const listFilter = new
|
|
1623
|
+
const listFilter = new GraphQLInputObjectType3({
|
|
1417
1624
|
name: `${resolveTypeName(targetTableName, typeNameMapper)}ListRelationFilter`,
|
|
1418
1625
|
fields: () => {
|
|
1419
1626
|
const targetFilters = generateTableFilterTypeCached(
|
|
@@ -1483,16 +1690,16 @@ var generateTableFilterTypeCached = (table, tableName, cacheCtx, typeNameMapper,
|
|
|
1483
1690
|
...generateRelationFilterFields(tableName, cacheCtx, typeNameMapper, filterColumns, relationMap, tables)
|
|
1484
1691
|
};
|
|
1485
1692
|
};
|
|
1486
|
-
const filters = new
|
|
1693
|
+
const filters = new GraphQLInputObjectType3({
|
|
1487
1694
|
name: `${resolveTypeName(tableName, typeNameMapper)}Filters`,
|
|
1488
1695
|
fields: () => ({
|
|
1489
1696
|
...buildFields(),
|
|
1490
1697
|
OR: {
|
|
1491
|
-
type: new
|
|
1698
|
+
type: new GraphQLList3(new GraphQLNonNull3(filters)),
|
|
1492
1699
|
description: "At least one branch matches; ANDed with any sibling fields"
|
|
1493
1700
|
},
|
|
1494
1701
|
AND: {
|
|
1495
|
-
type: new
|
|
1702
|
+
type: new GraphQLList3(new GraphQLNonNull3(filters)),
|
|
1496
1703
|
description: "Every branch matches"
|
|
1497
1704
|
},
|
|
1498
1705
|
NOT: {
|
|
@@ -1600,7 +1807,7 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
|
|
|
1600
1807
|
rawRelationFields.push([
|
|
1601
1808
|
relationName,
|
|
1602
1809
|
{
|
|
1603
|
-
type: isRequired ? new
|
|
1810
|
+
type: isRequired ? new GraphQLNonNull3(relType) : relType,
|
|
1604
1811
|
args: {
|
|
1605
1812
|
where: { type: relSelectData.filters }
|
|
1606
1813
|
},
|
|
@@ -1610,19 +1817,29 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
|
|
|
1610
1817
|
]);
|
|
1611
1818
|
continue;
|
|
1612
1819
|
}
|
|
1820
|
+
const targetDistinctEnum = cacheCtx.features.distinct ? generateDistinctEnum(tables[targetTableName], resolveTypeName(targetTableName, typeNameMapper)) : void 0;
|
|
1613
1821
|
rawRelationFields.push([
|
|
1614
1822
|
relationName,
|
|
1615
1823
|
{
|
|
1616
|
-
type: new
|
|
1824
|
+
type: new GraphQLNonNull3(new GraphQLList3(new GraphQLNonNull3(relType))),
|
|
1617
1825
|
args: {
|
|
1618
1826
|
where: { type: relSelectData.filters },
|
|
1619
1827
|
orderBy: { type: relSelectData.order },
|
|
1620
|
-
offset: { type:
|
|
1621
|
-
limit: { type:
|
|
1828
|
+
offset: { type: GraphQLInt3 },
|
|
1829
|
+
limit: { type: GraphQLInt3 },
|
|
1830
|
+
after: {
|
|
1831
|
+
type: GraphQLString2,
|
|
1832
|
+
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)."
|
|
1833
|
+
},
|
|
1834
|
+
...targetDistinctEnum ? { distinct: { type: new GraphQLList3(new GraphQLNonNull3(targetDistinctEnum)) } } : {}
|
|
1622
1835
|
},
|
|
1623
1836
|
resolve,
|
|
1624
1837
|
...relationDocs,
|
|
1625
|
-
...cacheCtx.complexity ? {
|
|
1838
|
+
...cacheCtx.complexity ? {
|
|
1839
|
+
extensions: {
|
|
1840
|
+
complexity: listFieldComplexity(cacheCtx.complexity, cacheCtx.limits?.(targetTableName))
|
|
1841
|
+
}
|
|
1842
|
+
} : {}
|
|
1626
1843
|
}
|
|
1627
1844
|
]);
|
|
1628
1845
|
const aggregateFieldName = `${relationName}Aggregate`;
|
|
@@ -1636,7 +1853,7 @@ var generateSelectFields = (tables, tableName, relationMap, fromTableName, fromR
|
|
|
1636
1853
|
rawRelationFields.push([
|
|
1637
1854
|
aggregateFieldName,
|
|
1638
1855
|
{
|
|
1639
|
-
type: new
|
|
1856
|
+
type: new GraphQLNonNull3(relationAggregate.type),
|
|
1640
1857
|
args: {
|
|
1641
1858
|
where: { type: relSelectData.filters }
|
|
1642
1859
|
},
|
|
@@ -1688,7 +1905,7 @@ var generateTableTypes = (tableName, tables, relationMap, withReturning, relatio
|
|
|
1688
1905
|
relationAggregateFactory
|
|
1689
1906
|
);
|
|
1690
1907
|
const table = tables[tableName];
|
|
1691
|
-
const columns =
|
|
1908
|
+
const columns = getColumns2(table);
|
|
1692
1909
|
const columnEntries = Object.entries(columns);
|
|
1693
1910
|
const relaxedColumns = nestedWrites?.relaxedColumns(tableName);
|
|
1694
1911
|
const insertFields = Object.fromEntries(
|
|
@@ -1710,18 +1927,17 @@ var generateTableTypes = (tableName, tables, relationMap, withReturning, relatio
|
|
|
1710
1927
|
const updateFields = Object.fromEntries(
|
|
1711
1928
|
columnEntries.map(([columnName, column]) => {
|
|
1712
1929
|
const converted = drizzleColumnToGraphQLType(column, columnName, tableName, true, false, true);
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
];
|
|
1930
|
+
const operations = cacheCtx.features.fieldUpdateOperations ? fieldUpdateInputType(column, columnName, tableName) : void 0;
|
|
1931
|
+
const field = operations ? { ...converted, type: operations } : converted;
|
|
1932
|
+
return [columnName, { ...field, ...inputFieldDocs(cacheCtx.docs, column, tableName, columnName, field.type) }];
|
|
1717
1933
|
})
|
|
1718
1934
|
);
|
|
1719
1935
|
const typeName = resolveTypeName(tableName, typeNameMapper);
|
|
1720
|
-
const insertInput = new
|
|
1936
|
+
const insertInput = new GraphQLInputObjectType3({
|
|
1721
1937
|
name: `${capitalize(insertPrefix)}${typeName}Input`,
|
|
1722
1938
|
fields: nestedWrites ? () => ({ ...insertFields, ...nestedWrites.createFields(tableName, typeName) }) : insertFields
|
|
1723
1939
|
});
|
|
1724
|
-
const updateInput = new
|
|
1940
|
+
const updateInput = new GraphQLInputObjectType3({
|
|
1725
1941
|
name: `${capitalize(updatePrefix)}${typeName}Input`,
|
|
1726
1942
|
fields: nestedWrites ? () => ({ ...updateFields, ...nestedWrites.updateFields(tableName, typeName) }) : updateFields
|
|
1727
1943
|
});
|
|
@@ -1730,10 +1946,10 @@ var generateTableTypes = (tableName, tables, relationMap, withReturning, relatio
|
|
|
1730
1946
|
description: cacheCtx.docs.describeTable?.(tableName),
|
|
1731
1947
|
fields: { ...tableFields, ...relationFields }
|
|
1732
1948
|
});
|
|
1733
|
-
const selectArrOutput = new
|
|
1949
|
+
const selectArrOutput = new GraphQLNonNull3(new GraphQLList3(new GraphQLNonNull3(selectSingleOutput)));
|
|
1734
1950
|
const arrTableItemOutput = withReturning ? (
|
|
1735
1951
|
// ? new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(singleTableItemOutput!)))
|
|
1736
|
-
new
|
|
1952
|
+
new GraphQLNonNull3(new GraphQLList3(new GraphQLNonNull3(selectSingleOutput)))
|
|
1737
1953
|
) : void 0;
|
|
1738
1954
|
const inputs = {
|
|
1739
1955
|
insertInput,
|
|
@@ -1758,7 +1974,7 @@ var generateTableTypes = (tableName, tables, relationMap, withReturning, relatio
|
|
|
1758
1974
|
};
|
|
1759
1975
|
var orderByEntries = (orderArgs) => Object.entries(orderArgs).sort((a, b) => (b[1]?.priority ?? 0) - (a[1]?.priority ?? 0)).filter(([, config]) => config).map(([column, config]) => {
|
|
1760
1976
|
if (typeof config === "object" && config.direction === void 0) {
|
|
1761
|
-
throw new
|
|
1977
|
+
throw new GraphQLError4(`ORDER BY ${column}: ordering through a relation is not supported in this query`);
|
|
1762
1978
|
}
|
|
1763
1979
|
return [column, config.direction, config.nulls ?? void 0];
|
|
1764
1980
|
});
|
|
@@ -1769,16 +1985,16 @@ var orderExpressions = (expr, direction, nulls, dialectColumn) => {
|
|
|
1769
1985
|
}
|
|
1770
1986
|
const isMySql = (dialectColumn.columnType ?? "").startsWith("MySql");
|
|
1771
1987
|
if (isMySql) {
|
|
1772
|
-
const nullsKey = nulls === "first" ? desc(
|
|
1988
|
+
const nullsKey = nulls === "first" ? desc(sql2`(${expr} is null)`) : asc(sql2`(${expr} is null)`);
|
|
1773
1989
|
return [nullsKey, directed];
|
|
1774
1990
|
}
|
|
1775
|
-
return [nulls === "first" ?
|
|
1991
|
+
return [nulls === "first" ? sql2`${directed} nulls first` : sql2`${directed} nulls last`];
|
|
1776
1992
|
};
|
|
1777
1993
|
var extendRelationOrderChain = (parentTable, relationName, relEntry, ctx, chain) => {
|
|
1778
1994
|
const targetTable = ctx.tables[relEntry.targetTableName];
|
|
1779
1995
|
const relation = relEntry.relation ?? relEntry;
|
|
1780
1996
|
if (!targetTable || !is3(relation, One2) || !isFilterableRelation(relation)) {
|
|
1781
|
-
throw new
|
|
1997
|
+
throw new GraphQLError4(`ORDER BY ${relationName}: Relation cannot be used for ordering`);
|
|
1782
1998
|
}
|
|
1783
1999
|
ctx.aliases ??= { n: 0 };
|
|
1784
2000
|
const aliasedTarget = aliasedTable(targetTable, `dgql_ord_${ctx.aliases.n++}`);
|
|
@@ -1795,7 +2011,7 @@ var extendRelationOrderChain = (parentTable, relationName, relEntry, ctx, chain)
|
|
|
1795
2011
|
};
|
|
1796
2012
|
};
|
|
1797
2013
|
var collectOrderEntries = (table, tableKey, orderArgs, ctx, chain, out) => {
|
|
1798
|
-
const columns =
|
|
2014
|
+
const columns = getColumns2(table);
|
|
1799
2015
|
const relations = ctx?.relationMap[tableKey];
|
|
1800
2016
|
for (const [key, config] of Object.entries(orderArgs)) {
|
|
1801
2017
|
if (config === null || config === void 0) {
|
|
@@ -1804,7 +2020,7 @@ var collectOrderEntries = (table, tableKey, orderArgs, ctx, chain, out) => {
|
|
|
1804
2020
|
const column = columns[key];
|
|
1805
2021
|
if (column) {
|
|
1806
2022
|
out.push({
|
|
1807
|
-
expression: chain ?
|
|
2023
|
+
expression: chain ? sql2`(select ${column} from ${sql2.join(chain.fromParts, sql2`, `)} where ${and(...chain.conditions)})` : column,
|
|
1808
2024
|
column,
|
|
1809
2025
|
direction: config.direction,
|
|
1810
2026
|
nulls: config.nulls ?? void 0,
|
|
@@ -1814,7 +2030,7 @@ var collectOrderEntries = (table, tableKey, orderArgs, ctx, chain, out) => {
|
|
|
1814
2030
|
}
|
|
1815
2031
|
const relEntry = relations?.[key];
|
|
1816
2032
|
if (!relEntry || !ctx) {
|
|
1817
|
-
throw new
|
|
2033
|
+
throw new GraphQLError4(`ORDER BY ${key}: Unknown column or relation`);
|
|
1818
2034
|
}
|
|
1819
2035
|
const nextChain = extendRelationOrderChain(chain?.table ?? table, key, relEntry, ctx, chain);
|
|
1820
2036
|
collectOrderEntries(nextChain.table, relEntry.targetTableName, config, ctx, nextChain, out);
|
|
@@ -1837,21 +2053,21 @@ var safeLikeOps = {
|
|
|
1837
2053
|
};
|
|
1838
2054
|
var safeLikeCondition = (column, pattern, insensitive) => {
|
|
1839
2055
|
if (!insensitive) {
|
|
1840
|
-
return
|
|
2056
|
+
return sql2`${column} like ${pattern} escape ${LIKE_ESCAPE_CHAR}`;
|
|
1841
2057
|
}
|
|
1842
2058
|
const isPg = (column.columnType ?? "").startsWith("Pg");
|
|
1843
|
-
return isPg ?
|
|
2059
|
+
return isPg ? sql2`${column} ilike ${pattern} escape ${LIKE_ESCAPE_CHAR}` : sql2`lower(${column}) like ${pattern.toLowerCase()} escape ${LIKE_ESCAPE_CHAR}`;
|
|
1844
2060
|
};
|
|
1845
2061
|
var isJsonColumn2 = (column) => (column.columnType ?? "").includes("Json");
|
|
1846
2062
|
var jsonContains = (column, columnName, value) => {
|
|
1847
2063
|
const serialized = JSON.stringify(value);
|
|
1848
2064
|
switch (columnDialect(column)) {
|
|
1849
2065
|
case "pg":
|
|
1850
|
-
return column.columnType === "PgJson" ?
|
|
2066
|
+
return column.columnType === "PgJson" ? sql2`${column}::jsonb @> ${serialized}::jsonb` : sql2`${column} @> ${serialized}::jsonb`;
|
|
1851
2067
|
case "mysql":
|
|
1852
|
-
return
|
|
2068
|
+
return sql2`json_contains(${column}, ${serialized})`;
|
|
1853
2069
|
default:
|
|
1854
|
-
throw new
|
|
2070
|
+
throw new GraphQLError4(`WHERE ${columnName}: Operator 'contains' is not supported for this dialect!`);
|
|
1855
2071
|
}
|
|
1856
2072
|
};
|
|
1857
2073
|
var extractFiltersColumn = (column, columnName, operators) => {
|
|
@@ -1882,7 +2098,7 @@ var extractFiltersColumn = (column, columnName, operators) => {
|
|
|
1882
2098
|
variants.push(safeLikeCondition(column, buildPattern(operatorValue), insensitive));
|
|
1883
2099
|
} else if (operatorName in arrayValueOps) {
|
|
1884
2100
|
if (!operatorValue.length) {
|
|
1885
|
-
throw new
|
|
2101
|
+
throw new GraphQLError4(`WHERE ${columnName}: Unable to use operator ${operatorName} with an empty array!`);
|
|
1886
2102
|
}
|
|
1887
2103
|
const arrayValue = operatorValue.map((val) => remapFromGraphQLCore(val, column, columnName));
|
|
1888
2104
|
variants.push(arrayValueOps[operatorName](column, arrayValue));
|
|
@@ -1890,15 +2106,15 @@ var extractFiltersColumn = (column, columnName, operators) => {
|
|
|
1890
2106
|
variants.push(arrayContains(column, [operatorValue]));
|
|
1891
2107
|
} else if (operatorName in arrayMembershipOps) {
|
|
1892
2108
|
if (!operatorValue.length) {
|
|
1893
|
-
throw new
|
|
2109
|
+
throw new GraphQLError4(`WHERE ${columnName}: Unable to use operator ${operatorName} with an empty array!`);
|
|
1894
2110
|
}
|
|
1895
2111
|
variants.push(arrayMembershipOps[operatorName](column, operatorValue));
|
|
1896
2112
|
} else if (operatorName === "isEmpty") {
|
|
1897
|
-
variants.push(
|
|
2113
|
+
variants.push(sql2`cardinality(${column}) = 0`);
|
|
1898
2114
|
} else if (operatorName in nullableOps) {
|
|
1899
2115
|
variants.push(nullableOps[operatorName](column));
|
|
1900
2116
|
} else {
|
|
1901
|
-
throw new
|
|
2117
|
+
throw new GraphQLError4(`WHERE ${columnName}: Unknown operator: ${operatorName}`);
|
|
1902
2118
|
}
|
|
1903
2119
|
}
|
|
1904
2120
|
if (AND?.length) {
|
|
@@ -1934,23 +2150,23 @@ var buildRelationJoinCondition = (parentTable, relation, aliasedTarget, relation
|
|
|
1934
2150
|
const sourceColumns = relation.sourceColumns;
|
|
1935
2151
|
const targetColumns = relation.targetColumns;
|
|
1936
2152
|
if (!sourceColumns?.length || sourceColumns.length !== targetColumns?.length) {
|
|
1937
|
-
throw new
|
|
2153
|
+
throw new GraphQLError4(`WHERE ${relationName}: Relation cannot be used as a filter`);
|
|
1938
2154
|
}
|
|
1939
|
-
const parentColumns = Object.values(
|
|
1940
|
-
const targetColumnsByName = Object.values(
|
|
2155
|
+
const parentColumns = Object.values(getColumns2(parentTable));
|
|
2156
|
+
const targetColumnsByName = Object.values(getColumns2(aliasedTarget));
|
|
1941
2157
|
const conditions = [];
|
|
1942
2158
|
for (let i = 0; i < sourceColumns.length; i++) {
|
|
1943
2159
|
const localColumn = parentColumns.find((c) => c.name === sourceColumns[i].name);
|
|
1944
2160
|
const foreignColumn = targetColumnsByName.find((c) => c.name === targetColumns[i].name);
|
|
1945
2161
|
if (!localColumn || !foreignColumn) {
|
|
1946
|
-
throw new
|
|
2162
|
+
throw new GraphQLError4(`WHERE ${relationName}: Relation cannot be used as a filter`);
|
|
1947
2163
|
}
|
|
1948
2164
|
conditions.push(eq(localColumn, foreignColumn));
|
|
1949
2165
|
}
|
|
1950
2166
|
return conditions.length > 1 ? and(...conditions) : conditions[0];
|
|
1951
2167
|
};
|
|
1952
2168
|
var resolveJunctionColumn = (aliasedThrough, junctionRef, relationName) => {
|
|
1953
|
-
const throughColumns =
|
|
2169
|
+
const throughColumns = getColumns2(aliasedThrough);
|
|
1954
2170
|
const key = junctionRef?._?.key;
|
|
1955
2171
|
const byKey = key ? throughColumns[key] : void 0;
|
|
1956
2172
|
if (byKey) {
|
|
@@ -1959,7 +2175,7 @@ var resolveJunctionColumn = (aliasedThrough, junctionRef, relationName) => {
|
|
|
1959
2175
|
const columnName = junctionRef?._?.column?.name;
|
|
1960
2176
|
const byName = columnName ? Object.values(throughColumns).find((c) => c.name === columnName) : void 0;
|
|
1961
2177
|
if (!byName) {
|
|
1962
|
-
throw new
|
|
2178
|
+
throw new GraphQLError4(`WHERE ${relationName}: Relation cannot be used as a filter`);
|
|
1963
2179
|
}
|
|
1964
2180
|
return byName;
|
|
1965
2181
|
};
|
|
@@ -1968,15 +2184,15 @@ var buildThroughJoinConditions = (parentTable, relation, aliasedThrough, aliased
|
|
|
1968
2184
|
const targetColumns = relation.targetColumns;
|
|
1969
2185
|
const through = relation.through;
|
|
1970
2186
|
if (!sourceColumns?.length || !targetColumns?.length || through?.source.length !== sourceColumns.length || through.target.length !== targetColumns.length) {
|
|
1971
|
-
throw new
|
|
2187
|
+
throw new GraphQLError4(`WHERE ${relationName}: Relation cannot be used as a filter`);
|
|
1972
2188
|
}
|
|
1973
|
-
const parentColumns = Object.values(
|
|
1974
|
-
const targetTableColumns = Object.values(
|
|
2189
|
+
const parentColumns = Object.values(getColumns2(parentTable));
|
|
2190
|
+
const targetTableColumns = Object.values(getColumns2(aliasedTarget));
|
|
1975
2191
|
const correlationConditions = [];
|
|
1976
2192
|
for (let i = 0; i < sourceColumns.length; i++) {
|
|
1977
2193
|
const localColumn = parentColumns.find((c) => c.name === sourceColumns[i].name);
|
|
1978
2194
|
if (!localColumn) {
|
|
1979
|
-
throw new
|
|
2195
|
+
throw new GraphQLError4(`WHERE ${relationName}: Relation cannot be used as a filter`);
|
|
1980
2196
|
}
|
|
1981
2197
|
correlationConditions.push(eq(localColumn, resolveJunctionColumn(aliasedThrough, through.source[i], relationName)));
|
|
1982
2198
|
}
|
|
@@ -1984,7 +2200,7 @@ var buildThroughJoinConditions = (parentTable, relation, aliasedThrough, aliased
|
|
|
1984
2200
|
for (let i = 0; i < targetColumns.length; i++) {
|
|
1985
2201
|
const foreignColumn = targetTableColumns.find((c) => c.name === targetColumns[i].name);
|
|
1986
2202
|
if (!foreignColumn) {
|
|
1987
|
-
throw new
|
|
2203
|
+
throw new GraphQLError4(`WHERE ${relationName}: Relation cannot be used as a filter`);
|
|
1988
2204
|
}
|
|
1989
2205
|
junctionJoinConditions.push(
|
|
1990
2206
|
eq(resolveJunctionColumn(aliasedThrough, through.target[i], relationName), foreignColumn)
|
|
@@ -2000,7 +2216,7 @@ var buildRelationExists = (parentTable, relationName, relEntry, innerFilters, mo
|
|
|
2000
2216
|
const targetTable = ctx.tables[targetTableName];
|
|
2001
2217
|
const relation = relEntry.relation ?? relEntry;
|
|
2002
2218
|
if (!targetTable) {
|
|
2003
|
-
throw new
|
|
2219
|
+
throw new GraphQLError4(`WHERE ${relationName}: Relation cannot be used as a filter`);
|
|
2004
2220
|
}
|
|
2005
2221
|
ctx.aliases ??= { n: 0 };
|
|
2006
2222
|
const aliases = ctx.aliases;
|
|
@@ -2017,7 +2233,7 @@ var buildRelationExists = (parentTable, relationName, relEntry, innerFilters, mo
|
|
|
2017
2233
|
aliasedTarget,
|
|
2018
2234
|
relationName
|
|
2019
2235
|
);
|
|
2020
|
-
fromClause =
|
|
2236
|
+
fromClause = sql2`${getTableAsAliasSQL(aliasedTarget)} inner join ${getTableAsAliasSQL(aliasedThrough)} on ${junctionJoin}`;
|
|
2021
2237
|
joinCondition = correlation;
|
|
2022
2238
|
} else {
|
|
2023
2239
|
fromClause = getTableAsAliasSQL(aliasedTarget);
|
|
@@ -2029,10 +2245,10 @@ var buildRelationExists = (parentTable, relationName, relEntry, innerFilters, mo
|
|
|
2029
2245
|
if (!inner) {
|
|
2030
2246
|
return void 0;
|
|
2031
2247
|
}
|
|
2032
|
-
return
|
|
2248
|
+
return sql2`not exists (select 1 from ${fromClause} where ${and(joinCondition, relationWhere, not(inner))})`;
|
|
2033
2249
|
}
|
|
2034
2250
|
const condition = and(joinCondition, relationWhere, inner);
|
|
2035
|
-
return mode === "none" ?
|
|
2251
|
+
return mode === "none" ? sql2`not exists (select 1 from ${fromClause} where ${condition})` : sql2`exists (select 1 from ${fromClause} where ${condition})`;
|
|
2036
2252
|
};
|
|
2037
2253
|
var extractRelationFilter = (parentTable, relationName, relEntry, value, ctx) => {
|
|
2038
2254
|
const relation = relEntry.relation ?? relEntry;
|
|
@@ -2046,7 +2262,7 @@ var extractRelationFilter = (parentTable, relationName, relEntry, value, ctx) =>
|
|
|
2046
2262
|
continue;
|
|
2047
2263
|
}
|
|
2048
2264
|
if (!relationMatchModes.includes(mode)) {
|
|
2049
|
-
throw new
|
|
2265
|
+
throw new GraphQLError4(`WHERE ${relationName}: Unknown relation filter key: ${mode}`);
|
|
2050
2266
|
}
|
|
2051
2267
|
const extracted = buildRelationExists(parentTable, relationName, relEntry, inner, mode, ctx);
|
|
2052
2268
|
if (extracted) {
|
|
@@ -2058,7 +2274,7 @@ var extractRelationFilter = (parentTable, relationName, relEntry, value, ctx) =>
|
|
|
2058
2274
|
var extractFilters = (table, tableName, filters, relationCtx) => {
|
|
2059
2275
|
const { OR, AND, NOT, ...fieldFilters } = filters;
|
|
2060
2276
|
const entries = Object.entries(fieldFilters);
|
|
2061
|
-
const columns =
|
|
2277
|
+
const columns = getColumns2(table);
|
|
2062
2278
|
const relations = relationCtx?.relationMap[relationCtx.tableKey];
|
|
2063
2279
|
const variants = [];
|
|
2064
2280
|
for (const [fieldName, operators] of entries) {
|
|
@@ -2067,7 +2283,7 @@ var extractFilters = (table, tableName, filters, relationCtx) => {
|
|
|
2067
2283
|
}
|
|
2068
2284
|
const column = columns[fieldName];
|
|
2069
2285
|
if (!column && !(relations?.[fieldName] && relationCtx)) {
|
|
2070
|
-
throw new
|
|
2286
|
+
throw new GraphQLError4(`WHERE ${tableName}: Unknown filter key: ${fieldName}`);
|
|
2071
2287
|
}
|
|
2072
2288
|
const extracted = column ? extractFiltersColumn(column, fieldName, operators) : extractRelationFilter(table, fieldName, relations[fieldName], operators, relationCtx);
|
|
2073
2289
|
if (extracted) {
|
|
@@ -2102,7 +2318,7 @@ var extractFilters = (table, tableName, filters, relationCtx) => {
|
|
|
2102
2318
|
}
|
|
2103
2319
|
return variants.length ? variants.length > 1 ? and(...variants) : variants[0] : void 0;
|
|
2104
2320
|
};
|
|
2105
|
-
var extractRelationsParamsInner = (relationMap, tables, tableName, typeName, originField, typeNameMapper, _isInitial = false, filterCtx) => {
|
|
2321
|
+
var extractRelationsParamsInner = (relationMap, tables, tableName, typeName, originField, typeNameMapper, _isInitial = false, filterCtx, limits) => {
|
|
2106
2322
|
const relationsForTable = relationMap[tableName];
|
|
2107
2323
|
if (!relationsForTable) {
|
|
2108
2324
|
return void 0;
|
|
@@ -2131,6 +2347,10 @@ var extractRelationsParamsInner = (relationMap, tables, tableName, typeName, ori
|
|
|
2131
2347
|
if (!relFieldSelection) {
|
|
2132
2348
|
continue;
|
|
2133
2349
|
}
|
|
2350
|
+
const eagerArgs = field.args;
|
|
2351
|
+
if (!is3(relEntry.relation ?? relEntry, One2) && (eagerArgs?.after != null || !!eagerArgs?.distinct?.length || isCursorFieldSelected(relFieldSelection, tables[targetTableName]))) {
|
|
2352
|
+
continue;
|
|
2353
|
+
}
|
|
2134
2354
|
const columns = extractSelectedColumnsFromTree(relFieldSelection, tables[targetTableName], {
|
|
2135
2355
|
tableName: targetTableName,
|
|
2136
2356
|
relationMap,
|
|
@@ -2142,7 +2362,7 @@ var extractRelationsParamsInner = (relationMap, tables, tableName, typeName, ori
|
|
|
2142
2362
|
const relationField = Object.values(baseField).find((e) => e.name === relName);
|
|
2143
2363
|
const relationArgs = relationField?.args;
|
|
2144
2364
|
const offset = relationArgs?.offset ?? void 0;
|
|
2145
|
-
const limit = relationArgs?.limit ?? void 0;
|
|
2365
|
+
const limit = is3(relEntry.relation, One2) ? relationArgs?.limit ?? void 0 : applyLimitPolicy(relationArgs?.limit, limits?.(targetTableName), `${tableName}.${relName}`);
|
|
2146
2366
|
const relWhere = relationArgs?.where;
|
|
2147
2367
|
thisRecord.where = relWhere ? {
|
|
2148
2368
|
RAW: (aliasedTable2) => extractFilters(aliasedTable2, relName, relWhere, relationFilterCtx(filterCtx, targetTableName))
|
|
@@ -2160,18 +2380,29 @@ var extractRelationsParamsInner = (relationMap, tables, tableName, typeName, ori
|
|
|
2160
2380
|
relationField,
|
|
2161
2381
|
typeNameMapper,
|
|
2162
2382
|
false,
|
|
2163
|
-
filterCtx
|
|
2383
|
+
filterCtx,
|
|
2384
|
+
limits
|
|
2164
2385
|
) : void 0;
|
|
2165
2386
|
thisRecord.with = relWith;
|
|
2166
2387
|
args[relName] = thisRecord;
|
|
2167
2388
|
}
|
|
2168
2389
|
return args;
|
|
2169
2390
|
};
|
|
2170
|
-
var extractRelationsParams = (relationMap, tables, tableName, info, typeName, typeNameMapper, filterCtx) => {
|
|
2391
|
+
var extractRelationsParams = (relationMap, tables, tableName, info, typeName, typeNameMapper, filterCtx, limits) => {
|
|
2171
2392
|
if (!info) {
|
|
2172
2393
|
return void 0;
|
|
2173
2394
|
}
|
|
2174
|
-
return extractRelationsParamsInner(
|
|
2395
|
+
return extractRelationsParamsInner(
|
|
2396
|
+
relationMap,
|
|
2397
|
+
tables,
|
|
2398
|
+
tableName,
|
|
2399
|
+
typeName,
|
|
2400
|
+
info,
|
|
2401
|
+
typeNameMapper,
|
|
2402
|
+
true,
|
|
2403
|
+
filterCtx,
|
|
2404
|
+
limits
|
|
2405
|
+
);
|
|
2175
2406
|
};
|
|
2176
2407
|
var pruneNonEagerRelations = (relationMap, shouldEagerLoad) => {
|
|
2177
2408
|
const out = {};
|
|
@@ -2183,7 +2414,7 @@ var pruneNonEagerRelations = (relationMap, shouldEagerLoad) => {
|
|
|
2183
2414
|
return out;
|
|
2184
2415
|
};
|
|
2185
2416
|
var getPrimaryKeyPropNames = (table, compositePkColumnNames) => {
|
|
2186
|
-
const cols =
|
|
2417
|
+
const cols = getColumns2(table);
|
|
2187
2418
|
const entries = Object.entries(cols);
|
|
2188
2419
|
const inlinePks = entries.filter(([, c]) => c.primary).map(([k]) => k);
|
|
2189
2420
|
if (inlinePks.length) {
|
|
@@ -2199,7 +2430,7 @@ var getPrimaryKeyPropNames = (table, compositePkColumnNames) => {
|
|
|
2199
2430
|
return [];
|
|
2200
2431
|
};
|
|
2201
2432
|
var withPrimaryKeyColumns = (columns, table, pkNames) => {
|
|
2202
|
-
const allCols =
|
|
2433
|
+
const allCols = getColumns2(table);
|
|
2203
2434
|
for (const pk of pkNames) {
|
|
2204
2435
|
if (!(pk in columns) && allCols[pk]) {
|
|
2205
2436
|
columns[pk] = allCols[pk];
|
|
@@ -2212,7 +2443,7 @@ var getPrimaryKeyPropNamesFromConfig = (table, getTableConfig4) => {
|
|
|
2212
2443
|
return getPrimaryKeyPropNames(table, compositePkColumnNames);
|
|
2213
2444
|
};
|
|
2214
2445
|
var primaryKeyOrderExprs = (table, pkNames) => {
|
|
2215
|
-
const cols =
|
|
2446
|
+
const cols = getColumns2(table);
|
|
2216
2447
|
return pkNames.map((n) => cols[n]).filter(Boolean).map((col) => asc(col));
|
|
2217
2448
|
};
|
|
2218
2449
|
var CURSOR_FIELD_NAME = "cursor";
|
|
@@ -2229,7 +2460,7 @@ var cursorOrderingEntries = (orderBy, pkNames) => {
|
|
|
2229
2460
|
return entries;
|
|
2230
2461
|
};
|
|
2231
2462
|
var cursorOrderExprs = (table, entries) => {
|
|
2232
|
-
const cols =
|
|
2463
|
+
const cols = getColumns2(table);
|
|
2233
2464
|
return entries.flatMap(
|
|
2234
2465
|
([column, direction, nulls]) => orderExpressions(cols[column], direction, nulls ?? void 0, cols[column])
|
|
2235
2466
|
);
|
|
@@ -2266,10 +2497,10 @@ var decodeCursor = (after, entries) => {
|
|
|
2266
2497
|
try {
|
|
2267
2498
|
payload = JSON.parse(Buffer.from(after, "base64url").toString("utf8"));
|
|
2268
2499
|
} catch (_e) {
|
|
2269
|
-
throw new
|
|
2500
|
+
throw new GraphQLError4("Invalid cursor: unable to decode it. Pass a cursor returned by a previous page.");
|
|
2270
2501
|
}
|
|
2271
2502
|
if (!payload || typeof payload !== "object" || !Array.isArray(payload.o) || !Array.isArray(payload.v) || payload.o.length !== payload.v.length) {
|
|
2272
|
-
throw new
|
|
2503
|
+
throw new GraphQLError4("Invalid cursor: malformed payload. Pass a cursor returned by a previous page.");
|
|
2273
2504
|
}
|
|
2274
2505
|
const matchesOrdering = payload.o.length === entries.length && payload.o.every(
|
|
2275
2506
|
(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.
|
|
@@ -2277,20 +2508,20 @@ var decodeCursor = (after, entries) => {
|
|
|
2277
2508
|
(entry[2] ?? null) === (entries[i][2] ?? null)
|
|
2278
2509
|
);
|
|
2279
2510
|
if (!matchesOrdering) {
|
|
2280
|
-
throw new
|
|
2511
|
+
throw new GraphQLError4(
|
|
2281
2512
|
"Invalid cursor: it was issued for a different ordering. Pass the same orderBy the cursor's page used."
|
|
2282
2513
|
);
|
|
2283
2514
|
}
|
|
2284
2515
|
return payload.v.map(decodeCursorValue);
|
|
2285
2516
|
};
|
|
2286
2517
|
var buildCursorCondition = (table, entries, values, nullOrdering) => {
|
|
2287
|
-
const cols =
|
|
2518
|
+
const cols = getColumns2(table);
|
|
2288
2519
|
const disjuncts = [];
|
|
2289
2520
|
const equalities = [];
|
|
2290
2521
|
entries.forEach(([column, direction, nulls], i) => {
|
|
2291
2522
|
const col = cols[column];
|
|
2292
2523
|
if (!col) {
|
|
2293
|
-
throw new
|
|
2524
|
+
throw new GraphQLError4(`Invalid cursor: unknown column '${column}'.`);
|
|
2294
2525
|
}
|
|
2295
2526
|
const value = values[i];
|
|
2296
2527
|
const nullsSortLast = nulls != null ? nulls === "last" : direction === "asc" === (nullOrdering === "nulls-largest");
|
|
@@ -2307,7 +2538,7 @@ var buildCursorCondition = (table, entries, values, nullOrdering) => {
|
|
|
2307
2538
|
equalities.push(value === null || value === void 0 ? isNull(col) : eq(col, value));
|
|
2308
2539
|
});
|
|
2309
2540
|
if (!disjuncts.length) {
|
|
2310
|
-
return
|
|
2541
|
+
return sql2`1 = 0`;
|
|
2311
2542
|
}
|
|
2312
2543
|
return disjuncts.length > 1 ? or(...disjuncts) : disjuncts[0];
|
|
2313
2544
|
};
|
|
@@ -2315,11 +2546,33 @@ var isCursorFieldSelected = (tree, table) => {
|
|
|
2315
2546
|
if (!tree) {
|
|
2316
2547
|
return false;
|
|
2317
2548
|
}
|
|
2318
|
-
if (
|
|
2549
|
+
if (getColumns2(table)[CURSOR_FIELD_NAME]) {
|
|
2319
2550
|
return false;
|
|
2320
2551
|
}
|
|
2321
2552
|
return Object.values(tree).some((field) => field.name === CURSOR_FIELD_NAME);
|
|
2322
2553
|
};
|
|
2554
|
+
var selectsCursorField = (info, table) => {
|
|
2555
|
+
if (getColumns2(table)[CURSOR_FIELD_NAME]) {
|
|
2556
|
+
return false;
|
|
2557
|
+
}
|
|
2558
|
+
const visited = /* @__PURE__ */ new Set();
|
|
2559
|
+
const walk = (selections) => selections.some((selection) => {
|
|
2560
|
+
if (selection.kind === "Field") {
|
|
2561
|
+
return selection.name.value === CURSOR_FIELD_NAME;
|
|
2562
|
+
}
|
|
2563
|
+
if (selection.kind === "InlineFragment") {
|
|
2564
|
+
return walk(selection.selectionSet.selections);
|
|
2565
|
+
}
|
|
2566
|
+
const name = selection.name?.value;
|
|
2567
|
+
if (!name || visited.has(name)) {
|
|
2568
|
+
return false;
|
|
2569
|
+
}
|
|
2570
|
+
visited.add(name);
|
|
2571
|
+
const fragment = info.fragments?.[name];
|
|
2572
|
+
return fragment ? walk(fragment.selectionSet.selections) : false;
|
|
2573
|
+
});
|
|
2574
|
+
return (info.fieldNodes ?? []).some((node) => !!node.selectionSet && walk(node.selectionSet.selections));
|
|
2575
|
+
};
|
|
2323
2576
|
var attachRowCursors = (rows, entries) => {
|
|
2324
2577
|
for (const row of rows) {
|
|
2325
2578
|
row[ROW_CURSOR_PROP] = encodeCursor(entries, row);
|
|
@@ -2327,7 +2580,7 @@ var attachRowCursors = (rows, entries) => {
|
|
|
2327
2580
|
};
|
|
2328
2581
|
var rowCursorResolver = (source) => source?.[ROW_CURSOR_PROP] ?? null;
|
|
2329
2582
|
var getUniqueColumnSets = (table, getTableConfig4) => {
|
|
2330
|
-
const cols =
|
|
2583
|
+
const cols = getColumns2(table);
|
|
2331
2584
|
const propNameByColumnName = new Map(Object.entries(cols).map(([propName, col]) => [col.name, propName]));
|
|
2332
2585
|
const toPropNames = (columnNames) => {
|
|
2333
2586
|
const propNames = [];
|
|
@@ -2372,7 +2625,7 @@ var generateColumnEnum = (table, enumName, description, predicate = () => true)
|
|
|
2372
2625
|
if (cached) {
|
|
2373
2626
|
return cached;
|
|
2374
2627
|
}
|
|
2375
|
-
const columnNames = Object.entries(
|
|
2628
|
+
const columnNames = Object.entries(getColumns2(table)).filter(([columnName, column]) => predicate(column, columnName)).map(([columnName]) => columnName);
|
|
2376
2629
|
if (!columnNames.length) {
|
|
2377
2630
|
return void 0;
|
|
2378
2631
|
}
|
|
@@ -2414,7 +2667,7 @@ var generateOnConflictInput = (params) => {
|
|
|
2414
2667
|
description: "Whether a conflicting row is overwritten or left alone. Defaults to UPDATE."
|
|
2415
2668
|
},
|
|
2416
2669
|
update: {
|
|
2417
|
-
type: new
|
|
2670
|
+
type: new GraphQLList3(new GraphQLNonNull3(updateEnum)),
|
|
2418
2671
|
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."
|
|
2419
2672
|
}
|
|
2420
2673
|
};
|
|
@@ -2430,7 +2683,7 @@ var generateOnConflictInput = (params) => {
|
|
|
2430
2683
|
return void 0;
|
|
2431
2684
|
}
|
|
2432
2685
|
fields["target"] = {
|
|
2433
|
-
type: new
|
|
2686
|
+
type: new GraphQLList3(new GraphQLNonNull3(targetEnum)),
|
|
2434
2687
|
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."
|
|
2435
2688
|
};
|
|
2436
2689
|
fields["where"] = {
|
|
@@ -2438,7 +2691,7 @@ var generateOnConflictInput = (params) => {
|
|
|
2438
2691
|
description: "Only overwrite conflicting rows that match this filter. Others are left alone."
|
|
2439
2692
|
};
|
|
2440
2693
|
}
|
|
2441
|
-
return new
|
|
2694
|
+
return new GraphQLInputObjectType3({
|
|
2442
2695
|
name: `${typeName}OnConflict`,
|
|
2443
2696
|
description: `Conflict handling for an upsert of ${typeName}`,
|
|
2444
2697
|
fields
|
|
@@ -2446,18 +2699,18 @@ var generateOnConflictInput = (params) => {
|
|
|
2446
2699
|
};
|
|
2447
2700
|
var resolveConflictPlan = (params) => {
|
|
2448
2701
|
const { table, values, onConflict, pkNames, uniqueSets, excludedRef, withTarget, buildWhere } = params;
|
|
2449
|
-
const columns =
|
|
2702
|
+
const columns = getColumns2(table);
|
|
2450
2703
|
let target;
|
|
2451
2704
|
if (withTarget) {
|
|
2452
2705
|
const targetNames2 = onConflict?.target?.length ? onConflict.target : [...pkNames];
|
|
2453
2706
|
if (!targetNames2.length) {
|
|
2454
|
-
throw new
|
|
2707
|
+
throw new GraphQLError4(
|
|
2455
2708
|
"Unable to upsert: no conflict target was given and this table has no primary key. Pass onConflict.target."
|
|
2456
2709
|
);
|
|
2457
2710
|
}
|
|
2458
2711
|
const requested = [...targetNames2].sort().join(",");
|
|
2459
2712
|
if (!uniqueSets.some((set2) => [...set2].sort().join(",") === requested)) {
|
|
2460
|
-
throw new
|
|
2713
|
+
throw new GraphQLError4(
|
|
2461
2714
|
`Unable to upsert: [${targetNames2.join(", ")}] is not a unique constraint on this table. Valid conflict targets: ${uniqueSets.map((set2) => `[${set2.join(", ")}]`).join(", ")}.`
|
|
2462
2715
|
);
|
|
2463
2716
|
}
|
|
@@ -2472,7 +2725,7 @@ var resolveConflictPlan = (params) => {
|
|
|
2472
2725
|
if (onConflict?.update?.length) {
|
|
2473
2726
|
const unsupplied = onConflict.update.filter((name) => !supplied.has(name));
|
|
2474
2727
|
if (unsupplied.length) {
|
|
2475
|
-
throw new
|
|
2728
|
+
throw new GraphQLError4(
|
|
2476
2729
|
`Unable to upsert: onConflict.update lists ${unsupplied.join(", ")}, which the values do not supply.`
|
|
2477
2730
|
);
|
|
2478
2731
|
}
|
|
@@ -2487,18 +2740,19 @@ var resolveConflictPlan = (params) => {
|
|
|
2487
2740
|
const setWhere = onConflict?.where && buildWhere ? buildWhere(onConflict.where) : void 0;
|
|
2488
2741
|
return { action: "UPDATE", target, set, setWhere };
|
|
2489
2742
|
};
|
|
2490
|
-
var excludedColumnRef = (columnName) =>
|
|
2491
|
-
var mysqlValuesColumnRef = (columnName) =>
|
|
2743
|
+
var excludedColumnRef = (columnName) => sql2`excluded.${sql2.identifier(columnName)}`;
|
|
2744
|
+
var mysqlValuesColumnRef = (columnName) => sql2`values(${sql2.identifier(columnName)})`;
|
|
2492
2745
|
var selectDistinctKeys = async (params) => {
|
|
2493
|
-
const { db, table, tableName, distinct, pkNames, where, orderBy, limit, offset } = params;
|
|
2494
|
-
const cols =
|
|
2746
|
+
const { db, table, tableName, distinct, pkNames, where, orderBy, limit, offset, partitionBy } = params;
|
|
2747
|
+
const cols = getColumns2(table);
|
|
2495
2748
|
if (!pkNames.length) {
|
|
2496
|
-
throw new
|
|
2749
|
+
throw new GraphQLError4(`Table ${tableName} has no primary key, so 'distinct' cannot be applied to it.`);
|
|
2497
2750
|
}
|
|
2498
|
-
const
|
|
2499
|
-
if (!
|
|
2500
|
-
throw new
|
|
2751
|
+
const requestedCols = distinct.map((name) => cols[name]).filter(Boolean);
|
|
2752
|
+
if (!requestedCols.length) {
|
|
2753
|
+
throw new GraphQLError4(`No known columns were given to 'distinct' on ${tableName}.`);
|
|
2501
2754
|
}
|
|
2755
|
+
const partitionCols = [...partitionBy ?? [], ...requestedCols];
|
|
2502
2756
|
const orderEntries = orderBy ? orderByEntries(orderBy) : [];
|
|
2503
2757
|
const windowOrder = [
|
|
2504
2758
|
...orderEntries.flatMap(
|
|
@@ -2506,9 +2760,9 @@ var selectDistinctKeys = async (params) => {
|
|
|
2506
2760
|
),
|
|
2507
2761
|
...primaryKeyOrderExprs(table, pkNames)
|
|
2508
2762
|
];
|
|
2509
|
-
const rowNumber =
|
|
2763
|
+
const rowNumber = sql2`row_number() over (partition by ${sql2.join(partitionCols, sql2`, `)} order by ${sql2.join(
|
|
2510
2764
|
windowOrder,
|
|
2511
|
-
|
|
2765
|
+
sql2`, `
|
|
2512
2766
|
)})`.as(DISTINCT_RN);
|
|
2513
2767
|
const sub = db.select({ ...cols, [DISTINCT_RN]: rowNumber }).from(table).where(where).as("__dgql_distinct");
|
|
2514
2768
|
const outerOrder = [
|
|
@@ -2527,7 +2781,7 @@ var selectDistinctKeys = async (params) => {
|
|
|
2527
2781
|
return await query;
|
|
2528
2782
|
};
|
|
2529
2783
|
var primaryKeyRestriction = (table, pkNames, keys) => {
|
|
2530
|
-
const cols =
|
|
2784
|
+
const cols = getColumns2(table);
|
|
2531
2785
|
if (pkNames.length === 1) {
|
|
2532
2786
|
const name = pkNames[0];
|
|
2533
2787
|
return inArray(
|
|
@@ -2539,7 +2793,16 @@ var primaryKeyRestriction = (table, pkNames, keys) => {
|
|
|
2539
2793
|
};
|
|
2540
2794
|
var prepareMutationRelationColumns = (params) => {
|
|
2541
2795
|
const { relationMap, tables, tableName, typeName, typeNameMapper, table, pkNames, parsedInfo } = params;
|
|
2542
|
-
const withParams = relationMap[tableName] ? extractRelationsParams(
|
|
2796
|
+
const withParams = relationMap[tableName] ? extractRelationsParams(
|
|
2797
|
+
relationMap,
|
|
2798
|
+
tables,
|
|
2799
|
+
tableName,
|
|
2800
|
+
parsedInfo,
|
|
2801
|
+
typeName,
|
|
2802
|
+
typeNameMapper,
|
|
2803
|
+
void 0,
|
|
2804
|
+
params.limits
|
|
2805
|
+
) : void 0;
|
|
2543
2806
|
const hasRelations = !!(withParams && Object.keys(withParams).length);
|
|
2544
2807
|
const baseColumns = extractSelectedColumnsFromTreeSQLFormat(parsedInfo.fieldsByTypeName[typeName], table, {
|
|
2545
2808
|
tableName,
|
|
@@ -2550,17 +2813,17 @@ var prepareMutationRelationColumns = (params) => {
|
|
|
2550
2813
|
return { columns, hasRelations, withParams };
|
|
2551
2814
|
};
|
|
2552
2815
|
var toGraphQLError = (e) => {
|
|
2553
|
-
if (e instanceof
|
|
2816
|
+
if (e instanceof GraphQLError4) {
|
|
2554
2817
|
return e;
|
|
2555
2818
|
}
|
|
2556
|
-
return e instanceof Error ? new
|
|
2819
|
+
return e instanceof Error ? new GraphQLError4(e.message, { originalError: e }) : e;
|
|
2557
2820
|
};
|
|
2558
2821
|
var defaultErrorMapper = (error) => {
|
|
2559
|
-
if (error instanceof
|
|
2822
|
+
if (error instanceof GraphQLError4 && !error.originalError) {
|
|
2560
2823
|
return error;
|
|
2561
2824
|
}
|
|
2562
|
-
return new
|
|
2563
|
-
originalError: error instanceof
|
|
2825
|
+
return new GraphQLError4("Internal server error", {
|
|
2826
|
+
originalError: error instanceof GraphQLError4 ? error.originalError ?? error : error instanceof Error ? error : null,
|
|
2564
2827
|
extensions: { code: "INTERNAL_SERVER_ERROR" }
|
|
2565
2828
|
});
|
|
2566
2829
|
};
|
|
@@ -2617,6 +2880,9 @@ var computeResolverFieldNames = (tableName, typeNameMapper, prefixes, suffixes)
|
|
|
2617
2880
|
const writeSingleSuffix = suffixes.single === "" ? "Single" : suffixes.single;
|
|
2618
2881
|
const updateSingleFieldName = `${updateFieldName}${writeSingleSuffix}`;
|
|
2619
2882
|
const deleteSingleFieldName = `${deleteFieldName}${writeSingleSuffix}`;
|
|
2883
|
+
const pluralNoun = mapped ? capitalize(mapped.plural) : capitalize(tableName);
|
|
2884
|
+
const updateCountFieldName = `${prefixes.update}${pluralNoun}Count`;
|
|
2885
|
+
const deleteCountFieldName = `${prefixes.delete}${pluralNoun}Count`;
|
|
2620
2886
|
return {
|
|
2621
2887
|
typeName,
|
|
2622
2888
|
listFieldName,
|
|
@@ -2630,13 +2896,15 @@ var computeResolverFieldNames = (tableName, typeNameMapper, prefixes, suffixes)
|
|
|
2630
2896
|
updateFieldName,
|
|
2631
2897
|
updateManyFieldName,
|
|
2632
2898
|
updateSingleFieldName,
|
|
2899
|
+
updateCountFieldName,
|
|
2633
2900
|
deleteFieldName,
|
|
2634
|
-
deleteSingleFieldName
|
|
2901
|
+
deleteSingleFieldName,
|
|
2902
|
+
deleteCountFieldName
|
|
2635
2903
|
};
|
|
2636
2904
|
};
|
|
2637
2905
|
var generateUpdateManyInput = (params) => {
|
|
2638
2906
|
const { typeName, updatePrefix, updateInput, tableFilters } = params;
|
|
2639
|
-
return new
|
|
2907
|
+
return new GraphQLInputObjectType3({
|
|
2640
2908
|
name: `${capitalize(updatePrefix)}${typeName}ManyInput`,
|
|
2641
2909
|
description: `One entry of a batch update of ${typeName}: the rows \`where\` matches get this entry's \`set\` applied.`,
|
|
2642
2910
|
fields: {
|
|
@@ -2645,7 +2913,7 @@ var generateUpdateManyInput = (params) => {
|
|
|
2645
2913
|
description: "Rows this entry updates. An omitted filter updates every row."
|
|
2646
2914
|
},
|
|
2647
2915
|
set: {
|
|
2648
|
-
type: new
|
|
2916
|
+
type: new GraphQLNonNull3(updateInput)
|
|
2649
2917
|
}
|
|
2650
2918
|
}
|
|
2651
2919
|
});
|
|
@@ -2653,29 +2921,101 @@ var generateUpdateManyInput = (params) => {
|
|
|
2653
2921
|
var extractRequiredFilters = (table, tableName, where, fieldName, relationCtx) => {
|
|
2654
2922
|
const filters = where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
2655
2923
|
if (!filters) {
|
|
2656
|
-
throw new
|
|
2924
|
+
throw new GraphQLError4(`${fieldName} requires a 'where' argument with at least one filter!`);
|
|
2657
2925
|
}
|
|
2658
2926
|
return filters;
|
|
2659
2927
|
};
|
|
2928
|
+
var rowsAffected = (result, fieldName) => {
|
|
2929
|
+
const asNumber = (value) => typeof value === "number" ? value : typeof value === "bigint" ? Number(value) : void 0;
|
|
2930
|
+
if (result && typeof result === "object") {
|
|
2931
|
+
for (const key of ["rowCount", "affectedRows", "rowsAffected", "changes", "count"]) {
|
|
2932
|
+
const value = asNumber(result[key]);
|
|
2933
|
+
if (value !== void 0) {
|
|
2934
|
+
return value;
|
|
2935
|
+
}
|
|
2936
|
+
}
|
|
2937
|
+
const header = Array.isArray(result) ? result[0] : void 0;
|
|
2938
|
+
const affected = header && typeof header === "object" ? asNumber(header.affectedRows) : void 0;
|
|
2939
|
+
if (affected !== void 0) {
|
|
2940
|
+
return affected;
|
|
2941
|
+
}
|
|
2942
|
+
}
|
|
2943
|
+
throw new GraphQLError4(`${fieldName}: the driver did not report how many rows the write affected.`);
|
|
2944
|
+
};
|
|
2660
2945
|
var assertSingleMatch = async (executor, table, filters, fieldName) => {
|
|
2661
|
-
const matched = await executor.select({ found:
|
|
2946
|
+
const matched = await executor.select({ found: sql2`1` }).from(table).where(filters).limit(2);
|
|
2662
2947
|
if (matched.length > 1) {
|
|
2663
|
-
throw new
|
|
2664
|
-
}
|
|
2948
|
+
throw new GraphQLError4(`${fieldName}: 'where' matched more than one row \u2014 nothing was written!`);
|
|
2949
|
+
}
|
|
2950
|
+
};
|
|
2951
|
+
var generateWriteCount = ({
|
|
2952
|
+
db,
|
|
2953
|
+
tableName,
|
|
2954
|
+
table,
|
|
2955
|
+
kind,
|
|
2956
|
+
setArgs,
|
|
2957
|
+
filterArgs,
|
|
2958
|
+
fieldName,
|
|
2959
|
+
requireWhere,
|
|
2960
|
+
filterCtx,
|
|
2961
|
+
txCtx,
|
|
2962
|
+
nested
|
|
2963
|
+
}) => {
|
|
2964
|
+
const queryArgs = {
|
|
2965
|
+
...setArgs ? { set: { type: new GraphQLNonNull3(setArgs) } } : {},
|
|
2966
|
+
where: {
|
|
2967
|
+
type: requireWhere ? new GraphQLNonNull3(filterArgs) : filterArgs
|
|
2968
|
+
}
|
|
2969
|
+
};
|
|
2970
|
+
return {
|
|
2971
|
+
name: fieldName,
|
|
2972
|
+
resolver: async (_source, args, context, info) => {
|
|
2973
|
+
try {
|
|
2974
|
+
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
2975
|
+
const { where, set } = args;
|
|
2976
|
+
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
2977
|
+
const filters = requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
2978
|
+
let query;
|
|
2979
|
+
if (kind === "delete") {
|
|
2980
|
+
query = executor.delete(table);
|
|
2981
|
+
} else {
|
|
2982
|
+
const entry = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
|
|
2983
|
+
if (entry && nested.hasOps(entry.ops)) {
|
|
2984
|
+
throw new GraphQLError4(
|
|
2985
|
+
`${fieldName} does not support nested writes \u2014 use ${fieldName.slice(0, -"Count".length)} instead.`
|
|
2986
|
+
);
|
|
2987
|
+
}
|
|
2988
|
+
const values = remapUpdateInput(entry ? entry.columns : set, table, tableName);
|
|
2989
|
+
if (!Object.keys(values).length) {
|
|
2990
|
+
throw new GraphQLError4("Unable to update with no values specified!");
|
|
2991
|
+
}
|
|
2992
|
+
query = executor.update(table).set(values);
|
|
2993
|
+
}
|
|
2994
|
+
if (filters) {
|
|
2995
|
+
query = query.where(filters);
|
|
2996
|
+
}
|
|
2997
|
+
return rowsAffected(await query, fieldName);
|
|
2998
|
+
});
|
|
2999
|
+
} catch (e) {
|
|
3000
|
+
throw toGraphQLError(e);
|
|
3001
|
+
}
|
|
3002
|
+
},
|
|
3003
|
+
args: queryArgs
|
|
3004
|
+
};
|
|
2665
3005
|
};
|
|
2666
3006
|
var selectArrayArgs = (orderArgs, filterArgs, distinctEnum) => ({
|
|
2667
|
-
offset: { type:
|
|
2668
|
-
limit: { type:
|
|
3007
|
+
offset: { type: GraphQLInt3 },
|
|
3008
|
+
limit: { type: GraphQLInt3 },
|
|
2669
3009
|
orderBy: { type: orderArgs },
|
|
2670
3010
|
where: { type: filterArgs },
|
|
2671
3011
|
after: {
|
|
2672
3012
|
type: GraphQLString2,
|
|
2673
3013
|
description: "Keyset pagination: only return rows strictly after this cursor (a row's `cursor` field from a previous page, under the same orderBy)."
|
|
2674
3014
|
},
|
|
2675
|
-
...distinctEnum ? { distinct: { type: new
|
|
3015
|
+
...distinctEnum ? { distinct: { type: new GraphQLList3(new GraphQLNonNull3(distinctEnum)) } } : {}
|
|
2676
3016
|
});
|
|
2677
3017
|
var selectSingleArgs = (orderArgs, filterArgs) => ({
|
|
2678
|
-
offset: { type:
|
|
3018
|
+
offset: { type: GraphQLInt3 },
|
|
2679
3019
|
orderBy: { type: orderArgs },
|
|
2680
3020
|
where: { type: filterArgs }
|
|
2681
3021
|
});
|
|
@@ -2702,17 +3042,17 @@ var runRelationalSelect = async (opts) => {
|
|
|
2702
3042
|
let cursorEntries;
|
|
2703
3043
|
if (!single && (after != null || cursorSelected)) {
|
|
2704
3044
|
if (after != null && distinct) {
|
|
2705
|
-
throw new
|
|
3045
|
+
throw new GraphQLError4("'after' cannot be combined with 'distinct'.");
|
|
2706
3046
|
}
|
|
2707
3047
|
if (orderByHasRelationEntry(orderBy)) {
|
|
2708
3048
|
if (after != null) {
|
|
2709
|
-
throw new
|
|
3049
|
+
throw new GraphQLError4(
|
|
2710
3050
|
"'after' cannot be combined with an orderBy that orders through a relation \u2014 a related row's value cannot be encoded into a cursor."
|
|
2711
3051
|
);
|
|
2712
3052
|
}
|
|
2713
3053
|
} else if (!pkNames?.length) {
|
|
2714
3054
|
if (after != null) {
|
|
2715
|
-
throw new
|
|
3055
|
+
throw new GraphQLError4(`Table ${tableName} has no primary key, so cursor pagination cannot be used on it.`);
|
|
2716
3056
|
}
|
|
2717
3057
|
} else {
|
|
2718
3058
|
cursorEntries = cursorOrderingEntries(orderBy, pkNames);
|
|
@@ -2766,7 +3106,16 @@ var runRelationalSelect = async (opts) => {
|
|
|
2766
3106
|
) : void 0
|
|
2767
3107
|
)
|
|
2768
3108
|
} : void 0,
|
|
2769
|
-
with: relationMap[tableName] ? extractRelationsParams(
|
|
3109
|
+
with: relationMap[tableName] ? extractRelationsParams(
|
|
3110
|
+
relationMap,
|
|
3111
|
+
tables,
|
|
3112
|
+
tableName,
|
|
3113
|
+
parsedInfo,
|
|
3114
|
+
typeName,
|
|
3115
|
+
typeNameMapper,
|
|
3116
|
+
filterCtx,
|
|
3117
|
+
opts.limits
|
|
3118
|
+
) : void 0
|
|
2770
3119
|
};
|
|
2771
3120
|
if (single) {
|
|
2772
3121
|
const result2 = await queryBase.findFirst(params);
|
|
@@ -2809,20 +3158,20 @@ var eagerLoadMutationRelations = async (db, tableName, rows, pkNames, withParams
|
|
|
2809
3158
|
whereRaw = (aliased) => inArray(aliased[pkName], ids);
|
|
2810
3159
|
} else {
|
|
2811
3160
|
whereRaw = (aliased) => {
|
|
2812
|
-
const lhs =
|
|
2813
|
-
pkNames.map((n) =>
|
|
2814
|
-
|
|
3161
|
+
const lhs = sql2.join(
|
|
3162
|
+
pkNames.map((n) => sql2`${aliased[n]}`),
|
|
3163
|
+
sql2`, `
|
|
2815
3164
|
);
|
|
2816
|
-
const tuples =
|
|
3165
|
+
const tuples = sql2.join(
|
|
2817
3166
|
keyableRows.map(
|
|
2818
|
-
(row) =>
|
|
2819
|
-
pkNames.map((n) =>
|
|
2820
|
-
|
|
3167
|
+
(row) => sql2`(${sql2.join(
|
|
3168
|
+
pkNames.map((n) => sql2`${row[n]}`),
|
|
3169
|
+
sql2`, `
|
|
2821
3170
|
)})`
|
|
2822
3171
|
),
|
|
2823
|
-
|
|
3172
|
+
sql2`, `
|
|
2824
3173
|
);
|
|
2825
|
-
return
|
|
3174
|
+
return sql2`(${lhs}) in (${tuples})`;
|
|
2826
3175
|
};
|
|
2827
3176
|
}
|
|
2828
3177
|
let enriched;
|
|
@@ -2857,9 +3206,10 @@ import { is as is4, One as One3 } from "drizzle-orm";
|
|
|
2857
3206
|
import { getTableConfig, MySqlTable } from "drizzle-orm/mysql-core";
|
|
2858
3207
|
import {
|
|
2859
3208
|
GraphQLBoolean as GraphQLBoolean3,
|
|
2860
|
-
GraphQLError as
|
|
2861
|
-
|
|
2862
|
-
|
|
3209
|
+
GraphQLError as GraphQLError6,
|
|
3210
|
+
GraphQLInt as GraphQLInt5,
|
|
3211
|
+
GraphQLList as GraphQLList5,
|
|
3212
|
+
GraphQLNonNull as GraphQLNonNull5,
|
|
2863
3213
|
GraphQLObjectType as GraphQLObjectType4
|
|
2864
3214
|
} from "graphql";
|
|
2865
3215
|
import { parseResolveInfo as parseResolveInfo2 } from "graphql-parse-resolve-info";
|
|
@@ -2872,7 +3222,7 @@ import {
|
|
|
2872
3222
|
countDistinct,
|
|
2873
3223
|
eq as eq2,
|
|
2874
3224
|
extractExtendedColumnType as extractExtendedColumnType3,
|
|
2875
|
-
getColumns as
|
|
3225
|
+
getColumns as getColumns3,
|
|
2876
3226
|
gt as gt2,
|
|
2877
3227
|
gte as gte2,
|
|
2878
3228
|
inArray as inArray2,
|
|
@@ -2884,12 +3234,12 @@ import {
|
|
|
2884
3234
|
sum
|
|
2885
3235
|
} from "drizzle-orm";
|
|
2886
3236
|
import {
|
|
2887
|
-
GraphQLError as
|
|
2888
|
-
GraphQLFloat as
|
|
2889
|
-
GraphQLInputObjectType as
|
|
2890
|
-
GraphQLInt as
|
|
2891
|
-
GraphQLList as
|
|
2892
|
-
GraphQLNonNull as
|
|
3237
|
+
GraphQLError as GraphQLError5,
|
|
3238
|
+
GraphQLFloat as GraphQLFloat4,
|
|
3239
|
+
GraphQLInputObjectType as GraphQLInputObjectType4,
|
|
3240
|
+
GraphQLInt as GraphQLInt4,
|
|
3241
|
+
GraphQLList as GraphQLList4,
|
|
3242
|
+
GraphQLNonNull as GraphQLNonNull4,
|
|
2893
3243
|
GraphQLObjectType as GraphQLObjectType3
|
|
2894
3244
|
} from "graphql";
|
|
2895
3245
|
import { parseResolveInfo } from "graphql-parse-resolve-info";
|
|
@@ -2908,11 +3258,11 @@ var classifyAggregateColumns = (table, tableName) => {
|
|
|
2908
3258
|
const numeric = {};
|
|
2909
3259
|
const orderable = {};
|
|
2910
3260
|
const all = {};
|
|
2911
|
-
for (const [columnName, column] of Object.entries(
|
|
3261
|
+
for (const [columnName, column] of Object.entries(getColumns3(table))) {
|
|
2912
3262
|
all[columnName] = column;
|
|
2913
3263
|
const converted = drizzleColumnToGraphQLType(column, columnName, tableName, true, false, false);
|
|
2914
3264
|
const gqlType = converted.type;
|
|
2915
|
-
if (gqlType instanceof
|
|
3265
|
+
if (gqlType instanceof GraphQLList4 || gqlType instanceof GraphQLObjectType3) {
|
|
2916
3266
|
continue;
|
|
2917
3267
|
}
|
|
2918
3268
|
const { type: dataType, constraint } = extractExtendedColumnType3(column);
|
|
@@ -2936,14 +3286,14 @@ var generateAggregateTypes = (table, tableName, typeName, cacheCtx) => {
|
|
|
2936
3286
|
}
|
|
2937
3287
|
const { numeric, orderable, all } = classifyAggregateColumns(table, tableName);
|
|
2938
3288
|
const fields = {
|
|
2939
|
-
count: { type: new
|
|
3289
|
+
count: { type: new GraphQLNonNull4(GraphQLInt4) }
|
|
2940
3290
|
};
|
|
2941
3291
|
if (Object.keys(numeric).length) {
|
|
2942
3292
|
for (const op of ["avg", "sum"]) {
|
|
2943
3293
|
fields[op] = {
|
|
2944
3294
|
type: new GraphQLObjectType3({
|
|
2945
3295
|
name: `${typeName}${capitalize(op)}Aggregate`,
|
|
2946
|
-
fields: Object.fromEntries(Object.keys(numeric).map((columnName) => [columnName, { type:
|
|
3296
|
+
fields: Object.fromEntries(Object.keys(numeric).map((columnName) => [columnName, { type: GraphQLFloat4 }]))
|
|
2947
3297
|
})
|
|
2948
3298
|
};
|
|
2949
3299
|
}
|
|
@@ -2973,7 +3323,7 @@ var generateAggregateTypes = (table, tableName, typeName, cacheCtx) => {
|
|
|
2973
3323
|
type: new GraphQLObjectType3({
|
|
2974
3324
|
name: `${typeName}${capitalize(op)}Aggregate`,
|
|
2975
3325
|
fields: Object.fromEntries(
|
|
2976
|
-
columnNames.map((columnName) => [columnName, { type: new
|
|
3326
|
+
columnNames.map((columnName) => [columnName, { type: new GraphQLNonNull4(GraphQLInt4) }])
|
|
2977
3327
|
)
|
|
2978
3328
|
})
|
|
2979
3329
|
};
|
|
@@ -3001,7 +3351,7 @@ var aggregateTarget = (table, tableName, typeName) => {
|
|
|
3001
3351
|
return {
|
|
3002
3352
|
tableName,
|
|
3003
3353
|
typeName,
|
|
3004
|
-
columns:
|
|
3354
|
+
columns: getColumns3(table),
|
|
3005
3355
|
dateTimeColumns: new Set(
|
|
3006
3356
|
Object.entries(orderable).filter(([, { converted }]) => converted.typeLabel === "DateTime").map(([columnName]) => columnName)
|
|
3007
3357
|
)
|
|
@@ -3152,7 +3502,7 @@ var HAVING_OPS = { eq: eq2, ne: ne2, gt: gt2, gte: gte2, lt: lt2, lte: lte2 };
|
|
|
3152
3502
|
var groupableColumns = (table, tableName) => {
|
|
3153
3503
|
const { orderable } = classifyAggregateColumns(table, tableName);
|
|
3154
3504
|
const groupable = { ...orderable };
|
|
3155
|
-
for (const [columnName, column] of Object.entries(
|
|
3505
|
+
for (const [columnName, column] of Object.entries(getColumns3(table))) {
|
|
3156
3506
|
if (groupable[columnName]) {
|
|
3157
3507
|
continue;
|
|
3158
3508
|
}
|
|
@@ -3176,10 +3526,10 @@ var generateGroupByEnum = (table, tableName, typeName) => {
|
|
|
3176
3526
|
(_column, columnName) => Boolean(groupable[columnName])
|
|
3177
3527
|
);
|
|
3178
3528
|
};
|
|
3179
|
-
var aggregateNumberFilter = new
|
|
3529
|
+
var aggregateNumberFilter = new GraphQLInputObjectType4({
|
|
3180
3530
|
name: "AggregateNumberFilter",
|
|
3181
3531
|
description: "Compares an aggregated value. Several operators in one filter are ANDed together.",
|
|
3182
|
-
fields: Object.fromEntries(Object.keys(HAVING_OPS).map((op) => [op, { type:
|
|
3532
|
+
fields: Object.fromEntries(Object.keys(HAVING_OPS).map((op) => [op, { type: GraphQLFloat4 }]))
|
|
3183
3533
|
});
|
|
3184
3534
|
var generateHavingInput = (table, tableName, typeName) => {
|
|
3185
3535
|
const { numeric, orderable, all } = classifyAggregateColumns(table, tableName);
|
|
@@ -3200,13 +3550,13 @@ var generateHavingInput = (table, tableName, typeName) => {
|
|
|
3200
3550
|
continue;
|
|
3201
3551
|
}
|
|
3202
3552
|
fields[op] = {
|
|
3203
|
-
type: new
|
|
3553
|
+
type: new GraphQLInputObjectType4({
|
|
3204
3554
|
name: `${typeName}${capitalize(op)}Having`,
|
|
3205
3555
|
fields: Object.fromEntries(columnNames.map((columnName) => [columnName, { type: aggregateNumberFilter }]))
|
|
3206
3556
|
})
|
|
3207
3557
|
};
|
|
3208
3558
|
}
|
|
3209
|
-
return new
|
|
3559
|
+
return new GraphQLInputObjectType4({
|
|
3210
3560
|
name: `${typeName}Having`,
|
|
3211
3561
|
description: `Filters ${typeName} groups by their aggregated values`,
|
|
3212
3562
|
fields
|
|
@@ -3236,7 +3586,7 @@ var generateGroupByType = (table, tableName, typeName, cacheCtx) => {
|
|
|
3236
3586
|
);
|
|
3237
3587
|
return new GraphQLObjectType3({
|
|
3238
3588
|
name: `${typeName}GroupBy`,
|
|
3239
|
-
fields: { group: { type: new
|
|
3589
|
+
fields: { group: { type: new GraphQLNonNull4(keysType) }, ...aggregateFields }
|
|
3240
3590
|
});
|
|
3241
3591
|
};
|
|
3242
3592
|
var havingComparisons = (expression, filter) => Object.entries(filter).filter(([op, value]) => value != null && op in HAVING_OPS).map(([op, value]) => HAVING_OPS[op](expression, value));
|
|
@@ -3269,11 +3619,11 @@ var buildHavingCondition = (having, columns) => {
|
|
|
3269
3619
|
var generateGroupBy = (db, tableName, table, typeName, fieldName, filterArgs, groupByEnum, havingInput, filterCtx) => {
|
|
3270
3620
|
const target = aggregateTarget(table, tableName, typeName);
|
|
3271
3621
|
const groupable = groupableColumns(table, tableName);
|
|
3272
|
-
const columns =
|
|
3622
|
+
const columns = getColumns3(table);
|
|
3273
3623
|
const rootTypeName = `${typeName}GroupBy`;
|
|
3274
3624
|
const queryArgs = {
|
|
3275
3625
|
groupBy: {
|
|
3276
|
-
type: new
|
|
3626
|
+
type: new GraphQLNonNull4(new GraphQLList4(new GraphQLNonNull4(groupByEnum))),
|
|
3277
3627
|
description: "Columns to group by. One result row per distinct combination of their values."
|
|
3278
3628
|
},
|
|
3279
3629
|
where: { type: filterArgs, description: "Filters the rows before they are grouped." },
|
|
@@ -3285,12 +3635,12 @@ var generateGroupBy = (db, tableName, table, typeName, fieldName, filterArgs, gr
|
|
|
3285
3635
|
try {
|
|
3286
3636
|
const requestedKeys = [...new Set(args.groupBy ?? [])];
|
|
3287
3637
|
if (!requestedKeys.length) {
|
|
3288
|
-
throw new
|
|
3638
|
+
throw new GraphQLError5("At least one column to group by is required!");
|
|
3289
3639
|
}
|
|
3290
3640
|
const keyColumns = requestedKeys.map((columnName) => {
|
|
3291
3641
|
const groupableColumn = groupable[columnName];
|
|
3292
3642
|
if (!groupableColumn) {
|
|
3293
|
-
throw new
|
|
3643
|
+
throw new GraphQLError5(`Cannot group ${typeName} by ${columnName}!`);
|
|
3294
3644
|
}
|
|
3295
3645
|
return [columnName, groupableColumn.column];
|
|
3296
3646
|
});
|
|
@@ -3327,7 +3677,7 @@ var generateGroupBy = (db, tableName, table, typeName, fieldName, filterArgs, gr
|
|
|
3327
3677
|
};
|
|
3328
3678
|
|
|
3329
3679
|
// src/util/builders/mysql.ts
|
|
3330
|
-
var generateSelectArray = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, distinctEnabled = true) => {
|
|
3680
|
+
var generateSelectArray = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, distinctEnabled = true, limits) => {
|
|
3331
3681
|
const queryBase = db.query[tableName];
|
|
3332
3682
|
if (!queryBase) {
|
|
3333
3683
|
throw new Error(
|
|
@@ -3335,6 +3685,7 @@ var generateSelectArray = (db, tableName, tables, relationMap, orderArgs, filter
|
|
|
3335
3685
|
);
|
|
3336
3686
|
}
|
|
3337
3687
|
const table = tables[tableName];
|
|
3688
|
+
const limitPolicy = limits?.(tableName);
|
|
3338
3689
|
const pkNames = mysqlPrimaryKeyPropNames(table);
|
|
3339
3690
|
const queryArgs = selectArrayArgs(
|
|
3340
3691
|
orderArgs,
|
|
@@ -3357,8 +3708,10 @@ var generateSelectArray = (db, tableName, tables, relationMap, orderArgs, filter
|
|
|
3357
3708
|
typeNameMapper,
|
|
3358
3709
|
parsedInfo,
|
|
3359
3710
|
...args,
|
|
3711
|
+
limit: applyLimitPolicy(args.limit, limitPolicy, fieldName),
|
|
3360
3712
|
single: false,
|
|
3361
3713
|
filterCtx,
|
|
3714
|
+
limits,
|
|
3362
3715
|
pkNames,
|
|
3363
3716
|
db: executor,
|
|
3364
3717
|
// MySQL sorts NULLs as the smallest values (first in ASC).
|
|
@@ -3371,7 +3724,7 @@ var generateSelectArray = (db, tableName, tables, relationMap, orderArgs, filter
|
|
|
3371
3724
|
args: queryArgs
|
|
3372
3725
|
};
|
|
3373
3726
|
};
|
|
3374
|
-
var generateSelectSingle = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx) => {
|
|
3727
|
+
var generateSelectSingle = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, limits) => {
|
|
3375
3728
|
const queryBase = db.query[tableName];
|
|
3376
3729
|
if (!queryBase) {
|
|
3377
3730
|
throw new Error(
|
|
@@ -3399,6 +3752,7 @@ var generateSelectSingle = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
3399
3752
|
...args,
|
|
3400
3753
|
single: true,
|
|
3401
3754
|
filterCtx,
|
|
3755
|
+
limits,
|
|
3402
3756
|
pkNames,
|
|
3403
3757
|
db: executor
|
|
3404
3758
|
});
|
|
@@ -3412,7 +3766,7 @@ var generateSelectSingle = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
3412
3766
|
var generateInsertArray = (db, _tableName, table, baseType, fieldName, txCtx) => {
|
|
3413
3767
|
const queryArgs = {
|
|
3414
3768
|
values: {
|
|
3415
|
-
type: new
|
|
3769
|
+
type: new GraphQLNonNull5(new GraphQLList5(new GraphQLNonNull5(baseType)))
|
|
3416
3770
|
}
|
|
3417
3771
|
};
|
|
3418
3772
|
return {
|
|
@@ -3422,7 +3776,7 @@ var generateInsertArray = (db, _tableName, table, baseType, fieldName, txCtx) =>
|
|
|
3422
3776
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
3423
3777
|
const input = remapFromGraphQLArrayInput(args.values, table);
|
|
3424
3778
|
if (!input.length) {
|
|
3425
|
-
throw new
|
|
3779
|
+
throw new GraphQLError6("No values were provided!");
|
|
3426
3780
|
}
|
|
3427
3781
|
await executor.insert(table).values(input);
|
|
3428
3782
|
return { isSuccess: true };
|
|
@@ -3437,7 +3791,7 @@ var generateInsertArray = (db, _tableName, table, baseType, fieldName, txCtx) =>
|
|
|
3437
3791
|
var generateInsertSingle = (db, _tableName, table, baseType, fieldName, txCtx) => {
|
|
3438
3792
|
const queryArgs = {
|
|
3439
3793
|
values: {
|
|
3440
|
-
type: new
|
|
3794
|
+
type: new GraphQLNonNull5(baseType)
|
|
3441
3795
|
}
|
|
3442
3796
|
};
|
|
3443
3797
|
return {
|
|
@@ -3459,7 +3813,7 @@ var generateInsertSingle = (db, _tableName, table, baseType, fieldName, txCtx) =
|
|
|
3459
3813
|
var generateUpsert = (db, table, baseType, onConflictType, fieldName, single, txCtx) => {
|
|
3460
3814
|
const queryArgs = {
|
|
3461
3815
|
values: {
|
|
3462
|
-
type: single ? new
|
|
3816
|
+
type: single ? new GraphQLNonNull5(baseType) : new GraphQLNonNull5(new GraphQLList5(new GraphQLNonNull5(baseType)))
|
|
3463
3817
|
},
|
|
3464
3818
|
onConflict: {
|
|
3465
3819
|
type: onConflictType,
|
|
@@ -3474,7 +3828,7 @@ var generateUpsert = (db, table, baseType, onConflictType, fieldName, single, tx
|
|
|
3474
3828
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
3475
3829
|
const input = single ? [remapFromGraphQLSingleInput(args.values, table)] : remapFromGraphQLArrayInput(args.values, table);
|
|
3476
3830
|
if (!input.length) {
|
|
3477
|
-
throw new
|
|
3831
|
+
throw new GraphQLError6("No values were provided!");
|
|
3478
3832
|
}
|
|
3479
3833
|
const plan = resolveConflictPlan({
|
|
3480
3834
|
table,
|
|
@@ -3502,10 +3856,10 @@ var generateUpsert = (db, table, baseType, onConflictType, fieldName, single, tx
|
|
|
3502
3856
|
var generateUpdate = (db, tableName, table, setArgs, filterArgs, fieldName, single, requireWhere, filterCtx, txCtx) => {
|
|
3503
3857
|
const queryArgs = {
|
|
3504
3858
|
set: {
|
|
3505
|
-
type: new
|
|
3859
|
+
type: new GraphQLNonNull5(setArgs)
|
|
3506
3860
|
},
|
|
3507
3861
|
where: {
|
|
3508
|
-
type: single || requireWhere ? new
|
|
3862
|
+
type: single || requireWhere ? new GraphQLNonNull5(filterArgs) : filterArgs
|
|
3509
3863
|
}
|
|
3510
3864
|
};
|
|
3511
3865
|
return {
|
|
@@ -3514,9 +3868,9 @@ var generateUpdate = (db, tableName, table, setArgs, filterArgs, fieldName, sing
|
|
|
3514
3868
|
try {
|
|
3515
3869
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
3516
3870
|
const { where, set } = args;
|
|
3517
|
-
const input =
|
|
3871
|
+
const input = remapUpdateInput(set, table, tableName);
|
|
3518
3872
|
if (!Object.keys(input).length) {
|
|
3519
|
-
throw new
|
|
3873
|
+
throw new GraphQLError6("Unable to update with no values specified!");
|
|
3520
3874
|
}
|
|
3521
3875
|
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
3522
3876
|
const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
@@ -3540,7 +3894,7 @@ var generateUpdate = (db, tableName, table, setArgs, filterArgs, fieldName, sing
|
|
|
3540
3894
|
var generateUpdateMany = (db, tableName, table, updateManyInput, fieldName, filterCtx, txCtx) => {
|
|
3541
3895
|
const queryArgs = {
|
|
3542
3896
|
updates: {
|
|
3543
|
-
type: new
|
|
3897
|
+
type: new GraphQLNonNull5(new GraphQLList5(new GraphQLNonNull5(updateManyInput)))
|
|
3544
3898
|
}
|
|
3545
3899
|
};
|
|
3546
3900
|
return {
|
|
@@ -3550,12 +3904,12 @@ var generateUpdateMany = (db, tableName, table, updateManyInput, fieldName, filt
|
|
|
3550
3904
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
3551
3905
|
const { updates } = args;
|
|
3552
3906
|
if (!updates.length) {
|
|
3553
|
-
throw new
|
|
3907
|
+
throw new GraphQLError6("No updates were provided!");
|
|
3554
3908
|
}
|
|
3555
3909
|
const entries = updates.map(({ where, set }) => {
|
|
3556
|
-
const input =
|
|
3910
|
+
const input = remapUpdateInput(set, table, tableName);
|
|
3557
3911
|
if (!Object.keys(input).length) {
|
|
3558
|
-
throw new
|
|
3912
|
+
throw new GraphQLError6("Unable to update with no values specified!");
|
|
3559
3913
|
}
|
|
3560
3914
|
return {
|
|
3561
3915
|
set: input,
|
|
@@ -3583,7 +3937,7 @@ var generateUpdateMany = (db, tableName, table, updateManyInput, fieldName, filt
|
|
|
3583
3937
|
var generateDelete = (db, tableName, table, filterArgs, fieldName, single, requireWhere, filterCtx, txCtx) => {
|
|
3584
3938
|
const queryArgs = {
|
|
3585
3939
|
where: {
|
|
3586
|
-
type: single || requireWhere ? new
|
|
3940
|
+
type: single || requireWhere ? new GraphQLNonNull5(filterArgs) : filterArgs
|
|
3587
3941
|
}
|
|
3588
3942
|
};
|
|
3589
3943
|
return {
|
|
@@ -3613,7 +3967,7 @@ var generateDelete = (db, tableName, table, filterArgs, fieldName, single, requi
|
|
|
3613
3967
|
};
|
|
3614
3968
|
var mysqlPrimaryKeyPropNames = (table) => getPrimaryKeyPropNamesFromConfig(table, getTableConfig);
|
|
3615
3969
|
var generateSchemaData = (db, schema, relations, options) => {
|
|
3616
|
-
const { relationsDepthLimit, prefixes, suffixes, typeNameMapper, shouldEagerLoad, features, complexity } = options;
|
|
3970
|
+
const { relationsDepthLimit, prefixes, suffixes, typeNameMapper, shouldEagerLoad, features, complexity, limits } = options;
|
|
3617
3971
|
const rawSchema = schema;
|
|
3618
3972
|
const schemaEntries = Object.entries(rawSchema);
|
|
3619
3973
|
const tableEntries = schemaEntries.filter(([_key, value]) => is4(value, MySqlTable));
|
|
@@ -3634,7 +3988,13 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3634
3988
|
attachTargetPrimaryKeys(namedRelations, tables, mysqlPrimaryKeyPropNames);
|
|
3635
3989
|
const eagerRelations = pruneNonEagerRelations(namedRelations, shouldEagerLoad);
|
|
3636
3990
|
const filterCtx = { tables, relationMap: namedRelations };
|
|
3637
|
-
const resolverFactory = createRelationResolverFactory(
|
|
3991
|
+
const resolverFactory = createRelationResolverFactory(
|
|
3992
|
+
db,
|
|
3993
|
+
tables,
|
|
3994
|
+
"nulls-smallest",
|
|
3995
|
+
filterCtx,
|
|
3996
|
+
limits
|
|
3997
|
+
);
|
|
3638
3998
|
const cacheCtx = {
|
|
3639
3999
|
genericFilterCache: /* @__PURE__ */ new Map(),
|
|
3640
4000
|
objectTypeCache: /* @__PURE__ */ new Map(),
|
|
@@ -3648,7 +4008,9 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3648
4008
|
listRelationFilterCache: /* @__PURE__ */ new Map(),
|
|
3649
4009
|
aggregateTypeCache: /* @__PURE__ */ new Map(),
|
|
3650
4010
|
complexity,
|
|
3651
|
-
|
|
4011
|
+
limits,
|
|
4012
|
+
docs: options.docs ?? {},
|
|
4013
|
+
features
|
|
3652
4014
|
};
|
|
3653
4015
|
const relationAggregateFactory = features.relationAggregates ? createRelationAggregateFactory(db, tables, cacheCtx, typeNameMapper, filterCtx) : void 0;
|
|
3654
4016
|
const queries = {};
|
|
@@ -3676,7 +4038,7 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3676
4038
|
name: "MutationReturn",
|
|
3677
4039
|
fields: {
|
|
3678
4040
|
isSuccess: {
|
|
3679
|
-
type: new
|
|
4041
|
+
type: new GraphQLNonNull5(GraphQLBoolean3)
|
|
3680
4042
|
}
|
|
3681
4043
|
}
|
|
3682
4044
|
});
|
|
@@ -3701,8 +4063,10 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3701
4063
|
updateFieldName,
|
|
3702
4064
|
updateManyFieldName,
|
|
3703
4065
|
updateSingleFieldName,
|
|
4066
|
+
updateCountFieldName,
|
|
3704
4067
|
deleteFieldName,
|
|
3705
|
-
deleteSingleFieldName
|
|
4068
|
+
deleteSingleFieldName,
|
|
4069
|
+
deleteCountFieldName
|
|
3706
4070
|
} = computeResolverFieldNames(tableName, typeNameMapper, prefixes, suffixes);
|
|
3707
4071
|
const selectArrGenerated = generateSelectArray(
|
|
3708
4072
|
db,
|
|
@@ -3715,7 +4079,8 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3715
4079
|
typeName,
|
|
3716
4080
|
typeNameMapper,
|
|
3717
4081
|
filterCtx,
|
|
3718
|
-
features.distinct
|
|
4082
|
+
features.distinct,
|
|
4083
|
+
limits
|
|
3719
4084
|
);
|
|
3720
4085
|
const selectSingleGenerated = generateSelectSingle(
|
|
3721
4086
|
db,
|
|
@@ -3727,7 +4092,8 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3727
4092
|
singleFieldName,
|
|
3728
4093
|
typeName,
|
|
3729
4094
|
typeNameMapper,
|
|
3730
|
-
filterCtx
|
|
4095
|
+
filterCtx,
|
|
4096
|
+
limits
|
|
3731
4097
|
);
|
|
3732
4098
|
const insertArrGenerated = features.insert ? generateInsertArray(
|
|
3733
4099
|
db,
|
|
@@ -3826,6 +4192,29 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3826
4192
|
filterCtx,
|
|
3827
4193
|
mutationTxCtx
|
|
3828
4194
|
) : void 0;
|
|
4195
|
+
const updateCountGenerated = features.update && features.countMutations ? generateWriteCount({
|
|
4196
|
+
db,
|
|
4197
|
+
tableName,
|
|
4198
|
+
table: schema[tableName],
|
|
4199
|
+
kind: "update",
|
|
4200
|
+
setArgs: updateInput,
|
|
4201
|
+
filterArgs: tableFilters,
|
|
4202
|
+
fieldName: updateCountFieldName,
|
|
4203
|
+
requireWhere: features.requireWhere,
|
|
4204
|
+
filterCtx,
|
|
4205
|
+
txCtx: mutationTxCtx
|
|
4206
|
+
}) : void 0;
|
|
4207
|
+
const deleteCountGenerated = features.delete && features.countMutations ? generateWriteCount({
|
|
4208
|
+
db,
|
|
4209
|
+
tableName,
|
|
4210
|
+
table: schema[tableName],
|
|
4211
|
+
kind: "delete",
|
|
4212
|
+
filterArgs: tableFilters,
|
|
4213
|
+
fieldName: deleteCountFieldName,
|
|
4214
|
+
requireWhere: features.requireWhere,
|
|
4215
|
+
filterCtx,
|
|
4216
|
+
txCtx: mutationTxCtx
|
|
4217
|
+
}) : void 0;
|
|
3829
4218
|
const aggregateType = features.aggregates ? generateAggregateTypes(schema[tableName], tableName, typeName, cacheCtx) : void 0;
|
|
3830
4219
|
const aggregateGenerated = features.aggregates ? generateAggregate(
|
|
3831
4220
|
db,
|
|
@@ -3854,7 +4243,7 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3854
4243
|
type: selectArrOutput,
|
|
3855
4244
|
args: selectArrGenerated.args,
|
|
3856
4245
|
resolve: selectArrGenerated.resolver,
|
|
3857
|
-
...complexity ? { extensions: { complexity: listFieldComplexity(complexity) } } : {}
|
|
4246
|
+
...complexity ? { extensions: { complexity: listFieldComplexity(complexity, limits?.(tableName)) } } : {}
|
|
3858
4247
|
};
|
|
3859
4248
|
queries[selectSingleGenerated.name] = {
|
|
3860
4249
|
type: selectSingleOutput,
|
|
@@ -3863,7 +4252,7 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3863
4252
|
};
|
|
3864
4253
|
if (aggregateGenerated && aggregateType) {
|
|
3865
4254
|
queries[aggregateGenerated.name] = {
|
|
3866
|
-
type: new
|
|
4255
|
+
type: new GraphQLNonNull5(aggregateType),
|
|
3867
4256
|
args: aggregateGenerated.args,
|
|
3868
4257
|
resolve: aggregateGenerated.resolver,
|
|
3869
4258
|
...complexity ? { extensions: { complexity: aggregateFieldComplexity(complexity) } } : {}
|
|
@@ -3871,7 +4260,7 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3871
4260
|
}
|
|
3872
4261
|
if (groupByGenerated && groupByType) {
|
|
3873
4262
|
queries[groupByGenerated.name] = {
|
|
3874
|
-
type: new
|
|
4263
|
+
type: new GraphQLNonNull5(new GraphQLList5(new GraphQLNonNull5(groupByType))),
|
|
3875
4264
|
args: groupByGenerated.args,
|
|
3876
4265
|
resolve: groupByGenerated.resolver,
|
|
3877
4266
|
...complexity ? { extensions: { complexity: aggregateFieldComplexity(complexity) } } : {}
|
|
@@ -3896,6 +4285,22 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3896
4285
|
};
|
|
3897
4286
|
}
|
|
3898
4287
|
}
|
|
4288
|
+
if (updateCountGenerated) {
|
|
4289
|
+
mutations[updateCountGenerated.name] = {
|
|
4290
|
+
type: new GraphQLNonNull5(GraphQLInt5),
|
|
4291
|
+
args: updateCountGenerated.args,
|
|
4292
|
+
resolve: updateCountGenerated.resolver,
|
|
4293
|
+
description: "How many rows the update touched. The rows themselves are not read back, which is the point of this mutation."
|
|
4294
|
+
};
|
|
4295
|
+
}
|
|
4296
|
+
if (deleteCountGenerated) {
|
|
4297
|
+
mutations[deleteCountGenerated.name] = {
|
|
4298
|
+
type: new GraphQLNonNull5(GraphQLInt5),
|
|
4299
|
+
args: deleteCountGenerated.args,
|
|
4300
|
+
resolve: deleteCountGenerated.resolver,
|
|
4301
|
+
description: "How many rows the delete removed. The rows themselves are not read back, which is the point of this mutation."
|
|
4302
|
+
};
|
|
4303
|
+
}
|
|
3899
4304
|
const activeInputs = [
|
|
3900
4305
|
// The insert input types the upsert mutations too, so either feature keeps it.
|
|
3901
4306
|
...features.insert || onConflictInput ? [insertInput] : [],
|
|
@@ -3940,23 +4345,24 @@ var generateSchemaData = (db, schema, relations, options) => {
|
|
|
3940
4345
|
};
|
|
3941
4346
|
|
|
3942
4347
|
// src/util/builders/pg.ts
|
|
3943
|
-
import { and as and4, getColumns as
|
|
4348
|
+
import { and as and4, getColumns as getColumns5, is as is6, One as One5 } from "drizzle-orm";
|
|
3944
4349
|
import { getTableConfig as getTableConfig2, PgTable } from "drizzle-orm/pg-core";
|
|
3945
4350
|
import {
|
|
3946
|
-
GraphQLError as
|
|
3947
|
-
|
|
3948
|
-
|
|
4351
|
+
GraphQLError as GraphQLError8,
|
|
4352
|
+
GraphQLInt as GraphQLInt6,
|
|
4353
|
+
GraphQLList as GraphQLList7,
|
|
4354
|
+
GraphQLNonNull as GraphQLNonNull7
|
|
3949
4355
|
} from "graphql";
|
|
3950
4356
|
import { parseResolveInfo as parseResolveInfo3 } from "graphql-parse-resolve-info";
|
|
3951
4357
|
|
|
3952
4358
|
// src/util/builders/nested-writes.ts
|
|
3953
|
-
import { and as and3, eq as eq3, getColumns as
|
|
4359
|
+
import { and as and3, eq as eq3, getColumns as getColumns4, is as is5, One as One4 } from "drizzle-orm";
|
|
3954
4360
|
import {
|
|
3955
4361
|
GraphQLBoolean as GraphQLBoolean4,
|
|
3956
|
-
GraphQLError as
|
|
3957
|
-
GraphQLInputObjectType as
|
|
3958
|
-
GraphQLList as
|
|
3959
|
-
GraphQLNonNull as
|
|
4362
|
+
GraphQLError as GraphQLError7,
|
|
4363
|
+
GraphQLInputObjectType as GraphQLInputObjectType5,
|
|
4364
|
+
GraphQLList as GraphQLList6,
|
|
4365
|
+
GraphQLNonNull as GraphQLNonNull6
|
|
3960
4366
|
} from "graphql";
|
|
3961
4367
|
var isOptionalOnInsert = (column) => !column.notNull || !!column.hasDefault || !!column.defaultFn;
|
|
3962
4368
|
var buildNestedWritePlans = (tables, relationMap, resolveUniqueSets, resolvePrimaryKeys, extractJoinColumns) => {
|
|
@@ -4001,7 +4407,7 @@ var buildNestedWritePlans = (tables, relationMap, resolveUniqueSets, resolvePrim
|
|
|
4001
4407
|
continue;
|
|
4002
4408
|
}
|
|
4003
4409
|
const { localColPropName, foreignCol, foreignColPropName } = joinColumns;
|
|
4004
|
-
const localCol =
|
|
4410
|
+
const localCol = getColumns4(table)[localColPropName];
|
|
4005
4411
|
if (!localCol) {
|
|
4006
4412
|
continue;
|
|
4007
4413
|
}
|
|
@@ -4057,12 +4463,12 @@ var createNestedWriteTypes = (params) => {
|
|
|
4057
4463
|
}
|
|
4058
4464
|
const omitted = plan.fkSide === "child" ? plan.foreignColPropName : void 0;
|
|
4059
4465
|
const fields = Object.fromEntries(
|
|
4060
|
-
Object.entries(
|
|
4466
|
+
Object.entries(getColumns4(plan.targetTable)).filter(([columnName]) => columnName !== omitted).map(([columnName, column]) => [
|
|
4061
4467
|
columnName,
|
|
4062
4468
|
drizzleColumnToGraphQLType(column, columnName, plan.targetTableName, false, true, true)
|
|
4063
4469
|
])
|
|
4064
4470
|
);
|
|
4065
|
-
const type = new
|
|
4471
|
+
const type = new GraphQLInputObjectType5({
|
|
4066
4472
|
name: `${capitalize(insertPrefix)}${typeName}${capitalize(plan.relationName)}Input`,
|
|
4067
4473
|
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.`,
|
|
4068
4474
|
fields
|
|
@@ -4071,7 +4477,7 @@ var createNestedWriteTypes = (params) => {
|
|
|
4071
4477
|
return type;
|
|
4072
4478
|
};
|
|
4073
4479
|
const targetFilters = (plan) => cacheCtx.filterTypeCache.get(plan.targetTable);
|
|
4074
|
-
const listOf = (type) => new
|
|
4480
|
+
const listOf = (type) => new GraphQLList6(new GraphQLNonNull6(type));
|
|
4075
4481
|
const wrapperType = (tableName, typeName, plan, forUpdate) => {
|
|
4076
4482
|
const key = `${tableName}.${plan.relationName}.${forUpdate ? "update" : "create"}`;
|
|
4077
4483
|
const cached = wrapperCache.get(key);
|
|
@@ -4115,7 +4521,7 @@ var createNestedWriteTypes = (params) => {
|
|
|
4115
4521
|
}
|
|
4116
4522
|
}
|
|
4117
4523
|
}
|
|
4118
|
-
const type = new
|
|
4524
|
+
const type = new GraphQLInputObjectType5({
|
|
4119
4525
|
name: `${typeName}${capitalize(plan.relationName)}Nested${forUpdate ? "Update" : "Create"}Input`,
|
|
4120
4526
|
description: `Writes through ${typeName}.${plan.relationName}`,
|
|
4121
4527
|
fields
|
|
@@ -4165,7 +4571,7 @@ var createNestedWriteRuntime = (params) => {
|
|
|
4165
4571
|
relationFilterCtx(filterCtx, plan.targetTableName)
|
|
4166
4572
|
);
|
|
4167
4573
|
if (!condition) {
|
|
4168
|
-
throw new
|
|
4574
|
+
throw new GraphQLError7(
|
|
4169
4575
|
`Drizzle-GraphQL Error: '${operation}' on '${plan.relationName}' needs a filter that selects rows \u2014 it was given one that matches everything.`
|
|
4170
4576
|
);
|
|
4171
4577
|
}
|
|
@@ -4174,7 +4580,7 @@ var createNestedWriteRuntime = (params) => {
|
|
|
4174
4580
|
const assertSingleOperation = (plan, op) => {
|
|
4175
4581
|
const supplied = ["create", "connect", "disconnect"].filter((key) => op[key] !== void 0 && op[key] !== null);
|
|
4176
4582
|
if (supplied.length > 1) {
|
|
4177
|
-
throw new
|
|
4583
|
+
throw new GraphQLError7(
|
|
4178
4584
|
`Drizzle-GraphQL Error: '${plan.relationName}' takes one of ${supplied.join(", ")} at a time \u2014 it holds a single row.`
|
|
4179
4585
|
);
|
|
4180
4586
|
}
|
|
@@ -4204,7 +4610,7 @@ var createNestedWriteRuntime = (params) => {
|
|
|
4204
4610
|
if (!tablePlans) {
|
|
4205
4611
|
return columns;
|
|
4206
4612
|
}
|
|
4207
|
-
const allColumns =
|
|
4613
|
+
const allColumns = getColumns4(table);
|
|
4208
4614
|
for (const relationName of Object.keys(ops)) {
|
|
4209
4615
|
const plan = tablePlans[relationName];
|
|
4210
4616
|
if (plan?.fkSide === "child" && !(plan.localColPropName in columns) && allColumns[plan.localColPropName]) {
|
|
@@ -4230,7 +4636,7 @@ var createNestedWriteRuntime = (params) => {
|
|
|
4230
4636
|
const inserted = await executor.insert(plan.targetTable).values(values).returning();
|
|
4231
4637
|
const created = inserted[0];
|
|
4232
4638
|
if (!created) {
|
|
4233
|
-
throw new
|
|
4639
|
+
throw new GraphQLError7(
|
|
4234
4640
|
`Drizzle-GraphQL Error: 'create' on '${relationName}' inserted no row, so there is nothing to attach.`
|
|
4235
4641
|
);
|
|
4236
4642
|
}
|
|
@@ -4238,7 +4644,7 @@ var createNestedWriteRuntime = (params) => {
|
|
|
4238
4644
|
} else if (op["connect"] !== void 0) {
|
|
4239
4645
|
const rows = await executor.select().from(plan.targetTable).where(conditionOf(plan, op["connect"], "connect"));
|
|
4240
4646
|
if (rows.length !== 1) {
|
|
4241
|
-
throw new
|
|
4647
|
+
throw new GraphQLError7(
|
|
4242
4648
|
`Drizzle-GraphQL Error: 'connect' on '${relationName}' matched ${rows.length} rows \u2014 it attaches a single row, so its filter must match exactly one.`
|
|
4243
4649
|
);
|
|
4244
4650
|
}
|
|
@@ -4265,7 +4671,7 @@ var createNestedWriteRuntime = (params) => {
|
|
|
4265
4671
|
for (const parentRow of parentRows) {
|
|
4266
4672
|
const key = parentRow?.[plan.localColPropName];
|
|
4267
4673
|
if (key === void 0 || key === null) {
|
|
4268
|
-
throw new
|
|
4674
|
+
throw new GraphQLError7(
|
|
4269
4675
|
`Drizzle-GraphQL Error: cannot write through '${relationName}': the ${tableName} row has no '${plan.localColPropName}' value to attach to.`
|
|
4270
4676
|
);
|
|
4271
4677
|
}
|
|
@@ -4333,9 +4739,10 @@ var updateWithNestedOps = async (params) => {
|
|
|
4333
4739
|
};
|
|
4334
4740
|
|
|
4335
4741
|
// src/util/builders/pg.ts
|
|
4336
|
-
var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, distinctEnabled = true) => {
|
|
4742
|
+
var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, distinctEnabled = true, limits) => {
|
|
4337
4743
|
const queryBase = db.query[tableName];
|
|
4338
4744
|
const table = tables[tableName];
|
|
4745
|
+
const limitPolicy = limits?.(tableName);
|
|
4339
4746
|
const pkNames = pgPrimaryKeyPropNames(table);
|
|
4340
4747
|
const queryArgs = selectArrayArgs(
|
|
4341
4748
|
orderArgs,
|
|
@@ -4348,6 +4755,7 @@ var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
4348
4755
|
try {
|
|
4349
4756
|
const parsedInfo = parseResolveInfo3(info, { deep: true });
|
|
4350
4757
|
const { executor, queryBase: requestQueryBase } = resolveQueryExecutor(db, context, tableName, queryBase);
|
|
4758
|
+
const limit = applyLimitPolicy(args.limit, limitPolicy, fieldName);
|
|
4351
4759
|
if (requestQueryBase) {
|
|
4352
4760
|
return await runRelationalSelect({
|
|
4353
4761
|
queryBase: requestQueryBase,
|
|
@@ -4359,15 +4767,17 @@ var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
4359
4767
|
typeNameMapper,
|
|
4360
4768
|
parsedInfo,
|
|
4361
4769
|
...args,
|
|
4770
|
+
limit,
|
|
4362
4771
|
single: false,
|
|
4363
4772
|
filterCtx,
|
|
4773
|
+
limits,
|
|
4364
4774
|
pkNames,
|
|
4365
4775
|
db: executor,
|
|
4366
4776
|
// PostgreSQL sorts NULLs as the largest values (last in ASC).
|
|
4367
4777
|
nullOrdering: "nulls-largest"
|
|
4368
4778
|
});
|
|
4369
4779
|
}
|
|
4370
|
-
const { offset,
|
|
4780
|
+
const { offset, orderBy, where, distinct, after } = args;
|
|
4371
4781
|
const selectedColumnsSql = extractSelectedColumnsFromTreeSQLFormat(
|
|
4372
4782
|
parsedInfo.fieldsByTypeName[typeName],
|
|
4373
4783
|
table,
|
|
@@ -4377,24 +4787,24 @@ var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
4377
4787
|
let cursorEntries;
|
|
4378
4788
|
if (after != null || cursorSelected) {
|
|
4379
4789
|
if (after != null && distinct?.length) {
|
|
4380
|
-
throw new
|
|
4790
|
+
throw new GraphQLError8("'after' cannot be combined with 'distinct'.");
|
|
4381
4791
|
}
|
|
4382
4792
|
if (orderByHasRelationEntry(orderBy)) {
|
|
4383
4793
|
if (after != null) {
|
|
4384
|
-
throw new
|
|
4794
|
+
throw new GraphQLError8(
|
|
4385
4795
|
"'after' cannot be combined with an orderBy that orders through a relation \u2014 a related row's value cannot be encoded into a cursor."
|
|
4386
4796
|
);
|
|
4387
4797
|
}
|
|
4388
4798
|
} else if (!pkNames.length) {
|
|
4389
4799
|
if (after != null) {
|
|
4390
|
-
throw new
|
|
4800
|
+
throw new GraphQLError8(
|
|
4391
4801
|
`Table ${tableName} has no primary key, so cursor pagination cannot be used on it.`
|
|
4392
4802
|
);
|
|
4393
4803
|
}
|
|
4394
4804
|
} else {
|
|
4395
4805
|
cursorEntries = cursorOrderingEntries(orderBy, pkNames);
|
|
4396
4806
|
if (cursorSelected) {
|
|
4397
|
-
const allColumns =
|
|
4807
|
+
const allColumns = getColumns5(table);
|
|
4398
4808
|
for (const [column] of cursorEntries) {
|
|
4399
4809
|
selectedColumnsSql[column] ??= allColumns[column];
|
|
4400
4810
|
}
|
|
@@ -4457,7 +4867,7 @@ var generateSelectArray2 = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
4457
4867
|
args: queryArgs
|
|
4458
4868
|
};
|
|
4459
4869
|
};
|
|
4460
|
-
var generateSelectSingle2 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx) => {
|
|
4870
|
+
var generateSelectSingle2 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, limits) => {
|
|
4461
4871
|
const queryBase = db.query[tableName];
|
|
4462
4872
|
const queryArgs = selectSingleArgs(orderArgs, filterArgs);
|
|
4463
4873
|
const table = tables[tableName];
|
|
@@ -4481,6 +4891,7 @@ var generateSelectSingle2 = (db, tableName, tables, relationMap, orderArgs, filt
|
|
|
4481
4891
|
...args,
|
|
4482
4892
|
single: true,
|
|
4483
4893
|
filterCtx,
|
|
4894
|
+
limits,
|
|
4484
4895
|
pkNames,
|
|
4485
4896
|
db: executor
|
|
4486
4897
|
});
|
|
@@ -4514,10 +4925,10 @@ var generateSelectSingle2 = (db, tableName, tables, relationMap, orderArgs, filt
|
|
|
4514
4925
|
};
|
|
4515
4926
|
};
|
|
4516
4927
|
var pgPrimaryKeyPropNames = (table) => getPrimaryKeyPropNamesFromConfig(table, getTableConfig2);
|
|
4517
|
-
var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested) => {
|
|
4928
|
+
var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested, limits) => {
|
|
4518
4929
|
const queryArgs = {
|
|
4519
4930
|
values: {
|
|
4520
|
-
type: new
|
|
4931
|
+
type: new GraphQLNonNull7(new GraphQLList7(new GraphQLNonNull7(baseType)))
|
|
4521
4932
|
}
|
|
4522
4933
|
};
|
|
4523
4934
|
const pkNames = pgPrimaryKeyPropNames(table);
|
|
@@ -4527,7 +4938,7 @@ var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
4527
4938
|
try {
|
|
4528
4939
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4529
4940
|
if (!args.values.length) {
|
|
4530
|
-
throw new
|
|
4941
|
+
throw new GraphQLError8("No values were provided!");
|
|
4531
4942
|
}
|
|
4532
4943
|
const entries = nested?.enabled(tableName) ? args.values.map((values) => nested.split(tableName, values)) : void 0;
|
|
4533
4944
|
const nestedEntries = entries?.some((entry) => nested.hasOps(entry.ops)) ? entries : void 0;
|
|
@@ -4543,7 +4954,8 @@ var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
4543
4954
|
typeNameMapper,
|
|
4544
4955
|
table,
|
|
4545
4956
|
pkNames,
|
|
4546
|
-
parsedInfo
|
|
4957
|
+
parsedInfo,
|
|
4958
|
+
limits
|
|
4547
4959
|
});
|
|
4548
4960
|
const returning = nestedEntries ? nested.withJoinColumns(tableName, mergedOps(nestedEntries), { ...columns }, table) : columns;
|
|
4549
4961
|
const runInsert = async (target, values) => {
|
|
@@ -4571,10 +4983,10 @@ var generateInsertArray2 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
4571
4983
|
args: queryArgs
|
|
4572
4984
|
};
|
|
4573
4985
|
};
|
|
4574
|
-
var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested) => {
|
|
4986
|
+
var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested, limits) => {
|
|
4575
4987
|
const queryArgs = {
|
|
4576
4988
|
values: {
|
|
4577
|
-
type: new
|
|
4989
|
+
type: new GraphQLNonNull7(baseType)
|
|
4578
4990
|
}
|
|
4579
4991
|
};
|
|
4580
4992
|
const pkNames = pgPrimaryKeyPropNames(table);
|
|
@@ -4597,7 +5009,8 @@ var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType
|
|
|
4597
5009
|
typeNameMapper,
|
|
4598
5010
|
table,
|
|
4599
5011
|
pkNames,
|
|
4600
|
-
parsedInfo
|
|
5012
|
+
parsedInfo,
|
|
5013
|
+
limits
|
|
4601
5014
|
});
|
|
4602
5015
|
const returning = nestedEntry ? nested.withJoinColumns(tableName, nestedEntry.ops, { ...columns }, table) : columns;
|
|
4603
5016
|
const runInsert = async (target, values) => {
|
|
@@ -4616,6 +5029,9 @@ var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType
|
|
|
4616
5029
|
write: runInsert
|
|
4617
5030
|
}) : await runInsert(executor, input);
|
|
4618
5031
|
if (!result[0]) {
|
|
5032
|
+
if (!conflictDoNothing) {
|
|
5033
|
+
throw new GraphQLError8(`${fieldName}: the insert returned no row.`);
|
|
5034
|
+
}
|
|
4619
5035
|
return void 0;
|
|
4620
5036
|
}
|
|
4621
5037
|
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
@@ -4628,10 +5044,10 @@ var generateInsertSingle2 = (db, tableName, table, tables, relationMap, baseType
|
|
|
4628
5044
|
args: queryArgs
|
|
4629
5045
|
};
|
|
4630
5046
|
};
|
|
4631
|
-
var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx, txCtx, nested) => {
|
|
5047
|
+
var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx, txCtx, nested, limits) => {
|
|
4632
5048
|
const queryArgs = {
|
|
4633
5049
|
values: {
|
|
4634
|
-
type: single ? new
|
|
5050
|
+
type: single ? new GraphQLNonNull7(baseType) : new GraphQLNonNull7(new GraphQLList7(new GraphQLNonNull7(baseType)))
|
|
4635
5051
|
},
|
|
4636
5052
|
onConflict: {
|
|
4637
5053
|
type: onConflictType,
|
|
@@ -4646,7 +5062,7 @@ var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
4646
5062
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4647
5063
|
const supplied = single ? [args.values] : args.values;
|
|
4648
5064
|
if (!supplied.length) {
|
|
4649
|
-
throw new
|
|
5065
|
+
throw new GraphQLError8("No values were provided!");
|
|
4650
5066
|
}
|
|
4651
5067
|
const entries = nested?.enabled(tableName) ? supplied.map((values) => nested.split(tableName, values)) : void 0;
|
|
4652
5068
|
const nestedEntries = entries?.some((entry) => nested.hasOps(entry.ops)) ? entries : void 0;
|
|
@@ -4660,7 +5076,8 @@ var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
4660
5076
|
typeNameMapper,
|
|
4661
5077
|
table,
|
|
4662
5078
|
pkNames,
|
|
4663
|
-
parsedInfo
|
|
5079
|
+
parsedInfo,
|
|
5080
|
+
limits
|
|
4664
5081
|
});
|
|
4665
5082
|
const returning = nestedEntries ? nested.withJoinColumns(tableName, mergedOps(nestedEntries), { ...columns }, table) : columns;
|
|
4666
5083
|
const runUpsert = async (target, values) => {
|
|
@@ -4699,13 +5116,13 @@ var generateUpsert2 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
4699
5116
|
args: queryArgs
|
|
4700
5117
|
};
|
|
4701
5118
|
};
|
|
4702
|
-
var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx, txCtx, nested) => {
|
|
5119
|
+
var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx, txCtx, nested, limits) => {
|
|
4703
5120
|
const queryArgs = {
|
|
4704
5121
|
set: {
|
|
4705
|
-
type: new
|
|
5122
|
+
type: new GraphQLNonNull7(setArgs)
|
|
4706
5123
|
},
|
|
4707
5124
|
where: {
|
|
4708
|
-
type: single || requireWhere ? new
|
|
5125
|
+
type: single || requireWhere ? new GraphQLNonNull7(filterArgs) : filterArgs
|
|
4709
5126
|
}
|
|
4710
5127
|
};
|
|
4711
5128
|
const pkNames = pgPrimaryKeyPropNames(table);
|
|
@@ -4726,13 +5143,14 @@ var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
4726
5143
|
typeNameMapper,
|
|
4727
5144
|
table,
|
|
4728
5145
|
pkNames,
|
|
4729
|
-
parsedInfo
|
|
5146
|
+
parsedInfo,
|
|
5147
|
+
limits
|
|
4730
5148
|
});
|
|
4731
5149
|
const entry = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
|
|
4732
5150
|
const nestedOps = entry && nested.hasOps(entry.ops) ? entry.ops : void 0;
|
|
4733
|
-
const input =
|
|
5151
|
+
const input = remapUpdateInput(entry ? entry.columns : set, table, tableName);
|
|
4734
5152
|
if (!Object.keys(input).length && !nestedOps) {
|
|
4735
|
-
throw new
|
|
5153
|
+
throw new GraphQLError8("Unable to update with no values specified!");
|
|
4736
5154
|
}
|
|
4737
5155
|
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
4738
5156
|
const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
@@ -4758,7 +5176,7 @@ var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
4758
5176
|
write: runUpdate
|
|
4759
5177
|
}) : await runUpdate(executor, input);
|
|
4760
5178
|
if (single && result.length > 1) {
|
|
4761
|
-
throw new
|
|
5179
|
+
throw new GraphQLError8(`${fieldName}: 'where' matched more than one row!`);
|
|
4762
5180
|
}
|
|
4763
5181
|
if (single && !result[0]) {
|
|
4764
5182
|
return void 0;
|
|
@@ -4773,10 +5191,10 @@ var generateUpdate2 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
4773
5191
|
args: queryArgs
|
|
4774
5192
|
};
|
|
4775
5193
|
};
|
|
4776
|
-
var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx, txCtx, nested) => {
|
|
5194
|
+
var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx, txCtx, nested, limits) => {
|
|
4777
5195
|
const queryArgs = {
|
|
4778
5196
|
updates: {
|
|
4779
|
-
type: new
|
|
5197
|
+
type: new GraphQLNonNull7(new GraphQLList7(new GraphQLNonNull7(updateManyInput)))
|
|
4780
5198
|
}
|
|
4781
5199
|
};
|
|
4782
5200
|
const pkNames = pgPrimaryKeyPropNames(table);
|
|
@@ -4787,7 +5205,7 @@ var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
4787
5205
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
4788
5206
|
const { updates } = args;
|
|
4789
5207
|
if (!updates.length) {
|
|
4790
|
-
throw new
|
|
5208
|
+
throw new GraphQLError8("No updates were provided!");
|
|
4791
5209
|
}
|
|
4792
5210
|
const parsedInfo = parseResolveInfo3(info, {
|
|
4793
5211
|
deep: true
|
|
@@ -4800,14 +5218,15 @@ var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
4800
5218
|
typeNameMapper,
|
|
4801
5219
|
table,
|
|
4802
5220
|
pkNames,
|
|
4803
|
-
parsedInfo
|
|
5221
|
+
parsedInfo,
|
|
5222
|
+
limits
|
|
4804
5223
|
});
|
|
4805
5224
|
const entries = updates.map(({ where, set }) => {
|
|
4806
5225
|
const split = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
|
|
4807
5226
|
const ops = split && nested.hasOps(split.ops) ? split.ops : void 0;
|
|
4808
|
-
const input =
|
|
5227
|
+
const input = remapUpdateInput(split ? split.columns : set, table, tableName);
|
|
4809
5228
|
if (!Object.keys(input).length && !ops) {
|
|
4810
|
-
throw new
|
|
5229
|
+
throw new GraphQLError8("Unable to update with no values specified!");
|
|
4811
5230
|
}
|
|
4812
5231
|
return {
|
|
4813
5232
|
set: input,
|
|
@@ -4866,7 +5285,7 @@ var generateUpdateMany2 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
4866
5285
|
var generateDelete2 = (db, tableName, table, filterArgs, fieldName, typeName, single, requireWhere, filterCtx, selectionCtx, txCtx) => {
|
|
4867
5286
|
const queryArgs = {
|
|
4868
5287
|
where: {
|
|
4869
|
-
type: single || requireWhere ? new
|
|
5288
|
+
type: single || requireWhere ? new GraphQLNonNull7(filterArgs) : filterArgs
|
|
4870
5289
|
}
|
|
4871
5290
|
};
|
|
4872
5291
|
return {
|
|
@@ -4895,7 +5314,7 @@ var generateDelete2 = (db, tableName, table, filterArgs, fieldName, typeName, si
|
|
|
4895
5314
|
query = query.returning(columns);
|
|
4896
5315
|
const result = await query;
|
|
4897
5316
|
if (single && result.length > 1) {
|
|
4898
|
-
throw new
|
|
5317
|
+
throw new GraphQLError8(`${fieldName}: 'where' matched more than one row!`);
|
|
4899
5318
|
}
|
|
4900
5319
|
if (single) {
|
|
4901
5320
|
return result[0] ? remapToGraphQLSingleOutput(result[0], tableName, table) : void 0;
|
|
@@ -4918,7 +5337,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4918
5337
|
typeNameMapper,
|
|
4919
5338
|
shouldEagerLoad,
|
|
4920
5339
|
features,
|
|
4921
|
-
complexity
|
|
5340
|
+
complexity,
|
|
5341
|
+
limits
|
|
4922
5342
|
} = options;
|
|
4923
5343
|
const schemaEntries = Object.entries(schema);
|
|
4924
5344
|
const tableEntries = schemaEntries.filter(([_key, value]) => is6(value, PgTable));
|
|
@@ -4934,7 +5354,13 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4934
5354
|
attachTargetPrimaryKeys(namedRelations, tables, pgPrimaryKeyPropNames);
|
|
4935
5355
|
const eagerRelations = pruneNonEagerRelations(namedRelations, shouldEagerLoad);
|
|
4936
5356
|
const filterCtx = { tables, relationMap: namedRelations };
|
|
4937
|
-
const resolverFactory = createRelationResolverFactory(
|
|
5357
|
+
const resolverFactory = createRelationResolverFactory(
|
|
5358
|
+
db,
|
|
5359
|
+
tables,
|
|
5360
|
+
"nulls-largest",
|
|
5361
|
+
filterCtx,
|
|
5362
|
+
limits
|
|
5363
|
+
);
|
|
4938
5364
|
const cacheCtx = {
|
|
4939
5365
|
genericFilterCache: /* @__PURE__ */ new Map(),
|
|
4940
5366
|
objectTypeCache: /* @__PURE__ */ new Map(),
|
|
@@ -4948,7 +5374,9 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
4948
5374
|
listRelationFilterCache: /* @__PURE__ */ new Map(),
|
|
4949
5375
|
aggregateTypeCache: /* @__PURE__ */ new Map(),
|
|
4950
5376
|
complexity,
|
|
4951
|
-
|
|
5377
|
+
limits,
|
|
5378
|
+
docs: options.docs ?? {},
|
|
5379
|
+
features
|
|
4952
5380
|
};
|
|
4953
5381
|
const nestedPlans = features.nestedWrites ? buildNestedWritePlans(
|
|
4954
5382
|
tables,
|
|
@@ -5000,8 +5428,10 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5000
5428
|
updateFieldName,
|
|
5001
5429
|
updateManyFieldName,
|
|
5002
5430
|
updateSingleFieldName,
|
|
5431
|
+
updateCountFieldName,
|
|
5003
5432
|
deleteFieldName,
|
|
5004
|
-
deleteSingleFieldName
|
|
5433
|
+
deleteSingleFieldName,
|
|
5434
|
+
deleteCountFieldName
|
|
5005
5435
|
} = computeResolverFieldNames(tableName, typeNameMapper, prefixes, suffixes);
|
|
5006
5436
|
const selectArrGenerated = generateSelectArray2(
|
|
5007
5437
|
db,
|
|
@@ -5014,7 +5444,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5014
5444
|
typeName,
|
|
5015
5445
|
typeNameMapper,
|
|
5016
5446
|
filterCtx,
|
|
5017
|
-
features.distinct
|
|
5447
|
+
features.distinct,
|
|
5448
|
+
limits
|
|
5018
5449
|
);
|
|
5019
5450
|
const selectSingleGenerated = generateSelectSingle2(
|
|
5020
5451
|
db,
|
|
@@ -5026,7 +5457,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5026
5457
|
singleFieldName,
|
|
5027
5458
|
typeName,
|
|
5028
5459
|
typeNameMapper,
|
|
5029
|
-
filterCtx
|
|
5460
|
+
filterCtx,
|
|
5461
|
+
limits
|
|
5030
5462
|
);
|
|
5031
5463
|
const insertArrGenerated = features.insert ? generateInsertArray2(
|
|
5032
5464
|
db,
|
|
@@ -5040,7 +5472,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5040
5472
|
typeNameMapper,
|
|
5041
5473
|
conflictDoNothing,
|
|
5042
5474
|
mutationTxCtx,
|
|
5043
|
-
nestedRuntime
|
|
5475
|
+
nestedRuntime,
|
|
5476
|
+
limits
|
|
5044
5477
|
) : void 0;
|
|
5045
5478
|
const insertSingleGenerated = features.insert ? generateInsertSingle2(
|
|
5046
5479
|
db,
|
|
@@ -5054,7 +5487,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5054
5487
|
typeNameMapper,
|
|
5055
5488
|
conflictDoNothing,
|
|
5056
5489
|
mutationTxCtx,
|
|
5057
|
-
nestedRuntime
|
|
5490
|
+
nestedRuntime,
|
|
5491
|
+
limits
|
|
5058
5492
|
) : void 0;
|
|
5059
5493
|
const uniqueSets = features.upsert ? getUniqueColumnSets(schema[tableName], getTableConfig2) : [];
|
|
5060
5494
|
const onConflictInput = features.upsert ? generateOnConflictInput({
|
|
@@ -5079,7 +5513,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5079
5513
|
typeNameMapper,
|
|
5080
5514
|
filterCtx,
|
|
5081
5515
|
mutationTxCtx,
|
|
5082
|
-
nestedRuntime
|
|
5516
|
+
nestedRuntime,
|
|
5517
|
+
limits
|
|
5083
5518
|
) : void 0;
|
|
5084
5519
|
const upsertSingleGenerated = onConflictInput ? generateUpsert2(
|
|
5085
5520
|
db,
|
|
@@ -5096,7 +5531,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5096
5531
|
typeNameMapper,
|
|
5097
5532
|
filterCtx,
|
|
5098
5533
|
mutationTxCtx,
|
|
5099
|
-
nestedRuntime
|
|
5534
|
+
nestedRuntime,
|
|
5535
|
+
limits
|
|
5100
5536
|
) : void 0;
|
|
5101
5537
|
const updateGenerated = features.update ? generateUpdate2(
|
|
5102
5538
|
db,
|
|
@@ -5113,7 +5549,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5113
5549
|
typeNameMapper,
|
|
5114
5550
|
filterCtx,
|
|
5115
5551
|
mutationTxCtx,
|
|
5116
|
-
nestedRuntime
|
|
5552
|
+
nestedRuntime,
|
|
5553
|
+
limits
|
|
5117
5554
|
) : void 0;
|
|
5118
5555
|
const updateSingleGenerated = features.update ? generateUpdate2(
|
|
5119
5556
|
db,
|
|
@@ -5130,7 +5567,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5130
5567
|
typeNameMapper,
|
|
5131
5568
|
filterCtx,
|
|
5132
5569
|
mutationTxCtx,
|
|
5133
|
-
nestedRuntime
|
|
5570
|
+
nestedRuntime,
|
|
5571
|
+
limits
|
|
5134
5572
|
) : void 0;
|
|
5135
5573
|
const updateManyInput = features.update && features.updateMany ? generateUpdateManyInput({ typeName, updatePrefix: prefixes.update, updateInput, tableFilters }) : void 0;
|
|
5136
5574
|
const updateManyGenerated = updateManyInput ? generateUpdateMany2(
|
|
@@ -5145,7 +5583,8 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5145
5583
|
typeNameMapper,
|
|
5146
5584
|
filterCtx,
|
|
5147
5585
|
mutationTxCtx,
|
|
5148
|
-
nestedRuntime
|
|
5586
|
+
nestedRuntime,
|
|
5587
|
+
limits
|
|
5149
5588
|
) : void 0;
|
|
5150
5589
|
const deleteGenerated = features.delete ? generateDelete2(
|
|
5151
5590
|
db,
|
|
@@ -5173,6 +5612,30 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5173
5612
|
{ tableName, relationMap: namedRelations, tables },
|
|
5174
5613
|
mutationTxCtx
|
|
5175
5614
|
) : void 0;
|
|
5615
|
+
const updateCountGenerated = features.update && features.countMutations ? generateWriteCount({
|
|
5616
|
+
db,
|
|
5617
|
+
tableName,
|
|
5618
|
+
table: schema[tableName],
|
|
5619
|
+
kind: "update",
|
|
5620
|
+
setArgs: updateInput,
|
|
5621
|
+
filterArgs: tableFilters,
|
|
5622
|
+
fieldName: updateCountFieldName,
|
|
5623
|
+
requireWhere: features.requireWhere,
|
|
5624
|
+
filterCtx,
|
|
5625
|
+
txCtx: mutationTxCtx,
|
|
5626
|
+
nested: nestedRuntime
|
|
5627
|
+
}) : void 0;
|
|
5628
|
+
const deleteCountGenerated = features.delete && features.countMutations ? generateWriteCount({
|
|
5629
|
+
db,
|
|
5630
|
+
tableName,
|
|
5631
|
+
table: schema[tableName],
|
|
5632
|
+
kind: "delete",
|
|
5633
|
+
filterArgs: tableFilters,
|
|
5634
|
+
fieldName: deleteCountFieldName,
|
|
5635
|
+
requireWhere: features.requireWhere,
|
|
5636
|
+
filterCtx,
|
|
5637
|
+
txCtx: mutationTxCtx
|
|
5638
|
+
}) : void 0;
|
|
5176
5639
|
const aggregateType = features.aggregates ? generateAggregateTypes(schema[tableName], tableName, typeName, cacheCtx) : void 0;
|
|
5177
5640
|
const aggregateGenerated = features.aggregates ? generateAggregate(
|
|
5178
5641
|
db,
|
|
@@ -5201,7 +5664,7 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5201
5664
|
type: selectArrOutput,
|
|
5202
5665
|
args: selectArrGenerated.args,
|
|
5203
5666
|
resolve: selectArrGenerated.resolver,
|
|
5204
|
-
...complexity ? { extensions: { complexity: listFieldComplexity(complexity) } } : {}
|
|
5667
|
+
...complexity ? { extensions: { complexity: listFieldComplexity(complexity, limits?.(tableName)) } } : {}
|
|
5205
5668
|
};
|
|
5206
5669
|
queries[selectSingleGenerated.name] = {
|
|
5207
5670
|
type: selectSingleOutput,
|
|
@@ -5210,7 +5673,7 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5210
5673
|
};
|
|
5211
5674
|
if (aggregateGenerated && aggregateType) {
|
|
5212
5675
|
queries[aggregateGenerated.name] = {
|
|
5213
|
-
type: new
|
|
5676
|
+
type: new GraphQLNonNull7(aggregateType),
|
|
5214
5677
|
args: aggregateGenerated.args,
|
|
5215
5678
|
resolve: aggregateGenerated.resolver,
|
|
5216
5679
|
...complexity ? { extensions: { complexity: aggregateFieldComplexity(complexity) } } : {}
|
|
@@ -5218,7 +5681,7 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5218
5681
|
}
|
|
5219
5682
|
if (groupByGenerated && groupByType) {
|
|
5220
5683
|
queries[groupByGenerated.name] = {
|
|
5221
|
-
type: new
|
|
5684
|
+
type: new GraphQLNonNull7(new GraphQLList7(new GraphQLNonNull7(groupByType))),
|
|
5222
5685
|
args: groupByGenerated.args,
|
|
5223
5686
|
resolve: groupByGenerated.resolver,
|
|
5224
5687
|
...complexity ? { extensions: { complexity: aggregateFieldComplexity(complexity) } } : {}
|
|
@@ -5233,7 +5696,9 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5233
5696
|
}
|
|
5234
5697
|
if (insertSingleGenerated) {
|
|
5235
5698
|
mutations[insertSingleGenerated.name] = {
|
|
5236
|
-
|
|
5699
|
+
// An insert either returns the row it inserted or throws — the one path to `null` is
|
|
5700
|
+
// `conflictDoNothing` swallowing the insert, so the field is nullable only there.
|
|
5701
|
+
type: conflictDoNothing ? singleTableItemOutput : new GraphQLNonNull7(singleTableItemOutput),
|
|
5237
5702
|
args: insertSingleGenerated.args,
|
|
5238
5703
|
resolve: insertSingleGenerated.resolver
|
|
5239
5704
|
};
|
|
@@ -5261,10 +5726,13 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5261
5726
|
}
|
|
5262
5727
|
if (updateManyGenerated) {
|
|
5263
5728
|
mutations[updateManyGenerated.name] = {
|
|
5264
|
-
|
|
5265
|
-
type: new GraphQLNonNull6(new GraphQLList6(singleTableItemOutput)),
|
|
5729
|
+
type: new GraphQLNonNull7(new GraphQLList7(singleTableItemOutput)),
|
|
5266
5730
|
args: updateManyGenerated.args,
|
|
5267
|
-
resolve: updateManyGenerated.resolver
|
|
5731
|
+
resolve: updateManyGenerated.resolver,
|
|
5732
|
+
// The nullable element is deliberate, and the reason this mutation's return type
|
|
5733
|
+
// differs from every sibling's: the result is aligned with the input, one slot per
|
|
5734
|
+
// entry, so an entry that matched nothing has to be able to say so.
|
|
5735
|
+
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."
|
|
5268
5736
|
};
|
|
5269
5737
|
}
|
|
5270
5738
|
if (updateSingleGenerated) {
|
|
@@ -5288,6 +5756,22 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5288
5756
|
resolve: deleteSingleGenerated.resolver
|
|
5289
5757
|
};
|
|
5290
5758
|
}
|
|
5759
|
+
if (updateCountGenerated) {
|
|
5760
|
+
mutations[updateCountGenerated.name] = {
|
|
5761
|
+
type: new GraphQLNonNull7(GraphQLInt6),
|
|
5762
|
+
args: updateCountGenerated.args,
|
|
5763
|
+
resolve: updateCountGenerated.resolver,
|
|
5764
|
+
description: "How many rows the update touched. The rows themselves are not read back, which is the point of this mutation."
|
|
5765
|
+
};
|
|
5766
|
+
}
|
|
5767
|
+
if (deleteCountGenerated) {
|
|
5768
|
+
mutations[deleteCountGenerated.name] = {
|
|
5769
|
+
type: new GraphQLNonNull7(GraphQLInt6),
|
|
5770
|
+
args: deleteCountGenerated.args,
|
|
5771
|
+
resolve: deleteCountGenerated.resolver,
|
|
5772
|
+
description: "How many rows the delete removed. The rows themselves are not read back, which is the point of this mutation."
|
|
5773
|
+
};
|
|
5774
|
+
}
|
|
5291
5775
|
const activeInputs = [
|
|
5292
5776
|
// The insert input types the upsert mutations too, so either feature keeps it.
|
|
5293
5777
|
...features.insert || onConflictInput ? [insertInput] : [],
|
|
@@ -5336,12 +5820,13 @@ function generateSchemaData2(db, schema, relations, options) {
|
|
|
5336
5820
|
import { is as is7, One as One6 } from "drizzle-orm";
|
|
5337
5821
|
import { getTableConfig as getTableConfig3, SQLiteTable } from "drizzle-orm/sqlite-core";
|
|
5338
5822
|
import {
|
|
5339
|
-
GraphQLError as
|
|
5340
|
-
|
|
5341
|
-
|
|
5823
|
+
GraphQLError as GraphQLError9,
|
|
5824
|
+
GraphQLInt as GraphQLInt7,
|
|
5825
|
+
GraphQLList as GraphQLList8,
|
|
5826
|
+
GraphQLNonNull as GraphQLNonNull8
|
|
5342
5827
|
} from "graphql";
|
|
5343
5828
|
import { parseResolveInfo as parseResolveInfo4 } from "graphql-parse-resolve-info";
|
|
5344
|
-
var generateSelectArray3 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, distinctEnabled = true) => {
|
|
5829
|
+
var generateSelectArray3 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, distinctEnabled = true, limits) => {
|
|
5345
5830
|
const queryBase = db.query[tableName];
|
|
5346
5831
|
if (!queryBase) {
|
|
5347
5832
|
throw new Error(
|
|
@@ -5349,6 +5834,7 @@ var generateSelectArray3 = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
5349
5834
|
);
|
|
5350
5835
|
}
|
|
5351
5836
|
const table = tables[tableName];
|
|
5837
|
+
const limitPolicy = limits?.(tableName);
|
|
5352
5838
|
const pkNames = sqlitePrimaryKeyPropNames(table);
|
|
5353
5839
|
const queryArgs = selectArrayArgs(
|
|
5354
5840
|
orderArgs,
|
|
@@ -5371,8 +5857,10 @@ var generateSelectArray3 = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
5371
5857
|
typeNameMapper,
|
|
5372
5858
|
parsedInfo,
|
|
5373
5859
|
...args,
|
|
5860
|
+
limit: applyLimitPolicy(args.limit, limitPolicy, fieldName),
|
|
5374
5861
|
single: false,
|
|
5375
5862
|
filterCtx,
|
|
5863
|
+
limits,
|
|
5376
5864
|
pkNames,
|
|
5377
5865
|
db: executor,
|
|
5378
5866
|
// SQLite sorts NULLs as the smallest values (first in ASC).
|
|
@@ -5385,7 +5873,7 @@ var generateSelectArray3 = (db, tableName, tables, relationMap, orderArgs, filte
|
|
|
5385
5873
|
args: queryArgs
|
|
5386
5874
|
};
|
|
5387
5875
|
};
|
|
5388
|
-
var generateSelectSingle3 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx) => {
|
|
5876
|
+
var generateSelectSingle3 = (db, tableName, tables, relationMap, orderArgs, filterArgs, fieldName, typeName, typeNameMapper, filterCtx, limits) => {
|
|
5389
5877
|
const queryBase = db.query[tableName];
|
|
5390
5878
|
if (!queryBase) {
|
|
5391
5879
|
throw new Error(
|
|
@@ -5413,6 +5901,7 @@ var generateSelectSingle3 = (db, tableName, tables, relationMap, orderArgs, filt
|
|
|
5413
5901
|
...args,
|
|
5414
5902
|
single: true,
|
|
5415
5903
|
filterCtx,
|
|
5904
|
+
limits,
|
|
5416
5905
|
pkNames,
|
|
5417
5906
|
db: executor
|
|
5418
5907
|
});
|
|
@@ -5424,10 +5913,10 @@ var generateSelectSingle3 = (db, tableName, tables, relationMap, orderArgs, filt
|
|
|
5424
5913
|
};
|
|
5425
5914
|
};
|
|
5426
5915
|
var sqlitePrimaryKeyPropNames = (table) => getPrimaryKeyPropNamesFromConfig(table, getTableConfig3);
|
|
5427
|
-
var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested) => {
|
|
5916
|
+
var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested, limits) => {
|
|
5428
5917
|
const queryArgs = {
|
|
5429
5918
|
values: {
|
|
5430
|
-
type: new
|
|
5919
|
+
type: new GraphQLNonNull8(new GraphQLList8(new GraphQLNonNull8(baseType)))
|
|
5431
5920
|
}
|
|
5432
5921
|
};
|
|
5433
5922
|
const pkNames = sqlitePrimaryKeyPropNames(table);
|
|
@@ -5437,7 +5926,7 @@ var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
5437
5926
|
try {
|
|
5438
5927
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
5439
5928
|
if (!args.values.length) {
|
|
5440
|
-
throw new
|
|
5929
|
+
throw new GraphQLError9("No values were provided!");
|
|
5441
5930
|
}
|
|
5442
5931
|
const entries = nested?.enabled(tableName) ? args.values.map((values) => nested.split(tableName, values)) : void 0;
|
|
5443
5932
|
const nestedEntries = entries?.some((entry) => nested.hasOps(entry.ops)) ? entries : void 0;
|
|
@@ -5453,7 +5942,8 @@ var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
5453
5942
|
typeNameMapper,
|
|
5454
5943
|
table,
|
|
5455
5944
|
pkNames,
|
|
5456
|
-
parsedInfo
|
|
5945
|
+
parsedInfo,
|
|
5946
|
+
limits
|
|
5457
5947
|
});
|
|
5458
5948
|
const returning = nestedEntries ? nested.withJoinColumns(tableName, mergedOps(nestedEntries), { ...columns }, table) : columns;
|
|
5459
5949
|
const runInsert = async (target, values) => {
|
|
@@ -5481,10 +5971,10 @@ var generateInsertArray3 = (db, tableName, table, tables, relationMap, baseType,
|
|
|
5481
5971
|
args: queryArgs
|
|
5482
5972
|
};
|
|
5483
5973
|
};
|
|
5484
|
-
var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested) => {
|
|
5974
|
+
var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested, limits) => {
|
|
5485
5975
|
const queryArgs = {
|
|
5486
5976
|
values: {
|
|
5487
|
-
type: new
|
|
5977
|
+
type: new GraphQLNonNull8(baseType)
|
|
5488
5978
|
}
|
|
5489
5979
|
};
|
|
5490
5980
|
const pkNames = sqlitePrimaryKeyPropNames(table);
|
|
@@ -5507,7 +5997,8 @@ var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType
|
|
|
5507
5997
|
typeNameMapper,
|
|
5508
5998
|
table,
|
|
5509
5999
|
pkNames,
|
|
5510
|
-
parsedInfo
|
|
6000
|
+
parsedInfo,
|
|
6001
|
+
limits
|
|
5511
6002
|
});
|
|
5512
6003
|
const returning = nestedEntry ? nested.withJoinColumns(tableName, nestedEntry.ops, { ...columns }, table) : columns;
|
|
5513
6004
|
const runInsert = async (target, values) => {
|
|
@@ -5526,6 +6017,9 @@ var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType
|
|
|
5526
6017
|
write: runInsert
|
|
5527
6018
|
}) : await runInsert(executor, input);
|
|
5528
6019
|
if (!result[0]) {
|
|
6020
|
+
if (!conflictDoNothing) {
|
|
6021
|
+
throw new GraphQLError9(`${fieldName}: the insert returned no row.`);
|
|
6022
|
+
}
|
|
5529
6023
|
return void 0;
|
|
5530
6024
|
}
|
|
5531
6025
|
const enriched = hasRelations ? await eagerLoadMutationRelations(executor, tableName, result, pkNames, withParams) : result;
|
|
@@ -5538,10 +6032,10 @@ var generateInsertSingle3 = (db, tableName, table, tables, relationMap, baseType
|
|
|
5538
6032
|
args: queryArgs
|
|
5539
6033
|
};
|
|
5540
6034
|
};
|
|
5541
|
-
var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx, txCtx, nested) => {
|
|
6035
|
+
var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx, txCtx, nested, limits) => {
|
|
5542
6036
|
const queryArgs = {
|
|
5543
6037
|
values: {
|
|
5544
|
-
type: single ? new
|
|
6038
|
+
type: single ? new GraphQLNonNull8(baseType) : new GraphQLNonNull8(new GraphQLList8(new GraphQLNonNull8(baseType)))
|
|
5545
6039
|
},
|
|
5546
6040
|
onConflict: {
|
|
5547
6041
|
type: onConflictType,
|
|
@@ -5556,7 +6050,7 @@ var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
5556
6050
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
5557
6051
|
const supplied = single ? [args.values] : args.values;
|
|
5558
6052
|
if (!supplied.length) {
|
|
5559
|
-
throw new
|
|
6053
|
+
throw new GraphQLError9("No values were provided!");
|
|
5560
6054
|
}
|
|
5561
6055
|
const entries = nested?.enabled(tableName) ? supplied.map((values) => nested.split(tableName, values)) : void 0;
|
|
5562
6056
|
const nestedEntries = entries?.some((entry) => nested.hasOps(entry.ops)) ? entries : void 0;
|
|
@@ -5570,7 +6064,8 @@ var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
5570
6064
|
typeNameMapper,
|
|
5571
6065
|
table,
|
|
5572
6066
|
pkNames,
|
|
5573
|
-
parsedInfo
|
|
6067
|
+
parsedInfo,
|
|
6068
|
+
limits
|
|
5574
6069
|
});
|
|
5575
6070
|
const returning = nestedEntries ? nested.withJoinColumns(tableName, mergedOps(nestedEntries), { ...columns }, table) : columns;
|
|
5576
6071
|
const runUpsert = async (target, values) => {
|
|
@@ -5609,13 +6104,13 @@ var generateUpsert3 = (db, tableName, table, tables, relationMap, baseType, onCo
|
|
|
5609
6104
|
args: queryArgs
|
|
5610
6105
|
};
|
|
5611
6106
|
};
|
|
5612
|
-
var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx, txCtx, nested) => {
|
|
6107
|
+
var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx, txCtx, nested, limits) => {
|
|
5613
6108
|
const queryArgs = {
|
|
5614
6109
|
set: {
|
|
5615
|
-
type: new
|
|
6110
|
+
type: new GraphQLNonNull8(setArgs)
|
|
5616
6111
|
},
|
|
5617
6112
|
where: {
|
|
5618
|
-
type: single || requireWhere ? new
|
|
6113
|
+
type: single || requireWhere ? new GraphQLNonNull8(filterArgs) : filterArgs
|
|
5619
6114
|
}
|
|
5620
6115
|
};
|
|
5621
6116
|
const pkNames = sqlitePrimaryKeyPropNames(table);
|
|
@@ -5636,13 +6131,14 @@ var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
5636
6131
|
typeNameMapper,
|
|
5637
6132
|
table,
|
|
5638
6133
|
pkNames,
|
|
5639
|
-
parsedInfo
|
|
6134
|
+
parsedInfo,
|
|
6135
|
+
limits
|
|
5640
6136
|
});
|
|
5641
6137
|
const entry = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
|
|
5642
6138
|
const nestedOps = entry && nested.hasOps(entry.ops) ? entry.ops : void 0;
|
|
5643
|
-
const input =
|
|
6139
|
+
const input = remapUpdateInput(entry ? entry.columns : set, table, tableName);
|
|
5644
6140
|
if (!Object.keys(input).length && !nestedOps) {
|
|
5645
|
-
throw new
|
|
6141
|
+
throw new GraphQLError9("Unable to update with no values specified!");
|
|
5646
6142
|
}
|
|
5647
6143
|
const relationCtx = relationFilterCtx(filterCtx, tableName);
|
|
5648
6144
|
const filters = single || requireWhere ? extractRequiredFilters(table, tableName, where, fieldName, relationCtx) : where ? extractFilters(table, tableName, where, relationCtx) : void 0;
|
|
@@ -5668,7 +6164,7 @@ var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
5668
6164
|
write: runUpdate
|
|
5669
6165
|
}) : await runUpdate(executor, input);
|
|
5670
6166
|
if (single && result.length > 1) {
|
|
5671
|
-
throw new
|
|
6167
|
+
throw new GraphQLError9(`${fieldName}: 'where' matched more than one row!`);
|
|
5672
6168
|
}
|
|
5673
6169
|
if (single && !result[0]) {
|
|
5674
6170
|
return void 0;
|
|
@@ -5683,10 +6179,10 @@ var generateUpdate3 = (db, tableName, table, tables, relationMap, setArgs, filte
|
|
|
5683
6179
|
args: queryArgs
|
|
5684
6180
|
};
|
|
5685
6181
|
};
|
|
5686
|
-
var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx, txCtx, nested) => {
|
|
6182
|
+
var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx, txCtx, nested, limits) => {
|
|
5687
6183
|
const queryArgs = {
|
|
5688
6184
|
updates: {
|
|
5689
|
-
type: new
|
|
6185
|
+
type: new GraphQLNonNull8(new GraphQLList8(new GraphQLNonNull8(updateManyInput)))
|
|
5690
6186
|
}
|
|
5691
6187
|
};
|
|
5692
6188
|
const pkNames = sqlitePrimaryKeyPropNames(table);
|
|
@@ -5697,7 +6193,7 @@ var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
5697
6193
|
return await runMutation(db, context, info, txCtx, async (executor) => {
|
|
5698
6194
|
const { updates } = args;
|
|
5699
6195
|
if (!updates.length) {
|
|
5700
|
-
throw new
|
|
6196
|
+
throw new GraphQLError9("No updates were provided!");
|
|
5701
6197
|
}
|
|
5702
6198
|
const parsedInfo = parseResolveInfo4(info, {
|
|
5703
6199
|
deep: true
|
|
@@ -5710,14 +6206,15 @@ var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
5710
6206
|
typeNameMapper,
|
|
5711
6207
|
table,
|
|
5712
6208
|
pkNames,
|
|
5713
|
-
parsedInfo
|
|
6209
|
+
parsedInfo,
|
|
6210
|
+
limits
|
|
5714
6211
|
});
|
|
5715
6212
|
const entries = updates.map(({ where, set }) => {
|
|
5716
6213
|
const split = nested?.enabled(tableName) ? nested.split(tableName, set) : void 0;
|
|
5717
6214
|
const ops = split && nested.hasOps(split.ops) ? split.ops : void 0;
|
|
5718
|
-
const input =
|
|
6215
|
+
const input = remapUpdateInput(split ? split.columns : set, table, tableName);
|
|
5719
6216
|
if (!Object.keys(input).length && !ops) {
|
|
5720
|
-
throw new
|
|
6217
|
+
throw new GraphQLError9("Unable to update with no values specified!");
|
|
5721
6218
|
}
|
|
5722
6219
|
return {
|
|
5723
6220
|
set: input,
|
|
@@ -5804,7 +6301,7 @@ var generateUpdateMany3 = (db, tableName, table, tables, relationMap, updateMany
|
|
|
5804
6301
|
var generateDelete3 = (db, tableName, table, filterArgs, fieldName, typeName, single, requireWhere, filterCtx, selectionCtx, txCtx) => {
|
|
5805
6302
|
const queryArgs = {
|
|
5806
6303
|
where: {
|
|
5807
|
-
type: single || requireWhere ? new
|
|
6304
|
+
type: single || requireWhere ? new GraphQLNonNull8(filterArgs) : filterArgs
|
|
5808
6305
|
}
|
|
5809
6306
|
};
|
|
5810
6307
|
return {
|
|
@@ -5833,7 +6330,7 @@ var generateDelete3 = (db, tableName, table, filterArgs, fieldName, typeName, si
|
|
|
5833
6330
|
query = query.returning(columns);
|
|
5834
6331
|
const result = await query;
|
|
5835
6332
|
if (single && result.length > 1) {
|
|
5836
|
-
throw new
|
|
6333
|
+
throw new GraphQLError9(`${fieldName}: 'where' matched more than one row!`);
|
|
5837
6334
|
}
|
|
5838
6335
|
if (single) {
|
|
5839
6336
|
return result[0] ? remapToGraphQLSingleOutput(result[0], tableName, table) : void 0;
|
|
@@ -5856,7 +6353,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5856
6353
|
typeNameMapper,
|
|
5857
6354
|
shouldEagerLoad,
|
|
5858
6355
|
features,
|
|
5859
|
-
complexity
|
|
6356
|
+
complexity,
|
|
6357
|
+
limits
|
|
5860
6358
|
} = options;
|
|
5861
6359
|
const rawSchema = schema;
|
|
5862
6360
|
const schemaEntries = Object.entries(rawSchema);
|
|
@@ -5873,7 +6371,13 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5873
6371
|
attachTargetPrimaryKeys(namedRelations, tables, sqlitePrimaryKeyPropNames);
|
|
5874
6372
|
const eagerRelations = pruneNonEagerRelations(namedRelations, shouldEagerLoad);
|
|
5875
6373
|
const filterCtx = { tables, relationMap: namedRelations };
|
|
5876
|
-
const resolverFactory = createRelationResolverFactory(
|
|
6374
|
+
const resolverFactory = createRelationResolverFactory(
|
|
6375
|
+
db,
|
|
6376
|
+
tables,
|
|
6377
|
+
"nulls-smallest",
|
|
6378
|
+
filterCtx,
|
|
6379
|
+
limits
|
|
6380
|
+
);
|
|
5877
6381
|
const cacheCtx = {
|
|
5878
6382
|
genericFilterCache: /* @__PURE__ */ new Map(),
|
|
5879
6383
|
objectTypeCache: /* @__PURE__ */ new Map(),
|
|
@@ -5887,7 +6391,9 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5887
6391
|
listRelationFilterCache: /* @__PURE__ */ new Map(),
|
|
5888
6392
|
aggregateTypeCache: /* @__PURE__ */ new Map(),
|
|
5889
6393
|
complexity,
|
|
5890
|
-
|
|
6394
|
+
limits,
|
|
6395
|
+
docs: options.docs ?? {},
|
|
6396
|
+
features
|
|
5891
6397
|
};
|
|
5892
6398
|
if (features.nestedWrites && db.resultKind === "sync") {
|
|
5893
6399
|
throw new Error(
|
|
@@ -5949,8 +6455,10 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5949
6455
|
updateFieldName,
|
|
5950
6456
|
updateManyFieldName,
|
|
5951
6457
|
updateSingleFieldName,
|
|
6458
|
+
updateCountFieldName,
|
|
5952
6459
|
deleteFieldName,
|
|
5953
|
-
deleteSingleFieldName
|
|
6460
|
+
deleteSingleFieldName,
|
|
6461
|
+
deleteCountFieldName
|
|
5954
6462
|
} = computeResolverFieldNames(tableName, typeNameMapper, prefixes, suffixes);
|
|
5955
6463
|
const selectArrGenerated = generateSelectArray3(
|
|
5956
6464
|
db,
|
|
@@ -5963,7 +6471,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5963
6471
|
typeName,
|
|
5964
6472
|
typeNameMapper,
|
|
5965
6473
|
filterCtx,
|
|
5966
|
-
features.distinct
|
|
6474
|
+
features.distinct,
|
|
6475
|
+
limits
|
|
5967
6476
|
);
|
|
5968
6477
|
const selectSingleGenerated = generateSelectSingle3(
|
|
5969
6478
|
db,
|
|
@@ -5975,7 +6484,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5975
6484
|
singleFieldName,
|
|
5976
6485
|
typeName,
|
|
5977
6486
|
typeNameMapper,
|
|
5978
|
-
filterCtx
|
|
6487
|
+
filterCtx,
|
|
6488
|
+
limits
|
|
5979
6489
|
);
|
|
5980
6490
|
const insertArrGenerated = features.insert ? generateInsertArray3(
|
|
5981
6491
|
db,
|
|
@@ -5989,7 +6499,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
5989
6499
|
typeNameMapper,
|
|
5990
6500
|
conflictDoNothing,
|
|
5991
6501
|
mutationTxCtx,
|
|
5992
|
-
nestedRuntime
|
|
6502
|
+
nestedRuntime,
|
|
6503
|
+
limits
|
|
5993
6504
|
) : void 0;
|
|
5994
6505
|
const insertSingleGenerated = features.insert ? generateInsertSingle3(
|
|
5995
6506
|
db,
|
|
@@ -6003,7 +6514,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
6003
6514
|
typeNameMapper,
|
|
6004
6515
|
conflictDoNothing,
|
|
6005
6516
|
mutationTxCtx,
|
|
6006
|
-
nestedRuntime
|
|
6517
|
+
nestedRuntime,
|
|
6518
|
+
limits
|
|
6007
6519
|
) : void 0;
|
|
6008
6520
|
const uniqueSets = features.upsert ? getUniqueColumnSets(schema[tableName], getTableConfig3) : [];
|
|
6009
6521
|
const onConflictInput = features.upsert ? generateOnConflictInput({
|
|
@@ -6028,7 +6540,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
6028
6540
|
typeNameMapper,
|
|
6029
6541
|
filterCtx,
|
|
6030
6542
|
mutationTxCtx,
|
|
6031
|
-
nestedRuntime
|
|
6543
|
+
nestedRuntime,
|
|
6544
|
+
limits
|
|
6032
6545
|
) : void 0;
|
|
6033
6546
|
const upsertSingleGenerated = onConflictInput ? generateUpsert3(
|
|
6034
6547
|
db,
|
|
@@ -6045,7 +6558,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
6045
6558
|
typeNameMapper,
|
|
6046
6559
|
filterCtx,
|
|
6047
6560
|
mutationTxCtx,
|
|
6048
|
-
nestedRuntime
|
|
6561
|
+
nestedRuntime,
|
|
6562
|
+
limits
|
|
6049
6563
|
) : void 0;
|
|
6050
6564
|
const updateGenerated = features.update ? generateUpdate3(
|
|
6051
6565
|
db,
|
|
@@ -6062,7 +6576,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
6062
6576
|
typeNameMapper,
|
|
6063
6577
|
filterCtx,
|
|
6064
6578
|
mutationTxCtx,
|
|
6065
|
-
nestedRuntime
|
|
6579
|
+
nestedRuntime,
|
|
6580
|
+
limits
|
|
6066
6581
|
) : void 0;
|
|
6067
6582
|
const updateSingleGenerated = features.update ? generateUpdate3(
|
|
6068
6583
|
db,
|
|
@@ -6079,7 +6594,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
6079
6594
|
typeNameMapper,
|
|
6080
6595
|
filterCtx,
|
|
6081
6596
|
mutationTxCtx,
|
|
6082
|
-
nestedRuntime
|
|
6597
|
+
nestedRuntime,
|
|
6598
|
+
limits
|
|
6083
6599
|
) : void 0;
|
|
6084
6600
|
const updateManyInput = features.update && features.updateMany ? generateUpdateManyInput({ typeName, updatePrefix: prefixes.update, updateInput, tableFilters }) : void 0;
|
|
6085
6601
|
const updateManyGenerated = updateManyInput ? generateUpdateMany3(
|
|
@@ -6094,7 +6610,8 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
6094
6610
|
typeNameMapper,
|
|
6095
6611
|
filterCtx,
|
|
6096
6612
|
mutationTxCtx,
|
|
6097
|
-
nestedRuntime
|
|
6613
|
+
nestedRuntime,
|
|
6614
|
+
limits
|
|
6098
6615
|
) : void 0;
|
|
6099
6616
|
const deleteGenerated = features.delete ? generateDelete3(
|
|
6100
6617
|
db,
|
|
@@ -6122,6 +6639,30 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
6122
6639
|
{ tableName, relationMap: namedRelations, tables },
|
|
6123
6640
|
mutationTxCtx
|
|
6124
6641
|
) : void 0;
|
|
6642
|
+
const updateCountGenerated = features.update && features.countMutations ? generateWriteCount({
|
|
6643
|
+
db,
|
|
6644
|
+
tableName,
|
|
6645
|
+
table: schema[tableName],
|
|
6646
|
+
kind: "update",
|
|
6647
|
+
setArgs: updateInput,
|
|
6648
|
+
filterArgs: tableFilters,
|
|
6649
|
+
fieldName: updateCountFieldName,
|
|
6650
|
+
requireWhere: features.requireWhere,
|
|
6651
|
+
filterCtx,
|
|
6652
|
+
txCtx: mutationTxCtx,
|
|
6653
|
+
nested: nestedRuntime
|
|
6654
|
+
}) : void 0;
|
|
6655
|
+
const deleteCountGenerated = features.delete && features.countMutations ? generateWriteCount({
|
|
6656
|
+
db,
|
|
6657
|
+
tableName,
|
|
6658
|
+
table: schema[tableName],
|
|
6659
|
+
kind: "delete",
|
|
6660
|
+
filterArgs: tableFilters,
|
|
6661
|
+
fieldName: deleteCountFieldName,
|
|
6662
|
+
requireWhere: features.requireWhere,
|
|
6663
|
+
filterCtx,
|
|
6664
|
+
txCtx: mutationTxCtx
|
|
6665
|
+
}) : void 0;
|
|
6125
6666
|
const aggregateType = features.aggregates ? generateAggregateTypes(schema[tableName], tableName, typeName, cacheCtx) : void 0;
|
|
6126
6667
|
const aggregateGenerated = features.aggregates ? generateAggregate(
|
|
6127
6668
|
db,
|
|
@@ -6150,7 +6691,7 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
6150
6691
|
type: selectArrOutput,
|
|
6151
6692
|
args: selectArrGenerated.args,
|
|
6152
6693
|
resolve: selectArrGenerated.resolver,
|
|
6153
|
-
...complexity ? { extensions: { complexity: listFieldComplexity(complexity) } } : {}
|
|
6694
|
+
...complexity ? { extensions: { complexity: listFieldComplexity(complexity, limits?.(tableName)) } } : {}
|
|
6154
6695
|
};
|
|
6155
6696
|
queries[selectSingleGenerated.name] = {
|
|
6156
6697
|
type: selectSingleOutput,
|
|
@@ -6159,7 +6700,7 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
6159
6700
|
};
|
|
6160
6701
|
if (aggregateGenerated && aggregateType) {
|
|
6161
6702
|
queries[aggregateGenerated.name] = {
|
|
6162
|
-
type: new
|
|
6703
|
+
type: new GraphQLNonNull8(aggregateType),
|
|
6163
6704
|
args: aggregateGenerated.args,
|
|
6164
6705
|
resolve: aggregateGenerated.resolver,
|
|
6165
6706
|
...complexity ? { extensions: { complexity: aggregateFieldComplexity(complexity) } } : {}
|
|
@@ -6167,7 +6708,7 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
6167
6708
|
}
|
|
6168
6709
|
if (groupByGenerated && groupByType) {
|
|
6169
6710
|
queries[groupByGenerated.name] = {
|
|
6170
|
-
type: new
|
|
6711
|
+
type: new GraphQLNonNull8(new GraphQLList8(new GraphQLNonNull8(groupByType))),
|
|
6171
6712
|
args: groupByGenerated.args,
|
|
6172
6713
|
resolve: groupByGenerated.resolver,
|
|
6173
6714
|
...complexity ? { extensions: { complexity: aggregateFieldComplexity(complexity) } } : {}
|
|
@@ -6182,7 +6723,9 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
6182
6723
|
}
|
|
6183
6724
|
if (insertSingleGenerated) {
|
|
6184
6725
|
mutations[insertSingleGenerated.name] = {
|
|
6185
|
-
|
|
6726
|
+
// An insert either returns the row it inserted or throws — the one path to `null` is
|
|
6727
|
+
// `conflictDoNothing` swallowing the insert, so the field is nullable only there.
|
|
6728
|
+
type: conflictDoNothing ? singleTableItemOutput : new GraphQLNonNull8(singleTableItemOutput),
|
|
6186
6729
|
args: insertSingleGenerated.args,
|
|
6187
6730
|
resolve: insertSingleGenerated.resolver
|
|
6188
6731
|
};
|
|
@@ -6210,10 +6753,13 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
6210
6753
|
}
|
|
6211
6754
|
if (updateManyGenerated) {
|
|
6212
6755
|
mutations[updateManyGenerated.name] = {
|
|
6213
|
-
|
|
6214
|
-
type: new GraphQLNonNull7(new GraphQLList7(singleTableItemOutput)),
|
|
6756
|
+
type: new GraphQLNonNull8(new GraphQLList8(singleTableItemOutput)),
|
|
6215
6757
|
args: updateManyGenerated.args,
|
|
6216
|
-
resolve: updateManyGenerated.resolver
|
|
6758
|
+
resolve: updateManyGenerated.resolver,
|
|
6759
|
+
// The nullable element is deliberate, and the reason this mutation's return type
|
|
6760
|
+
// differs from every sibling's: the result is aligned with the input, one slot per
|
|
6761
|
+
// entry, so an entry that matched nothing has to be able to say so.
|
|
6762
|
+
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."
|
|
6217
6763
|
};
|
|
6218
6764
|
}
|
|
6219
6765
|
if (updateSingleGenerated) {
|
|
@@ -6237,6 +6783,22 @@ var generateSchemaData3 = (db, schema, relations, options) => {
|
|
|
6237
6783
|
resolve: deleteSingleGenerated.resolver
|
|
6238
6784
|
};
|
|
6239
6785
|
}
|
|
6786
|
+
if (updateCountGenerated) {
|
|
6787
|
+
mutations[updateCountGenerated.name] = {
|
|
6788
|
+
type: new GraphQLNonNull8(GraphQLInt7),
|
|
6789
|
+
args: updateCountGenerated.args,
|
|
6790
|
+
resolve: updateCountGenerated.resolver,
|
|
6791
|
+
description: "How many rows the update touched. The rows themselves are not read back, which is the point of this mutation."
|
|
6792
|
+
};
|
|
6793
|
+
}
|
|
6794
|
+
if (deleteCountGenerated) {
|
|
6795
|
+
mutations[deleteCountGenerated.name] = {
|
|
6796
|
+
type: new GraphQLNonNull8(GraphQLInt7),
|
|
6797
|
+
args: deleteCountGenerated.args,
|
|
6798
|
+
resolve: deleteCountGenerated.resolver,
|
|
6799
|
+
description: "How many rows the delete removed. The rows themselves are not read back, which is the point of this mutation."
|
|
6800
|
+
};
|
|
6801
|
+
}
|
|
6240
6802
|
const activeInputs = [
|
|
6241
6803
|
// The insert input types the upsert mutations too, so either feature keeps it.
|
|
6242
6804
|
...features.insert || onConflictInput ? [insertInput] : [],
|
|
@@ -6314,6 +6876,8 @@ var buildSchema = (db, config) => {
|
|
|
6314
6876
|
delete: config?.features?.delete ?? true,
|
|
6315
6877
|
upsert: config?.features?.upsert ?? false,
|
|
6316
6878
|
nestedWrites: config?.features?.nestedWrites ?? false,
|
|
6879
|
+
fieldUpdateOperations: config?.features?.fieldUpdateOperations ?? false,
|
|
6880
|
+
countMutations: config?.features?.countMutations ?? false,
|
|
6317
6881
|
requireWhere: config?.features?.requireWhere ?? false
|
|
6318
6882
|
};
|
|
6319
6883
|
const complexityConfig = config?.complexity ?? true;
|
|
@@ -6323,6 +6887,33 @@ var buildSchema = (db, config) => {
|
|
|
6323
6887
|
};
|
|
6324
6888
|
const transactionsOpt = config?.transactions;
|
|
6325
6889
|
const transactions = transactionsOpt === void 0 || transactionsOpt === "none" ? void 0 : { timeoutMs: (transactionsOpt === "auto" ? void 0 : transactionsOpt.timeoutMs) ?? 3e4 };
|
|
6890
|
+
const limitsConfig = config?.limits;
|
|
6891
|
+
if (limitsConfig) {
|
|
6892
|
+
const check = (policy, where) => {
|
|
6893
|
+
for (const key of ["defaultLimit", "maxLimit"]) {
|
|
6894
|
+
const value = policy[key];
|
|
6895
|
+
if (value === void 0) {
|
|
6896
|
+
continue;
|
|
6897
|
+
}
|
|
6898
|
+
if (!Number.isInteger(value) || value < 1) {
|
|
6899
|
+
throw new Error(`Drizzle-GraphQL Error: config.limits${where}.${key} must be a positive integer.`);
|
|
6900
|
+
}
|
|
6901
|
+
}
|
|
6902
|
+
};
|
|
6903
|
+
check(limitsConfig, "");
|
|
6904
|
+
for (const [tableName, policy] of Object.entries(limitsConfig.tables ?? {})) {
|
|
6905
|
+
check(policy, `.tables.${tableName}`);
|
|
6906
|
+
}
|
|
6907
|
+
}
|
|
6908
|
+
const limitPolicyCache = /* @__PURE__ */ new Map();
|
|
6909
|
+
const limits = limitsConfig ? (tableName) => {
|
|
6910
|
+
if (limitPolicyCache.has(tableName)) {
|
|
6911
|
+
return limitPolicyCache.get(tableName);
|
|
6912
|
+
}
|
|
6913
|
+
const resolved = resolveLimitPolicy(limitsConfig, limitsConfig.tables?.[tableName]);
|
|
6914
|
+
limitPolicyCache.set(tableName, resolved);
|
|
6915
|
+
return resolved;
|
|
6916
|
+
} : void 0;
|
|
6326
6917
|
const eagerOpt = config?.eagerLoadRelations;
|
|
6327
6918
|
const shouldEagerLoad = eagerOpt === void 0 || eagerOpt === true ? () => true : eagerOpt === false ? () => false : eagerOpt;
|
|
6328
6919
|
if (!typeNameMapper && suffixes.list === suffixes.single) {
|
|
@@ -6355,6 +6946,7 @@ var buildSchema = (db, config) => {
|
|
|
6355
6946
|
mapColumnType: config?.mapColumnType,
|
|
6356
6947
|
enumNameMapper: config?.enumNameMapper,
|
|
6357
6948
|
transactions,
|
|
6949
|
+
limits,
|
|
6358
6950
|
docs: {
|
|
6359
6951
|
describeColumn: config?.describeColumn,
|
|
6360
6952
|
describeTable: config?.describeTable,
|