@vantreeseba/drizzle-graphql 13.1.0 → 14.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +106 -7
- package/dist/index.cjs +547 -268
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +86 -8
- package/dist/index.d.ts +86 -8
- package/dist/index.js +547 -268
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -337,6 +337,13 @@ type DrizzleFieldExtension = {
|
|
|
337
337
|
* Absent everywhere else, so a wrapper can gate purging without parsing arguments.
|
|
338
338
|
*/
|
|
339
339
|
hardDelete?: boolean;
|
|
340
|
+
/**
|
|
341
|
+
* `true` on the count mutations (`update<Table>Count` / `delete<Table>Count`,
|
|
342
|
+
* `features.countMutations`): the field writes like its plural `update` / `delete` sibling
|
|
343
|
+
* — same `operation`, same rows — but resolves to how many rows it wrote (`Int!`) rather
|
|
344
|
+
* than to the rows. Absent everywhere else.
|
|
345
|
+
*/
|
|
346
|
+
count?: boolean;
|
|
340
347
|
/** For `kind: 'relation'` and `operation: 'relationAggregate'`: the relation's name. */
|
|
341
348
|
relation?: string;
|
|
342
349
|
/** For `kind: 'relation'` and `operation: 'relationAggregate'`: the table it hangs off. */
|
|
@@ -804,17 +811,50 @@ declare const extractFilters: <TTable extends Table>(table: TTable, tableName: s
|
|
|
804
811
|
//#region src/util/builders/common/write-hooks.d.ts
|
|
805
812
|
/** The write a hook is attached to. `restore` only exists for a soft-deleting table. */
|
|
806
813
|
type WriteOperation = 'insert' | 'update' | 'updateMany' | 'upsert' | 'delete' | 'restore';
|
|
814
|
+
/** Which input of a relation field a nested write came from. */
|
|
815
|
+
type NestedWriteOp = 'create' | 'connect' | 'disconnect' | 'set';
|
|
816
|
+
/**
|
|
817
|
+
* Where a nested write came from: set on the payload of a hook that fires for a row a nested
|
|
818
|
+
* `create` / `connect` / `disconnect` / `set` wrote, and absent at the mutation field's own
|
|
819
|
+
* table. See {@link WriteHookPayload.nested}.
|
|
820
|
+
*/
|
|
821
|
+
type NestedWriteOrigin = {
|
|
822
|
+
/** Drizzle schema key of the table whose input carried the relation field. */
|
|
823
|
+
parentTable: string;
|
|
824
|
+
/** The relation field the write went through, as named on the parent table. */
|
|
825
|
+
relation: string;
|
|
826
|
+
/** The relation field's input that produced this statement. */
|
|
827
|
+
op: NestedWriteOp;
|
|
828
|
+
};
|
|
807
829
|
/** What a write hook is handed. See {@link BuildSchemaConfig.onWrite}. */
|
|
808
830
|
type WriteHookPayload = {
|
|
809
831
|
/** Drizzle schema key of the table being written. */
|
|
810
832
|
table: string;
|
|
833
|
+
/**
|
|
834
|
+
* What happened to `table`. A nested write reports what its statement did to *that* table:
|
|
835
|
+
* `insert` for a nested `create`, `update` for a `connect` / `disconnect` / `set` that
|
|
836
|
+
* changes the foreign key on the target, and `insert` / `delete` on the junction table for
|
|
837
|
+
* a many-to-many link / unlink.
|
|
838
|
+
*/
|
|
811
839
|
operation: WriteOperation;
|
|
812
840
|
/** `'before'` runs ahead of the statement, `'after'` once it has returned. */
|
|
813
841
|
position: 'before' | 'after';
|
|
814
|
-
/**
|
|
842
|
+
/**
|
|
843
|
+
* Whether the field writes a single row (`createUsersSingle`) or a list. For a nested
|
|
844
|
+
* write, whether the relation it went through is a to-one.
|
|
845
|
+
*/
|
|
815
846
|
single: boolean;
|
|
816
|
-
/**
|
|
847
|
+
/**
|
|
848
|
+
* The field's GraphQL arguments, exactly as the resolver received them — for a nested
|
|
849
|
+
* write, the arguments of the root mutation field it is part of.
|
|
850
|
+
*/
|
|
817
851
|
args: any;
|
|
852
|
+
/**
|
|
853
|
+
* Set when the rows were written by a nested write under another table's mutation, and
|
|
854
|
+
* `undefined` for the mutation field's own table. A hook that only cares about root writes
|
|
855
|
+
* skips the rest with `if (payload.nested) return;`.
|
|
856
|
+
*/
|
|
857
|
+
nested?: NestedWriteOrigin;
|
|
818
858
|
/**
|
|
819
859
|
* The rows the write produced, as the database returned them — before the output mapper,
|
|
820
860
|
* so values are database-shaped. Empty at the `before` position, and on MySQL, whose
|
|
@@ -822,7 +862,11 @@ type WriteHookPayload = {
|
|
|
822
862
|
*
|
|
823
863
|
* Each row holds the columns the client's selection asked for (plus any key a relation or
|
|
824
864
|
* nested write needed), **and** every column the hook names in `columns`. A column the
|
|
825
|
-
* client did not select and the hook did not name is absent.
|
|
865
|
+
* client did not select and the hook did not name is absent. The count mutations select
|
|
866
|
+
* nothing, so there a row holds the named columns, or the primary key when none are named.
|
|
867
|
+
*
|
|
868
|
+
* A nested write has no selection of its own, so its rows hold the table's primary key and
|
|
869
|
+
* the join column(s) the write changed, plus the hook's `columns`.
|
|
826
870
|
*/
|
|
827
871
|
rows: any[];
|
|
828
872
|
context: any;
|
|
@@ -1441,8 +1485,8 @@ type SchemaFeatures = {
|
|
|
1441
1485
|
* columns only.
|
|
1442
1486
|
*
|
|
1443
1487
|
* A many-to-many (`.through()`) relation is written as junction rows: `connect` on the
|
|
1444
|
-
* create input, and `connect` / `disconnect` / `set` on the update input,
|
|
1445
|
-
*
|
|
1488
|
+
* create input, and `connect` / `disconnect` / `set` on the update input, whatever the
|
|
1489
|
+
* columns' nullability, since unlinking deletes a junction row rather than nulling a column.
|
|
1446
1490
|
* It offers no `create` — inserting a row and linking it are two writes to two tables —
|
|
1447
1491
|
* and `set: []` clears the relation.
|
|
1448
1492
|
*
|
|
@@ -1451,6 +1495,21 @@ type SchemaFeatures = {
|
|
|
1451
1495
|
* offered) becomes nullable on the create input, since the relation is the other way to
|
|
1452
1496
|
* supply it.
|
|
1453
1497
|
*
|
|
1498
|
+
* A nested write follows the rules of the table it writes:
|
|
1499
|
+
*
|
|
1500
|
+
* - **`features`** — each input is generated only when that table has the write it needs:
|
|
1501
|
+
* `create` needs the target's `insert` (plus its `update` on a to-one whose nullable key
|
|
1502
|
+
* lives on the target, since attaching detaches the previous row); a `connect` /
|
|
1503
|
+
* `disconnect` / `set` that moves the target's foreign key needs its `update`; a
|
|
1504
|
+
* parent-side `connect` / `disconnect` needs nothing of the target. Many-to-many inputs
|
|
1505
|
+
* need the junction's `insert` (`connect`), `delete` (`disconnect`) or both (`set`), and
|
|
1506
|
+
* an excluded junction removes them. What is left out is noted on the console, and a
|
|
1507
|
+
* relation left with no input loses its field.
|
|
1508
|
+
* - **`onWrite`** — the hooks of the table a nested statement writes fire on the same `tx`,
|
|
1509
|
+
* with `payload.nested` set. See {@link BuildSchemaConfig.onWrite}.
|
|
1510
|
+
* - **`scope`** and **`contextValues`** — `connect` / `disconnect` / `set` reach only
|
|
1511
|
+
* in-scope rows, and a nested `create` is stamped like any insert.
|
|
1512
|
+
*
|
|
1454
1513
|
* PostgreSQL and SQLite only. MySQL cannot return the rows it just wrote, which is how a
|
|
1455
1514
|
* nested write learns the parent's key, so `buildSchema` rejects the flag there. On SQLite
|
|
1456
1515
|
* the driver must be asynchronous (libsql, D1, …): a synchronous one commits before an
|
|
@@ -1499,6 +1558,17 @@ type SchemaFeatures = {
|
|
|
1499
1558
|
* for nothing. Each mutation is generated only when its plural counterpart is
|
|
1500
1559
|
* (`features.update` / `features.delete`), and honours `features.requireWhere`.
|
|
1501
1560
|
*
|
|
1561
|
+
* Apart from the answer, they obey every rule the plural write does: the table's `scope`
|
|
1562
|
+
* is ANDed into the `where`; on a `softDelete` table the delete marks rows instead of
|
|
1563
|
+
* removing them (taking `hard` where the plural delete does) and neither mutation reaches
|
|
1564
|
+
* an already-marked row; `contextValues` columns are never reassigned by the update; and
|
|
1565
|
+
* `onWrite` hooks run `before` and `after`, in a transaction, with the plural payload
|
|
1566
|
+
* (`single: false`). An `after` hook needs rows, so on a table with one the write adds a
|
|
1567
|
+
* `RETURNING` of the hook's `columns` — or of the primary key if it names none (every column
|
|
1568
|
+
* on a table without one) — and the count is the number of rows returned. On MySQL, which has
|
|
1569
|
+
* no `RETURNING`, the hook gets `rows: []` as on every MySQL mutation. Their
|
|
1570
|
+
* `extensions.drizzle` carries the plural write's `operation` plus `count: true`.
|
|
1571
|
+
*
|
|
1502
1572
|
* Off unless asked for, so an existing schema does not grow new mutations on upgrade.
|
|
1503
1573
|
*
|
|
1504
1574
|
* @default false
|
|
@@ -2103,8 +2173,16 @@ type BuildSchemaConfig = {
|
|
|
2103
2173
|
* is unchanged. An unknown column, or `columns` with no `after` hook, fails the build; on
|
|
2104
2174
|
* a top-level registration a named column must exist on every table. MySQL returns no
|
|
2105
2175
|
* rows, so `columns` has no effect there.
|
|
2106
|
-
* -
|
|
2107
|
-
*
|
|
2176
|
+
* - **With `nestedWrites`, a nested statement fires the hooks of the table it writes**, on
|
|
2177
|
+
* the same `tx`, once per relation input and operation (not per row): `insert` for a
|
|
2178
|
+
* nested `create`; `update` for a `connect` / `disconnect` / `set` that moves the
|
|
2179
|
+
* target's foreign key; `insert` / `delete` on the junction table for a many-to-many
|
|
2180
|
+
* link / unlink (`set` is both). A parent-side `connect` / `disconnect` writes only the
|
|
2181
|
+
* parent's own row, so only the parent's hook sees it. `payload.nested` is
|
|
2182
|
+
* `{ parentTable, relation, op }` there and `undefined` at the mutation field's own
|
|
2183
|
+
* table — `if (payload.nested) return;` keeps a hook to root writes. A nested
|
|
2184
|
+
* statement's `rows` hold the table's primary key and the join column(s) it changed, plus
|
|
2185
|
+
* the hook's `columns`. A throw rolls the whole tree back, parent row included.
|
|
2108
2186
|
*
|
|
2109
2187
|
* Off by default, and a build without it opens exactly the transactions it did before.
|
|
2110
2188
|
*/
|
|
@@ -2574,5 +2652,5 @@ declare const resolveSelection: (info: GraphQLResolveInfo | ResolveTree, options
|
|
|
2574
2652
|
//#region src/index.d.ts
|
|
2575
2653
|
declare const buildSchema: <TDbClient extends AnyDrizzleDB<any>, TConfig extends BuildSchemaConfig = BuildSchemaConfig>(db: TDbClient, config?: TConfig) => GeneratedData<TDbClient, NamingOf<TConfig>>;
|
|
2576
2654
|
//#endregion
|
|
2577
|
-
export { type AggregateResolver, type AnyDrizzleDB, type BuildSchemaConfig, type ColumnDeprecator, type ColumnDescriber, type ColumnDocInfo, type ColumnTypeMapper, type ColumnTypeMapperInfo, type ComplexityConfig, type ContextValuesConfig, type DefaultOrderByEntry, type DefaultsConfig, type DeleteResolver, type DeleteSingleResolver, type DerivedTypeNameMapper, type DrizzleErrorCode, type DrizzleErrorContext, type DrizzleExtension, type DrizzleFieldExtension, type DrizzleFieldKind, type DrizzleFieldOperation, type DrizzleTargetArg, type DrizzleTypeExtension, type EnumNameInfo, type EnumNameMapper, type EnumValueNameInfo, type EnumValueNameMapper, type ExtractRelations, type ExtractTableByName, type ExtractTableRelations, type ExtractTables, type FeatureSwitch, type FieldsByTypeName, type GeneratedData, type GeneratedEntities, type GeneratedInputs, type GeneratedOutputs, type GeneratedTypeInfo, type GeneratedTypeKind, GraphQLBigIntString, GraphQLDate, GraphQLDateTime, GraphQLDecimalString, GraphQLJSON, GraphQLUUID, type IdentifiedRows, type InsertArrResolver, type InsertResolver, type LimitsConfig, type MutationReturnlessResult, type MutationsCore, type NamingOf, type OnWriteConfig, type ParseResolveInfoOptions, type Pluralize, type QueriesCore, type RelationDescriber, type RelationResolverFactory, type ResolveSelectionOptions, type ResolveTree, type RowScope, type RowScopeFilter, type ScalarOverride, type ScalarOverridesConfig, type SchemaDocs, type SchemaExclusions, type SchemaFeatures, type ScopeConfig, type SelectResolver, type SelectSingleResolver, type SelectionOptions, type Singularize, type SoftDeleteColumn, type SoftDeleteConfig, type TableDefaults, type TableDescriber, type TableLimitPolicy, type TableNamedRelations, type TypeNameMapper, type TypeNaming, type UpdateManyArgs, type UpdateManyEntry, type UpdateManyResolver, type UpdateResolver, type UpdateSingleResolver, type UpsertArgs, type UpsertArrResolver, type UpsertConflictArgs, type UpsertResolver, type WriteHook, type WriteHookPayload, type WriteHookPositions, type WriteHooks, type WriteOperation, buildSchema, createRelationResolverFactory, defaultErrorMapper, drizzleError, drizzleExecutorKey, drizzleExtension, extractFilters, extractOrderBy, extractRelationJoinColumns, identifyRows, isDrizzleFieldExtension, parseResolveInfo, resolveSelection, selectionToWith, singularizeMapper };
|
|
2655
|
+
export { type AggregateResolver, type AnyDrizzleDB, type BuildSchemaConfig, type ColumnDeprecator, type ColumnDescriber, type ColumnDocInfo, type ColumnTypeMapper, type ColumnTypeMapperInfo, type ComplexityConfig, type ContextValuesConfig, type DefaultOrderByEntry, type DefaultsConfig, type DeleteResolver, type DeleteSingleResolver, type DerivedTypeNameMapper, type DrizzleErrorCode, type DrizzleErrorContext, type DrizzleExtension, type DrizzleFieldExtension, type DrizzleFieldKind, type DrizzleFieldOperation, type DrizzleTargetArg, type DrizzleTypeExtension, type EnumNameInfo, type EnumNameMapper, type EnumValueNameInfo, type EnumValueNameMapper, type ExtractRelations, type ExtractTableByName, type ExtractTableRelations, type ExtractTables, type FeatureSwitch, type FieldsByTypeName, type GeneratedData, type GeneratedEntities, type GeneratedInputs, type GeneratedOutputs, type GeneratedTypeInfo, type GeneratedTypeKind, GraphQLBigIntString, GraphQLDate, GraphQLDateTime, GraphQLDecimalString, GraphQLJSON, GraphQLUUID, type IdentifiedRows, type InsertArrResolver, type InsertResolver, type LimitsConfig, type MutationReturnlessResult, type MutationsCore, type NamingOf, type NestedWriteOp, type NestedWriteOrigin, type OnWriteConfig, type ParseResolveInfoOptions, type Pluralize, type QueriesCore, type RelationDescriber, type RelationResolverFactory, type ResolveSelectionOptions, type ResolveTree, type RowScope, type RowScopeFilter, type ScalarOverride, type ScalarOverridesConfig, type SchemaDocs, type SchemaExclusions, type SchemaFeatures, type ScopeConfig, type SelectResolver, type SelectSingleResolver, type SelectionOptions, type Singularize, type SoftDeleteColumn, type SoftDeleteConfig, type TableDefaults, type TableDescriber, type TableLimitPolicy, type TableNamedRelations, type TypeNameMapper, type TypeNaming, type UpdateManyArgs, type UpdateManyEntry, type UpdateManyResolver, type UpdateResolver, type UpdateSingleResolver, type UpsertArgs, type UpsertArrResolver, type UpsertConflictArgs, type UpsertResolver, type WriteHook, type WriteHookPayload, type WriteHookPositions, type WriteHooks, type WriteOperation, buildSchema, createRelationResolverFactory, defaultErrorMapper, drizzleError, drizzleExecutorKey, drizzleExtension, extractFilters, extractOrderBy, extractRelationJoinColumns, identifyRows, isDrizzleFieldExtension, parseResolveInfo, resolveSelection, selectionToWith, singularizeMapper };
|
|
2578
2656
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -337,6 +337,13 @@ type DrizzleFieldExtension = {
|
|
|
337
337
|
* Absent everywhere else, so a wrapper can gate purging without parsing arguments.
|
|
338
338
|
*/
|
|
339
339
|
hardDelete?: boolean;
|
|
340
|
+
/**
|
|
341
|
+
* `true` on the count mutations (`update<Table>Count` / `delete<Table>Count`,
|
|
342
|
+
* `features.countMutations`): the field writes like its plural `update` / `delete` sibling
|
|
343
|
+
* — same `operation`, same rows — but resolves to how many rows it wrote (`Int!`) rather
|
|
344
|
+
* than to the rows. Absent everywhere else.
|
|
345
|
+
*/
|
|
346
|
+
count?: boolean;
|
|
340
347
|
/** For `kind: 'relation'` and `operation: 'relationAggregate'`: the relation's name. */
|
|
341
348
|
relation?: string;
|
|
342
349
|
/** For `kind: 'relation'` and `operation: 'relationAggregate'`: the table it hangs off. */
|
|
@@ -804,17 +811,50 @@ declare const extractFilters: <TTable extends Table>(table: TTable, tableName: s
|
|
|
804
811
|
//#region src/util/builders/common/write-hooks.d.ts
|
|
805
812
|
/** The write a hook is attached to. `restore` only exists for a soft-deleting table. */
|
|
806
813
|
type WriteOperation = 'insert' | 'update' | 'updateMany' | 'upsert' | 'delete' | 'restore';
|
|
814
|
+
/** Which input of a relation field a nested write came from. */
|
|
815
|
+
type NestedWriteOp = 'create' | 'connect' | 'disconnect' | 'set';
|
|
816
|
+
/**
|
|
817
|
+
* Where a nested write came from: set on the payload of a hook that fires for a row a nested
|
|
818
|
+
* `create` / `connect` / `disconnect` / `set` wrote, and absent at the mutation field's own
|
|
819
|
+
* table. See {@link WriteHookPayload.nested}.
|
|
820
|
+
*/
|
|
821
|
+
type NestedWriteOrigin = {
|
|
822
|
+
/** Drizzle schema key of the table whose input carried the relation field. */
|
|
823
|
+
parentTable: string;
|
|
824
|
+
/** The relation field the write went through, as named on the parent table. */
|
|
825
|
+
relation: string;
|
|
826
|
+
/** The relation field's input that produced this statement. */
|
|
827
|
+
op: NestedWriteOp;
|
|
828
|
+
};
|
|
807
829
|
/** What a write hook is handed. See {@link BuildSchemaConfig.onWrite}. */
|
|
808
830
|
type WriteHookPayload = {
|
|
809
831
|
/** Drizzle schema key of the table being written. */
|
|
810
832
|
table: string;
|
|
833
|
+
/**
|
|
834
|
+
* What happened to `table`. A nested write reports what its statement did to *that* table:
|
|
835
|
+
* `insert` for a nested `create`, `update` for a `connect` / `disconnect` / `set` that
|
|
836
|
+
* changes the foreign key on the target, and `insert` / `delete` on the junction table for
|
|
837
|
+
* a many-to-many link / unlink.
|
|
838
|
+
*/
|
|
811
839
|
operation: WriteOperation;
|
|
812
840
|
/** `'before'` runs ahead of the statement, `'after'` once it has returned. */
|
|
813
841
|
position: 'before' | 'after';
|
|
814
|
-
/**
|
|
842
|
+
/**
|
|
843
|
+
* Whether the field writes a single row (`createUsersSingle`) or a list. For a nested
|
|
844
|
+
* write, whether the relation it went through is a to-one.
|
|
845
|
+
*/
|
|
815
846
|
single: boolean;
|
|
816
|
-
/**
|
|
847
|
+
/**
|
|
848
|
+
* The field's GraphQL arguments, exactly as the resolver received them — for a nested
|
|
849
|
+
* write, the arguments of the root mutation field it is part of.
|
|
850
|
+
*/
|
|
817
851
|
args: any;
|
|
852
|
+
/**
|
|
853
|
+
* Set when the rows were written by a nested write under another table's mutation, and
|
|
854
|
+
* `undefined` for the mutation field's own table. A hook that only cares about root writes
|
|
855
|
+
* skips the rest with `if (payload.nested) return;`.
|
|
856
|
+
*/
|
|
857
|
+
nested?: NestedWriteOrigin;
|
|
818
858
|
/**
|
|
819
859
|
* The rows the write produced, as the database returned them — before the output mapper,
|
|
820
860
|
* so values are database-shaped. Empty at the `before` position, and on MySQL, whose
|
|
@@ -822,7 +862,11 @@ type WriteHookPayload = {
|
|
|
822
862
|
*
|
|
823
863
|
* Each row holds the columns the client's selection asked for (plus any key a relation or
|
|
824
864
|
* nested write needed), **and** every column the hook names in `columns`. A column the
|
|
825
|
-
* client did not select and the hook did not name is absent.
|
|
865
|
+
* client did not select and the hook did not name is absent. The count mutations select
|
|
866
|
+
* nothing, so there a row holds the named columns, or the primary key when none are named.
|
|
867
|
+
*
|
|
868
|
+
* A nested write has no selection of its own, so its rows hold the table's primary key and
|
|
869
|
+
* the join column(s) the write changed, plus the hook's `columns`.
|
|
826
870
|
*/
|
|
827
871
|
rows: any[];
|
|
828
872
|
context: any;
|
|
@@ -1441,8 +1485,8 @@ type SchemaFeatures = {
|
|
|
1441
1485
|
* columns only.
|
|
1442
1486
|
*
|
|
1443
1487
|
* A many-to-many (`.through()`) relation is written as junction rows: `connect` on the
|
|
1444
|
-
* create input, and `connect` / `disconnect` / `set` on the update input,
|
|
1445
|
-
*
|
|
1488
|
+
* create input, and `connect` / `disconnect` / `set` on the update input, whatever the
|
|
1489
|
+
* columns' nullability, since unlinking deletes a junction row rather than nulling a column.
|
|
1446
1490
|
* It offers no `create` — inserting a row and linking it are two writes to two tables —
|
|
1447
1491
|
* and `set: []` clears the relation.
|
|
1448
1492
|
*
|
|
@@ -1451,6 +1495,21 @@ type SchemaFeatures = {
|
|
|
1451
1495
|
* offered) becomes nullable on the create input, since the relation is the other way to
|
|
1452
1496
|
* supply it.
|
|
1453
1497
|
*
|
|
1498
|
+
* A nested write follows the rules of the table it writes:
|
|
1499
|
+
*
|
|
1500
|
+
* - **`features`** — each input is generated only when that table has the write it needs:
|
|
1501
|
+
* `create` needs the target's `insert` (plus its `update` on a to-one whose nullable key
|
|
1502
|
+
* lives on the target, since attaching detaches the previous row); a `connect` /
|
|
1503
|
+
* `disconnect` / `set` that moves the target's foreign key needs its `update`; a
|
|
1504
|
+
* parent-side `connect` / `disconnect` needs nothing of the target. Many-to-many inputs
|
|
1505
|
+
* need the junction's `insert` (`connect`), `delete` (`disconnect`) or both (`set`), and
|
|
1506
|
+
* an excluded junction removes them. What is left out is noted on the console, and a
|
|
1507
|
+
* relation left with no input loses its field.
|
|
1508
|
+
* - **`onWrite`** — the hooks of the table a nested statement writes fire on the same `tx`,
|
|
1509
|
+
* with `payload.nested` set. See {@link BuildSchemaConfig.onWrite}.
|
|
1510
|
+
* - **`scope`** and **`contextValues`** — `connect` / `disconnect` / `set` reach only
|
|
1511
|
+
* in-scope rows, and a nested `create` is stamped like any insert.
|
|
1512
|
+
*
|
|
1454
1513
|
* PostgreSQL and SQLite only. MySQL cannot return the rows it just wrote, which is how a
|
|
1455
1514
|
* nested write learns the parent's key, so `buildSchema` rejects the flag there. On SQLite
|
|
1456
1515
|
* the driver must be asynchronous (libsql, D1, …): a synchronous one commits before an
|
|
@@ -1499,6 +1558,17 @@ type SchemaFeatures = {
|
|
|
1499
1558
|
* for nothing. Each mutation is generated only when its plural counterpart is
|
|
1500
1559
|
* (`features.update` / `features.delete`), and honours `features.requireWhere`.
|
|
1501
1560
|
*
|
|
1561
|
+
* Apart from the answer, they obey every rule the plural write does: the table's `scope`
|
|
1562
|
+
* is ANDed into the `where`; on a `softDelete` table the delete marks rows instead of
|
|
1563
|
+
* removing them (taking `hard` where the plural delete does) and neither mutation reaches
|
|
1564
|
+
* an already-marked row; `contextValues` columns are never reassigned by the update; and
|
|
1565
|
+
* `onWrite` hooks run `before` and `after`, in a transaction, with the plural payload
|
|
1566
|
+
* (`single: false`). An `after` hook needs rows, so on a table with one the write adds a
|
|
1567
|
+
* `RETURNING` of the hook's `columns` — or of the primary key if it names none (every column
|
|
1568
|
+
* on a table without one) — and the count is the number of rows returned. On MySQL, which has
|
|
1569
|
+
* no `RETURNING`, the hook gets `rows: []` as on every MySQL mutation. Their
|
|
1570
|
+
* `extensions.drizzle` carries the plural write's `operation` plus `count: true`.
|
|
1571
|
+
*
|
|
1502
1572
|
* Off unless asked for, so an existing schema does not grow new mutations on upgrade.
|
|
1503
1573
|
*
|
|
1504
1574
|
* @default false
|
|
@@ -2103,8 +2173,16 @@ type BuildSchemaConfig = {
|
|
|
2103
2173
|
* is unchanged. An unknown column, or `columns` with no `after` hook, fails the build; on
|
|
2104
2174
|
* a top-level registration a named column must exist on every table. MySQL returns no
|
|
2105
2175
|
* rows, so `columns` has no effect there.
|
|
2106
|
-
* -
|
|
2107
|
-
*
|
|
2176
|
+
* - **With `nestedWrites`, a nested statement fires the hooks of the table it writes**, on
|
|
2177
|
+
* the same `tx`, once per relation input and operation (not per row): `insert` for a
|
|
2178
|
+
* nested `create`; `update` for a `connect` / `disconnect` / `set` that moves the
|
|
2179
|
+
* target's foreign key; `insert` / `delete` on the junction table for a many-to-many
|
|
2180
|
+
* link / unlink (`set` is both). A parent-side `connect` / `disconnect` writes only the
|
|
2181
|
+
* parent's own row, so only the parent's hook sees it. `payload.nested` is
|
|
2182
|
+
* `{ parentTable, relation, op }` there and `undefined` at the mutation field's own
|
|
2183
|
+
* table — `if (payload.nested) return;` keeps a hook to root writes. A nested
|
|
2184
|
+
* statement's `rows` hold the table's primary key and the join column(s) it changed, plus
|
|
2185
|
+
* the hook's `columns`. A throw rolls the whole tree back, parent row included.
|
|
2108
2186
|
*
|
|
2109
2187
|
* Off by default, and a build without it opens exactly the transactions it did before.
|
|
2110
2188
|
*/
|
|
@@ -2574,5 +2652,5 @@ declare const resolveSelection: (info: GraphQLResolveInfo | ResolveTree, options
|
|
|
2574
2652
|
//#region src/index.d.ts
|
|
2575
2653
|
declare const buildSchema: <TDbClient extends AnyDrizzleDB<any>, TConfig extends BuildSchemaConfig = BuildSchemaConfig>(db: TDbClient, config?: TConfig) => GeneratedData<TDbClient, NamingOf<TConfig>>;
|
|
2576
2654
|
//#endregion
|
|
2577
|
-
export { type AggregateResolver, type AnyDrizzleDB, type BuildSchemaConfig, type ColumnDeprecator, type ColumnDescriber, type ColumnDocInfo, type ColumnTypeMapper, type ColumnTypeMapperInfo, type ComplexityConfig, type ContextValuesConfig, type DefaultOrderByEntry, type DefaultsConfig, type DeleteResolver, type DeleteSingleResolver, type DerivedTypeNameMapper, type DrizzleErrorCode, type DrizzleErrorContext, type DrizzleExtension, type DrizzleFieldExtension, type DrizzleFieldKind, type DrizzleFieldOperation, type DrizzleTargetArg, type DrizzleTypeExtension, type EnumNameInfo, type EnumNameMapper, type EnumValueNameInfo, type EnumValueNameMapper, type ExtractRelations, type ExtractTableByName, type ExtractTableRelations, type ExtractTables, type FeatureSwitch, type FieldsByTypeName, type GeneratedData, type GeneratedEntities, type GeneratedInputs, type GeneratedOutputs, type GeneratedTypeInfo, type GeneratedTypeKind, GraphQLBigIntString, GraphQLDate, GraphQLDateTime, GraphQLDecimalString, GraphQLJSON, GraphQLUUID, type IdentifiedRows, type InsertArrResolver, type InsertResolver, type LimitsConfig, type MutationReturnlessResult, type MutationsCore, type NamingOf, type OnWriteConfig, type ParseResolveInfoOptions, type Pluralize, type QueriesCore, type RelationDescriber, type RelationResolverFactory, type ResolveSelectionOptions, type ResolveTree, type RowScope, type RowScopeFilter, type ScalarOverride, type ScalarOverridesConfig, type SchemaDocs, type SchemaExclusions, type SchemaFeatures, type ScopeConfig, type SelectResolver, type SelectSingleResolver, type SelectionOptions, type Singularize, type SoftDeleteColumn, type SoftDeleteConfig, type TableDefaults, type TableDescriber, type TableLimitPolicy, type TableNamedRelations, type TypeNameMapper, type TypeNaming, type UpdateManyArgs, type UpdateManyEntry, type UpdateManyResolver, type UpdateResolver, type UpdateSingleResolver, type UpsertArgs, type UpsertArrResolver, type UpsertConflictArgs, type UpsertResolver, type WriteHook, type WriteHookPayload, type WriteHookPositions, type WriteHooks, type WriteOperation, buildSchema, createRelationResolverFactory, defaultErrorMapper, drizzleError, drizzleExecutorKey, drizzleExtension, extractFilters, extractOrderBy, extractRelationJoinColumns, identifyRows, isDrizzleFieldExtension, parseResolveInfo, resolveSelection, selectionToWith, singularizeMapper };
|
|
2655
|
+
export { type AggregateResolver, type AnyDrizzleDB, type BuildSchemaConfig, type ColumnDeprecator, type ColumnDescriber, type ColumnDocInfo, type ColumnTypeMapper, type ColumnTypeMapperInfo, type ComplexityConfig, type ContextValuesConfig, type DefaultOrderByEntry, type DefaultsConfig, type DeleteResolver, type DeleteSingleResolver, type DerivedTypeNameMapper, type DrizzleErrorCode, type DrizzleErrorContext, type DrizzleExtension, type DrizzleFieldExtension, type DrizzleFieldKind, type DrizzleFieldOperation, type DrizzleTargetArg, type DrizzleTypeExtension, type EnumNameInfo, type EnumNameMapper, type EnumValueNameInfo, type EnumValueNameMapper, type ExtractRelations, type ExtractTableByName, type ExtractTableRelations, type ExtractTables, type FeatureSwitch, type FieldsByTypeName, type GeneratedData, type GeneratedEntities, type GeneratedInputs, type GeneratedOutputs, type GeneratedTypeInfo, type GeneratedTypeKind, GraphQLBigIntString, GraphQLDate, GraphQLDateTime, GraphQLDecimalString, GraphQLJSON, GraphQLUUID, type IdentifiedRows, type InsertArrResolver, type InsertResolver, type LimitsConfig, type MutationReturnlessResult, type MutationsCore, type NamingOf, type NestedWriteOp, type NestedWriteOrigin, type OnWriteConfig, type ParseResolveInfoOptions, type Pluralize, type QueriesCore, type RelationDescriber, type RelationResolverFactory, type ResolveSelectionOptions, type ResolveTree, type RowScope, type RowScopeFilter, type ScalarOverride, type ScalarOverridesConfig, type SchemaDocs, type SchemaExclusions, type SchemaFeatures, type ScopeConfig, type SelectResolver, type SelectSingleResolver, type SelectionOptions, type Singularize, type SoftDeleteColumn, type SoftDeleteConfig, type TableDefaults, type TableDescriber, type TableLimitPolicy, type TableNamedRelations, type TypeNameMapper, type TypeNaming, type UpdateManyArgs, type UpdateManyEntry, type UpdateManyResolver, type UpdateResolver, type UpdateSingleResolver, type UpsertArgs, type UpsertArrResolver, type UpsertConflictArgs, type UpsertResolver, type WriteHook, type WriteHookPayload, type WriteHookPositions, type WriteHooks, type WriteOperation, buildSchema, createRelationResolverFactory, defaultErrorMapper, drizzleError, drizzleExecutorKey, drizzleExtension, extractFilters, extractOrderBy, extractRelationJoinColumns, identifyRows, isDrizzleFieldExtension, parseResolveInfo, resolveSelection, selectionToWith, singularizeMapper };
|
|
2578
2656
|
//# sourceMappingURL=index.d.ts.map
|