@vantreeseba/drizzle-graphql 13.0.0 → 13.1.1
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 +111 -5
- package/dist/index.cjs +334 -153
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +98 -4
- package/dist/index.d.ts +98 -4
- package/dist/index.js +334 -153
- 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. */
|
|
@@ -566,6 +573,23 @@ type EnumNameInfo = {
|
|
|
566
573
|
* `BuildSchemaConfig.enumNameMapper`.
|
|
567
574
|
*/
|
|
568
575
|
type EnumNameMapper = (info: EnumNameInfo) => string | undefined;
|
|
576
|
+
/**
|
|
577
|
+
* Everything an {@link EnumValueNameMapper} needs to name one value of a generated enum: the
|
|
578
|
+
* value itself, plus the same context an {@link EnumNameMapper} gets for the enum around it.
|
|
579
|
+
*/
|
|
580
|
+
type EnumValueNameInfo = EnumNameInfo & {
|
|
581
|
+
/** The stored value being named. It stays the GraphQL value's internal `value` either way. */
|
|
582
|
+
value: string;
|
|
583
|
+
/** The value's position in {@link EnumNameInfo.values}. */
|
|
584
|
+
index: number;
|
|
585
|
+
/** The GraphQL type name the enum was given — after `enumNameMapper`, if there is one. */
|
|
586
|
+
typeName: string;
|
|
587
|
+
};
|
|
588
|
+
/**
|
|
589
|
+
* Names one value of a generated GraphQL enum. Return `undefined` to keep the default name.
|
|
590
|
+
* See `BuildSchemaConfig.enumValueNameMapper`.
|
|
591
|
+
*/
|
|
592
|
+
type EnumValueNameMapper = (info: EnumValueNameInfo) => string | undefined;
|
|
569
593
|
/** Context handed to the documentation and deprecation hooks alongside the column itself. */
|
|
570
594
|
type ColumnDocInfo = {
|
|
571
595
|
/** The table's key in the Drizzle schema object. */
|
|
@@ -802,6 +826,11 @@ type WriteHookPayload = {
|
|
|
802
826
|
* The rows the write produced, as the database returned them — before the output mapper,
|
|
803
827
|
* so values are database-shaped. Empty at the `before` position, and on MySQL, whose
|
|
804
828
|
* mutations return no rows.
|
|
829
|
+
*
|
|
830
|
+
* Each row holds the columns the client's selection asked for (plus any key a relation or
|
|
831
|
+
* nested write needed), **and** every column the hook names in `columns`. A column the
|
|
832
|
+
* client did not select and the hook did not name is absent. The count mutations select
|
|
833
|
+
* nothing, so there a row holds the named columns, or the primary key when none are named.
|
|
805
834
|
*/
|
|
806
835
|
rows: any[];
|
|
807
836
|
context: any;
|
|
@@ -813,12 +842,26 @@ type WriteHook = (payload: WriteHookPayload) => void | Promise<void>;
|
|
|
813
842
|
type WriteHookPositions = {
|
|
814
843
|
before?: WriteHook;
|
|
815
844
|
after?: WriteHook;
|
|
845
|
+
/**
|
|
846
|
+
* Columns the `after` hook's `rows` always carry, whatever the client selected: a list of
|
|
847
|
+
* column keys (the table object's property names, as `rows` is keyed), or `'all'` for
|
|
848
|
+
* every column of the table. They are added to the statement's `RETURNING` and taken back
|
|
849
|
+
* off before the result is mapped, so the client's response is unchanged.
|
|
850
|
+
*
|
|
851
|
+
* An unknown column fails the build, and so does `columns` without an `after` hook. On a
|
|
852
|
+
* top-level (every-table) registration a named column must exist on every table.
|
|
853
|
+
*/
|
|
854
|
+
columns?: readonly string[] | 'all';
|
|
816
855
|
};
|
|
817
856
|
type WriteHooks = WriteHook | WriteHookPositions;
|
|
818
|
-
/**
|
|
857
|
+
/**
|
|
858
|
+
* Resolved, per-field hooks: `undefined` when the table registered none. `columns` is the
|
|
859
|
+
* hook's `columns` resolved against the table, or `undefined` when it named none.
|
|
860
|
+
*/
|
|
819
861
|
type ResolvedWriteHooks = {
|
|
820
862
|
before?: WriteHook;
|
|
821
863
|
after?: WriteHook;
|
|
864
|
+
columns?: Record<string, Column>;
|
|
822
865
|
};
|
|
823
866
|
/** Build-time lookup of a table's hooks, installed on {@link TablePolicies}. */
|
|
824
867
|
type WriteHookFor = (tableName: string, operation: WriteOperation) => ResolvedWriteHooks | undefined;
|
|
@@ -1464,6 +1507,17 @@ type SchemaFeatures = {
|
|
|
1464
1507
|
* for nothing. Each mutation is generated only when its plural counterpart is
|
|
1465
1508
|
* (`features.update` / `features.delete`), and honours `features.requireWhere`.
|
|
1466
1509
|
*
|
|
1510
|
+
* Apart from the answer, they obey every rule the plural write does: the table's `scope`
|
|
1511
|
+
* is ANDed into the `where`; on a `softDelete` table the delete marks rows instead of
|
|
1512
|
+
* removing them (taking `hard` where the plural delete does) and neither mutation reaches
|
|
1513
|
+
* an already-marked row; `contextValues` columns are never reassigned by the update; and
|
|
1514
|
+
* `onWrite` hooks run `before` and `after`, in a transaction, with the plural payload
|
|
1515
|
+
* (`single: false`). An `after` hook needs rows, so on a table with one the write adds a
|
|
1516
|
+
* `RETURNING` of the hook's `columns` — or of the primary key if it names none (every column
|
|
1517
|
+
* on a table without one) — and the count is the number of rows returned. On MySQL, which has
|
|
1518
|
+
* no `RETURNING`, the hook gets `rows: []` as on every MySQL mutation. Their
|
|
1519
|
+
* `extensions.drizzle` carries the plural write's `operation` plus `count: true`.
|
|
1520
|
+
*
|
|
1467
1521
|
* Off unless asked for, so an existing schema does not grow new mutations on upgrade.
|
|
1468
1522
|
*
|
|
1469
1523
|
* @default false
|
|
@@ -2038,8 +2092,12 @@ type BuildSchemaConfig = {
|
|
|
2038
2092
|
* ```ts
|
|
2039
2093
|
* buildSchema(db, {
|
|
2040
2094
|
* onWrite: {
|
|
2041
|
-
* posts:
|
|
2042
|
-
*
|
|
2095
|
+
* posts: {
|
|
2096
|
+
* after: async ({ table, operation, rows, tx }) => {
|
|
2097
|
+
* await tx.insert(auditLog).values(rows.map((row) => ({ table, operation, rowId: row.id })));
|
|
2098
|
+
* },
|
|
2099
|
+
* // `rows` always carries `id`, whether or not the client selected it.
|
|
2100
|
+
* columns: ['id'],
|
|
2043
2101
|
* },
|
|
2044
2102
|
* },
|
|
2045
2103
|
* });
|
|
@@ -2057,6 +2115,13 @@ type BuildSchemaConfig = {
|
|
|
2057
2115
|
* - **Throwing rolls the mutation back.** That is the point of the position.
|
|
2058
2116
|
* - **`rows` are the post-write rows as the database returned them**, before the output
|
|
2059
2117
|
* mapper. Empty at the `before` position, and on MySQL, whose mutations return no rows.
|
|
2118
|
+
* - **A row holds the columns the client selected**, because `RETURNING` is built from the
|
|
2119
|
+
* selection — plus every column the registration names in `columns` (column keys, or
|
|
2120
|
+
* `'all'`). Those are added to `RETURNING` for insert, upsert, update, `updateMany`, delete
|
|
2121
|
+
* and restore, and taken back off before the result is mapped, so the client's response
|
|
2122
|
+
* is unchanged. An unknown column, or `columns` with no `after` hook, fails the build; on
|
|
2123
|
+
* a top-level registration a named column must exist on every table. MySQL returns no
|
|
2124
|
+
* rows, so `columns` has no effect there.
|
|
2060
2125
|
* - The hook fires for the **mutation field's own table**. Rows a nested write creates in
|
|
2061
2126
|
* another table do not fire that table's hook.
|
|
2062
2127
|
*
|
|
@@ -2380,6 +2445,35 @@ type BuildSchemaConfig = {
|
|
|
2380
2445
|
* Return `undefined` to keep the default name.
|
|
2381
2446
|
*/
|
|
2382
2447
|
enumNameMapper?: EnumNameMapper;
|
|
2448
|
+
/**
|
|
2449
|
+
* Names the *values* of the generated GraphQL enum types.
|
|
2450
|
+
*
|
|
2451
|
+
* By default a value's GraphQL name is the stored value itself (`'running'` → `running`),
|
|
2452
|
+
* or `Option<index>` when the stored value is not a usable GraphQL name. This hook overrides
|
|
2453
|
+
* that per value — most often to follow GraphQL's SCREAMING_CASE convention while the
|
|
2454
|
+
* database keeps its lowercase values:
|
|
2455
|
+
*
|
|
2456
|
+
* ```ts
|
|
2457
|
+
* buildSchema(db, {
|
|
2458
|
+
* enumValueNameMapper: ({ value }) => value.toUpperCase(),
|
|
2459
|
+
* });
|
|
2460
|
+
* // enum RunsStatusEnum { RUNNING OK ERROR STOPPED }
|
|
2461
|
+
* ```
|
|
2462
|
+
*
|
|
2463
|
+
* Only the GraphQL name changes. Each value's internal `value` stays the stored string, so
|
|
2464
|
+
* filters, create/update inputs, outputs and resolvers keep sending and receiving exactly
|
|
2465
|
+
* what the database stores; the generated TypeScript types keep the stored values too.
|
|
2466
|
+
*
|
|
2467
|
+
* Pass the string `'constant'` for the built-in preset, which CONSTANT_CASEs every value
|
|
2468
|
+
* (`inProgress` / `in-progress` → `IN_PROGRESS`).
|
|
2469
|
+
*
|
|
2470
|
+
* The mapper receives the stored `value`, its `index`, the enum's GraphQL `typeName` (after
|
|
2471
|
+
* `enumNameMapper`), and everything `enumNameMapper` receives. Return `undefined` to keep the
|
|
2472
|
+
* default name for that value. The build throws when a returned name is not a valid GraphQL
|
|
2473
|
+
* enum value name, when two values of one enum map to the same name, or when columns sharing
|
|
2474
|
+
* one enum type would name its values differently.
|
|
2475
|
+
*/
|
|
2476
|
+
enumValueNameMapper?: 'constant' | EnumValueNameMapper;
|
|
2383
2477
|
};
|
|
2384
2478
|
//#endregion
|
|
2385
2479
|
//#region src/util/case-ops/index.d.ts
|
|
@@ -2499,5 +2593,5 @@ declare const resolveSelection: (info: GraphQLResolveInfo | ResolveTree, options
|
|
|
2499
2593
|
//#region src/index.d.ts
|
|
2500
2594
|
declare const buildSchema: <TDbClient extends AnyDrizzleDB<any>, TConfig extends BuildSchemaConfig = BuildSchemaConfig>(db: TDbClient, config?: TConfig) => GeneratedData<TDbClient, NamingOf<TConfig>>;
|
|
2501
2595
|
//#endregion
|
|
2502
|
-
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 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 };
|
|
2596
|
+
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 };
|
|
2503
2597
|
//# 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. */
|
|
@@ -566,6 +573,23 @@ type EnumNameInfo = {
|
|
|
566
573
|
* `BuildSchemaConfig.enumNameMapper`.
|
|
567
574
|
*/
|
|
568
575
|
type EnumNameMapper = (info: EnumNameInfo) => string | undefined;
|
|
576
|
+
/**
|
|
577
|
+
* Everything an {@link EnumValueNameMapper} needs to name one value of a generated enum: the
|
|
578
|
+
* value itself, plus the same context an {@link EnumNameMapper} gets for the enum around it.
|
|
579
|
+
*/
|
|
580
|
+
type EnumValueNameInfo = EnumNameInfo & {
|
|
581
|
+
/** The stored value being named. It stays the GraphQL value's internal `value` either way. */
|
|
582
|
+
value: string;
|
|
583
|
+
/** The value's position in {@link EnumNameInfo.values}. */
|
|
584
|
+
index: number;
|
|
585
|
+
/** The GraphQL type name the enum was given — after `enumNameMapper`, if there is one. */
|
|
586
|
+
typeName: string;
|
|
587
|
+
};
|
|
588
|
+
/**
|
|
589
|
+
* Names one value of a generated GraphQL enum. Return `undefined` to keep the default name.
|
|
590
|
+
* See `BuildSchemaConfig.enumValueNameMapper`.
|
|
591
|
+
*/
|
|
592
|
+
type EnumValueNameMapper = (info: EnumValueNameInfo) => string | undefined;
|
|
569
593
|
/** Context handed to the documentation and deprecation hooks alongside the column itself. */
|
|
570
594
|
type ColumnDocInfo = {
|
|
571
595
|
/** The table's key in the Drizzle schema object. */
|
|
@@ -802,6 +826,11 @@ type WriteHookPayload = {
|
|
|
802
826
|
* The rows the write produced, as the database returned them — before the output mapper,
|
|
803
827
|
* so values are database-shaped. Empty at the `before` position, and on MySQL, whose
|
|
804
828
|
* mutations return no rows.
|
|
829
|
+
*
|
|
830
|
+
* Each row holds the columns the client's selection asked for (plus any key a relation or
|
|
831
|
+
* nested write needed), **and** every column the hook names in `columns`. A column the
|
|
832
|
+
* client did not select and the hook did not name is absent. The count mutations select
|
|
833
|
+
* nothing, so there a row holds the named columns, or the primary key when none are named.
|
|
805
834
|
*/
|
|
806
835
|
rows: any[];
|
|
807
836
|
context: any;
|
|
@@ -813,12 +842,26 @@ type WriteHook = (payload: WriteHookPayload) => void | Promise<void>;
|
|
|
813
842
|
type WriteHookPositions = {
|
|
814
843
|
before?: WriteHook;
|
|
815
844
|
after?: WriteHook;
|
|
845
|
+
/**
|
|
846
|
+
* Columns the `after` hook's `rows` always carry, whatever the client selected: a list of
|
|
847
|
+
* column keys (the table object's property names, as `rows` is keyed), or `'all'` for
|
|
848
|
+
* every column of the table. They are added to the statement's `RETURNING` and taken back
|
|
849
|
+
* off before the result is mapped, so the client's response is unchanged.
|
|
850
|
+
*
|
|
851
|
+
* An unknown column fails the build, and so does `columns` without an `after` hook. On a
|
|
852
|
+
* top-level (every-table) registration a named column must exist on every table.
|
|
853
|
+
*/
|
|
854
|
+
columns?: readonly string[] | 'all';
|
|
816
855
|
};
|
|
817
856
|
type WriteHooks = WriteHook | WriteHookPositions;
|
|
818
|
-
/**
|
|
857
|
+
/**
|
|
858
|
+
* Resolved, per-field hooks: `undefined` when the table registered none. `columns` is the
|
|
859
|
+
* hook's `columns` resolved against the table, or `undefined` when it named none.
|
|
860
|
+
*/
|
|
819
861
|
type ResolvedWriteHooks = {
|
|
820
862
|
before?: WriteHook;
|
|
821
863
|
after?: WriteHook;
|
|
864
|
+
columns?: Record<string, Column>;
|
|
822
865
|
};
|
|
823
866
|
/** Build-time lookup of a table's hooks, installed on {@link TablePolicies}. */
|
|
824
867
|
type WriteHookFor = (tableName: string, operation: WriteOperation) => ResolvedWriteHooks | undefined;
|
|
@@ -1464,6 +1507,17 @@ type SchemaFeatures = {
|
|
|
1464
1507
|
* for nothing. Each mutation is generated only when its plural counterpart is
|
|
1465
1508
|
* (`features.update` / `features.delete`), and honours `features.requireWhere`.
|
|
1466
1509
|
*
|
|
1510
|
+
* Apart from the answer, they obey every rule the plural write does: the table's `scope`
|
|
1511
|
+
* is ANDed into the `where`; on a `softDelete` table the delete marks rows instead of
|
|
1512
|
+
* removing them (taking `hard` where the plural delete does) and neither mutation reaches
|
|
1513
|
+
* an already-marked row; `contextValues` columns are never reassigned by the update; and
|
|
1514
|
+
* `onWrite` hooks run `before` and `after`, in a transaction, with the plural payload
|
|
1515
|
+
* (`single: false`). An `after` hook needs rows, so on a table with one the write adds a
|
|
1516
|
+
* `RETURNING` of the hook's `columns` — or of the primary key if it names none (every column
|
|
1517
|
+
* on a table without one) — and the count is the number of rows returned. On MySQL, which has
|
|
1518
|
+
* no `RETURNING`, the hook gets `rows: []` as on every MySQL mutation. Their
|
|
1519
|
+
* `extensions.drizzle` carries the plural write's `operation` plus `count: true`.
|
|
1520
|
+
*
|
|
1467
1521
|
* Off unless asked for, so an existing schema does not grow new mutations on upgrade.
|
|
1468
1522
|
*
|
|
1469
1523
|
* @default false
|
|
@@ -2038,8 +2092,12 @@ type BuildSchemaConfig = {
|
|
|
2038
2092
|
* ```ts
|
|
2039
2093
|
* buildSchema(db, {
|
|
2040
2094
|
* onWrite: {
|
|
2041
|
-
* posts:
|
|
2042
|
-
*
|
|
2095
|
+
* posts: {
|
|
2096
|
+
* after: async ({ table, operation, rows, tx }) => {
|
|
2097
|
+
* await tx.insert(auditLog).values(rows.map((row) => ({ table, operation, rowId: row.id })));
|
|
2098
|
+
* },
|
|
2099
|
+
* // `rows` always carries `id`, whether or not the client selected it.
|
|
2100
|
+
* columns: ['id'],
|
|
2043
2101
|
* },
|
|
2044
2102
|
* },
|
|
2045
2103
|
* });
|
|
@@ -2057,6 +2115,13 @@ type BuildSchemaConfig = {
|
|
|
2057
2115
|
* - **Throwing rolls the mutation back.** That is the point of the position.
|
|
2058
2116
|
* - **`rows` are the post-write rows as the database returned them**, before the output
|
|
2059
2117
|
* mapper. Empty at the `before` position, and on MySQL, whose mutations return no rows.
|
|
2118
|
+
* - **A row holds the columns the client selected**, because `RETURNING` is built from the
|
|
2119
|
+
* selection — plus every column the registration names in `columns` (column keys, or
|
|
2120
|
+
* `'all'`). Those are added to `RETURNING` for insert, upsert, update, `updateMany`, delete
|
|
2121
|
+
* and restore, and taken back off before the result is mapped, so the client's response
|
|
2122
|
+
* is unchanged. An unknown column, or `columns` with no `after` hook, fails the build; on
|
|
2123
|
+
* a top-level registration a named column must exist on every table. MySQL returns no
|
|
2124
|
+
* rows, so `columns` has no effect there.
|
|
2060
2125
|
* - The hook fires for the **mutation field's own table**. Rows a nested write creates in
|
|
2061
2126
|
* another table do not fire that table's hook.
|
|
2062
2127
|
*
|
|
@@ -2380,6 +2445,35 @@ type BuildSchemaConfig = {
|
|
|
2380
2445
|
* Return `undefined` to keep the default name.
|
|
2381
2446
|
*/
|
|
2382
2447
|
enumNameMapper?: EnumNameMapper;
|
|
2448
|
+
/**
|
|
2449
|
+
* Names the *values* of the generated GraphQL enum types.
|
|
2450
|
+
*
|
|
2451
|
+
* By default a value's GraphQL name is the stored value itself (`'running'` → `running`),
|
|
2452
|
+
* or `Option<index>` when the stored value is not a usable GraphQL name. This hook overrides
|
|
2453
|
+
* that per value — most often to follow GraphQL's SCREAMING_CASE convention while the
|
|
2454
|
+
* database keeps its lowercase values:
|
|
2455
|
+
*
|
|
2456
|
+
* ```ts
|
|
2457
|
+
* buildSchema(db, {
|
|
2458
|
+
* enumValueNameMapper: ({ value }) => value.toUpperCase(),
|
|
2459
|
+
* });
|
|
2460
|
+
* // enum RunsStatusEnum { RUNNING OK ERROR STOPPED }
|
|
2461
|
+
* ```
|
|
2462
|
+
*
|
|
2463
|
+
* Only the GraphQL name changes. Each value's internal `value` stays the stored string, so
|
|
2464
|
+
* filters, create/update inputs, outputs and resolvers keep sending and receiving exactly
|
|
2465
|
+
* what the database stores; the generated TypeScript types keep the stored values too.
|
|
2466
|
+
*
|
|
2467
|
+
* Pass the string `'constant'` for the built-in preset, which CONSTANT_CASEs every value
|
|
2468
|
+
* (`inProgress` / `in-progress` → `IN_PROGRESS`).
|
|
2469
|
+
*
|
|
2470
|
+
* The mapper receives the stored `value`, its `index`, the enum's GraphQL `typeName` (after
|
|
2471
|
+
* `enumNameMapper`), and everything `enumNameMapper` receives. Return `undefined` to keep the
|
|
2472
|
+
* default name for that value. The build throws when a returned name is not a valid GraphQL
|
|
2473
|
+
* enum value name, when two values of one enum map to the same name, or when columns sharing
|
|
2474
|
+
* one enum type would name its values differently.
|
|
2475
|
+
*/
|
|
2476
|
+
enumValueNameMapper?: 'constant' | EnumValueNameMapper;
|
|
2383
2477
|
};
|
|
2384
2478
|
//#endregion
|
|
2385
2479
|
//#region src/util/case-ops/index.d.ts
|
|
@@ -2499,5 +2593,5 @@ declare const resolveSelection: (info: GraphQLResolveInfo | ResolveTree, options
|
|
|
2499
2593
|
//#region src/index.d.ts
|
|
2500
2594
|
declare const buildSchema: <TDbClient extends AnyDrizzleDB<any>, TConfig extends BuildSchemaConfig = BuildSchemaConfig>(db: TDbClient, config?: TConfig) => GeneratedData<TDbClient, NamingOf<TConfig>>;
|
|
2501
2595
|
//#endregion
|
|
2502
|
-
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 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 };
|
|
2596
|
+
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 };
|
|
2503
2597
|
//# sourceMappingURL=index.d.ts.map
|