@vantreeseba/drizzle-graphql 7.0.0 → 7.2.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/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,44 @@ 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
+ };
797
+ /**
798
+ * {@link BuildSchemaConfig.exclude} — tables and columns to keep out of the generated schema.
799
+ *
800
+ * Both lists are keyed by the Drizzle schema key, not the database name and not the generated
801
+ * GraphQL name.
802
+ */
803
+ type SchemaExclusions = {
804
+ /**
805
+ * Tables that generate nothing at all: no object type, no queries, no mutations, and no
806
+ * relation fields on other tables that point at them.
807
+ */
808
+ tables?: string[];
809
+ /** Per-table column exclusions, keyed by the table's key in the Drizzle schema. */
810
+ columns?: Record<string, string[]>;
811
+ };
763
812
  type BuildSchemaConfig = {
764
813
  /**
765
814
  * Determines whether generated mutations will be passed to returned schema.
@@ -911,6 +960,73 @@ type BuildSchemaConfig = {
911
960
  mode: 'auto';
912
961
  timeoutMs?: number;
913
962
  };
963
+ /**
964
+ * Bounds on the `limit` argument of list queries and to-many relation fields.
965
+ *
966
+ * Both knobs are off by default: without them a client can omit `limit` and pull a whole
967
+ * table, or pass `limit: 1000000` and do the same thing politely. Turning either on changes
968
+ * observable behavior for existing consumers, so nothing is applied unless asked for.
969
+ *
970
+ * ```ts
971
+ * buildSchema(db, {
972
+ * limits: {
973
+ * defaultLimit: 50, // used when the client passes no `limit`
974
+ * maxLimit: 500, // anything above is rejected
975
+ * tables: {
976
+ * auditLog: { defaultLimit: 20, maxLimit: 100 },
977
+ * },
978
+ * },
979
+ * });
980
+ * ```
981
+ *
982
+ * - Applies to root list queries **and** to to-many relation fields — an unbounded relation
983
+ * inside a bounded root is the same scan one level down. A relation field takes the policy
984
+ * of the table it *targets*, so a table is bounded wherever it is reached from. Single-row
985
+ * queries and aggregates take no `limit` and are unaffected.
986
+ * - A `limit` above `maxLimit` is rejected with a GraphQL error. Set `clampToMax: true` to
987
+ * silently reduce it instead — honest paginating clients prefer the error, since a clamped
988
+ * page looks like the end of the results.
989
+ * - `maxLimit` on its own also bounds the *omitted* case: no `limit` means every row, which
990
+ * is above any maximum. `defaultLimit` is what a request without `limit` gets, capped by
991
+ * `maxLimit` if both are set.
992
+ * - `tables` overrides per table, keyed by the Drizzle schema key. A table's entry replaces
993
+ * the top-level value for whichever keys it sets.
994
+ * - Cursor pagination inherits the same policy — a keyset page needs a limit to be
995
+ * meaningful, and `defaultLimit` is what makes `after`-only pagination well-formed.
996
+ * - The complexity hints price the *effective* limit, so cost estimation and enforcement
997
+ * agree.
998
+ */
999
+ limits?: LimitsConfig;
1000
+ /**
1001
+ * Tables and columns to leave out of the generated schema entirely.
1002
+ *
1003
+ * ```ts
1004
+ * buildSchema(db, {
1005
+ * exclude: {
1006
+ * tables: ['magicLinks', 'sessions'],
1007
+ * columns: { apiKeys: ['keyHash'] },
1008
+ * },
1009
+ * });
1010
+ * ```
1011
+ *
1012
+ * An excluded **table** generates nothing: no object type, no root queries or mutations, no
1013
+ * aggregates, and no relation field on any other table that points at it. Filtering another
1014
+ * table by a relation to it is gone too, so it is unreachable rather than merely unnamed.
1015
+ *
1016
+ * An excluded **column** disappears from every surface at once — the object type, the
1017
+ * create/update/upsert inputs, the filter type, `orderBy`, the aggregate fields, the
1018
+ * `distinct` and `groupBy` enums, and the upsert conflict targets. The exclusion is
1019
+ * deliberately all-or-nothing: a column you can filter on but not select is an oracle, since
1020
+ * `where: { keyHash: { eq: '…' } }` confirms a value without ever returning it.
1021
+ *
1022
+ * Excluding a `NOT NULL` column that has no default makes that table's inserts impossible to
1023
+ * satisfy — `buildSchema` warns on the console when it sees this, and still builds, since a
1024
+ * read-only table is a reasonable thing to want.
1025
+ *
1026
+ * Names that match nothing throw, so a renamed column fails the build instead of quietly
1027
+ * un-hiding itself.
1028
+ */
1029
+ exclude?: SchemaExclusions;
914
1030
  /**
915
1031
  * Optional mapper from table key to singular/plural name pair.
916
1032
  * When provided for a table, overrides the default (table key) naming for GraphQL type names,
@@ -1139,4 +1255,4 @@ declare const GraphQLDecimalString: GraphQLScalarType<string, string>;
1139
1255
 
1140
1256
  declare const buildSchema: <TDbClient extends AnyDrizzleDB<any>>(db: TDbClient, config?: BuildSchemaConfig) => GeneratedData<TDbClient>;
1141
1257
 
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 };
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 };
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,44 @@ 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
+ };
797
+ /**
798
+ * {@link BuildSchemaConfig.exclude} — tables and columns to keep out of the generated schema.
799
+ *
800
+ * Both lists are keyed by the Drizzle schema key, not the database name and not the generated
801
+ * GraphQL name.
802
+ */
803
+ type SchemaExclusions = {
804
+ /**
805
+ * Tables that generate nothing at all: no object type, no queries, no mutations, and no
806
+ * relation fields on other tables that point at them.
807
+ */
808
+ tables?: string[];
809
+ /** Per-table column exclusions, keyed by the table's key in the Drizzle schema. */
810
+ columns?: Record<string, string[]>;
811
+ };
763
812
  type BuildSchemaConfig = {
764
813
  /**
765
814
  * Determines whether generated mutations will be passed to returned schema.
@@ -911,6 +960,73 @@ type BuildSchemaConfig = {
911
960
  mode: 'auto';
912
961
  timeoutMs?: number;
913
962
  };
963
+ /**
964
+ * Bounds on the `limit` argument of list queries and to-many relation fields.
965
+ *
966
+ * Both knobs are off by default: without them a client can omit `limit` and pull a whole
967
+ * table, or pass `limit: 1000000` and do the same thing politely. Turning either on changes
968
+ * observable behavior for existing consumers, so nothing is applied unless asked for.
969
+ *
970
+ * ```ts
971
+ * buildSchema(db, {
972
+ * limits: {
973
+ * defaultLimit: 50, // used when the client passes no `limit`
974
+ * maxLimit: 500, // anything above is rejected
975
+ * tables: {
976
+ * auditLog: { defaultLimit: 20, maxLimit: 100 },
977
+ * },
978
+ * },
979
+ * });
980
+ * ```
981
+ *
982
+ * - Applies to root list queries **and** to to-many relation fields — an unbounded relation
983
+ * inside a bounded root is the same scan one level down. A relation field takes the policy
984
+ * of the table it *targets*, so a table is bounded wherever it is reached from. Single-row
985
+ * queries and aggregates take no `limit` and are unaffected.
986
+ * - A `limit` above `maxLimit` is rejected with a GraphQL error. Set `clampToMax: true` to
987
+ * silently reduce it instead — honest paginating clients prefer the error, since a clamped
988
+ * page looks like the end of the results.
989
+ * - `maxLimit` on its own also bounds the *omitted* case: no `limit` means every row, which
990
+ * is above any maximum. `defaultLimit` is what a request without `limit` gets, capped by
991
+ * `maxLimit` if both are set.
992
+ * - `tables` overrides per table, keyed by the Drizzle schema key. A table's entry replaces
993
+ * the top-level value for whichever keys it sets.
994
+ * - Cursor pagination inherits the same policy — a keyset page needs a limit to be
995
+ * meaningful, and `defaultLimit` is what makes `after`-only pagination well-formed.
996
+ * - The complexity hints price the *effective* limit, so cost estimation and enforcement
997
+ * agree.
998
+ */
999
+ limits?: LimitsConfig;
1000
+ /**
1001
+ * Tables and columns to leave out of the generated schema entirely.
1002
+ *
1003
+ * ```ts
1004
+ * buildSchema(db, {
1005
+ * exclude: {
1006
+ * tables: ['magicLinks', 'sessions'],
1007
+ * columns: { apiKeys: ['keyHash'] },
1008
+ * },
1009
+ * });
1010
+ * ```
1011
+ *
1012
+ * An excluded **table** generates nothing: no object type, no root queries or mutations, no
1013
+ * aggregates, and no relation field on any other table that points at it. Filtering another
1014
+ * table by a relation to it is gone too, so it is unreachable rather than merely unnamed.
1015
+ *
1016
+ * An excluded **column** disappears from every surface at once — the object type, the
1017
+ * create/update/upsert inputs, the filter type, `orderBy`, the aggregate fields, the
1018
+ * `distinct` and `groupBy` enums, and the upsert conflict targets. The exclusion is
1019
+ * deliberately all-or-nothing: a column you can filter on but not select is an oracle, since
1020
+ * `where: { keyHash: { eq: '…' } }` confirms a value without ever returning it.
1021
+ *
1022
+ * Excluding a `NOT NULL` column that has no default makes that table's inserts impossible to
1023
+ * satisfy — `buildSchema` warns on the console when it sees this, and still builds, since a
1024
+ * read-only table is a reasonable thing to want.
1025
+ *
1026
+ * Names that match nothing throw, so a renamed column fails the build instead of quietly
1027
+ * un-hiding itself.
1028
+ */
1029
+ exclude?: SchemaExclusions;
914
1030
  /**
915
1031
  * Optional mapper from table key to singular/plural name pair.
916
1032
  * When provided for a table, overrides the default (table key) naming for GraphQL type names,
@@ -1139,4 +1255,4 @@ declare const GraphQLDecimalString: GraphQLScalarType<string, string>;
1139
1255
 
1140
1256
  declare const buildSchema: <TDbClient extends AnyDrizzleDB<any>>(db: TDbClient, config?: BuildSchemaConfig) => GeneratedData<TDbClient>;
1141
1257
 
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 };
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 };