@vantreeseba/drizzle-graphql 12.0.0 → 13.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -4296,17 +4296,15 @@ const computeResolverFieldNames = (tableName, typeNameMapper, prefixes, suffixes
4296
4296
  const upsertPrefix = prefixes.upsert ?? "upsert";
4297
4297
  const upsertArrayFieldName = `${upsertPrefix}${pluralNoun}${suffixes.list}`;
4298
4298
  const upsertSingleFieldName = mapped ? `${upsertPrefix}${capitalize(mapped.singular)}` : `${upsertPrefix}${capitalize(tableName)}${suffixes.single}`;
4299
- const updateBase = `${prefixes.update}${singularNoun}`;
4300
- const deleteBase = `${prefixes.delete}${singularNoun}`;
4301
- const restoreBase = `${prefixes.restore ?? "restore"}${singularNoun}`;
4302
- const updateFieldName = `${updateBase}${suffixes.list}`;
4299
+ const restorePrefix = prefixes.restore ?? "restore";
4300
+ const updateFieldName = `${prefixes.update}${pluralNoun}${suffixes.list}`;
4303
4301
  const updateManyFieldName = `${prefixes.update}${pluralNoun}Many`;
4304
- const deleteFieldName = `${deleteBase}${suffixes.list}`;
4305
- const restoreFieldName = `${restoreBase}${suffixes.list}`;
4306
- const writeSingleSuffix = suffixes.single === suffixes.list ? "Single" : suffixes.single;
4307
- const updateSingleFieldName = `${updateBase}${writeSingleSuffix}`;
4308
- const deleteSingleFieldName = `${deleteBase}${writeSingleSuffix}`;
4309
- const restoreSingleFieldName = `${restoreBase}${writeSingleSuffix}`;
4302
+ const deleteFieldName = `${prefixes.delete}${pluralNoun}${suffixes.list}`;
4303
+ const restoreFieldName = `${restorePrefix}${pluralNoun}${suffixes.list}`;
4304
+ const singleWrite = (prefix) => mapped ? `${prefix}${singularNoun}` : `${prefix}${singularNoun}${suffixes.single}`;
4305
+ const updateSingleFieldName = singleWrite(prefixes.update);
4306
+ const deleteSingleFieldName = singleWrite(prefixes.delete);
4307
+ const restoreSingleFieldName = singleWrite(restorePrefix);
4310
4308
  return {
4311
4309
  typeName,
4312
4310
  listFieldName,
@@ -6506,6 +6504,72 @@ const createSchemaBuilder = (adapter) => {
6506
6504
  havingInput
6507
6505
  };
6508
6506
  };
6507
+ /**
6508
+ * The per-table loop, run once for every table the build covers.
6509
+ *
6510
+ * The dialect's callback receives the values the loop has already worked out — the feature
6511
+ * flags, the extension factory, the field names, the table's generated types and its
6512
+ * soft-delete config — and answers with the mutations it generated. Registering them, and
6513
+ * registering the inputs and outputs those mutations reference, happens here: both sides
6514
+ * did it identically, down to the `description` strings on the count mutations, so a gate
6515
+ * changed on one side and forgotten on the other used to be a silent dialect divergence.
6516
+ *
6517
+ * What stays in the dialect is what genuinely differs — which generators run, what each
6518
+ * mutation returns, and (on MySQL) that a write cannot report the rows it touched.
6519
+ */
6520
+ const forEachTable = (ctx, perTable) => {
6521
+ const { schema, featureOf, softDeleteOf, typeNameMapper, gqlSchemaTypes, mutations, inputs, outputs } = ctx;
6522
+ const { prefixes, suffixes } = ctx.options;
6523
+ for (const [tableName, tableTypes] of Object.entries(gqlSchemaTypes)) {
6524
+ const tableFeatures = featureOf(tableName);
6525
+ const drizzleMeta = tableFieldExtensions(tableName, primaryKeyPropNames(schema[tableName]));
6526
+ const names = computeResolverFieldNames(tableName, typeNameMapper, prefixes, suffixes);
6527
+ const softDeleteInfo = softDeleteOf?.(tableName);
6528
+ const readTypes = addReadFields(ctx, tableName, names, tableTypes, drizzleMeta);
6529
+ const built = perTable({
6530
+ tableName,
6531
+ table: schema[tableName],
6532
+ tableFeatures,
6533
+ drizzleMeta,
6534
+ names,
6535
+ types: tableTypes,
6536
+ softDeleteInfo
6537
+ });
6538
+ for (const { generated, type, meta, description } of built.mutations) if (generated) defineRootField(mutations, "mutation", generated.name, {
6539
+ type,
6540
+ args: generated.args,
6541
+ resolve: generated.resolver,
6542
+ ...meta ? { extensions: { drizzle: drizzleMeta({
6543
+ kind: "mutation",
6544
+ ...meta
6545
+ }) } } : {},
6546
+ ...description ? { description } : {}
6547
+ });
6548
+ const { insertInput, updateInput, tableFilters, tableOrder } = tableTypes.inputs;
6549
+ [
6550
+ ...tableFeatures.insert || built.onConflictInput ? [insertInput] : [],
6551
+ ...built.onConflictInput ? [built.onConflictInput] : [],
6552
+ ...tableFeatures.update ? [updateInput] : [],
6553
+ ...built.updateManyInput ? [built.updateManyInput] : [],
6554
+ tableFilters,
6555
+ tableOrder
6556
+ ].forEach((e) => {
6557
+ inputs[e.name] = e;
6558
+ });
6559
+ const { selectSingleOutput } = tableTypes.outputs;
6560
+ outputs[selectSingleOutput.name] = selectSingleOutput;
6561
+ if (adapter.returnsRows) {
6562
+ const { singleTableItemOutput } = tableTypes.outputs;
6563
+ outputs[singleTableItemOutput.name] = singleTableItemOutput;
6564
+ }
6565
+ const { aggregateType, groupByType, havingInput } = readTypes;
6566
+ if (aggregateType) outputs[aggregateType.name] = aggregateType;
6567
+ if (groupByType && havingInput) {
6568
+ outputs[groupByType.name] = groupByType;
6569
+ inputs[havingInput.name] = havingInput;
6570
+ }
6571
+ }
6572
+ };
6509
6573
  /** The relation field resolvers and the transaction roster, once every root field exists. */
6510
6574
  const finalizeBuild = (ctx) => {
6511
6575
  if (ctx.mutationTxCtx) for (const name of Object.keys(ctx.mutations)) ctx.mutationTxCtx.fieldNames.add(name);
@@ -6536,7 +6600,7 @@ const createSchemaBuilder = (adapter) => {
6536
6600
  primaryKeyPropNames,
6537
6601
  uniqueColumnSets,
6538
6602
  prepareBuild,
6539
- addReadFields,
6603
+ forEachTable,
6540
6604
  finalizeBuild
6541
6605
  };
6542
6606
  };
@@ -6745,7 +6809,7 @@ const generateDelete = (db, tableName, table, filterArgs, fieldName, single, req
6745
6809
  const getTableConfig$5 = memoizeTableConfig(getTableConfig);
6746
6810
  /** Primary-key property names for a MySQL table, including table-level composite keys. */
6747
6811
  const mysqlPrimaryKeyPropNames = (table) => getPrimaryKeyPropNamesFromConfig(table, getTableConfig$5);
6748
- const { prepareBuild, addReadFields, finalizeBuild } = createSchemaBuilder({
6812
+ const { prepareBuild, forEachTable, finalizeBuild } = createSchemaBuilder({
6749
6813
  tableClass: MySqlTable,
6750
6814
  getTableConfig: getTableConfig$5,
6751
6815
  primaryKeyPropNames: mysqlPrimaryKeyPropNames,
@@ -6756,9 +6820,9 @@ const { prepareBuild, addReadFields, finalizeBuild } = createSchemaBuilder({
6756
6820
  }
6757
6821
  });
6758
6822
  const generateSchemaData$2 = (db, schema, relations, options) => {
6759
- const { prefixes, suffixes, typeNameMapper } = options;
6823
+ const { prefixes } = options;
6760
6824
  const ctx = prepareBuild(db, schema, relations, options);
6761
- const { featureOf, anyTable, filterCtx, policies, softDeleteOf, cacheCtx, mutationTxCtx, gqlSchemaTypes, mutations, inputs, outputs } = ctx;
6825
+ const { anyTable, filterCtx, policies, cacheCtx, mutationTxCtx, outputs } = ctx;
6762
6826
  const mutationReturnType = new GraphQLObjectType({
6763
6827
  name: cacheCtx.typeName({
6764
6828
  kind: "shared",
@@ -6772,15 +6836,9 @@ const generateSchemaData$2 = (db, schema, relations, options) => {
6772
6836
  "update",
6773
6837
  "delete"
6774
6838
  ].some((feature) => anyTable(feature))) outputs["MutationReturn"] = mutationReturnType;
6775
- for (const [tableName, tableTypes] of Object.entries(gqlSchemaTypes)) {
6776
- const tableFeatures = featureOf(tableName);
6777
- const drizzleMeta = tableFieldExtensions(tableName, mysqlPrimaryKeyPropNames(schema[tableName]));
6778
- const { insertInput, updateInput, tableFilters, tableOrder } = tableTypes.inputs;
6779
- const { selectSingleOutput } = tableTypes.outputs;
6780
- const names = computeResolverFieldNames(tableName, typeNameMapper, prefixes, suffixes);
6839
+ forEachTable(ctx, ({ tableName, tableFeatures, names, types, softDeleteInfo }) => {
6840
+ const { insertInput, updateInput, tableFilters } = types.inputs;
6781
6841
  const { typeName, createArrayFieldName, createSingleFieldName, upsertArrayFieldName, upsertSingleFieldName, updateFieldName, updateManyFieldName, updateSingleFieldName, updateCountFieldName, deleteFieldName, deleteSingleFieldName, restoreFieldName, restoreSingleFieldName, deleteCountFieldName } = names;
6782
- const softDeleteInfo = softDeleteOf?.(tableName);
6783
- const { aggregateType, groupByType, havingInput } = addReadFields(ctx, tableName, names, tableTypes, drizzleMeta);
6784
6842
  const insertArrGenerated = tableFeatures.insert ? generateInsertArray(db, tableName, schema[tableName], insertInput, createArrayFieldName, mutationTxCtx, policies) : void 0;
6785
6843
  const insertSingleGenerated = tableFeatures.insert ? generateInsertSingle(db, tableName, schema[tableName], insertInput, createSingleFieldName, mutationTxCtx, policies) : void 0;
6786
6844
  const onConflictInput = tableFeatures.upsert ? generateOnConflictInput({
@@ -6833,103 +6891,85 @@ const generateSchemaData$2 = (db, schema, relations, options) => {
6833
6891
  txCtx: mutationTxCtx
6834
6892
  }) : void 0;
6835
6893
  const hardDeleteMeta = softDeleteInfo?.hardDelete ? { hardDelete: true } : {};
6836
- const generatedMutations = [
6837
- [insertArrGenerated, {
6838
- operation: "insert",
6839
- single: false,
6840
- targetArg: "values"
6841
- }],
6842
- [insertSingleGenerated, {
6843
- operation: "insert",
6844
- single: true,
6845
- targetArg: "values"
6846
- }],
6847
- [upsertArrGenerated, {
6848
- operation: "upsert",
6849
- single: false,
6850
- targetArg: "values"
6851
- }],
6852
- [upsertSingleGenerated, {
6853
- operation: "upsert",
6854
- single: true,
6855
- targetArg: "values"
6856
- }],
6857
- [updateGenerated, {
6858
- operation: "update",
6859
- single: false,
6860
- targetArg: "where"
6861
- }],
6862
- [updateManyGenerated, {
6863
- operation: "updateMany",
6864
- single: false,
6865
- targetArg: "updates"
6866
- }],
6867
- [updateSingleGenerated, {
6868
- operation: "update",
6869
- single: true,
6870
- targetArg: "where"
6871
- }],
6872
- [deleteGenerated, {
6873
- operation: "delete",
6874
- single: false,
6875
- targetArg: "where",
6876
- ...hardDeleteMeta
6877
- }],
6878
- [deleteSingleGenerated, {
6879
- operation: "delete",
6880
- single: true,
6881
- targetArg: "where",
6882
- ...hardDeleteMeta
6883
- }],
6884
- [restoreGenerated, {
6885
- operation: "restore",
6886
- single: false,
6887
- targetArg: "where"
6888
- }],
6889
- [restoreSingleGenerated, {
6890
- operation: "restore",
6891
- single: true,
6892
- targetArg: "where"
6893
- }]
6894
- ];
6895
- for (const [generated, meta] of generatedMutations) if (generated) defineRootField(mutations, "mutation", generated.name, {
6894
+ const withMeta = (generated, meta) => ({
6895
+ generated,
6896
6896
  type: mutationReturnType,
6897
- args: generated.args,
6898
- resolve: generated.resolver,
6899
- extensions: { drizzle: drizzleMeta({
6900
- kind: "mutation",
6901
- ...meta
6902
- }) }
6903
- });
6904
- if (updateCountGenerated) defineRootField(mutations, "mutation", updateCountGenerated.name, {
6905
- type: new GraphQLNonNull(GraphQLInt),
6906
- args: updateCountGenerated.args,
6907
- resolve: updateCountGenerated.resolver,
6908
- description: "How many rows the update touched. The rows themselves are not read back, which is the point of this mutation."
6909
- });
6910
- if (deleteCountGenerated) defineRootField(mutations, "mutation", deleteCountGenerated.name, {
6911
- type: new GraphQLNonNull(GraphQLInt),
6912
- args: deleteCountGenerated.args,
6913
- resolve: deleteCountGenerated.resolver,
6914
- description: "How many rows the delete removed. The rows themselves are not read back, which is the point of this mutation."
6897
+ meta
6915
6898
  });
6916
- [
6917
- ...tableFeatures.insert || onConflictInput ? [insertInput] : [],
6918
- ...onConflictInput ? [onConflictInput] : [],
6919
- ...tableFeatures.update ? [updateInput] : [],
6920
- ...updateManyInput ? [updateManyInput] : [],
6921
- tableFilters,
6922
- tableOrder
6923
- ].forEach((e) => {
6924
- inputs[e.name] = e;
6925
- });
6926
- outputs[selectSingleOutput.name] = selectSingleOutput;
6927
- if (aggregateType) outputs[aggregateType.name] = aggregateType;
6928
- if (groupByType && havingInput) {
6929
- outputs[groupByType.name] = groupByType;
6930
- inputs[havingInput.name] = havingInput;
6931
- }
6932
- }
6899
+ return {
6900
+ mutations: [
6901
+ withMeta(insertArrGenerated, {
6902
+ operation: "insert",
6903
+ single: false,
6904
+ targetArg: "values"
6905
+ }),
6906
+ withMeta(insertSingleGenerated, {
6907
+ operation: "insert",
6908
+ single: true,
6909
+ targetArg: "values"
6910
+ }),
6911
+ withMeta(upsertArrGenerated, {
6912
+ operation: "upsert",
6913
+ single: false,
6914
+ targetArg: "values"
6915
+ }),
6916
+ withMeta(upsertSingleGenerated, {
6917
+ operation: "upsert",
6918
+ single: true,
6919
+ targetArg: "values"
6920
+ }),
6921
+ withMeta(updateGenerated, {
6922
+ operation: "update",
6923
+ single: false,
6924
+ targetArg: "where"
6925
+ }),
6926
+ withMeta(updateManyGenerated, {
6927
+ operation: "updateMany",
6928
+ single: false,
6929
+ targetArg: "updates"
6930
+ }),
6931
+ withMeta(updateSingleGenerated, {
6932
+ operation: "update",
6933
+ single: true,
6934
+ targetArg: "where"
6935
+ }),
6936
+ withMeta(deleteGenerated, {
6937
+ operation: "delete",
6938
+ single: false,
6939
+ targetArg: "where",
6940
+ ...hardDeleteMeta
6941
+ }),
6942
+ withMeta(deleteSingleGenerated, {
6943
+ operation: "delete",
6944
+ single: true,
6945
+ targetArg: "where",
6946
+ ...hardDeleteMeta
6947
+ }),
6948
+ withMeta(restoreGenerated, {
6949
+ operation: "restore",
6950
+ single: false,
6951
+ targetArg: "where"
6952
+ }),
6953
+ withMeta(restoreSingleGenerated, {
6954
+ operation: "restore",
6955
+ single: true,
6956
+ targetArg: "where"
6957
+ }),
6958
+ {
6959
+ generated: updateCountGenerated,
6960
+ type: new GraphQLNonNull(GraphQLInt),
6961
+ description: "How many rows the update touched. The rows themselves are not read back, which is the point of this mutation."
6962
+ },
6963
+ {
6964
+ generated: deleteCountGenerated,
6965
+ type: new GraphQLNonNull(GraphQLInt),
6966
+ description: "How many rows the delete removed. The rows themselves are not read back, which is the point of this mutation."
6967
+ }
6968
+ ],
6969
+ onConflictInput,
6970
+ updateManyInput
6971
+ };
6972
+ });
6933
6973
  return finalizeBuild(ctx);
6934
6974
  };
6935
6975
  //#endregion
@@ -6939,26 +6979,36 @@ const generateSchemaData$2 = (db, schema, relations, options) => {
6939
6979
  * result, so the generator call sites read exactly as they did when the functions were local.
6940
6980
  */
6941
6981
  const buildWriteResolvers = (primaryKeyPropNames) => {
6942
- const generateInsertArray = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested, limits, policies, resolveName) => {
6943
- const queryArgs = { values: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(baseType))) } };
6982
+ /**
6983
+ * `insert<Table>` / `insert<Table>Single` — one generator for both shapes, the way
6984
+ * {@link generateUpsert} handles its pair. `single` decides the argument type, whether the
6985
+ * result is remapped as a row or a list, and whether an empty return is an error; the write
6986
+ * itself is the same multi-row statement either way, with the single variant supplying a
6987
+ * one-element list.
6988
+ */
6989
+ const generateInsert = (build, opts) => {
6990
+ const { db, tables, relationMap, typeNameMapper, txCtx, nested, limits, policies, resolveName } = build;
6991
+ const { tableName, table, baseType, fieldName, typeName, single, conflictDoNothing = false } = opts;
6992
+ const queryArgs = { values: { type: single ? new GraphQLNonNull(baseType) : new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(baseType))) } };
6944
6993
  const pkNames = primaryKeyPropNames(table);
6945
6994
  return writeResolver({
6946
6995
  db,
6947
6996
  tableName,
6948
6997
  operation: "insert",
6949
- single: false,
6998
+ single,
6950
6999
  fieldName,
6951
7000
  txCtx,
6952
7001
  policies,
6953
7002
  args: queryArgs,
6954
7003
  run: async ({ executor, args, context, info, before, after }) => {
6955
- if (!args.values.length) throw drizzleError("No values were provided!", { code: "DRIZZLE_NO_VALUES" });
7004
+ const supplied = single ? [args.values] : args.values;
7005
+ if (!supplied.length) throw drizzleError("No values were provided!", { code: "DRIZZLE_NO_VALUES" });
6956
7006
  await before();
6957
- const entries = nested?.enabled(tableName) ? args.values.map((values) => nested.split(tableName, values)) : void 0;
7007
+ const entries = nested?.enabled(tableName) ? supplied.map((values) => nested.split(tableName, values)) : void 0;
6958
7008
  const nestedEntries = entries?.some((entry) => nested.hasOps(entry.ops)) ? entries : void 0;
6959
7009
  const contextColumns = policies?.contextValues?.(tableName);
6960
7010
  const scope = policies?.scope?.(context);
6961
- const input = nestedEntries ? [] : applyContextValuesAll(remapFromGraphQLArrayInput(entries ? entries.map((entry) => entry.columns) : args.values, table), contextColumns, context);
7011
+ const input = nestedEntries ? [] : applyContextValuesAll(remapFromGraphQLArrayInput(entries ? entries.map((entry) => entry.columns) : supplied, table), contextColumns, context);
6962
7012
  const { columns, hasRelations, withParams } = mutationSelection(info, {
6963
7013
  relationMap,
6964
7014
  tables,
@@ -6988,65 +7038,12 @@ const buildWriteResolvers = (primaryKeyPropNames) => {
6988
7038
  context
6989
7039
  }) : await runInsert(executor, input);
6990
7040
  await after(result);
6991
- const enriched = await withEagerRelations(executor, tableName, result, pkNames, withParams, hasRelations);
6992
- return remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
6993
- }
6994
- });
6995
- };
6996
- const generateInsertSingle = (db, tableName, table, tables, relationMap, baseType, fieldName, typeName, typeNameMapper, conflictDoNothing = false, txCtx, nested, limits, policies, resolveName) => {
6997
- const queryArgs = { values: { type: new GraphQLNonNull(baseType) } };
6998
- const pkNames = primaryKeyPropNames(table);
6999
- return writeResolver({
7000
- db,
7001
- tableName,
7002
- operation: "insert",
7003
- single: true,
7004
- fieldName,
7005
- txCtx,
7006
- policies,
7007
- args: queryArgs,
7008
- run: async ({ executor, args, context, info, before, after }) => {
7009
- await before();
7010
- const entry = nested?.enabled(tableName) ? nested.split(tableName, args.values) : void 0;
7011
- const nestedEntry = entry && nested.hasOps(entry.ops) ? entry : void 0;
7012
- const contextColumns = policies?.contextValues?.(tableName);
7013
- const scope = policies?.scope?.(context);
7014
- const input = nestedEntry ? {} : applyContextValues(remapFromGraphQLSingleInput(entry ? entry.columns : args.values, table), contextColumns, context);
7015
- const { columns, hasRelations, withParams } = mutationSelection(info, {
7016
- relationMap,
7017
- tables,
7018
- tableName,
7019
- typeName,
7020
- typeNameMapper,
7021
- resolveName,
7022
- table,
7023
- pkNames,
7024
- limits,
7025
- scope,
7026
- defaultOrderBy: policies?.defaultOrderBy
7027
- });
7028
- const returning = nestedEntry ? nested.withJoinColumns(tableName, nestedEntry.ops, { ...columns }, table) : columns;
7029
- const runInsert = async (target, values) => {
7030
- let query = target.insert(table).values(values).returning(returning);
7031
- if (conflictDoNothing) query = query.onConflictDoNothing();
7032
- return await query;
7033
- };
7034
- const result = nestedEntry ? await writeWithNestedOps({
7035
- executor,
7036
- runtime: nested,
7037
- tableName,
7038
- entries: [nestedEntry],
7039
- remapValues: (values) => applyContextValues(remapFromGraphQLSingleInput(values, table), contextColumns, context),
7040
- write: runInsert,
7041
- context
7042
- }) : await runInsert(executor, input);
7043
- await after(result);
7044
- if (!result[0]) {
7041
+ if (single && !result[0]) {
7045
7042
  if (!conflictDoNothing) throw drizzleError("The insert returned no row.", { code: "DRIZZLE_NO_ROW_RETURNED" });
7046
7043
  return;
7047
7044
  }
7048
7045
  const enriched = await withEagerRelations(executor, tableName, result, pkNames, withParams, hasRelations);
7049
- return remapToGraphQLSingleOutput(enriched[0], tableName, table, relationMap);
7046
+ return single ? remapToGraphQLSingleOutput(enriched[0], tableName, table, relationMap) : remapToGraphQLArrayOutput(enriched, tableName, table, relationMap);
7050
7047
  }
7051
7048
  });
7052
7049
  };
@@ -7056,7 +7053,9 @@ const buildWriteResolvers = (primaryKeyPropNames) => {
7056
7053
  *
7057
7054
  * Shares the insert input: an upsert supplies a whole row, same as a create.
7058
7055
  */
7059
- const generateUpsert = (db, tableName, table, tables, relationMap, baseType, onConflictType, uniqueSets, fieldName, typeName, single, typeNameMapper, filterCtx, txCtx, nested, limits, policies, resolveName) => {
7056
+ const generateUpsert = (build, opts) => {
7057
+ const { db, tables, relationMap, typeNameMapper, filterCtx, txCtx, nested, limits, policies, resolveName } = build;
7058
+ const { tableName, table, baseType, onConflictType, uniqueSets, fieldName, typeName, single } = opts;
7060
7059
  const queryArgs = {
7061
7060
  values: { type: single ? new GraphQLNonNull(baseType) : new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(baseType))) },
7062
7061
  onConflict: {
@@ -7133,7 +7132,9 @@ const buildWriteResolvers = (primaryKeyPropNames) => {
7133
7132
  }
7134
7133
  });
7135
7134
  };
7136
- const generateUpdate = (db, tableName, table, tables, relationMap, setArgs, filterArgs, fieldName, typeName, single, requireWhere, typeNameMapper, filterCtx, txCtx, nested, limits, policies, resolveName) => {
7135
+ const generateUpdate = (build, opts) => {
7136
+ const { db, tables, relationMap, typeNameMapper, filterCtx, txCtx, nested, limits, policies, resolveName } = build;
7137
+ const { tableName, table, setArgs, filterArgs, fieldName, typeName, single, requireWhere } = opts;
7137
7138
  const queryArgs = {
7138
7139
  set: { type: new GraphQLNonNull(setArgs) },
7139
7140
  where: { type: single || requireWhere ? new GraphQLNonNull(filterArgs) : filterArgs }
@@ -7216,7 +7217,10 @@ const buildWriteResolvers = (primaryKeyPropNames) => {
7216
7217
  * `DELETE` — emptying the trash, reclaiming a unique key. It reads at `INCLUDE`, since the
7217
7218
  * rows it mostly exists to remove are the ones already marked; a `scope` still confines it.
7218
7219
  */
7219
- const generateDelete = (db, tableName, table, filterArgs, fieldName, typeName, single, requireWhere, filterCtx, selectionCtx, txCtx, policies, restore = false, resolveName) => {
7220
+ const generateDelete = (build, opts) => {
7221
+ const { db, filterCtx, txCtx, policies, resolveName } = build;
7222
+ const { tableName, table, filterArgs, fieldName, typeName, single, requireWhere, selectionCtx } = opts;
7223
+ const restore = opts.restore ?? false;
7220
7224
  const softDelete = policies?.softDelete?.(tableName);
7221
7225
  const operation = restore ? "restore" : "delete";
7222
7226
  const canHardDelete = !restore && softDelete?.hardDelete === true;
@@ -7263,8 +7267,7 @@ const buildWriteResolvers = (primaryKeyPropNames) => {
7263
7267
  });
7264
7268
  };
7265
7269
  return {
7266
- generateInsertArray,
7267
- generateInsertSingle,
7270
+ generateInsert,
7268
7271
  generateUpsert,
7269
7272
  generateUpdate,
7270
7273
  generateDelete
@@ -7281,23 +7284,46 @@ const buildWriteResolvers = (primaryKeyPropNames) => {
7281
7284
  const createSchemaDataGenerator = (adapter) => {
7282
7285
  const primaryKeyPropNames = adapter.primaryKeyPropNames;
7283
7286
  const uniqueColumnSets = (table) => getUniqueColumnSets(table, adapter.getTableConfig);
7284
- const { generateInsertArray, generateInsertSingle, generateUpsert, generateUpdate, generateDelete } = buildWriteResolvers(primaryKeyPropNames);
7285
- const { prepareBuild, addReadFields, finalizeBuild } = createSchemaBuilder(adapter);
7287
+ const { generateInsert, generateUpsert, generateUpdate, generateDelete } = buildWriteResolvers(primaryKeyPropNames);
7288
+ const { prepareBuild, forEachTable, finalizeBuild } = createSchemaBuilder(adapter);
7286
7289
  return (db, schema, relations, options) => {
7287
- const { prefixes, suffixes, conflictDoNothing, typeNameMapper, limits } = options;
7290
+ const { prefixes, conflictDoNothing, typeNameMapper, limits } = options;
7288
7291
  const ctx = prepareBuild(db, schema, relations, options);
7289
- const { tables, featureOf, eagerRelations, filterCtx, policies, softDeleteOf, namedRelations, cacheCtx, nestedRuntime, mutationTxCtx, gqlSchemaTypes, mutations, inputs, outputs } = ctx;
7290
- for (const [tableName, tableTypes] of Object.entries(gqlSchemaTypes)) {
7291
- const tableFeatures = featureOf(tableName);
7292
- const drizzleMeta = tableFieldExtensions(tableName, primaryKeyPropNames(schema[tableName]));
7293
- const { insertInput, updateInput, tableFilters, tableOrder } = tableTypes.inputs;
7294
- const { selectSingleOutput, singleTableItemOutput, arrTableItemOutput } = tableTypes.outputs;
7295
- const names = computeResolverFieldNames(tableName, typeNameMapper, prefixes, suffixes);
7292
+ const { tables, eagerRelations, filterCtx, policies, namedRelations, cacheCtx, nestedRuntime, mutationTxCtx } = ctx;
7293
+ const writeBuild = {
7294
+ db,
7295
+ tables,
7296
+ relationMap: eagerRelations,
7297
+ typeNameMapper,
7298
+ filterCtx,
7299
+ txCtx: mutationTxCtx,
7300
+ nested: nestedRuntime,
7301
+ limits,
7302
+ policies,
7303
+ resolveName: cacheCtx.typeName
7304
+ };
7305
+ forEachTable(ctx, ({ tableName, tableFeatures, names, types, softDeleteInfo }) => {
7306
+ const { insertInput, updateInput, tableFilters } = types.inputs;
7307
+ const { singleTableItemOutput, arrTableItemOutput } = types.outputs;
7296
7308
  const { typeName, createArrayFieldName, createSingleFieldName, upsertArrayFieldName, upsertSingleFieldName, updateFieldName, updateManyFieldName, updateSingleFieldName, updateCountFieldName, deleteFieldName, deleteSingleFieldName, restoreFieldName, restoreSingleFieldName, deleteCountFieldName } = names;
7297
- const softDeleteInfo = softDeleteOf?.(tableName);
7298
- const { aggregateType, groupByType, havingInput } = addReadFields(ctx, tableName, names, tableTypes, drizzleMeta);
7299
- const insertArrGenerated = tableFeatures.insert ? generateInsertArray(db, tableName, schema[tableName], tables, eagerRelations, insertInput, createArrayFieldName, typeName, typeNameMapper, conflictDoNothing, mutationTxCtx, nestedRuntime, limits, policies, cacheCtx.typeName) : void 0;
7300
- const insertSingleGenerated = tableFeatures.insert ? generateInsertSingle(db, tableName, schema[tableName], tables, eagerRelations, insertInput, createSingleFieldName, typeName, typeNameMapper, conflictDoNothing, mutationTxCtx, nestedRuntime, limits, policies, cacheCtx.typeName) : void 0;
7309
+ const insertArrGenerated = tableFeatures.insert ? generateInsert(writeBuild, {
7310
+ tableName,
7311
+ table: schema[tableName],
7312
+ baseType: insertInput,
7313
+ fieldName: createArrayFieldName,
7314
+ typeName,
7315
+ single: false,
7316
+ conflictDoNothing
7317
+ }) : void 0;
7318
+ const insertSingleGenerated = tableFeatures.insert ? generateInsert(writeBuild, {
7319
+ tableName,
7320
+ table: schema[tableName],
7321
+ baseType: insertInput,
7322
+ fieldName: createSingleFieldName,
7323
+ typeName,
7324
+ single: true,
7325
+ conflictDoNothing
7326
+ }) : void 0;
7301
7327
  const uniqueSets = tableFeatures.upsert ? uniqueColumnSets(schema[tableName]) : [];
7302
7328
  const onConflictInput = tableFeatures.upsert ? generateOnConflictInput({
7303
7329
  table: schema[tableName],
@@ -7308,10 +7334,46 @@ const createSchemaDataGenerator = (adapter) => {
7308
7334
  withTarget: true,
7309
7335
  cacheCtx
7310
7336
  }) : void 0;
7311
- const upsertArrGenerated = onConflictInput ? generateUpsert(db, tableName, schema[tableName], tables, eagerRelations, insertInput, onConflictInput, uniqueSets, upsertArrayFieldName, typeName, false, typeNameMapper, filterCtx, mutationTxCtx, nestedRuntime, limits, policies, cacheCtx.typeName) : void 0;
7312
- const upsertSingleGenerated = onConflictInput ? generateUpsert(db, tableName, schema[tableName], tables, eagerRelations, insertInput, onConflictInput, uniqueSets, upsertSingleFieldName, typeName, true, typeNameMapper, filterCtx, mutationTxCtx, nestedRuntime, limits, policies, cacheCtx.typeName) : void 0;
7313
- const updateGenerated = tableFeatures.update ? generateUpdate(db, tableName, schema[tableName], tables, eagerRelations, updateInput, tableFilters, updateFieldName, typeName, false, tableFeatures.requireWhere, typeNameMapper, filterCtx, mutationTxCtx, nestedRuntime, limits, policies, cacheCtx.typeName) : void 0;
7314
- const updateSingleGenerated = tableFeatures.update ? generateUpdate(db, tableName, schema[tableName], tables, eagerRelations, updateInput, tableFilters, updateSingleFieldName, typeName, true, tableFeatures.requireWhere, typeNameMapper, filterCtx, mutationTxCtx, nestedRuntime, limits, policies, cacheCtx.typeName) : void 0;
7337
+ const upsertArrGenerated = onConflictInput ? generateUpsert(writeBuild, {
7338
+ tableName,
7339
+ table: schema[tableName],
7340
+ baseType: insertInput,
7341
+ onConflictType: onConflictInput,
7342
+ uniqueSets,
7343
+ fieldName: upsertArrayFieldName,
7344
+ typeName,
7345
+ single: false
7346
+ }) : void 0;
7347
+ const upsertSingleGenerated = onConflictInput ? generateUpsert(writeBuild, {
7348
+ tableName,
7349
+ table: schema[tableName],
7350
+ baseType: insertInput,
7351
+ onConflictType: onConflictInput,
7352
+ uniqueSets,
7353
+ fieldName: upsertSingleFieldName,
7354
+ typeName,
7355
+ single: true
7356
+ }) : void 0;
7357
+ const updateGenerated = tableFeatures.update ? generateUpdate(writeBuild, {
7358
+ tableName,
7359
+ table: schema[tableName],
7360
+ setArgs: updateInput,
7361
+ filterArgs: tableFilters,
7362
+ fieldName: updateFieldName,
7363
+ typeName,
7364
+ single: false,
7365
+ requireWhere: tableFeatures.requireWhere
7366
+ }) : void 0;
7367
+ const updateSingleGenerated = tableFeatures.update ? generateUpdate(writeBuild, {
7368
+ tableName,
7369
+ table: schema[tableName],
7370
+ setArgs: updateInput,
7371
+ filterArgs: tableFilters,
7372
+ fieldName: updateSingleFieldName,
7373
+ typeName,
7374
+ single: true,
7375
+ requireWhere: tableFeatures.requireWhere
7376
+ }) : void 0;
7315
7377
  const updateManyInput = tableFeatures.update && tableFeatures.updateMany ? generateUpdateManyInput({
7316
7378
  tableName,
7317
7379
  typeName,
@@ -7320,27 +7382,73 @@ const createSchemaDataGenerator = (adapter) => {
7320
7382
  tableFilters,
7321
7383
  cacheCtx
7322
7384
  }) : void 0;
7323
- const updateManyGenerated = updateManyInput ? adapter.generateUpdateMany(db, tableName, schema[tableName], tables, eagerRelations, updateManyInput, updateManyFieldName, typeName, typeNameMapper, filterCtx, mutationTxCtx, nestedRuntime, limits, policies, cacheCtx.typeName) : void 0;
7324
- const deleteGenerated = tableFeatures.delete ? generateDelete(db, tableName, schema[tableName], tableFilters, deleteFieldName, typeName, false, tableFeatures.requireWhere, filterCtx, {
7385
+ const updateManyGenerated = updateManyInput ? adapter.generateUpdateMany(writeBuild, {
7325
7386
  tableName,
7326
- relationMap: namedRelations,
7327
- tables
7328
- }, mutationTxCtx, policies, false, cacheCtx.typeName) : void 0;
7329
- const deleteSingleGenerated = tableFeatures.delete ? generateDelete(db, tableName, schema[tableName], tableFilters, deleteSingleFieldName, typeName, true, tableFeatures.requireWhere, filterCtx, {
7387
+ table: schema[tableName],
7388
+ updateManyInput,
7389
+ fieldName: updateManyFieldName,
7390
+ typeName
7391
+ }) : void 0;
7392
+ const deleteGenerated = tableFeatures.delete ? generateDelete(writeBuild, {
7393
+ tableName,
7394
+ table: schema[tableName],
7395
+ filterArgs: tableFilters,
7396
+ fieldName: deleteFieldName,
7397
+ typeName,
7398
+ single: false,
7399
+ requireWhere: tableFeatures.requireWhere,
7400
+ restore: false,
7401
+ selectionCtx: {
7402
+ tableName,
7403
+ relationMap: namedRelations,
7404
+ tables
7405
+ }
7406
+ }) : void 0;
7407
+ const deleteSingleGenerated = tableFeatures.delete ? generateDelete(writeBuild, {
7330
7408
  tableName,
7331
- relationMap: namedRelations,
7332
- tables
7333
- }, mutationTxCtx, policies, false, cacheCtx.typeName) : void 0;
7334
- const restoreGenerated = softDeleteInfo ? generateDelete(db, tableName, schema[tableName], tableFilters, restoreFieldName, typeName, false, tableFeatures.requireWhere, filterCtx, {
7409
+ table: schema[tableName],
7410
+ filterArgs: tableFilters,
7411
+ fieldName: deleteSingleFieldName,
7412
+ typeName,
7413
+ single: true,
7414
+ requireWhere: tableFeatures.requireWhere,
7415
+ restore: false,
7416
+ selectionCtx: {
7417
+ tableName,
7418
+ relationMap: namedRelations,
7419
+ tables
7420
+ }
7421
+ }) : void 0;
7422
+ const restoreGenerated = softDeleteInfo ? generateDelete(writeBuild, {
7335
7423
  tableName,
7336
- relationMap: namedRelations,
7337
- tables
7338
- }, mutationTxCtx, policies, true, cacheCtx.typeName) : void 0;
7339
- const restoreSingleGenerated = softDeleteInfo ? generateDelete(db, tableName, schema[tableName], tableFilters, restoreSingleFieldName, typeName, true, tableFeatures.requireWhere, filterCtx, {
7424
+ table: schema[tableName],
7425
+ filterArgs: tableFilters,
7426
+ fieldName: restoreFieldName,
7427
+ typeName,
7428
+ single: false,
7429
+ requireWhere: tableFeatures.requireWhere,
7430
+ restore: true,
7431
+ selectionCtx: {
7432
+ tableName,
7433
+ relationMap: namedRelations,
7434
+ tables
7435
+ }
7436
+ }) : void 0;
7437
+ const restoreSingleGenerated = softDeleteInfo ? generateDelete(writeBuild, {
7340
7438
  tableName,
7341
- relationMap: namedRelations,
7342
- tables
7343
- }, mutationTxCtx, policies, true, cacheCtx.typeName) : void 0;
7439
+ table: schema[tableName],
7440
+ filterArgs: tableFilters,
7441
+ fieldName: restoreSingleFieldName,
7442
+ typeName,
7443
+ single: true,
7444
+ requireWhere: tableFeatures.requireWhere,
7445
+ restore: true,
7446
+ selectionCtx: {
7447
+ tableName,
7448
+ relationMap: namedRelations,
7449
+ tables
7450
+ }
7451
+ }) : void 0;
7344
7452
  const updateCountGenerated = tableFeatures.update && tableFeatures.countMutations ? generateWriteCount({
7345
7453
  db,
7346
7454
  tableName,
@@ -7365,160 +7473,126 @@ const createSchemaDataGenerator = (adapter) => {
7365
7473
  filterCtx,
7366
7474
  txCtx: mutationTxCtx
7367
7475
  }) : void 0;
7368
- if (insertArrGenerated) defineRootField(mutations, "mutation", insertArrGenerated.name, {
7369
- type: arrTableItemOutput,
7370
- args: insertArrGenerated.args,
7371
- resolve: insertArrGenerated.resolver,
7372
- extensions: { drizzle: drizzleMeta({
7373
- kind: "mutation",
7374
- operation: "insert",
7375
- single: false,
7376
- targetArg: "values"
7377
- }) }
7378
- });
7379
- if (insertSingleGenerated) defineRootField(mutations, "mutation", insertSingleGenerated.name, {
7380
- type: conflictDoNothing ? singleTableItemOutput : new GraphQLNonNull(singleTableItemOutput),
7381
- args: insertSingleGenerated.args,
7382
- resolve: insertSingleGenerated.resolver,
7383
- extensions: { drizzle: drizzleMeta({
7384
- kind: "mutation",
7385
- operation: "insert",
7386
- single: true,
7387
- targetArg: "values"
7388
- }) }
7389
- });
7390
- if (upsertArrGenerated) defineRootField(mutations, "mutation", upsertArrGenerated.name, {
7391
- type: arrTableItemOutput,
7392
- args: upsertArrGenerated.args,
7393
- resolve: upsertArrGenerated.resolver,
7394
- extensions: { drizzle: drizzleMeta({
7395
- kind: "mutation",
7396
- operation: "upsert",
7397
- single: false,
7398
- targetArg: "values"
7399
- }) }
7400
- });
7401
- if (upsertSingleGenerated) defineRootField(mutations, "mutation", upsertSingleGenerated.name, {
7402
- type: singleTableItemOutput,
7403
- args: upsertSingleGenerated.args,
7404
- resolve: upsertSingleGenerated.resolver,
7405
- extensions: { drizzle: drizzleMeta({
7406
- kind: "mutation",
7407
- operation: "upsert",
7408
- single: true,
7409
- targetArg: "values"
7410
- }) }
7411
- });
7412
- if (updateGenerated) defineRootField(mutations, "mutation", updateGenerated.name, {
7413
- type: arrTableItemOutput,
7414
- args: updateGenerated.args,
7415
- resolve: updateGenerated.resolver,
7416
- extensions: { drizzle: drizzleMeta({
7417
- kind: "mutation",
7418
- operation: "update",
7419
- single: false,
7420
- targetArg: "where"
7421
- }) }
7422
- });
7423
- if (updateManyGenerated) defineRootField(mutations, "mutation", updateManyGenerated.name, {
7424
- type: new GraphQLNonNull(new GraphQLList(singleTableItemOutput)),
7425
- args: updateManyGenerated.args,
7426
- resolve: updateManyGenerated.resolver,
7427
- extensions: { drizzle: drizzleMeta({
7428
- kind: "mutation",
7429
- operation: "updateMany",
7430
- single: false,
7431
- targetArg: "updates"
7432
- }) },
7433
- 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."
7434
- });
7435
- if (updateSingleGenerated) defineRootField(mutations, "mutation", updateSingleGenerated.name, {
7436
- type: singleTableItemOutput,
7437
- args: updateSingleGenerated.args,
7438
- resolve: updateSingleGenerated.resolver,
7439
- extensions: { drizzle: drizzleMeta({
7440
- kind: "mutation",
7441
- operation: "update",
7442
- single: true,
7443
- targetArg: "where"
7444
- }) }
7445
- });
7446
- if (deleteGenerated) defineRootField(mutations, "mutation", deleteGenerated.name, {
7447
- type: arrTableItemOutput,
7448
- args: deleteGenerated.args,
7449
- resolve: deleteGenerated.resolver,
7450
- extensions: { drizzle: drizzleMeta({
7451
- kind: "mutation",
7452
- operation: "delete",
7453
- single: false,
7454
- targetArg: "where",
7455
- ...softDeleteInfo?.hardDelete ? { hardDelete: true } : {}
7456
- }) }
7457
- });
7458
- if (deleteSingleGenerated) defineRootField(mutations, "mutation", deleteSingleGenerated.name, {
7459
- type: singleTableItemOutput,
7460
- args: deleteSingleGenerated.args,
7461
- resolve: deleteSingleGenerated.resolver,
7462
- extensions: { drizzle: drizzleMeta({
7463
- kind: "mutation",
7464
- operation: "delete",
7465
- single: true,
7466
- targetArg: "where",
7467
- ...softDeleteInfo?.hardDelete ? { hardDelete: true } : {}
7468
- }) }
7469
- });
7470
- if (restoreGenerated) defineRootField(mutations, "mutation", restoreGenerated.name, {
7471
- type: arrTableItemOutput,
7472
- args: restoreGenerated.args,
7473
- resolve: restoreGenerated.resolver,
7474
- extensions: { drizzle: drizzleMeta({
7475
- kind: "mutation",
7476
- operation: "restore",
7477
- single: false,
7478
- targetArg: "where"
7479
- }) }
7480
- });
7481
- if (restoreSingleGenerated) defineRootField(mutations, "mutation", restoreSingleGenerated.name, {
7482
- type: singleTableItemOutput,
7483
- args: restoreSingleGenerated.args,
7484
- resolve: restoreSingleGenerated.resolver,
7485
- extensions: { drizzle: drizzleMeta({
7486
- kind: "mutation",
7487
- operation: "restore",
7488
- single: true,
7489
- targetArg: "where"
7490
- }) }
7491
- });
7492
- if (updateCountGenerated) defineRootField(mutations, "mutation", updateCountGenerated.name, {
7493
- type: new GraphQLNonNull(GraphQLInt),
7494
- args: updateCountGenerated.args,
7495
- resolve: updateCountGenerated.resolver,
7496
- description: "How many rows the update touched. The rows themselves are not read back, which is the point of this mutation."
7497
- });
7498
- if (deleteCountGenerated) defineRootField(mutations, "mutation", deleteCountGenerated.name, {
7499
- type: new GraphQLNonNull(GraphQLInt),
7500
- args: deleteCountGenerated.args,
7501
- resolve: deleteCountGenerated.resolver,
7502
- description: "How many rows the delete removed. The rows themselves are not read back, which is the point of this mutation."
7503
- });
7504
- [
7505
- ...tableFeatures.insert || onConflictInput ? [insertInput] : [],
7506
- ...onConflictInput ? [onConflictInput] : [],
7507
- ...tableFeatures.update ? [updateInput] : [],
7508
- ...updateManyInput ? [updateManyInput] : [],
7509
- tableFilters,
7510
- tableOrder
7511
- ].forEach((e) => {
7512
- inputs[e.name] = e;
7513
- });
7514
- outputs[selectSingleOutput.name] = selectSingleOutput;
7515
- outputs[singleTableItemOutput.name] = singleTableItemOutput;
7516
- if (aggregateType) outputs[aggregateType.name] = aggregateType;
7517
- if (groupByType && havingInput) {
7518
- outputs[groupByType.name] = groupByType;
7519
- inputs[havingInput.name] = havingInput;
7520
- }
7521
- }
7476
+ const hardDeleteMeta = softDeleteInfo?.hardDelete ? { hardDelete: true } : {};
7477
+ return {
7478
+ mutations: [
7479
+ {
7480
+ generated: insertArrGenerated,
7481
+ type: arrTableItemOutput,
7482
+ meta: {
7483
+ operation: "insert",
7484
+ single: false,
7485
+ targetArg: "values"
7486
+ }
7487
+ },
7488
+ {
7489
+ generated: insertSingleGenerated,
7490
+ type: conflictDoNothing ? singleTableItemOutput : new GraphQLNonNull(singleTableItemOutput),
7491
+ meta: {
7492
+ operation: "insert",
7493
+ single: true,
7494
+ targetArg: "values"
7495
+ }
7496
+ },
7497
+ {
7498
+ generated: upsertArrGenerated,
7499
+ type: arrTableItemOutput,
7500
+ meta: {
7501
+ operation: "upsert",
7502
+ single: false,
7503
+ targetArg: "values"
7504
+ }
7505
+ },
7506
+ {
7507
+ generated: upsertSingleGenerated,
7508
+ type: singleTableItemOutput,
7509
+ meta: {
7510
+ operation: "upsert",
7511
+ single: true,
7512
+ targetArg: "values"
7513
+ }
7514
+ },
7515
+ {
7516
+ generated: updateGenerated,
7517
+ type: arrTableItemOutput,
7518
+ meta: {
7519
+ operation: "update",
7520
+ single: false,
7521
+ targetArg: "where"
7522
+ }
7523
+ },
7524
+ {
7525
+ generated: updateManyGenerated,
7526
+ type: new GraphQLNonNull(new GraphQLList(singleTableItemOutput)),
7527
+ meta: {
7528
+ operation: "updateMany",
7529
+ single: false,
7530
+ targetArg: "updates"
7531
+ },
7532
+ 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."
7533
+ },
7534
+ {
7535
+ generated: updateSingleGenerated,
7536
+ type: singleTableItemOutput,
7537
+ meta: {
7538
+ operation: "update",
7539
+ single: true,
7540
+ targetArg: "where"
7541
+ }
7542
+ },
7543
+ {
7544
+ generated: deleteGenerated,
7545
+ type: arrTableItemOutput,
7546
+ meta: {
7547
+ operation: "delete",
7548
+ single: false,
7549
+ targetArg: "where",
7550
+ ...hardDeleteMeta
7551
+ }
7552
+ },
7553
+ {
7554
+ generated: deleteSingleGenerated,
7555
+ type: singleTableItemOutput,
7556
+ meta: {
7557
+ operation: "delete",
7558
+ single: true,
7559
+ targetArg: "where",
7560
+ ...hardDeleteMeta
7561
+ }
7562
+ },
7563
+ {
7564
+ generated: restoreGenerated,
7565
+ type: arrTableItemOutput,
7566
+ meta: {
7567
+ operation: "restore",
7568
+ single: false,
7569
+ targetArg: "where"
7570
+ }
7571
+ },
7572
+ {
7573
+ generated: restoreSingleGenerated,
7574
+ type: singleTableItemOutput,
7575
+ meta: {
7576
+ operation: "restore",
7577
+ single: true,
7578
+ targetArg: "where"
7579
+ }
7580
+ },
7581
+ {
7582
+ generated: updateCountGenerated,
7583
+ type: new GraphQLNonNull(GraphQLInt),
7584
+ description: "How many rows the update touched. The rows themselves are not read back, which is the point of this mutation."
7585
+ },
7586
+ {
7587
+ generated: deleteCountGenerated,
7588
+ type: new GraphQLNonNull(GraphQLInt),
7589
+ description: "How many rows the delete removed. The rows themselves are not read back, which is the point of this mutation."
7590
+ }
7591
+ ],
7592
+ onConflictInput,
7593
+ updateManyInput
7594
+ };
7595
+ });
7522
7596
  return finalizeBuild(ctx);
7523
7597
  };
7524
7598
  };
@@ -7560,7 +7634,9 @@ const runUpdateManyBatch = ({ executor, entries, table, returning, nested, table
7560
7634
  * @param runBatch how the entries execute; defaults to {@link runUpdateManyBatch}
7561
7635
  */
7562
7636
  const createUpdateManyGenerator = (primaryKeyPropNames, runBatch = runUpdateManyBatch) => {
7563
- return (db, tableName, table, tables, relationMap, updateManyInput, fieldName, typeName, typeNameMapper, filterCtx, txCtx, nested, limits, policies, resolveName) => {
7637
+ return (build, opts) => {
7638
+ const { db, tables, relationMap, typeNameMapper, filterCtx, txCtx, nested, limits, policies, resolveName } = build;
7639
+ const { tableName, table, updateManyInput, fieldName, typeName } = opts;
7564
7640
  const queryArgs = { updates: { type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(updateManyInput))) } };
7565
7641
  const pkNames = primaryKeyPropNames(table);
7566
7642
  return writeResolver({
@@ -7603,11 +7679,12 @@ const createUpdateManyGenerator = (primaryKeyPropNames, runBatch = runUpdateMany
7603
7679
  };
7604
7680
  });
7605
7681
  const anyNested = entries.some((entry) => entry.ops);
7682
+ const returning = anyNested ? nested.withJoinColumns(tableName, mergedOps(entries.map((entry) => ({ ops: entry.ops ?? {} }))), { ...columns }, table) : columns;
7606
7683
  const perEntry = await runBatch({
7607
7684
  executor,
7608
7685
  entries,
7609
7686
  table,
7610
- returning: anyNested ? nested.withJoinColumns(tableName, mergedOps(entries.map((entry) => ({ ops: entry.ops ?? {} }))), { ...columns }, table) : columns,
7687
+ returning,
7611
7688
  anyNested,
7612
7689
  nested,
7613
7690
  tableName,