@vantreeseba/drizzle-graphql 5.4.0 → 5.6.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
@@ -1,10 +1,46 @@
1
- import { Table, Column, Relation, SQL, One, Many } from 'drizzle-orm';
1
+ import { Column, Table, Relation, SQL, One, Many } from 'drizzle-orm';
2
2
  import { MySqlDatabase } from 'drizzle-orm/mysql-core';
3
3
  import { PgAsyncDatabase } from 'drizzle-orm/pg-core';
4
4
  import { BaseSQLiteDatabase } from 'drizzle-orm/sqlite-core';
5
- import { GraphQLFieldResolver, GraphQLResolveInfo, GraphQLSchema, GraphQLInputObjectType, GraphQLObjectType, GraphQLNonNull, GraphQLList, GraphQLScalarType, GraphQLEnumType } from 'graphql';
5
+ import { GraphQLScalarType, GraphQLOutputType, GraphQLInputType, GraphQLFieldResolver, GraphQLResolveInfo, GraphQLSchema, GraphQLInputObjectType, GraphQLObjectType, GraphQLNonNull, GraphQLList, GraphQLEnumType } from 'graphql';
6
6
  export { GraphQLDate, GraphQLDateTime, GraphQLJSON, GraphQLUUID } from 'graphql-scalars';
7
7
 
8
+ /**
9
+ * A scalar override for one column. A bare scalar applies to both directions; the object form
10
+ * lets output (object type, aggregate min/max) and input (create/update inputs, filter operands)
11
+ * use different scalars — or override only one side, leaving the other on built-in detection.
12
+ */
13
+ type ScalarOverride = GraphQLScalarType | {
14
+ output?: GraphQLScalarType;
15
+ input?: GraphQLScalarType;
16
+ };
17
+ /**
18
+ * Declarative per-table, per-column scalar overrides. Keys are the Drizzle schema keys —
19
+ * the table's key in the schema object and the column's property name (not the SQL names).
20
+ */
21
+ type ScalarOverridesConfig = Record<string, Record<string, ScalarOverride>>;
22
+ /** Context handed to {@link ColumnTypeMapper} alongside the column itself. */
23
+ type ColumnTypeMapperInfo = {
24
+ /** The table's key in the Drizzle schema object. */
25
+ tableName: string;
26
+ /** The column's property name on the table object. */
27
+ columnName: string;
28
+ /**
29
+ * The GraphQL type built-in detection would use for output positions (without nullability
30
+ * wrapping). `undefined` when detection has no mapping for the column's data type — the
31
+ * mapper is then the only way to give the column a type.
32
+ */
33
+ defaultType: GraphQLOutputType | undefined;
34
+ /** The input-position counterpart of `defaultType`. */
35
+ defaultInputType: GraphQLInputType | undefined;
36
+ };
37
+ /**
38
+ * Rule-based scalar mapping, called once per column at build time. Return a scalar (or
39
+ * `{ output, input }` pair) to override the column's GraphQL type, or `undefined` to keep
40
+ * the built-in detection.
41
+ */
42
+ type ColumnTypeMapper = (column: Column, info: ColumnTypeMapperInfo) => ScalarOverride | undefined;
43
+
8
44
  type TableNamedRelations = {
9
45
  relation: Relation;
10
46
  targetTableName: string;
@@ -693,6 +729,40 @@ type BuildSchemaConfig = {
693
729
  * queries are always generated, so `Query` is never empty.
694
730
  */
695
731
  features?: SchemaFeatures;
732
+ /**
733
+ * Automatic transactions for GraphQL documents that fire more than one mutation.
734
+ *
735
+ * `'none'` (default) — every root mutation field runs on its own connection, so a failure
736
+ * mid-document leaves the earlier mutations committed (today's behavior).
737
+ *
738
+ * `'auto'` — when a request's document selects more than one root mutation field, the
739
+ * library opens `db.transaction()` once for the whole request and runs every mutation
740
+ * field (and the reads nested under them) inside it. The transaction commits when the
741
+ * last mutation field completes and rolls back when any of them fails; mutation fields
742
+ * after a failure are not executed against the rolled-back transaction — they fail fast.
743
+ * The object form additionally sets the safety timeout (default 30000ms) after which an
744
+ * abandoned transaction — e.g. the host server stopped calling resolvers because of a
745
+ * non-null completion error — is rolled back instead of leaking a connection.
746
+ *
747
+ * Never nests: a caller-supplied executor on the GraphQL context under
748
+ * `drizzleExecutorKey` always wins, and the library opens nothing of its own.
749
+ *
750
+ * Requirements and caveats:
751
+ * - The driver must support `db.transaction()` (e.g. `neon-http` does not). For SQLite
752
+ * only asynchronous drivers (libsql, better-sqlite3 is synchronous) can hold a
753
+ * transaction open across resolvers; `buildSchema` throws for synchronous ones.
754
+ * - The GraphQL context value must be a fresh object per request (every mainstream
755
+ * server does this) — it keys the per-request transaction state.
756
+ * - Documents that mix in mutation fields not generated by this build (consumer
757
+ * extensions) are left alone: their completion cannot be tracked, so no transaction
758
+ * is opened.
759
+ *
760
+ * @default 'none'
761
+ */
762
+ transactions?: 'auto' | 'none' | {
763
+ mode: 'auto';
764
+ timeoutMs?: number;
765
+ };
696
766
  /**
697
767
  * Optional mapper from table key to singular/plural name pair.
698
768
  * When provided for a table, overrides the default (table key) naming for GraphQL type names,
@@ -740,6 +810,56 @@ type BuildSchemaConfig = {
740
810
  * @default true
741
811
  */
742
812
  eagerLoadRelations?: boolean | ((tableName: string, relationName: string) => boolean);
813
+ /**
814
+ * Declarative per-table, per-column scalar overrides — replaces the GraphQL type built-in
815
+ * detection would pick for a column with the scalar you provide, everywhere that column's
816
+ * type surfaces: the object type, create/update inputs, filter operands (in a filter type
817
+ * named `${Scalar}Filter`), and aggregate min/max fields.
818
+ *
819
+ * Keys are the Drizzle schema keys: the table's key in your schema object and the column's
820
+ * property name. The value is either one scalar for both directions, or `{ output, input }`
821
+ * to type outputs and inputs differently (either side may be omitted to keep the default).
822
+ *
823
+ * ```ts
824
+ * buildSchema(db, {
825
+ * scalars: {
826
+ * users: {
827
+ * balance: GraphQLBigIntString, // both directions
828
+ * settings: { output: PrettyJSON }, // output only, input stays default
829
+ * },
830
+ * },
831
+ * });
832
+ * ```
833
+ *
834
+ * Validation and coercion become the scalar's job: for an overridden column the generated
835
+ * resolvers pass values through untouched — `parseValue`/`parseLiteral` results go to the
836
+ * database driver as-is, and raw driver values go to `serialize` as-is — so the scalar must
837
+ * accept what the driver produces and produce what the driver accepts.
838
+ *
839
+ * A declarative entry fully decides its column and wins over {@link mapColumnType}.
840
+ */
841
+ scalars?: ScalarOverridesConfig;
842
+ /**
843
+ * Rule-based scalar mapping, called once per column at build time — the tool for applying
844
+ * a convention across many columns (e.g. "every `numeric` column is `Money`") or for typing
845
+ * custom column types the built-in detection does not know.
846
+ *
847
+ * Return a scalar (or `{ output, input }` pair) to override the column, or `undefined` to
848
+ * keep the default. `info` carries the table/column schema keys and the types built-in
849
+ * detection would use (`defaultType` / `defaultInputType`), so rules can key off either the
850
+ * Drizzle column or the default GraphQL type.
851
+ *
852
+ * ```ts
853
+ * buildSchema(db, {
854
+ * mapColumnType: (column, { columnName }) =>
855
+ * column.columnType === 'PgNumeric' ? MoneyScalar : undefined,
856
+ * });
857
+ * ```
858
+ *
859
+ * Same semantics as {@link scalars} otherwise; a column matched by both is decided by
860
+ * `scalars` alone.
861
+ */
862
+ mapColumnType?: ColumnTypeMapper;
743
863
  /**
744
864
  * Called for every error thrown by a generated resolver, before it reaches the client.
745
865
  *
@@ -783,4 +903,4 @@ declare const GraphQLDecimalString: GraphQLScalarType<string, string>;
783
903
 
784
904
  declare const buildSchema: <TDbClient extends AnyDrizzleDB<any>>(db: TDbClient, config?: BuildSchemaConfig) => GeneratedData<TDbClient>;
785
905
 
786
- export { type AggregateResolver, type AnyDrizzleDB, type BuildSchemaConfig, type ComplexityConfig, type DeleteResolver, type DeleteSingleResolver, 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 RelationResolverFactory, type SchemaFeatures, type SelectResolver, type SelectSingleResolver, 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 };
906
+ export { type AggregateResolver, type AnyDrizzleDB, type BuildSchemaConfig, type ColumnTypeMapper, type ColumnTypeMapperInfo, type ComplexityConfig, type DeleteResolver, type DeleteSingleResolver, 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 RelationResolverFactory, type ScalarOverride, type ScalarOverridesConfig, type SchemaFeatures, type SelectResolver, type SelectSingleResolver, 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
@@ -1,10 +1,46 @@
1
- import { Table, Column, Relation, SQL, One, Many } from 'drizzle-orm';
1
+ import { Column, Table, Relation, SQL, One, Many } from 'drizzle-orm';
2
2
  import { MySqlDatabase } from 'drizzle-orm/mysql-core';
3
3
  import { PgAsyncDatabase } from 'drizzle-orm/pg-core';
4
4
  import { BaseSQLiteDatabase } from 'drizzle-orm/sqlite-core';
5
- import { GraphQLFieldResolver, GraphQLResolveInfo, GraphQLSchema, GraphQLInputObjectType, GraphQLObjectType, GraphQLNonNull, GraphQLList, GraphQLScalarType, GraphQLEnumType } from 'graphql';
5
+ import { GraphQLScalarType, GraphQLOutputType, GraphQLInputType, GraphQLFieldResolver, GraphQLResolveInfo, GraphQLSchema, GraphQLInputObjectType, GraphQLObjectType, GraphQLNonNull, GraphQLList, GraphQLEnumType } from 'graphql';
6
6
  export { GraphQLDate, GraphQLDateTime, GraphQLJSON, GraphQLUUID } from 'graphql-scalars';
7
7
 
8
+ /**
9
+ * A scalar override for one column. A bare scalar applies to both directions; the object form
10
+ * lets output (object type, aggregate min/max) and input (create/update inputs, filter operands)
11
+ * use different scalars — or override only one side, leaving the other on built-in detection.
12
+ */
13
+ type ScalarOverride = GraphQLScalarType | {
14
+ output?: GraphQLScalarType;
15
+ input?: GraphQLScalarType;
16
+ };
17
+ /**
18
+ * Declarative per-table, per-column scalar overrides. Keys are the Drizzle schema keys —
19
+ * the table's key in the schema object and the column's property name (not the SQL names).
20
+ */
21
+ type ScalarOverridesConfig = Record<string, Record<string, ScalarOverride>>;
22
+ /** Context handed to {@link ColumnTypeMapper} alongside the column itself. */
23
+ type ColumnTypeMapperInfo = {
24
+ /** The table's key in the Drizzle schema object. */
25
+ tableName: string;
26
+ /** The column's property name on the table object. */
27
+ columnName: string;
28
+ /**
29
+ * The GraphQL type built-in detection would use for output positions (without nullability
30
+ * wrapping). `undefined` when detection has no mapping for the column's data type — the
31
+ * mapper is then the only way to give the column a type.
32
+ */
33
+ defaultType: GraphQLOutputType | undefined;
34
+ /** The input-position counterpart of `defaultType`. */
35
+ defaultInputType: GraphQLInputType | undefined;
36
+ };
37
+ /**
38
+ * Rule-based scalar mapping, called once per column at build time. Return a scalar (or
39
+ * `{ output, input }` pair) to override the column's GraphQL type, or `undefined` to keep
40
+ * the built-in detection.
41
+ */
42
+ type ColumnTypeMapper = (column: Column, info: ColumnTypeMapperInfo) => ScalarOverride | undefined;
43
+
8
44
  type TableNamedRelations = {
9
45
  relation: Relation;
10
46
  targetTableName: string;
@@ -693,6 +729,40 @@ type BuildSchemaConfig = {
693
729
  * queries are always generated, so `Query` is never empty.
694
730
  */
695
731
  features?: SchemaFeatures;
732
+ /**
733
+ * Automatic transactions for GraphQL documents that fire more than one mutation.
734
+ *
735
+ * `'none'` (default) — every root mutation field runs on its own connection, so a failure
736
+ * mid-document leaves the earlier mutations committed (today's behavior).
737
+ *
738
+ * `'auto'` — when a request's document selects more than one root mutation field, the
739
+ * library opens `db.transaction()` once for the whole request and runs every mutation
740
+ * field (and the reads nested under them) inside it. The transaction commits when the
741
+ * last mutation field completes and rolls back when any of them fails; mutation fields
742
+ * after a failure are not executed against the rolled-back transaction — they fail fast.
743
+ * The object form additionally sets the safety timeout (default 30000ms) after which an
744
+ * abandoned transaction — e.g. the host server stopped calling resolvers because of a
745
+ * non-null completion error — is rolled back instead of leaking a connection.
746
+ *
747
+ * Never nests: a caller-supplied executor on the GraphQL context under
748
+ * `drizzleExecutorKey` always wins, and the library opens nothing of its own.
749
+ *
750
+ * Requirements and caveats:
751
+ * - The driver must support `db.transaction()` (e.g. `neon-http` does not). For SQLite
752
+ * only asynchronous drivers (libsql, better-sqlite3 is synchronous) can hold a
753
+ * transaction open across resolvers; `buildSchema` throws for synchronous ones.
754
+ * - The GraphQL context value must be a fresh object per request (every mainstream
755
+ * server does this) — it keys the per-request transaction state.
756
+ * - Documents that mix in mutation fields not generated by this build (consumer
757
+ * extensions) are left alone: their completion cannot be tracked, so no transaction
758
+ * is opened.
759
+ *
760
+ * @default 'none'
761
+ */
762
+ transactions?: 'auto' | 'none' | {
763
+ mode: 'auto';
764
+ timeoutMs?: number;
765
+ };
696
766
  /**
697
767
  * Optional mapper from table key to singular/plural name pair.
698
768
  * When provided for a table, overrides the default (table key) naming for GraphQL type names,
@@ -740,6 +810,56 @@ type BuildSchemaConfig = {
740
810
  * @default true
741
811
  */
742
812
  eagerLoadRelations?: boolean | ((tableName: string, relationName: string) => boolean);
813
+ /**
814
+ * Declarative per-table, per-column scalar overrides — replaces the GraphQL type built-in
815
+ * detection would pick for a column with the scalar you provide, everywhere that column's
816
+ * type surfaces: the object type, create/update inputs, filter operands (in a filter type
817
+ * named `${Scalar}Filter`), and aggregate min/max fields.
818
+ *
819
+ * Keys are the Drizzle schema keys: the table's key in your schema object and the column's
820
+ * property name. The value is either one scalar for both directions, or `{ output, input }`
821
+ * to type outputs and inputs differently (either side may be omitted to keep the default).
822
+ *
823
+ * ```ts
824
+ * buildSchema(db, {
825
+ * scalars: {
826
+ * users: {
827
+ * balance: GraphQLBigIntString, // both directions
828
+ * settings: { output: PrettyJSON }, // output only, input stays default
829
+ * },
830
+ * },
831
+ * });
832
+ * ```
833
+ *
834
+ * Validation and coercion become the scalar's job: for an overridden column the generated
835
+ * resolvers pass values through untouched — `parseValue`/`parseLiteral` results go to the
836
+ * database driver as-is, and raw driver values go to `serialize` as-is — so the scalar must
837
+ * accept what the driver produces and produce what the driver accepts.
838
+ *
839
+ * A declarative entry fully decides its column and wins over {@link mapColumnType}.
840
+ */
841
+ scalars?: ScalarOverridesConfig;
842
+ /**
843
+ * Rule-based scalar mapping, called once per column at build time — the tool for applying
844
+ * a convention across many columns (e.g. "every `numeric` column is `Money`") or for typing
845
+ * custom column types the built-in detection does not know.
846
+ *
847
+ * Return a scalar (or `{ output, input }` pair) to override the column, or `undefined` to
848
+ * keep the default. `info` carries the table/column schema keys and the types built-in
849
+ * detection would use (`defaultType` / `defaultInputType`), so rules can key off either the
850
+ * Drizzle column or the default GraphQL type.
851
+ *
852
+ * ```ts
853
+ * buildSchema(db, {
854
+ * mapColumnType: (column, { columnName }) =>
855
+ * column.columnType === 'PgNumeric' ? MoneyScalar : undefined,
856
+ * });
857
+ * ```
858
+ *
859
+ * Same semantics as {@link scalars} otherwise; a column matched by both is decided by
860
+ * `scalars` alone.
861
+ */
862
+ mapColumnType?: ColumnTypeMapper;
743
863
  /**
744
864
  * Called for every error thrown by a generated resolver, before it reaches the client.
745
865
  *
@@ -783,4 +903,4 @@ declare const GraphQLDecimalString: GraphQLScalarType<string, string>;
783
903
 
784
904
  declare const buildSchema: <TDbClient extends AnyDrizzleDB<any>>(db: TDbClient, config?: BuildSchemaConfig) => GeneratedData<TDbClient>;
785
905
 
786
- export { type AggregateResolver, type AnyDrizzleDB, type BuildSchemaConfig, type ComplexityConfig, type DeleteResolver, type DeleteSingleResolver, 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 RelationResolverFactory, type SchemaFeatures, type SelectResolver, type SelectSingleResolver, 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 };
906
+ export { type AggregateResolver, type AnyDrizzleDB, type BuildSchemaConfig, type ColumnTypeMapper, type ColumnTypeMapperInfo, type ComplexityConfig, type DeleteResolver, type DeleteSingleResolver, 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 RelationResolverFactory, type ScalarOverride, type ScalarOverridesConfig, type SchemaFeatures, type SelectResolver, type SelectSingleResolver, 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 };