@vantreeseba/drizzle-graphql 7.0.0 → 7.1.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 +262 -7
- package/dist/README.md +262 -7
- package/dist/index.cjs +214 -68
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +73 -2
- package/dist/index.d.ts +73 -2
- package/dist/index.js +214 -68
- package/dist/index.js.map +1 -1
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -239,7 +239,18 @@ declare const drizzleExecutorKey: unique symbol;
|
|
|
239
239
|
* each dialect builder states it: `'nulls-largest'` for PostgreSQL, `'nulls-smallest'` for
|
|
240
240
|
* MySQL and SQLite.
|
|
241
241
|
*/
|
|
242
|
-
declare const createRelationResolverFactory: (db: any, tables: Record<string, Table>, nullOrdering: NullOrdering, filterCtx?: RelationFilterBase) => RelationResolverFactory;
|
|
242
|
+
declare const createRelationResolverFactory: (db: any, tables: Record<string, Table>, nullOrdering: NullOrdering, filterCtx?: RelationFilterBase, limits?: LimitPolicyFor) => RelationResolverFactory;
|
|
243
|
+
/** {@link BuildSchemaConfig.limits} resolved for one table. `undefined` means no policy. */
|
|
244
|
+
type ResolvedLimitPolicy = {
|
|
245
|
+
defaultLimit: number | undefined;
|
|
246
|
+
maxLimit: number | undefined;
|
|
247
|
+
clampToMax: boolean;
|
|
248
|
+
};
|
|
249
|
+
/**
|
|
250
|
+
* Looks up the limit policy for a table by its Drizzle schema key. Built once per schema by
|
|
251
|
+
* `buildSchema`; `undefined` for a table the caller left unbounded.
|
|
252
|
+
*/
|
|
253
|
+
type LimitPolicyFor = (tableName: string) => ResolvedLimitPolicy | undefined;
|
|
243
254
|
/**
|
|
244
255
|
* Compiles an `orderBy` argument into ORDER BY expressions, highest priority first.
|
|
245
256
|
*
|
|
@@ -760,6 +771,29 @@ type ComplexityConfig = {
|
|
|
760
771
|
*/
|
|
761
772
|
aggregateCost?: number;
|
|
762
773
|
};
|
|
774
|
+
/**
|
|
775
|
+
* A limit policy: what a request without `limit` gets, and how large a `limit` may be.
|
|
776
|
+
* Every field is optional — an empty policy is the default unbounded behavior.
|
|
777
|
+
*/
|
|
778
|
+
type TableLimitPolicy = {
|
|
779
|
+
/** Applied when the client passes no `limit`. Capped by `maxLimit` when both are set. */
|
|
780
|
+
defaultLimit?: number;
|
|
781
|
+
/**
|
|
782
|
+
* The largest `limit` a client may ask for. Also bounds a request that passes no `limit` at
|
|
783
|
+
* all, since that means every row.
|
|
784
|
+
*/
|
|
785
|
+
maxLimit?: number;
|
|
786
|
+
/**
|
|
787
|
+
* `false` (default) rejects a `limit` above `maxLimit` with a GraphQL error; `true` reduces
|
|
788
|
+
* it to `maxLimit` instead.
|
|
789
|
+
*/
|
|
790
|
+
clampToMax?: boolean;
|
|
791
|
+
};
|
|
792
|
+
/** {@link BuildSchemaConfig.limits} — a global policy plus per-table overrides. */
|
|
793
|
+
type LimitsConfig = TableLimitPolicy & {
|
|
794
|
+
/** Per-table overrides, keyed by the table's key in the Drizzle schema. */
|
|
795
|
+
tables?: Record<string, TableLimitPolicy>;
|
|
796
|
+
};
|
|
763
797
|
type BuildSchemaConfig = {
|
|
764
798
|
/**
|
|
765
799
|
* Determines whether generated mutations will be passed to returned schema.
|
|
@@ -911,6 +945,43 @@ type BuildSchemaConfig = {
|
|
|
911
945
|
mode: 'auto';
|
|
912
946
|
timeoutMs?: number;
|
|
913
947
|
};
|
|
948
|
+
/**
|
|
949
|
+
* Bounds on the `limit` argument of list queries and to-many relation fields.
|
|
950
|
+
*
|
|
951
|
+
* Both knobs are off by default: without them a client can omit `limit` and pull a whole
|
|
952
|
+
* table, or pass `limit: 1000000` and do the same thing politely. Turning either on changes
|
|
953
|
+
* observable behavior for existing consumers, so nothing is applied unless asked for.
|
|
954
|
+
*
|
|
955
|
+
* ```ts
|
|
956
|
+
* buildSchema(db, {
|
|
957
|
+
* limits: {
|
|
958
|
+
* defaultLimit: 50, // used when the client passes no `limit`
|
|
959
|
+
* maxLimit: 500, // anything above is rejected
|
|
960
|
+
* tables: {
|
|
961
|
+
* auditLog: { defaultLimit: 20, maxLimit: 100 },
|
|
962
|
+
* },
|
|
963
|
+
* },
|
|
964
|
+
* });
|
|
965
|
+
* ```
|
|
966
|
+
*
|
|
967
|
+
* - Applies to root list queries **and** to to-many relation fields — an unbounded relation
|
|
968
|
+
* inside a bounded root is the same scan one level down. A relation field takes the policy
|
|
969
|
+
* of the table it *targets*, so a table is bounded wherever it is reached from. Single-row
|
|
970
|
+
* queries and aggregates take no `limit` and are unaffected.
|
|
971
|
+
* - A `limit` above `maxLimit` is rejected with a GraphQL error. Set `clampToMax: true` to
|
|
972
|
+
* silently reduce it instead — honest paginating clients prefer the error, since a clamped
|
|
973
|
+
* page looks like the end of the results.
|
|
974
|
+
* - `maxLimit` on its own also bounds the *omitted* case: no `limit` means every row, which
|
|
975
|
+
* is above any maximum. `defaultLimit` is what a request without `limit` gets, capped by
|
|
976
|
+
* `maxLimit` if both are set.
|
|
977
|
+
* - `tables` overrides per table, keyed by the Drizzle schema key. A table's entry replaces
|
|
978
|
+
* the top-level value for whichever keys it sets.
|
|
979
|
+
* - Cursor pagination inherits the same policy — a keyset page needs a limit to be
|
|
980
|
+
* meaningful, and `defaultLimit` is what makes `after`-only pagination well-formed.
|
|
981
|
+
* - The complexity hints price the *effective* limit, so cost estimation and enforcement
|
|
982
|
+
* agree.
|
|
983
|
+
*/
|
|
984
|
+
limits?: LimitsConfig;
|
|
914
985
|
/**
|
|
915
986
|
* Optional mapper from table key to singular/plural name pair.
|
|
916
987
|
* When provided for a table, overrides the default (table key) naming for GraphQL type names,
|
|
@@ -1139,4 +1210,4 @@ declare const GraphQLDecimalString: GraphQLScalarType<string, string>;
|
|
|
1139
1210
|
|
|
1140
1211
|
declare const buildSchema: <TDbClient extends AnyDrizzleDB<any>>(db: TDbClient, config?: BuildSchemaConfig) => GeneratedData<TDbClient>;
|
|
1141
1212
|
|
|
1142
|
-
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 MutationReturnlessResult, type MutationsCore, type QueriesCore, type RelationDescriber, type RelationResolverFactory, type ScalarOverride, type ScalarOverridesConfig, type SchemaDocs, type SchemaFeatures, type SelectResolver, type SelectSingleResolver, type TableDescriber, 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 };
|
|
1213
|
+
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 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -239,7 +239,18 @@ declare const drizzleExecutorKey: unique symbol;
|
|
|
239
239
|
* each dialect builder states it: `'nulls-largest'` for PostgreSQL, `'nulls-smallest'` for
|
|
240
240
|
* MySQL and SQLite.
|
|
241
241
|
*/
|
|
242
|
-
declare const createRelationResolverFactory: (db: any, tables: Record<string, Table>, nullOrdering: NullOrdering, filterCtx?: RelationFilterBase) => RelationResolverFactory;
|
|
242
|
+
declare const createRelationResolverFactory: (db: any, tables: Record<string, Table>, nullOrdering: NullOrdering, filterCtx?: RelationFilterBase, limits?: LimitPolicyFor) => RelationResolverFactory;
|
|
243
|
+
/** {@link BuildSchemaConfig.limits} resolved for one table. `undefined` means no policy. */
|
|
244
|
+
type ResolvedLimitPolicy = {
|
|
245
|
+
defaultLimit: number | undefined;
|
|
246
|
+
maxLimit: number | undefined;
|
|
247
|
+
clampToMax: boolean;
|
|
248
|
+
};
|
|
249
|
+
/**
|
|
250
|
+
* Looks up the limit policy for a table by its Drizzle schema key. Built once per schema by
|
|
251
|
+
* `buildSchema`; `undefined` for a table the caller left unbounded.
|
|
252
|
+
*/
|
|
253
|
+
type LimitPolicyFor = (tableName: string) => ResolvedLimitPolicy | undefined;
|
|
243
254
|
/**
|
|
244
255
|
* Compiles an `orderBy` argument into ORDER BY expressions, highest priority first.
|
|
245
256
|
*
|
|
@@ -760,6 +771,29 @@ type ComplexityConfig = {
|
|
|
760
771
|
*/
|
|
761
772
|
aggregateCost?: number;
|
|
762
773
|
};
|
|
774
|
+
/**
|
|
775
|
+
* A limit policy: what a request without `limit` gets, and how large a `limit` may be.
|
|
776
|
+
* Every field is optional — an empty policy is the default unbounded behavior.
|
|
777
|
+
*/
|
|
778
|
+
type TableLimitPolicy = {
|
|
779
|
+
/** Applied when the client passes no `limit`. Capped by `maxLimit` when both are set. */
|
|
780
|
+
defaultLimit?: number;
|
|
781
|
+
/**
|
|
782
|
+
* The largest `limit` a client may ask for. Also bounds a request that passes no `limit` at
|
|
783
|
+
* all, since that means every row.
|
|
784
|
+
*/
|
|
785
|
+
maxLimit?: number;
|
|
786
|
+
/**
|
|
787
|
+
* `false` (default) rejects a `limit` above `maxLimit` with a GraphQL error; `true` reduces
|
|
788
|
+
* it to `maxLimit` instead.
|
|
789
|
+
*/
|
|
790
|
+
clampToMax?: boolean;
|
|
791
|
+
};
|
|
792
|
+
/** {@link BuildSchemaConfig.limits} — a global policy plus per-table overrides. */
|
|
793
|
+
type LimitsConfig = TableLimitPolicy & {
|
|
794
|
+
/** Per-table overrides, keyed by the table's key in the Drizzle schema. */
|
|
795
|
+
tables?: Record<string, TableLimitPolicy>;
|
|
796
|
+
};
|
|
763
797
|
type BuildSchemaConfig = {
|
|
764
798
|
/**
|
|
765
799
|
* Determines whether generated mutations will be passed to returned schema.
|
|
@@ -911,6 +945,43 @@ type BuildSchemaConfig = {
|
|
|
911
945
|
mode: 'auto';
|
|
912
946
|
timeoutMs?: number;
|
|
913
947
|
};
|
|
948
|
+
/**
|
|
949
|
+
* Bounds on the `limit` argument of list queries and to-many relation fields.
|
|
950
|
+
*
|
|
951
|
+
* Both knobs are off by default: without them a client can omit `limit` and pull a whole
|
|
952
|
+
* table, or pass `limit: 1000000` and do the same thing politely. Turning either on changes
|
|
953
|
+
* observable behavior for existing consumers, so nothing is applied unless asked for.
|
|
954
|
+
*
|
|
955
|
+
* ```ts
|
|
956
|
+
* buildSchema(db, {
|
|
957
|
+
* limits: {
|
|
958
|
+
* defaultLimit: 50, // used when the client passes no `limit`
|
|
959
|
+
* maxLimit: 500, // anything above is rejected
|
|
960
|
+
* tables: {
|
|
961
|
+
* auditLog: { defaultLimit: 20, maxLimit: 100 },
|
|
962
|
+
* },
|
|
963
|
+
* },
|
|
964
|
+
* });
|
|
965
|
+
* ```
|
|
966
|
+
*
|
|
967
|
+
* - Applies to root list queries **and** to to-many relation fields — an unbounded relation
|
|
968
|
+
* inside a bounded root is the same scan one level down. A relation field takes the policy
|
|
969
|
+
* of the table it *targets*, so a table is bounded wherever it is reached from. Single-row
|
|
970
|
+
* queries and aggregates take no `limit` and are unaffected.
|
|
971
|
+
* - A `limit` above `maxLimit` is rejected with a GraphQL error. Set `clampToMax: true` to
|
|
972
|
+
* silently reduce it instead — honest paginating clients prefer the error, since a clamped
|
|
973
|
+
* page looks like the end of the results.
|
|
974
|
+
* - `maxLimit` on its own also bounds the *omitted* case: no `limit` means every row, which
|
|
975
|
+
* is above any maximum. `defaultLimit` is what a request without `limit` gets, capped by
|
|
976
|
+
* `maxLimit` if both are set.
|
|
977
|
+
* - `tables` overrides per table, keyed by the Drizzle schema key. A table's entry replaces
|
|
978
|
+
* the top-level value for whichever keys it sets.
|
|
979
|
+
* - Cursor pagination inherits the same policy — a keyset page needs a limit to be
|
|
980
|
+
* meaningful, and `defaultLimit` is what makes `after`-only pagination well-formed.
|
|
981
|
+
* - The complexity hints price the *effective* limit, so cost estimation and enforcement
|
|
982
|
+
* agree.
|
|
983
|
+
*/
|
|
984
|
+
limits?: LimitsConfig;
|
|
914
985
|
/**
|
|
915
986
|
* Optional mapper from table key to singular/plural name pair.
|
|
916
987
|
* When provided for a table, overrides the default (table key) naming for GraphQL type names,
|
|
@@ -1139,4 +1210,4 @@ declare const GraphQLDecimalString: GraphQLScalarType<string, string>;
|
|
|
1139
1210
|
|
|
1140
1211
|
declare const buildSchema: <TDbClient extends AnyDrizzleDB<any>>(db: TDbClient, config?: BuildSchemaConfig) => GeneratedData<TDbClient>;
|
|
1141
1212
|
|
|
1142
|
-
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 MutationReturnlessResult, type MutationsCore, type QueriesCore, type RelationDescriber, type RelationResolverFactory, type ScalarOverride, type ScalarOverridesConfig, type SchemaDocs, type SchemaFeatures, type SelectResolver, type SelectSingleResolver, type TableDescriber, 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 };
|
|
1213
|
+
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 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 };
|