@vantreeseba/drizzle-graphql 5.5.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;
@@ -774,6 +810,56 @@ type BuildSchemaConfig = {
774
810
  * @default true
775
811
  */
776
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;
777
863
  /**
778
864
  * Called for every error thrown by a generated resolver, before it reaches the client.
779
865
  *
@@ -817,4 +903,4 @@ declare const GraphQLDecimalString: GraphQLScalarType<string, string>;
817
903
 
818
904
  declare const buildSchema: <TDbClient extends AnyDrizzleDB<any>>(db: TDbClient, config?: BuildSchemaConfig) => GeneratedData<TDbClient>;
819
905
 
820
- 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;
@@ -774,6 +810,56 @@ type BuildSchemaConfig = {
774
810
  * @default true
775
811
  */
776
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;
777
863
  /**
778
864
  * Called for every error thrown by a generated resolver, before it reaches the client.
779
865
  *
@@ -817,4 +903,4 @@ declare const GraphQLDecimalString: GraphQLScalarType<string, string>;
817
903
 
818
904
  declare const buildSchema: <TDbClient extends AnyDrizzleDB<any>>(db: TDbClient, config?: BuildSchemaConfig) => GeneratedData<TDbClient>;
819
905
 
820
- 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 };