@vantreeseba/drizzle-graphql 7.2.0 → 7.4.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 +182 -2
- package/dist/README.md +182 -2
- package/dist/index.cjs +394 -127
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +101 -24
- package/dist/index.d.ts +101 -24
- package/dist/index.js +392 -126
- package/dist/index.js.map +1 -1
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -188,6 +188,12 @@ type OrderByArgs<TTable extends Table> = {
|
|
|
188
188
|
* emulated with an extra `IS NULL` sort key on MySQL.
|
|
189
189
|
*/
|
|
190
190
|
nulls?: 'first' | 'last';
|
|
191
|
+
/**
|
|
192
|
+
* Sort by the column's position in the `inArray` list the same request's `where` gives
|
|
193
|
+
* it, rather than by the column's own value. Requires that `inArray` filter; cannot be
|
|
194
|
+
* combined with `after` or `distinct`.
|
|
195
|
+
*/
|
|
196
|
+
matchFilterOrder?: boolean;
|
|
191
197
|
};
|
|
192
198
|
};
|
|
193
199
|
|
|
@@ -262,10 +268,13 @@ type LimitPolicyFor = (tableName: string) => ResolvedLimitPolicy | undefined;
|
|
|
262
268
|
* across relation boundaries. Each entry may also carry `nulls: first | last`
|
|
263
269
|
* (see {@link orderExpressions} for how MySQL emulates it).
|
|
264
270
|
*
|
|
271
|
+
* An entry may instead set `matchFilterOrder`, which sorts by the column's position in the
|
|
272
|
+
* `inArray` list the same request's `where` gives it — `whereArgs` is that `where`.
|
|
273
|
+
*
|
|
265
274
|
* `ctx` supplies the tables and relation map that relation ordering needs; callers whose
|
|
266
275
|
* inputs cannot contain relation keys may omit it.
|
|
267
276
|
*/
|
|
268
|
-
declare const extractOrderBy: <TTable extends Table, TArgs extends OrderByArgs<any> = OrderByArgs<TTable>>(table: TTable, orderArgs: TArgs, ctx?: RelationFilterContext) => SQL[];
|
|
277
|
+
declare const extractOrderBy: <TTable extends Table, TArgs extends OrderByArgs<any> = OrderByArgs<TTable>>(table: TTable, orderArgs: TArgs, ctx?: RelationFilterContext, whereArgs?: Record<string, any>) => SQL[];
|
|
269
278
|
/**
|
|
270
279
|
* Everything `extractFilters` needs to turn a relation key in a `where` argument into a
|
|
271
280
|
* correlated subquery. Omitted by callers that don't generate relation filters, in which case
|
|
@@ -623,27 +632,39 @@ type GeneratedData<TDatabase extends AnyDrizzleDB<any>> = {
|
|
|
623
632
|
entities: GeneratedEntities<TDatabase>;
|
|
624
633
|
};
|
|
625
634
|
/**
|
|
626
|
-
*
|
|
635
|
+
* A feature switch. `true` / `false` decides for the whole build; a predicate decides per
|
|
636
|
+
* table, receiving the table's key in the Drizzle schema.
|
|
637
|
+
*
|
|
638
|
+
* ```ts
|
|
639
|
+
* features: { delete: (table) => table !== 'auditLog' }
|
|
640
|
+
* ```
|
|
641
|
+
*/
|
|
642
|
+
type FeatureSwitch = boolean | ((tableName: string) => boolean);
|
|
643
|
+
/**
|
|
644
|
+
* Per-feature switches for what `buildSchema` generates. Every flag defaults to `true` except
|
|
645
|
+
* `upsert`, `nestedWrites`, `fieldUpdateOperations`, `countMutations` and `requireWhere`.
|
|
646
|
+
* Each one takes a boolean or a per-table predicate, apart from `nestedWrites`, which is
|
|
647
|
+
* build-wide.
|
|
627
648
|
* See {@link BuildSchemaConfig.features}.
|
|
628
649
|
*/
|
|
629
650
|
type SchemaFeatures = {
|
|
630
651
|
/** `<plural>Aggregate` root queries and the aggregate output types. @default true */
|
|
631
|
-
aggregates?:
|
|
652
|
+
aggregates?: FeatureSwitch;
|
|
632
653
|
/**
|
|
633
654
|
* `<plural>GroupBy` root queries — the same aggregates, one row per group. Requires
|
|
634
655
|
* `aggregates`, whose output types the grouped result reuses.
|
|
635
656
|
*
|
|
636
657
|
* @default true
|
|
637
658
|
*/
|
|
638
|
-
groupBy?:
|
|
659
|
+
groupBy?: FeatureSwitch;
|
|
639
660
|
/** `<relation>Aggregate` fields on object types, for to-many relations. @default true */
|
|
640
|
-
relationAggregates?:
|
|
661
|
+
relationAggregates?: FeatureSwitch;
|
|
641
662
|
/** The `distinct` argument on list queries. @default true */
|
|
642
|
-
distinct?:
|
|
663
|
+
distinct?: FeatureSwitch;
|
|
643
664
|
/** `create<Table>` / `create<Table>Single` mutations. @default true */
|
|
644
|
-
insert?:
|
|
665
|
+
insert?: FeatureSwitch;
|
|
645
666
|
/** `update<Table>` / `update<Table>Single` mutations. @default true */
|
|
646
|
-
update?:
|
|
667
|
+
update?: FeatureSwitch;
|
|
647
668
|
/**
|
|
648
669
|
* `update<Table>Many` mutations — batch update with a per-entry `set` and `where`,
|
|
649
670
|
* executed inside one transaction. Only generated when `update` is also enabled,
|
|
@@ -651,9 +672,9 @@ type SchemaFeatures = {
|
|
|
651
672
|
*
|
|
652
673
|
* @default true
|
|
653
674
|
*/
|
|
654
|
-
updateMany?:
|
|
675
|
+
updateMany?: FeatureSwitch;
|
|
655
676
|
/** `delete<Table>` / `delete<Table>Single` mutations. @default true */
|
|
656
|
-
delete?:
|
|
677
|
+
delete?: FeatureSwitch;
|
|
657
678
|
/**
|
|
658
679
|
* `upsert<Table>` / `upsert<Table>Single` mutations — insert, or update the row that
|
|
659
680
|
* already holds the same unique key. Off unless asked for, so an existing schema does
|
|
@@ -661,7 +682,7 @@ type SchemaFeatures = {
|
|
|
661
682
|
*
|
|
662
683
|
* @default false
|
|
663
684
|
*/
|
|
664
|
-
upsert?:
|
|
685
|
+
upsert?: FeatureSwitch;
|
|
665
686
|
/**
|
|
666
687
|
* Relation fields on `Create<Table>Input` and `Update<Table>Input`, so a parent row and
|
|
667
688
|
* the rows it is related to can be written in one mutation. Off unless asked for: it adds
|
|
@@ -719,7 +740,7 @@ type SchemaFeatures = {
|
|
|
719
740
|
*
|
|
720
741
|
* @default false
|
|
721
742
|
*/
|
|
722
|
-
fieldUpdateOperations?:
|
|
743
|
+
fieldUpdateOperations?: FeatureSwitch;
|
|
723
744
|
/**
|
|
724
745
|
* `update<Table>Count` / `delete<Table>Count` mutations — the same write as the plural
|
|
725
746
|
* `update<Table>` / `delete<Table>`, returning the number of rows affected instead of the
|
|
@@ -738,7 +759,7 @@ type SchemaFeatures = {
|
|
|
738
759
|
*
|
|
739
760
|
* @default false
|
|
740
761
|
*/
|
|
741
|
-
countMutations?:
|
|
762
|
+
countMutations?: FeatureSwitch;
|
|
742
763
|
/**
|
|
743
764
|
* Makes `where` non-null on the plural `update<Table>` / `delete<Table>` mutations, and
|
|
744
765
|
* rejects a `where` that collapses to no filters (e.g. `where: {}`), so a schema can rule
|
|
@@ -749,7 +770,7 @@ type SchemaFeatures = {
|
|
|
749
770
|
*
|
|
750
771
|
* @default false
|
|
751
772
|
*/
|
|
752
|
-
requireWhere?:
|
|
773
|
+
requireWhere?: FeatureSwitch;
|
|
753
774
|
};
|
|
754
775
|
/**
|
|
755
776
|
* Per-field cost hints for `graphql-query-complexity` (or any estimator that reads
|
|
@@ -903,11 +924,11 @@ type BuildSchemaConfig = {
|
|
|
903
924
|
*/
|
|
904
925
|
complexity?: boolean | ComplexityConfig;
|
|
905
926
|
/**
|
|
906
|
-
* Turns individual generated features off.
|
|
927
|
+
* Turns individual generated features off, for the whole build or per table.
|
|
907
928
|
*
|
|
908
|
-
* Every flag defaults to `true` except `upsert`, which
|
|
909
|
-
* `features` block generates exactly what it generated before this option
|
|
910
|
-
* Turning one off removes both the schema surface it adds and the work behind it.
|
|
929
|
+
* Every flag defaults to `true` except `upsert` and `nestedWrites`, which are opt-in: a
|
|
930
|
+
* build with no `features` block generates exactly what it generated before this option
|
|
931
|
+
* existed. Turning one off removes both the schema surface it adds and the work behind it.
|
|
911
932
|
*
|
|
912
933
|
* ```ts
|
|
913
934
|
* buildSchema(db, {
|
|
@@ -921,9 +942,34 @@ type BuildSchemaConfig = {
|
|
|
921
942
|
* });
|
|
922
943
|
* ```
|
|
923
944
|
*
|
|
924
|
-
*
|
|
925
|
-
*
|
|
926
|
-
*
|
|
945
|
+
* Any flag may instead be a predicate, which is asked once per table with the table's key
|
|
946
|
+
* in the Drizzle schema — the usual case, where a handful of tables must not be written
|
|
947
|
+
* through the API and the rest want the full set:
|
|
948
|
+
*
|
|
949
|
+
* ```ts
|
|
950
|
+
* buildSchema(db, {
|
|
951
|
+
* features: {
|
|
952
|
+
* delete: (table) => table !== 'auditLog',
|
|
953
|
+
* update: (table) => !ownedByCustomResolver.has(table),
|
|
954
|
+
* upsert: (table) => table === 'settings',
|
|
955
|
+
* },
|
|
956
|
+
* });
|
|
957
|
+
* ```
|
|
958
|
+
*
|
|
959
|
+
* A table that generates nothing at all belongs in {@link BuildSchemaConfig.exclude}; this
|
|
960
|
+
* decides which operations a table that *is* in the schema offers. `nestedWrites` is the one
|
|
961
|
+
* flag that stays build-wide: its plans are computed once over the whole relation graph, and
|
|
962
|
+
* a nested write reaches a second table by definition.
|
|
963
|
+
*
|
|
964
|
+
* Some operations are built out of others — an upsert writes through insert and update, a
|
|
965
|
+
* batch update reuses the update input, a grouped query reuses the aggregate types. Flags
|
|
966
|
+
* that contradict those implications warn on the console at build time (naming the tables)
|
|
967
|
+
* rather than leaving a second write path past the operation you turned off to be found
|
|
968
|
+
* later.
|
|
969
|
+
*
|
|
970
|
+
* Turning off every mutation feature for every table omits the `Mutation` type entirely,
|
|
971
|
+
* exactly as `mutations: false` does. Query-side features can all be off — the list and
|
|
972
|
+
* single queries are always generated, so `Query` is never empty.
|
|
927
973
|
*/
|
|
928
974
|
features?: SchemaFeatures;
|
|
929
975
|
/**
|
|
@@ -1036,11 +1082,23 @@ type BuildSchemaConfig = {
|
|
|
1036
1082
|
* Example: `(name) => name === 'users' ? { singular: 'user', plural: 'users' } : undefined`
|
|
1037
1083
|
* produces type `User`, queries `users` / `user`, mutations `createUsers` / `createUser` for
|
|
1038
1084
|
* the `users` table, and leaves other tables with their default names.
|
|
1085
|
+
*
|
|
1086
|
+
* Pass the string `'singularize'` for the built-in preset, which derives both forms of every
|
|
1087
|
+
* table key with the library's own `pluralize` — the mapper most schemas with plural table
|
|
1088
|
+
* keys would otherwise write by hand:
|
|
1089
|
+
*
|
|
1090
|
+
* ```ts
|
|
1091
|
+
* buildSchema(db, { typeNameMapper: 'singularize' });
|
|
1092
|
+
* // tasks -> type Task, queries `tasks` / `task`, mutations `createTasks` / `createTask`
|
|
1093
|
+
* ```
|
|
1094
|
+
*
|
|
1095
|
+
* The same function is exported as `singularizeMapper` for wrapping — e.g. to keep one
|
|
1096
|
+
* table's names as they are: `(t) => (t === 'audit_log' ? undefined : singularizeMapper(t))`.
|
|
1039
1097
|
*/
|
|
1040
|
-
typeNameMapper?: (tableName: string) => {
|
|
1098
|
+
typeNameMapper?: 'singularize' | ((tableName: string) => {
|
|
1041
1099
|
singular: string;
|
|
1042
1100
|
plural: string;
|
|
1043
|
-
} | undefined;
|
|
1101
|
+
} | undefined);
|
|
1044
1102
|
/**
|
|
1045
1103
|
* Controls whether a relation is eagerly pre-fetched via Drizzle's `with:` clause
|
|
1046
1104
|
* when its parent is loaded through a generated query or mutation.
|
|
@@ -1238,6 +1296,25 @@ type BuildSchemaConfig = {
|
|
|
1238
1296
|
enumNameMapper?: EnumNameMapper;
|
|
1239
1297
|
};
|
|
1240
1298
|
|
|
1299
|
+
/**
|
|
1300
|
+
* The `typeNameMapper` preset behind `typeNameMapper: 'singularize'`.
|
|
1301
|
+
*
|
|
1302
|
+
* Derives the singular and plural forms of a table key with the library's own `pluralize`,
|
|
1303
|
+
* which is what nearly every consumer with plural table keys (`export const tasks =
|
|
1304
|
+
* pgTable('tasks', …)`) was writing by hand — and adding `pluralize` to their own
|
|
1305
|
+
* dependencies to write.
|
|
1306
|
+
*
|
|
1307
|
+
* `tasks` becomes type `Task`, queries `tasks` / `task`, mutations `createTasks` /
|
|
1308
|
+
* `createTask`. A key that is already singular is pluralized for the list side, so `task`
|
|
1309
|
+
* yields the same names, and a capitalized key (`Tasks`) yields them too — the field forms
|
|
1310
|
+
* are uncapitalized so the generated names follow GraphQL's camelCase convention whatever
|
|
1311
|
+
* the schema key looks like. The type name is capitalized by the generator either way.
|
|
1312
|
+
*/
|
|
1313
|
+
declare const singularizeMapper: (tableName: string) => {
|
|
1314
|
+
singular: string;
|
|
1315
|
+
plural: string;
|
|
1316
|
+
};
|
|
1317
|
+
|
|
1241
1318
|
/**
|
|
1242
1319
|
* A 64-bit integer. Always transported as a decimal string, in both directions, so no value
|
|
1243
1320
|
* is ever silently rounded by JSON's double-precision numbers. `graphql-scalars`' own
|
|
@@ -1255,4 +1332,4 @@ declare const GraphQLDecimalString: GraphQLScalarType<string, string>;
|
|
|
1255
1332
|
|
|
1256
1333
|
declare const buildSchema: <TDbClient extends AnyDrizzleDB<any>>(db: TDbClient, config?: BuildSchemaConfig) => GeneratedData<TDbClient>;
|
|
1257
1334
|
|
|
1258
|
-
export { type AggregateResolver, type AnyDrizzleDB, type BuildSchemaConfig, type ColumnDeprecator, type ColumnDescriber, type ColumnDocInfo, type ColumnTypeMapper, type ColumnTypeMapperInfo, type ComplexityConfig, type DeleteResolver, type DeleteSingleResolver, type EnumNameInfo, type EnumNameMapper, type ExtractRelations, type ExtractTableByName, type ExtractTableRelations, type ExtractTables, type GeneratedData, type GeneratedEntities, type GeneratedInputs, type GeneratedOutputs, GraphQLBigIntString, GraphQLDecimalString, type InsertArrResolver, type InsertResolver, type LimitsConfig, type MutationReturnlessResult, type MutationsCore, type QueriesCore, type RelationDescriber, type RelationResolverFactory, type ScalarOverride, type ScalarOverridesConfig, type SchemaDocs, type SchemaExclusions, type SchemaFeatures, type SelectResolver, type SelectSingleResolver, type TableDescriber, type TableLimitPolicy, type TableNamedRelations, type UpdateManyArgs, type UpdateManyEntry, type UpdateManyResolver, type UpdateResolver, type UpdateSingleResolver, type UpsertArgs, type UpsertArrResolver, type UpsertConflictArgs, type UpsertResolver, buildSchema, createRelationResolverFactory, defaultErrorMapper, drizzleExecutorKey, extractFilters, extractOrderBy, extractRelationJoinColumns };
|
|
1335
|
+
export { type AggregateResolver, type AnyDrizzleDB, type BuildSchemaConfig, type ColumnDeprecator, type ColumnDescriber, type ColumnDocInfo, type ColumnTypeMapper, type ColumnTypeMapperInfo, type ComplexityConfig, type DeleteResolver, type DeleteSingleResolver, type EnumNameInfo, type EnumNameMapper, type ExtractRelations, type ExtractTableByName, type ExtractTableRelations, type ExtractTables, type FeatureSwitch, type GeneratedData, type GeneratedEntities, type GeneratedInputs, type GeneratedOutputs, GraphQLBigIntString, GraphQLDecimalString, type InsertArrResolver, type InsertResolver, type LimitsConfig, type MutationReturnlessResult, type MutationsCore, type QueriesCore, type RelationDescriber, type RelationResolverFactory, type ScalarOverride, type ScalarOverridesConfig, type SchemaDocs, type SchemaExclusions, type SchemaFeatures, type SelectResolver, type SelectSingleResolver, type TableDescriber, type TableLimitPolicy, type TableNamedRelations, type UpdateManyArgs, type UpdateManyEntry, type UpdateManyResolver, type UpdateResolver, type UpdateSingleResolver, type UpsertArgs, type UpsertArrResolver, type UpsertConflictArgs, type UpsertResolver, buildSchema, createRelationResolverFactory, defaultErrorMapper, drizzleExecutorKey, extractFilters, extractOrderBy, extractRelationJoinColumns, singularizeMapper };
|
package/dist/index.d.ts
CHANGED
|
@@ -188,6 +188,12 @@ type OrderByArgs<TTable extends Table> = {
|
|
|
188
188
|
* emulated with an extra `IS NULL` sort key on MySQL.
|
|
189
189
|
*/
|
|
190
190
|
nulls?: 'first' | 'last';
|
|
191
|
+
/**
|
|
192
|
+
* Sort by the column's position in the `inArray` list the same request's `where` gives
|
|
193
|
+
* it, rather than by the column's own value. Requires that `inArray` filter; cannot be
|
|
194
|
+
* combined with `after` or `distinct`.
|
|
195
|
+
*/
|
|
196
|
+
matchFilterOrder?: boolean;
|
|
191
197
|
};
|
|
192
198
|
};
|
|
193
199
|
|
|
@@ -262,10 +268,13 @@ type LimitPolicyFor = (tableName: string) => ResolvedLimitPolicy | undefined;
|
|
|
262
268
|
* across relation boundaries. Each entry may also carry `nulls: first | last`
|
|
263
269
|
* (see {@link orderExpressions} for how MySQL emulates it).
|
|
264
270
|
*
|
|
271
|
+
* An entry may instead set `matchFilterOrder`, which sorts by the column's position in the
|
|
272
|
+
* `inArray` list the same request's `where` gives it — `whereArgs` is that `where`.
|
|
273
|
+
*
|
|
265
274
|
* `ctx` supplies the tables and relation map that relation ordering needs; callers whose
|
|
266
275
|
* inputs cannot contain relation keys may omit it.
|
|
267
276
|
*/
|
|
268
|
-
declare const extractOrderBy: <TTable extends Table, TArgs extends OrderByArgs<any> = OrderByArgs<TTable>>(table: TTable, orderArgs: TArgs, ctx?: RelationFilterContext) => SQL[];
|
|
277
|
+
declare const extractOrderBy: <TTable extends Table, TArgs extends OrderByArgs<any> = OrderByArgs<TTable>>(table: TTable, orderArgs: TArgs, ctx?: RelationFilterContext, whereArgs?: Record<string, any>) => SQL[];
|
|
269
278
|
/**
|
|
270
279
|
* Everything `extractFilters` needs to turn a relation key in a `where` argument into a
|
|
271
280
|
* correlated subquery. Omitted by callers that don't generate relation filters, in which case
|
|
@@ -623,27 +632,39 @@ type GeneratedData<TDatabase extends AnyDrizzleDB<any>> = {
|
|
|
623
632
|
entities: GeneratedEntities<TDatabase>;
|
|
624
633
|
};
|
|
625
634
|
/**
|
|
626
|
-
*
|
|
635
|
+
* A feature switch. `true` / `false` decides for the whole build; a predicate decides per
|
|
636
|
+
* table, receiving the table's key in the Drizzle schema.
|
|
637
|
+
*
|
|
638
|
+
* ```ts
|
|
639
|
+
* features: { delete: (table) => table !== 'auditLog' }
|
|
640
|
+
* ```
|
|
641
|
+
*/
|
|
642
|
+
type FeatureSwitch = boolean | ((tableName: string) => boolean);
|
|
643
|
+
/**
|
|
644
|
+
* Per-feature switches for what `buildSchema` generates. Every flag defaults to `true` except
|
|
645
|
+
* `upsert`, `nestedWrites`, `fieldUpdateOperations`, `countMutations` and `requireWhere`.
|
|
646
|
+
* Each one takes a boolean or a per-table predicate, apart from `nestedWrites`, which is
|
|
647
|
+
* build-wide.
|
|
627
648
|
* See {@link BuildSchemaConfig.features}.
|
|
628
649
|
*/
|
|
629
650
|
type SchemaFeatures = {
|
|
630
651
|
/** `<plural>Aggregate` root queries and the aggregate output types. @default true */
|
|
631
|
-
aggregates?:
|
|
652
|
+
aggregates?: FeatureSwitch;
|
|
632
653
|
/**
|
|
633
654
|
* `<plural>GroupBy` root queries — the same aggregates, one row per group. Requires
|
|
634
655
|
* `aggregates`, whose output types the grouped result reuses.
|
|
635
656
|
*
|
|
636
657
|
* @default true
|
|
637
658
|
*/
|
|
638
|
-
groupBy?:
|
|
659
|
+
groupBy?: FeatureSwitch;
|
|
639
660
|
/** `<relation>Aggregate` fields on object types, for to-many relations. @default true */
|
|
640
|
-
relationAggregates?:
|
|
661
|
+
relationAggregates?: FeatureSwitch;
|
|
641
662
|
/** The `distinct` argument on list queries. @default true */
|
|
642
|
-
distinct?:
|
|
663
|
+
distinct?: FeatureSwitch;
|
|
643
664
|
/** `create<Table>` / `create<Table>Single` mutations. @default true */
|
|
644
|
-
insert?:
|
|
665
|
+
insert?: FeatureSwitch;
|
|
645
666
|
/** `update<Table>` / `update<Table>Single` mutations. @default true */
|
|
646
|
-
update?:
|
|
667
|
+
update?: FeatureSwitch;
|
|
647
668
|
/**
|
|
648
669
|
* `update<Table>Many` mutations — batch update with a per-entry `set` and `where`,
|
|
649
670
|
* executed inside one transaction. Only generated when `update` is also enabled,
|
|
@@ -651,9 +672,9 @@ type SchemaFeatures = {
|
|
|
651
672
|
*
|
|
652
673
|
* @default true
|
|
653
674
|
*/
|
|
654
|
-
updateMany?:
|
|
675
|
+
updateMany?: FeatureSwitch;
|
|
655
676
|
/** `delete<Table>` / `delete<Table>Single` mutations. @default true */
|
|
656
|
-
delete?:
|
|
677
|
+
delete?: FeatureSwitch;
|
|
657
678
|
/**
|
|
658
679
|
* `upsert<Table>` / `upsert<Table>Single` mutations — insert, or update the row that
|
|
659
680
|
* already holds the same unique key. Off unless asked for, so an existing schema does
|
|
@@ -661,7 +682,7 @@ type SchemaFeatures = {
|
|
|
661
682
|
*
|
|
662
683
|
* @default false
|
|
663
684
|
*/
|
|
664
|
-
upsert?:
|
|
685
|
+
upsert?: FeatureSwitch;
|
|
665
686
|
/**
|
|
666
687
|
* Relation fields on `Create<Table>Input` and `Update<Table>Input`, so a parent row and
|
|
667
688
|
* the rows it is related to can be written in one mutation. Off unless asked for: it adds
|
|
@@ -719,7 +740,7 @@ type SchemaFeatures = {
|
|
|
719
740
|
*
|
|
720
741
|
* @default false
|
|
721
742
|
*/
|
|
722
|
-
fieldUpdateOperations?:
|
|
743
|
+
fieldUpdateOperations?: FeatureSwitch;
|
|
723
744
|
/**
|
|
724
745
|
* `update<Table>Count` / `delete<Table>Count` mutations — the same write as the plural
|
|
725
746
|
* `update<Table>` / `delete<Table>`, returning the number of rows affected instead of the
|
|
@@ -738,7 +759,7 @@ type SchemaFeatures = {
|
|
|
738
759
|
*
|
|
739
760
|
* @default false
|
|
740
761
|
*/
|
|
741
|
-
countMutations?:
|
|
762
|
+
countMutations?: FeatureSwitch;
|
|
742
763
|
/**
|
|
743
764
|
* Makes `where` non-null on the plural `update<Table>` / `delete<Table>` mutations, and
|
|
744
765
|
* rejects a `where` that collapses to no filters (e.g. `where: {}`), so a schema can rule
|
|
@@ -749,7 +770,7 @@ type SchemaFeatures = {
|
|
|
749
770
|
*
|
|
750
771
|
* @default false
|
|
751
772
|
*/
|
|
752
|
-
requireWhere?:
|
|
773
|
+
requireWhere?: FeatureSwitch;
|
|
753
774
|
};
|
|
754
775
|
/**
|
|
755
776
|
* Per-field cost hints for `graphql-query-complexity` (or any estimator that reads
|
|
@@ -903,11 +924,11 @@ type BuildSchemaConfig = {
|
|
|
903
924
|
*/
|
|
904
925
|
complexity?: boolean | ComplexityConfig;
|
|
905
926
|
/**
|
|
906
|
-
* Turns individual generated features off.
|
|
927
|
+
* Turns individual generated features off, for the whole build or per table.
|
|
907
928
|
*
|
|
908
|
-
* Every flag defaults to `true` except `upsert`, which
|
|
909
|
-
* `features` block generates exactly what it generated before this option
|
|
910
|
-
* Turning one off removes both the schema surface it adds and the work behind it.
|
|
929
|
+
* Every flag defaults to `true` except `upsert` and `nestedWrites`, which are opt-in: a
|
|
930
|
+
* build with no `features` block generates exactly what it generated before this option
|
|
931
|
+
* existed. Turning one off removes both the schema surface it adds and the work behind it.
|
|
911
932
|
*
|
|
912
933
|
* ```ts
|
|
913
934
|
* buildSchema(db, {
|
|
@@ -921,9 +942,34 @@ type BuildSchemaConfig = {
|
|
|
921
942
|
* });
|
|
922
943
|
* ```
|
|
923
944
|
*
|
|
924
|
-
*
|
|
925
|
-
*
|
|
926
|
-
*
|
|
945
|
+
* Any flag may instead be a predicate, which is asked once per table with the table's key
|
|
946
|
+
* in the Drizzle schema — the usual case, where a handful of tables must not be written
|
|
947
|
+
* through the API and the rest want the full set:
|
|
948
|
+
*
|
|
949
|
+
* ```ts
|
|
950
|
+
* buildSchema(db, {
|
|
951
|
+
* features: {
|
|
952
|
+
* delete: (table) => table !== 'auditLog',
|
|
953
|
+
* update: (table) => !ownedByCustomResolver.has(table),
|
|
954
|
+
* upsert: (table) => table === 'settings',
|
|
955
|
+
* },
|
|
956
|
+
* });
|
|
957
|
+
* ```
|
|
958
|
+
*
|
|
959
|
+
* A table that generates nothing at all belongs in {@link BuildSchemaConfig.exclude}; this
|
|
960
|
+
* decides which operations a table that *is* in the schema offers. `nestedWrites` is the one
|
|
961
|
+
* flag that stays build-wide: its plans are computed once over the whole relation graph, and
|
|
962
|
+
* a nested write reaches a second table by definition.
|
|
963
|
+
*
|
|
964
|
+
* Some operations are built out of others — an upsert writes through insert and update, a
|
|
965
|
+
* batch update reuses the update input, a grouped query reuses the aggregate types. Flags
|
|
966
|
+
* that contradict those implications warn on the console at build time (naming the tables)
|
|
967
|
+
* rather than leaving a second write path past the operation you turned off to be found
|
|
968
|
+
* later.
|
|
969
|
+
*
|
|
970
|
+
* Turning off every mutation feature for every table omits the `Mutation` type entirely,
|
|
971
|
+
* exactly as `mutations: false` does. Query-side features can all be off — the list and
|
|
972
|
+
* single queries are always generated, so `Query` is never empty.
|
|
927
973
|
*/
|
|
928
974
|
features?: SchemaFeatures;
|
|
929
975
|
/**
|
|
@@ -1036,11 +1082,23 @@ type BuildSchemaConfig = {
|
|
|
1036
1082
|
* Example: `(name) => name === 'users' ? { singular: 'user', plural: 'users' } : undefined`
|
|
1037
1083
|
* produces type `User`, queries `users` / `user`, mutations `createUsers` / `createUser` for
|
|
1038
1084
|
* the `users` table, and leaves other tables with their default names.
|
|
1085
|
+
*
|
|
1086
|
+
* Pass the string `'singularize'` for the built-in preset, which derives both forms of every
|
|
1087
|
+
* table key with the library's own `pluralize` — the mapper most schemas with plural table
|
|
1088
|
+
* keys would otherwise write by hand:
|
|
1089
|
+
*
|
|
1090
|
+
* ```ts
|
|
1091
|
+
* buildSchema(db, { typeNameMapper: 'singularize' });
|
|
1092
|
+
* // tasks -> type Task, queries `tasks` / `task`, mutations `createTasks` / `createTask`
|
|
1093
|
+
* ```
|
|
1094
|
+
*
|
|
1095
|
+
* The same function is exported as `singularizeMapper` for wrapping — e.g. to keep one
|
|
1096
|
+
* table's names as they are: `(t) => (t === 'audit_log' ? undefined : singularizeMapper(t))`.
|
|
1039
1097
|
*/
|
|
1040
|
-
typeNameMapper?: (tableName: string) => {
|
|
1098
|
+
typeNameMapper?: 'singularize' | ((tableName: string) => {
|
|
1041
1099
|
singular: string;
|
|
1042
1100
|
plural: string;
|
|
1043
|
-
} | undefined;
|
|
1101
|
+
} | undefined);
|
|
1044
1102
|
/**
|
|
1045
1103
|
* Controls whether a relation is eagerly pre-fetched via Drizzle's `with:` clause
|
|
1046
1104
|
* when its parent is loaded through a generated query or mutation.
|
|
@@ -1238,6 +1296,25 @@ type BuildSchemaConfig = {
|
|
|
1238
1296
|
enumNameMapper?: EnumNameMapper;
|
|
1239
1297
|
};
|
|
1240
1298
|
|
|
1299
|
+
/**
|
|
1300
|
+
* The `typeNameMapper` preset behind `typeNameMapper: 'singularize'`.
|
|
1301
|
+
*
|
|
1302
|
+
* Derives the singular and plural forms of a table key with the library's own `pluralize`,
|
|
1303
|
+
* which is what nearly every consumer with plural table keys (`export const tasks =
|
|
1304
|
+
* pgTable('tasks', …)`) was writing by hand — and adding `pluralize` to their own
|
|
1305
|
+
* dependencies to write.
|
|
1306
|
+
*
|
|
1307
|
+
* `tasks` becomes type `Task`, queries `tasks` / `task`, mutations `createTasks` /
|
|
1308
|
+
* `createTask`. A key that is already singular is pluralized for the list side, so `task`
|
|
1309
|
+
* yields the same names, and a capitalized key (`Tasks`) yields them too — the field forms
|
|
1310
|
+
* are uncapitalized so the generated names follow GraphQL's camelCase convention whatever
|
|
1311
|
+
* the schema key looks like. The type name is capitalized by the generator either way.
|
|
1312
|
+
*/
|
|
1313
|
+
declare const singularizeMapper: (tableName: string) => {
|
|
1314
|
+
singular: string;
|
|
1315
|
+
plural: string;
|
|
1316
|
+
};
|
|
1317
|
+
|
|
1241
1318
|
/**
|
|
1242
1319
|
* A 64-bit integer. Always transported as a decimal string, in both directions, so no value
|
|
1243
1320
|
* is ever silently rounded by JSON's double-precision numbers. `graphql-scalars`' own
|
|
@@ -1255,4 +1332,4 @@ declare const GraphQLDecimalString: GraphQLScalarType<string, string>;
|
|
|
1255
1332
|
|
|
1256
1333
|
declare const buildSchema: <TDbClient extends AnyDrizzleDB<any>>(db: TDbClient, config?: BuildSchemaConfig) => GeneratedData<TDbClient>;
|
|
1257
1334
|
|
|
1258
|
-
export { type AggregateResolver, type AnyDrizzleDB, type BuildSchemaConfig, type ColumnDeprecator, type ColumnDescriber, type ColumnDocInfo, type ColumnTypeMapper, type ColumnTypeMapperInfo, type ComplexityConfig, type DeleteResolver, type DeleteSingleResolver, type EnumNameInfo, type EnumNameMapper, type ExtractRelations, type ExtractTableByName, type ExtractTableRelations, type ExtractTables, type GeneratedData, type GeneratedEntities, type GeneratedInputs, type GeneratedOutputs, GraphQLBigIntString, GraphQLDecimalString, type InsertArrResolver, type InsertResolver, type LimitsConfig, type MutationReturnlessResult, type MutationsCore, type QueriesCore, type RelationDescriber, type RelationResolverFactory, type ScalarOverride, type ScalarOverridesConfig, type SchemaDocs, type SchemaExclusions, type SchemaFeatures, type SelectResolver, type SelectSingleResolver, type TableDescriber, type TableLimitPolicy, type TableNamedRelations, type UpdateManyArgs, type UpdateManyEntry, type UpdateManyResolver, type UpdateResolver, type UpdateSingleResolver, type UpsertArgs, type UpsertArrResolver, type UpsertConflictArgs, type UpsertResolver, buildSchema, createRelationResolverFactory, defaultErrorMapper, drizzleExecutorKey, extractFilters, extractOrderBy, extractRelationJoinColumns };
|
|
1335
|
+
export { type AggregateResolver, type AnyDrizzleDB, type BuildSchemaConfig, type ColumnDeprecator, type ColumnDescriber, type ColumnDocInfo, type ColumnTypeMapper, type ColumnTypeMapperInfo, type ComplexityConfig, type DeleteResolver, type DeleteSingleResolver, type EnumNameInfo, type EnumNameMapper, type ExtractRelations, type ExtractTableByName, type ExtractTableRelations, type ExtractTables, type FeatureSwitch, type GeneratedData, type GeneratedEntities, type GeneratedInputs, type GeneratedOutputs, GraphQLBigIntString, GraphQLDecimalString, type InsertArrResolver, type InsertResolver, type LimitsConfig, type MutationReturnlessResult, type MutationsCore, type QueriesCore, type RelationDescriber, type RelationResolverFactory, type ScalarOverride, type ScalarOverridesConfig, type SchemaDocs, type SchemaExclusions, type SchemaFeatures, type SelectResolver, type SelectSingleResolver, type TableDescriber, type TableLimitPolicy, type TableNamedRelations, type UpdateManyArgs, type UpdateManyEntry, type UpdateManyResolver, type UpdateResolver, type UpdateSingleResolver, type UpsertArgs, type UpsertArrResolver, type UpsertConflictArgs, type UpsertResolver, buildSchema, createRelationResolverFactory, defaultErrorMapper, drizzleExecutorKey, extractFilters, extractOrderBy, extractRelationJoinColumns, singularizeMapper };
|