@vantreeseba/drizzle-graphql 7.8.0 → 7.9.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 +57 -0
- package/dist/README.md +57 -0
- package/dist/index.cjs +114 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +66 -6
- package/dist/index.d.ts +66 -6
- package/dist/index.js +114 -41
- package/dist/index.js.map +1 -1
- package/dist/package.json +3 -10
- package/package.json +3 -10
package/dist/index.d.cts
CHANGED
|
@@ -111,19 +111,19 @@ type TableNamedRelations = {
|
|
|
111
111
|
};
|
|
112
112
|
type ColTypeIsNull<TColumn extends Column, TColType> = TColumn['_']['notNull'] extends true ? TColType : TColType | null;
|
|
113
113
|
type ColTypeIsNullOrUndefinedWithDefault<TColumn extends Column, TColType> = TColumn['_']['notNull'] extends true ? TColumn['_']['hasDefault'] extends true ? TColType | null | undefined : TColumn['defaultFn'] extends undefined ? TColType : TColType | null | undefined : TColType | null | undefined;
|
|
114
|
-
type GetColumnGqlDataType<TColumn extends Column> = TColumn['dataType'] extends 'boolean' ? ColTypeIsNull<TColumn, boolean> : TColumn['dataType'] extends 'json' ? TColumn['
|
|
114
|
+
type GetColumnGqlDataType<TColumn extends Column> = TColumn['dataType'] extends 'boolean' ? ColTypeIsNull<TColumn, boolean> : TColumn['dataType'] extends 'json' ? TColumn['columnType'] extends 'PgGeometryObject' ? ColTypeIsNull<TColumn, {
|
|
115
115
|
x: number;
|
|
116
116
|
y: number;
|
|
117
117
|
}> : ColTypeIsNull<TColumn, string> : TColumn['dataType'] extends 'date' | 'string' | 'bigint' ? TColumn['enumValues'] extends [string, ...string[]] ? ColTypeIsNull<TColumn, TColumn['enumValues'][number]> : ColTypeIsNull<TColumn, string> : TColumn['dataType'] extends 'number' ? ColTypeIsNull<TColumn, number> : TColumn['dataType'] extends 'buffer' ? ColTypeIsNull<TColumn, number[]> : TColumn['dataType'] extends 'array' ? TColumn['columnType'] extends 'PgVector' ? ColTypeIsNull<TColumn, number[]> : TColumn['columnType'] extends 'PgGeometry' ? ColTypeIsNullOrUndefinedWithDefault<TColumn, [number, number]> : ColTypeIsNull<TColumn, Array<GetColumnGqlDataType<TColumn extends {
|
|
118
118
|
baseColumn: Column;
|
|
119
119
|
} ? TColumn['baseColumn'] : never> extends infer InnerColType ? InnerColType extends null | undefined ? never : InnerColType : never>> : never;
|
|
120
|
-
type GetColumnGqlInsertDataType<TColumn extends Column> = TColumn['dataType'] extends 'boolean' ? ColTypeIsNullOrUndefinedWithDefault<TColumn, boolean> : TColumn['dataType'] extends 'json' ? TColumn['
|
|
120
|
+
type GetColumnGqlInsertDataType<TColumn extends Column> = TColumn['dataType'] extends 'boolean' ? ColTypeIsNullOrUndefinedWithDefault<TColumn, boolean> : TColumn['dataType'] extends 'json' ? TColumn['columnType'] extends 'PgGeometryObject' ? ColTypeIsNullOrUndefinedWithDefault<TColumn, {
|
|
121
121
|
x: number;
|
|
122
122
|
y: number;
|
|
123
123
|
}> : ColTypeIsNullOrUndefinedWithDefault<TColumn, string> : TColumn['dataType'] extends 'date' | 'string' | 'bigint' ? TColumn['enumValues'] extends [string, ...string[]] ? ColTypeIsNullOrUndefinedWithDefault<TColumn, TColumn['enumValues'][number]> : ColTypeIsNullOrUndefinedWithDefault<TColumn, string> : TColumn['dataType'] extends 'number' ? ColTypeIsNullOrUndefinedWithDefault<TColumn, number> : TColumn['dataType'] extends 'buffer' ? ColTypeIsNullOrUndefinedWithDefault<TColumn, number[]> : TColumn['dataType'] extends 'array' ? TColumn['columnType'] extends 'PgVector' ? ColTypeIsNullOrUndefinedWithDefault<TColumn, number[]> : TColumn['columnType'] extends 'PgGeometry' ? ColTypeIsNullOrUndefinedWithDefault<TColumn, [number, number]> : ColTypeIsNullOrUndefinedWithDefault<TColumn, Array<GetColumnGqlDataType<TColumn extends {
|
|
124
124
|
baseColumn: Column;
|
|
125
125
|
} ? TColumn['baseColumn'] : never> extends infer InnerColType ? InnerColType extends null | undefined ? never : InnerColType : never>> : never;
|
|
126
|
-
type GetColumnGqlUpdateDataType<TColumn extends Column> = TColumn['dataType'] extends 'boolean' ? boolean | null | undefined : TColumn['dataType'] extends 'json' ? TColumn['
|
|
126
|
+
type GetColumnGqlUpdateDataType<TColumn extends Column> = TColumn['dataType'] extends 'boolean' ? boolean | null | undefined : TColumn['dataType'] extends 'json' ? TColumn['columnType'] extends 'PgGeometryObject' ? {
|
|
127
127
|
x: number;
|
|
128
128
|
y: number;
|
|
129
129
|
} | null | undefined : string | null | undefined : TColumn['dataType'] extends 'date' | 'string' | 'bigint' ? TColumn['enumValues'] extends [string, ...string[]] ? TColumn['enumValues'][number] | null | undefined : string | null | undefined : TColumn['dataType'] extends 'number' ? number | null | undefined : TColumn['dataType'] extends 'buffer' ? number[] | null | undefined : TColumn['dataType'] extends 'array' ? TColumn['columnType'] extends 'PgVector' ? number[] | null | undefined : TColumn['columnType'] extends 'PgGeometry' ? [number, number] | null | undefined : Array<GetColumnGqlDataType<TColumn extends {
|
|
@@ -300,6 +300,13 @@ type ResolvedLimitPolicy = {
|
|
|
300
300
|
* `buildSchema`; `undefined` for a table the caller left unbounded.
|
|
301
301
|
*/
|
|
302
302
|
type LimitPolicyFor = (tableName: string) => ResolvedLimitPolicy | undefined;
|
|
303
|
+
/**
|
|
304
|
+
* {@link BuildSchemaConfig.defaults} resolved for one table: the `orderBy` a read falls back
|
|
305
|
+
* to when the request passes none, already in the shape the generated argument has.
|
|
306
|
+
* `undefined` means the table declares no default and keeps whatever order the database
|
|
307
|
+
* returns.
|
|
308
|
+
*/
|
|
309
|
+
type DefaultOrderByFor = (tableName: string) => Record<string, any> | undefined;
|
|
303
310
|
/**
|
|
304
311
|
* Compiles an `orderBy` argument into ORDER BY expressions, highest priority first.
|
|
305
312
|
*
|
|
@@ -399,6 +406,8 @@ type TablePolicies = {
|
|
|
399
406
|
softDelete?: SoftDeleteFor;
|
|
400
407
|
/** See `BuildSchemaConfig.onWrite`. */
|
|
401
408
|
onWrite?: WriteHookFor;
|
|
409
|
+
/** See `BuildSchemaConfig.defaults`. */
|
|
410
|
+
defaultOrderBy?: DefaultOrderByFor;
|
|
402
411
|
};
|
|
403
412
|
/**
|
|
404
413
|
* Where a dialect's default sort places NULLs relative to non-NULL values:
|
|
@@ -499,10 +508,10 @@ type DeleteSingleArgs<TTable extends Table> = {
|
|
|
499
508
|
where: Filters<TTable>;
|
|
500
509
|
};
|
|
501
510
|
type SelectResolver<TTable extends Table, TTables extends Record<string, Table>, TRelations extends Record<string, Relation>> = (source: any, args: Partial<QueryArgs<TTable, false>>, context: any, info: GraphQLResolveInfo) => Promise<keyof TRelations extends infer RelKey ? RelKey extends string ? Array<GetRemappedTableDataType<TTable> & {
|
|
502
|
-
[K in RelKey]: TRelations[K] extends One<
|
|
511
|
+
[K in RelKey]: TRelations[K] extends One<infer TTargetName, any> ? GetRemappedTableDataType<ExtractTableByName<TTables, TTargetName> extends infer T ? T[keyof T] : never> | null : TRelations[K] extends Many<infer TTargetName> ? Array<GetRemappedTableDataType<ExtractTableByName<TTables, TTargetName> extends infer T ? T[keyof T] : never>> : never;
|
|
503
512
|
}> : Array<GetRemappedTableDataType<TTable>> : Array<GetRemappedTableDataType<TTable>>>;
|
|
504
513
|
type SelectSingleResolver<TTable extends Table, TTables extends Record<string, Table>, TRelations extends Record<string, Relation>> = (source: any, args: Partial<QueryArgs<TTable, true>>, context: any, info: GraphQLResolveInfo) => Promise<(keyof TRelations extends infer RelKey ? RelKey extends string ? GetRemappedTableDataType<TTable> & {
|
|
505
|
-
[K in RelKey]: TRelations[K] extends One<
|
|
514
|
+
[K in RelKey]: TRelations[K] extends One<infer TTargetName, any> ? GetRemappedTableDataType<ExtractTableByName<TTables, TTargetName> extends infer T ? T[keyof T] : never> | null : TRelations[K] extends Many<infer TTargetName> ? Array<GetRemappedTableDataType<ExtractTableByName<TTables, TTargetName> extends infer T ? T[keyof T] : never>> : never;
|
|
506
515
|
} : GetRemappedTableDataType<TTable> : GetRemappedTableDataType<TTable>) | null>;
|
|
507
516
|
/** Resolver for `create<Table>Single`: one row in, one row (or `undefined`) out. */
|
|
508
517
|
type InsertResolver<TTable extends Table, IsReturnless extends boolean> = (source: any, args: Partial<InsertArgs<TTable, true>>, context: any, info: GraphQLResolveInfo) => Promise<IsReturnless extends false ? GetRemappedTableDataType<TTable> | undefined : MutationReturnlessResult>;
|
|
@@ -915,6 +924,25 @@ type TableLimitPolicy = {
|
|
|
915
924
|
*/
|
|
916
925
|
clampToMax?: boolean;
|
|
917
926
|
};
|
|
927
|
+
/**
|
|
928
|
+
* One entry of a {@link TableDefaults} ordering: a direction, or a direction with the
|
|
929
|
+
* priority that decides where it sits among the other entries (higher first, as in the
|
|
930
|
+
* generated `orderBy` argument).
|
|
931
|
+
*/
|
|
932
|
+
type DefaultOrderByEntry = 'asc' | 'desc' | {
|
|
933
|
+
direction: 'asc' | 'desc';
|
|
934
|
+
priority?: number;
|
|
935
|
+
};
|
|
936
|
+
/** {@link DefaultsConfig} — what one table falls back to when the request does not say. */
|
|
937
|
+
type TableDefaults = {
|
|
938
|
+
/**
|
|
939
|
+
* The ordering a read of this table runs with when the request passes no `orderBy`, keyed
|
|
940
|
+
* by column property name.
|
|
941
|
+
*/
|
|
942
|
+
orderBy?: Record<string, DefaultOrderByEntry>;
|
|
943
|
+
};
|
|
944
|
+
/** {@link BuildSchemaConfig.defaults} — per-table defaults, keyed by the Drizzle schema key. */
|
|
945
|
+
type DefaultsConfig = Record<string, TableDefaults>;
|
|
918
946
|
/** {@link BuildSchemaConfig.limits} — a global policy plus per-table overrides. */
|
|
919
947
|
type LimitsConfig = TableLimitPolicy & {
|
|
920
948
|
/** Per-table overrides, keyed by the table's key in the Drizzle schema. */
|
|
@@ -1213,6 +1241,38 @@ type BuildSchemaConfig = {
|
|
|
1213
1241
|
* agree.
|
|
1214
1242
|
*/
|
|
1215
1243
|
limits?: LimitsConfig;
|
|
1244
|
+
/**
|
|
1245
|
+
* Per-table defaults for arguments the request leaves out. Today that is `orderBy`: the
|
|
1246
|
+
* presentation order a table has, declared once on the server instead of repeated by every
|
|
1247
|
+
* client.
|
|
1248
|
+
*
|
|
1249
|
+
* ```ts
|
|
1250
|
+
* buildSchema(db, {
|
|
1251
|
+
* defaults: {
|
|
1252
|
+
* Todos: { orderBy: { priority: 'desc', createdAt: 'desc' } },
|
|
1253
|
+
* AuditLog: { orderBy: { createdAt: { direction: 'desc', priority: 10 } } },
|
|
1254
|
+
* },
|
|
1255
|
+
* });
|
|
1256
|
+
* ```
|
|
1257
|
+
*
|
|
1258
|
+
* - Applies to the table's list and single queries, and to every to-many relation field
|
|
1259
|
+
* that *targets* it — a relation is ordered by the default of the table it reads, so a
|
|
1260
|
+
* table presents the same way wherever it is reached from. Eagerly and lazily loaded
|
|
1261
|
+
* relations agree.
|
|
1262
|
+
* - Only a missing `orderBy` is replaced. `orderBy: {}` is a request for no ordering and
|
|
1263
|
+
* stays one, and any `orderBy` the client sends replaces the default outright rather than
|
|
1264
|
+
* merging with it.
|
|
1265
|
+
* - Cursor pagination is defined over the effective ordering, so a default `orderBy` is
|
|
1266
|
+
* what an `after`-only page is ordered by. Changing a table's default changes what its
|
|
1267
|
+
* existing cursors mean.
|
|
1268
|
+
* - Entries name column property names of that table; a direction alone is shorthand for
|
|
1269
|
+
* `{ direction }`. Unknown table or column names throw at build time.
|
|
1270
|
+
* - Aggregates and `groupBy` take their own ordering and are unaffected.
|
|
1271
|
+
*
|
|
1272
|
+
* Off by default: a table with no entry keeps returning rows in whatever order the database
|
|
1273
|
+
* gives them, tiebroken by primary key where an operation needs a total order.
|
|
1274
|
+
*/
|
|
1275
|
+
defaults?: DefaultsConfig;
|
|
1216
1276
|
/**
|
|
1217
1277
|
* Row-level scoping: a predicate, derived from the GraphQL context, that every read and
|
|
1218
1278
|
* write of a table is confined to. This is the multi-tenancy / ownership knob — the one
|
|
@@ -1812,4 +1872,4 @@ declare const resolveSelection: (info: GraphQLResolveInfo | ResolveTree, options
|
|
|
1812
1872
|
|
|
1813
1873
|
declare const buildSchema: <TDbClient extends AnyDrizzleDB<any>>(db: TDbClient, config?: BuildSchemaConfig) => GeneratedData<TDbClient>;
|
|
1814
1874
|
|
|
1815
|
-
export { type AggregateResolver, type AnyDrizzleDB, type BuildSchemaConfig, type ColumnDeprecator, type ColumnDescriber, type ColumnDocInfo, type ColumnTypeMapper, type ColumnTypeMapperInfo, type ComplexityConfig, type ContextValuesConfig, type DeleteResolver, type DeleteSingleResolver, 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 GeneratedData, type GeneratedEntities, type GeneratedInputs, type GeneratedOutputs, GraphQLBigIntString, GraphQLDecimalString, type IdentifiedRows, type InsertArrResolver, type InsertResolver, type LimitsConfig, type MutationReturnlessResult, type MutationsCore, type OnWriteConfig, type QueriesCore, type RelationDescriber, type RelationResolverFactory, type ResolveSelectionOptions, type RowScope, type RowScopeFilter, type ScalarOverride, type ScalarOverridesConfig, type SchemaDocs, type SchemaExclusions, type SchemaFeatures, type ScopeConfig, type SelectResolver, type SelectSingleResolver, type SelectionOptions, type SoftDeleteColumn, type SoftDeleteConfig, type TableDescriber, type TableLimitPolicy, type TableNamedRelations, 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, drizzleExecutorKey, drizzleExtension, extractFilters, extractOrderBy, extractRelationJoinColumns, identifyRows, isDrizzleFieldExtension, resolveSelection, selectionToWith, singularizeMapper };
|
|
1875
|
+
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 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 GeneratedData, type GeneratedEntities, type GeneratedInputs, type GeneratedOutputs, GraphQLBigIntString, GraphQLDecimalString, type IdentifiedRows, type InsertArrResolver, type InsertResolver, type LimitsConfig, type MutationReturnlessResult, type MutationsCore, type OnWriteConfig, type QueriesCore, type RelationDescriber, type RelationResolverFactory, type ResolveSelectionOptions, type RowScope, type RowScopeFilter, type ScalarOverride, type ScalarOverridesConfig, type SchemaDocs, type SchemaExclusions, type SchemaFeatures, type ScopeConfig, type SelectResolver, type SelectSingleResolver, type SelectionOptions, type SoftDeleteColumn, type SoftDeleteConfig, type TableDefaults, type TableDescriber, type TableLimitPolicy, type TableNamedRelations, 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, drizzleExecutorKey, drizzleExtension, extractFilters, extractOrderBy, extractRelationJoinColumns, identifyRows, isDrizzleFieldExtension, resolveSelection, selectionToWith, singularizeMapper };
|
package/dist/index.d.ts
CHANGED
|
@@ -111,19 +111,19 @@ type TableNamedRelations = {
|
|
|
111
111
|
};
|
|
112
112
|
type ColTypeIsNull<TColumn extends Column, TColType> = TColumn['_']['notNull'] extends true ? TColType : TColType | null;
|
|
113
113
|
type ColTypeIsNullOrUndefinedWithDefault<TColumn extends Column, TColType> = TColumn['_']['notNull'] extends true ? TColumn['_']['hasDefault'] extends true ? TColType | null | undefined : TColumn['defaultFn'] extends undefined ? TColType : TColType | null | undefined : TColType | null | undefined;
|
|
114
|
-
type GetColumnGqlDataType<TColumn extends Column> = TColumn['dataType'] extends 'boolean' ? ColTypeIsNull<TColumn, boolean> : TColumn['dataType'] extends 'json' ? TColumn['
|
|
114
|
+
type GetColumnGqlDataType<TColumn extends Column> = TColumn['dataType'] extends 'boolean' ? ColTypeIsNull<TColumn, boolean> : TColumn['dataType'] extends 'json' ? TColumn['columnType'] extends 'PgGeometryObject' ? ColTypeIsNull<TColumn, {
|
|
115
115
|
x: number;
|
|
116
116
|
y: number;
|
|
117
117
|
}> : ColTypeIsNull<TColumn, string> : TColumn['dataType'] extends 'date' | 'string' | 'bigint' ? TColumn['enumValues'] extends [string, ...string[]] ? ColTypeIsNull<TColumn, TColumn['enumValues'][number]> : ColTypeIsNull<TColumn, string> : TColumn['dataType'] extends 'number' ? ColTypeIsNull<TColumn, number> : TColumn['dataType'] extends 'buffer' ? ColTypeIsNull<TColumn, number[]> : TColumn['dataType'] extends 'array' ? TColumn['columnType'] extends 'PgVector' ? ColTypeIsNull<TColumn, number[]> : TColumn['columnType'] extends 'PgGeometry' ? ColTypeIsNullOrUndefinedWithDefault<TColumn, [number, number]> : ColTypeIsNull<TColumn, Array<GetColumnGqlDataType<TColumn extends {
|
|
118
118
|
baseColumn: Column;
|
|
119
119
|
} ? TColumn['baseColumn'] : never> extends infer InnerColType ? InnerColType extends null | undefined ? never : InnerColType : never>> : never;
|
|
120
|
-
type GetColumnGqlInsertDataType<TColumn extends Column> = TColumn['dataType'] extends 'boolean' ? ColTypeIsNullOrUndefinedWithDefault<TColumn, boolean> : TColumn['dataType'] extends 'json' ? TColumn['
|
|
120
|
+
type GetColumnGqlInsertDataType<TColumn extends Column> = TColumn['dataType'] extends 'boolean' ? ColTypeIsNullOrUndefinedWithDefault<TColumn, boolean> : TColumn['dataType'] extends 'json' ? TColumn['columnType'] extends 'PgGeometryObject' ? ColTypeIsNullOrUndefinedWithDefault<TColumn, {
|
|
121
121
|
x: number;
|
|
122
122
|
y: number;
|
|
123
123
|
}> : ColTypeIsNullOrUndefinedWithDefault<TColumn, string> : TColumn['dataType'] extends 'date' | 'string' | 'bigint' ? TColumn['enumValues'] extends [string, ...string[]] ? ColTypeIsNullOrUndefinedWithDefault<TColumn, TColumn['enumValues'][number]> : ColTypeIsNullOrUndefinedWithDefault<TColumn, string> : TColumn['dataType'] extends 'number' ? ColTypeIsNullOrUndefinedWithDefault<TColumn, number> : TColumn['dataType'] extends 'buffer' ? ColTypeIsNullOrUndefinedWithDefault<TColumn, number[]> : TColumn['dataType'] extends 'array' ? TColumn['columnType'] extends 'PgVector' ? ColTypeIsNullOrUndefinedWithDefault<TColumn, number[]> : TColumn['columnType'] extends 'PgGeometry' ? ColTypeIsNullOrUndefinedWithDefault<TColumn, [number, number]> : ColTypeIsNullOrUndefinedWithDefault<TColumn, Array<GetColumnGqlDataType<TColumn extends {
|
|
124
124
|
baseColumn: Column;
|
|
125
125
|
} ? TColumn['baseColumn'] : never> extends infer InnerColType ? InnerColType extends null | undefined ? never : InnerColType : never>> : never;
|
|
126
|
-
type GetColumnGqlUpdateDataType<TColumn extends Column> = TColumn['dataType'] extends 'boolean' ? boolean | null | undefined : TColumn['dataType'] extends 'json' ? TColumn['
|
|
126
|
+
type GetColumnGqlUpdateDataType<TColumn extends Column> = TColumn['dataType'] extends 'boolean' ? boolean | null | undefined : TColumn['dataType'] extends 'json' ? TColumn['columnType'] extends 'PgGeometryObject' ? {
|
|
127
127
|
x: number;
|
|
128
128
|
y: number;
|
|
129
129
|
} | null | undefined : string | null | undefined : TColumn['dataType'] extends 'date' | 'string' | 'bigint' ? TColumn['enumValues'] extends [string, ...string[]] ? TColumn['enumValues'][number] | null | undefined : string | null | undefined : TColumn['dataType'] extends 'number' ? number | null | undefined : TColumn['dataType'] extends 'buffer' ? number[] | null | undefined : TColumn['dataType'] extends 'array' ? TColumn['columnType'] extends 'PgVector' ? number[] | null | undefined : TColumn['columnType'] extends 'PgGeometry' ? [number, number] | null | undefined : Array<GetColumnGqlDataType<TColumn extends {
|
|
@@ -300,6 +300,13 @@ type ResolvedLimitPolicy = {
|
|
|
300
300
|
* `buildSchema`; `undefined` for a table the caller left unbounded.
|
|
301
301
|
*/
|
|
302
302
|
type LimitPolicyFor = (tableName: string) => ResolvedLimitPolicy | undefined;
|
|
303
|
+
/**
|
|
304
|
+
* {@link BuildSchemaConfig.defaults} resolved for one table: the `orderBy` a read falls back
|
|
305
|
+
* to when the request passes none, already in the shape the generated argument has.
|
|
306
|
+
* `undefined` means the table declares no default and keeps whatever order the database
|
|
307
|
+
* returns.
|
|
308
|
+
*/
|
|
309
|
+
type DefaultOrderByFor = (tableName: string) => Record<string, any> | undefined;
|
|
303
310
|
/**
|
|
304
311
|
* Compiles an `orderBy` argument into ORDER BY expressions, highest priority first.
|
|
305
312
|
*
|
|
@@ -399,6 +406,8 @@ type TablePolicies = {
|
|
|
399
406
|
softDelete?: SoftDeleteFor;
|
|
400
407
|
/** See `BuildSchemaConfig.onWrite`. */
|
|
401
408
|
onWrite?: WriteHookFor;
|
|
409
|
+
/** See `BuildSchemaConfig.defaults`. */
|
|
410
|
+
defaultOrderBy?: DefaultOrderByFor;
|
|
402
411
|
};
|
|
403
412
|
/**
|
|
404
413
|
* Where a dialect's default sort places NULLs relative to non-NULL values:
|
|
@@ -499,10 +508,10 @@ type DeleteSingleArgs<TTable extends Table> = {
|
|
|
499
508
|
where: Filters<TTable>;
|
|
500
509
|
};
|
|
501
510
|
type SelectResolver<TTable extends Table, TTables extends Record<string, Table>, TRelations extends Record<string, Relation>> = (source: any, args: Partial<QueryArgs<TTable, false>>, context: any, info: GraphQLResolveInfo) => Promise<keyof TRelations extends infer RelKey ? RelKey extends string ? Array<GetRemappedTableDataType<TTable> & {
|
|
502
|
-
[K in RelKey]: TRelations[K] extends One<
|
|
511
|
+
[K in RelKey]: TRelations[K] extends One<infer TTargetName, any> ? GetRemappedTableDataType<ExtractTableByName<TTables, TTargetName> extends infer T ? T[keyof T] : never> | null : TRelations[K] extends Many<infer TTargetName> ? Array<GetRemappedTableDataType<ExtractTableByName<TTables, TTargetName> extends infer T ? T[keyof T] : never>> : never;
|
|
503
512
|
}> : Array<GetRemappedTableDataType<TTable>> : Array<GetRemappedTableDataType<TTable>>>;
|
|
504
513
|
type SelectSingleResolver<TTable extends Table, TTables extends Record<string, Table>, TRelations extends Record<string, Relation>> = (source: any, args: Partial<QueryArgs<TTable, true>>, context: any, info: GraphQLResolveInfo) => Promise<(keyof TRelations extends infer RelKey ? RelKey extends string ? GetRemappedTableDataType<TTable> & {
|
|
505
|
-
[K in RelKey]: TRelations[K] extends One<
|
|
514
|
+
[K in RelKey]: TRelations[K] extends One<infer TTargetName, any> ? GetRemappedTableDataType<ExtractTableByName<TTables, TTargetName> extends infer T ? T[keyof T] : never> | null : TRelations[K] extends Many<infer TTargetName> ? Array<GetRemappedTableDataType<ExtractTableByName<TTables, TTargetName> extends infer T ? T[keyof T] : never>> : never;
|
|
506
515
|
} : GetRemappedTableDataType<TTable> : GetRemappedTableDataType<TTable>) | null>;
|
|
507
516
|
/** Resolver for `create<Table>Single`: one row in, one row (or `undefined`) out. */
|
|
508
517
|
type InsertResolver<TTable extends Table, IsReturnless extends boolean> = (source: any, args: Partial<InsertArgs<TTable, true>>, context: any, info: GraphQLResolveInfo) => Promise<IsReturnless extends false ? GetRemappedTableDataType<TTable> | undefined : MutationReturnlessResult>;
|
|
@@ -915,6 +924,25 @@ type TableLimitPolicy = {
|
|
|
915
924
|
*/
|
|
916
925
|
clampToMax?: boolean;
|
|
917
926
|
};
|
|
927
|
+
/**
|
|
928
|
+
* One entry of a {@link TableDefaults} ordering: a direction, or a direction with the
|
|
929
|
+
* priority that decides where it sits among the other entries (higher first, as in the
|
|
930
|
+
* generated `orderBy` argument).
|
|
931
|
+
*/
|
|
932
|
+
type DefaultOrderByEntry = 'asc' | 'desc' | {
|
|
933
|
+
direction: 'asc' | 'desc';
|
|
934
|
+
priority?: number;
|
|
935
|
+
};
|
|
936
|
+
/** {@link DefaultsConfig} — what one table falls back to when the request does not say. */
|
|
937
|
+
type TableDefaults = {
|
|
938
|
+
/**
|
|
939
|
+
* The ordering a read of this table runs with when the request passes no `orderBy`, keyed
|
|
940
|
+
* by column property name.
|
|
941
|
+
*/
|
|
942
|
+
orderBy?: Record<string, DefaultOrderByEntry>;
|
|
943
|
+
};
|
|
944
|
+
/** {@link BuildSchemaConfig.defaults} — per-table defaults, keyed by the Drizzle schema key. */
|
|
945
|
+
type DefaultsConfig = Record<string, TableDefaults>;
|
|
918
946
|
/** {@link BuildSchemaConfig.limits} — a global policy plus per-table overrides. */
|
|
919
947
|
type LimitsConfig = TableLimitPolicy & {
|
|
920
948
|
/** Per-table overrides, keyed by the table's key in the Drizzle schema. */
|
|
@@ -1213,6 +1241,38 @@ type BuildSchemaConfig = {
|
|
|
1213
1241
|
* agree.
|
|
1214
1242
|
*/
|
|
1215
1243
|
limits?: LimitsConfig;
|
|
1244
|
+
/**
|
|
1245
|
+
* Per-table defaults for arguments the request leaves out. Today that is `orderBy`: the
|
|
1246
|
+
* presentation order a table has, declared once on the server instead of repeated by every
|
|
1247
|
+
* client.
|
|
1248
|
+
*
|
|
1249
|
+
* ```ts
|
|
1250
|
+
* buildSchema(db, {
|
|
1251
|
+
* defaults: {
|
|
1252
|
+
* Todos: { orderBy: { priority: 'desc', createdAt: 'desc' } },
|
|
1253
|
+
* AuditLog: { orderBy: { createdAt: { direction: 'desc', priority: 10 } } },
|
|
1254
|
+
* },
|
|
1255
|
+
* });
|
|
1256
|
+
* ```
|
|
1257
|
+
*
|
|
1258
|
+
* - Applies to the table's list and single queries, and to every to-many relation field
|
|
1259
|
+
* that *targets* it — a relation is ordered by the default of the table it reads, so a
|
|
1260
|
+
* table presents the same way wherever it is reached from. Eagerly and lazily loaded
|
|
1261
|
+
* relations agree.
|
|
1262
|
+
* - Only a missing `orderBy` is replaced. `orderBy: {}` is a request for no ordering and
|
|
1263
|
+
* stays one, and any `orderBy` the client sends replaces the default outright rather than
|
|
1264
|
+
* merging with it.
|
|
1265
|
+
* - Cursor pagination is defined over the effective ordering, so a default `orderBy` is
|
|
1266
|
+
* what an `after`-only page is ordered by. Changing a table's default changes what its
|
|
1267
|
+
* existing cursors mean.
|
|
1268
|
+
* - Entries name column property names of that table; a direction alone is shorthand for
|
|
1269
|
+
* `{ direction }`. Unknown table or column names throw at build time.
|
|
1270
|
+
* - Aggregates and `groupBy` take their own ordering and are unaffected.
|
|
1271
|
+
*
|
|
1272
|
+
* Off by default: a table with no entry keeps returning rows in whatever order the database
|
|
1273
|
+
* gives them, tiebroken by primary key where an operation needs a total order.
|
|
1274
|
+
*/
|
|
1275
|
+
defaults?: DefaultsConfig;
|
|
1216
1276
|
/**
|
|
1217
1277
|
* Row-level scoping: a predicate, derived from the GraphQL context, that every read and
|
|
1218
1278
|
* write of a table is confined to. This is the multi-tenancy / ownership knob — the one
|
|
@@ -1812,4 +1872,4 @@ declare const resolveSelection: (info: GraphQLResolveInfo | ResolveTree, options
|
|
|
1812
1872
|
|
|
1813
1873
|
declare const buildSchema: <TDbClient extends AnyDrizzleDB<any>>(db: TDbClient, config?: BuildSchemaConfig) => GeneratedData<TDbClient>;
|
|
1814
1874
|
|
|
1815
|
-
export { type AggregateResolver, type AnyDrizzleDB, type BuildSchemaConfig, type ColumnDeprecator, type ColumnDescriber, type ColumnDocInfo, type ColumnTypeMapper, type ColumnTypeMapperInfo, type ComplexityConfig, type ContextValuesConfig, type DeleteResolver, type DeleteSingleResolver, 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 GeneratedData, type GeneratedEntities, type GeneratedInputs, type GeneratedOutputs, GraphQLBigIntString, GraphQLDecimalString, type IdentifiedRows, type InsertArrResolver, type InsertResolver, type LimitsConfig, type MutationReturnlessResult, type MutationsCore, type OnWriteConfig, type QueriesCore, type RelationDescriber, type RelationResolverFactory, type ResolveSelectionOptions, type RowScope, type RowScopeFilter, type ScalarOverride, type ScalarOverridesConfig, type SchemaDocs, type SchemaExclusions, type SchemaFeatures, type ScopeConfig, type SelectResolver, type SelectSingleResolver, type SelectionOptions, type SoftDeleteColumn, type SoftDeleteConfig, type TableDescriber, type TableLimitPolicy, type TableNamedRelations, 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, drizzleExecutorKey, drizzleExtension, extractFilters, extractOrderBy, extractRelationJoinColumns, identifyRows, isDrizzleFieldExtension, resolveSelection, selectionToWith, singularizeMapper };
|
|
1875
|
+
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 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 GeneratedData, type GeneratedEntities, type GeneratedInputs, type GeneratedOutputs, GraphQLBigIntString, GraphQLDecimalString, type IdentifiedRows, type InsertArrResolver, type InsertResolver, type LimitsConfig, type MutationReturnlessResult, type MutationsCore, type OnWriteConfig, type QueriesCore, type RelationDescriber, type RelationResolverFactory, type ResolveSelectionOptions, type RowScope, type RowScopeFilter, type ScalarOverride, type ScalarOverridesConfig, type SchemaDocs, type SchemaExclusions, type SchemaFeatures, type ScopeConfig, type SelectResolver, type SelectSingleResolver, type SelectionOptions, type SoftDeleteColumn, type SoftDeleteConfig, type TableDefaults, type TableDescriber, type TableLimitPolicy, type TableNamedRelations, 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, drizzleExecutorKey, drizzleExtension, extractFilters, extractOrderBy, extractRelationJoinColumns, identifyRows, isDrizzleFieldExtension, resolveSelection, selectionToWith, singularizeMapper };
|