@vantreeseba/drizzle-graphql 5.5.0 → 6.0.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 +913 -768
- package/dist/README.md +913 -768
- package/dist/index.cjs +1253 -485
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +266 -3
- package/dist/index.d.ts +266 -3
- package/dist/index.js +1340 -564
- package/dist/index.js.map +1 -1
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,103 @@
|
|
|
1
|
-
import {
|
|
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,
|
|
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
|
+
/** Everything an {@link EnumNameMapper} needs to name — or opt a column out of — a generated enum type. */
|
|
44
|
+
type EnumNameInfo = {
|
|
45
|
+
/**
|
|
46
|
+
* The name the enum type was declared with (`pgEnum('status', …)`), shared by every column
|
|
47
|
+
* that uses it. `undefined` for an inline value list (`text({ enum: [...] })`,
|
|
48
|
+
* `mysqlEnum(...)`), which belongs to the one column that declares it.
|
|
49
|
+
*/
|
|
50
|
+
enumName: string | undefined;
|
|
51
|
+
/** The Postgres schema the named enum was declared in, when it declares one. */
|
|
52
|
+
schema: string | undefined;
|
|
53
|
+
/** The table's key in the Drizzle schema object. */
|
|
54
|
+
tableName: string;
|
|
55
|
+
/** The column's property name on the table object. */
|
|
56
|
+
columnName: string;
|
|
57
|
+
/** The enum's values, in declaration order. */
|
|
58
|
+
values: readonly string[];
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Names a generated GraphQL enum type. Return `undefined` to keep the default name. See
|
|
62
|
+
* `BuildSchemaConfig.enumNameMapper`.
|
|
63
|
+
*/
|
|
64
|
+
type EnumNameMapper = (info: EnumNameInfo) => string | undefined;
|
|
65
|
+
/** Context handed to the documentation and deprecation hooks alongside the column itself. */
|
|
66
|
+
type ColumnDocInfo = {
|
|
67
|
+
/** The table's key in the Drizzle schema object. */
|
|
68
|
+
tableName: string;
|
|
69
|
+
/** The column's property name on the table object. */
|
|
70
|
+
columnName: string;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Supplies the GraphQL `description` for a generated column field. See
|
|
74
|
+
* `BuildSchemaConfig.describeColumn`.
|
|
75
|
+
*/
|
|
76
|
+
type ColumnDescriber = (column: Column, info: ColumnDocInfo) => string | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Supplies the GraphQL `deprecationReason` for a generated column field. See
|
|
79
|
+
* `BuildSchemaConfig.deprecateColumn`.
|
|
80
|
+
*/
|
|
81
|
+
type ColumnDeprecator = (column: Column, info: ColumnDocInfo) => string | undefined;
|
|
82
|
+
/** Supplies the GraphQL `description` for a table's object type. See `BuildSchemaConfig.describeTable`. */
|
|
83
|
+
type TableDescriber = (tableName: string) => string | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Supplies the GraphQL `description` for a relation field. See
|
|
86
|
+
* `BuildSchemaConfig.describeRelation`.
|
|
87
|
+
*/
|
|
88
|
+
type RelationDescriber = (tableName: string, relationName: string) => string | undefined;
|
|
89
|
+
/**
|
|
90
|
+
* The documentation hooks a build was configured with, resolved once and threaded through
|
|
91
|
+
* type generation. Every member is optional; a build with no hooks generates fields with no
|
|
92
|
+
* descriptions at all.
|
|
93
|
+
*/
|
|
94
|
+
type SchemaDocs = {
|
|
95
|
+
describeColumn?: ColumnDescriber;
|
|
96
|
+
describeTable?: TableDescriber;
|
|
97
|
+
describeRelation?: RelationDescriber;
|
|
98
|
+
deprecateColumn?: ColumnDeprecator;
|
|
99
|
+
};
|
|
100
|
+
|
|
8
101
|
type TableNamedRelations = {
|
|
9
102
|
relation: Relation;
|
|
10
103
|
targetTableName: string;
|
|
@@ -544,6 +637,38 @@ type SchemaFeatures = {
|
|
|
544
637
|
* @default false
|
|
545
638
|
*/
|
|
546
639
|
upsert?: boolean;
|
|
640
|
+
/**
|
|
641
|
+
* Relation fields on `Create<Table>Input` and `Update<Table>Input`, so a parent row and
|
|
642
|
+
* the rows it is related to can be written in one mutation. Off unless asked for: it adds
|
|
643
|
+
* a field per writable relation to every create and update input.
|
|
644
|
+
*
|
|
645
|
+
* ```graphql
|
|
646
|
+
* createPostsSingle(values: {
|
|
647
|
+
* title: "Hello"
|
|
648
|
+
* author: { connect: { id: { eq: "a1" } } }
|
|
649
|
+
* tags: { create: [{ name: "drizzle" }] }
|
|
650
|
+
* }) { id }
|
|
651
|
+
* ```
|
|
652
|
+
*
|
|
653
|
+
* Each relation field offers `create` and `connect`; the update input adds `disconnect`
|
|
654
|
+
* and, for a to-many relation, `set` (replace the whole set). `disconnect` and `set` are
|
|
655
|
+
* generated only when the foreign key is nullable — there is no way to detach a row whose
|
|
656
|
+
* key is NOT NULL — and many-to-many (`.through()`) relations are not written through at
|
|
657
|
+
* all. Nesting is one level deep: the row a nested `create` inserts takes columns only.
|
|
658
|
+
*
|
|
659
|
+
* The whole tree runs in one transaction (a savepoint when the request already carries
|
|
660
|
+
* one), and a column a relation fills in (`authorId`, when `author: { create: … }` is
|
|
661
|
+
* offered) becomes nullable on the create input, since the relation is the other way to
|
|
662
|
+
* supply it.
|
|
663
|
+
*
|
|
664
|
+
* PostgreSQL and SQLite only. MySQL cannot return the rows it just wrote, which is how a
|
|
665
|
+
* nested write learns the parent's key, so `buildSchema` rejects the flag there. On SQLite
|
|
666
|
+
* the driver must be asynchronous (libsql, D1, …): a synchronous one commits before an
|
|
667
|
+
* awaited statement runs, so `buildSchema` rejects the combination outright.
|
|
668
|
+
*
|
|
669
|
+
* @default false
|
|
670
|
+
*/
|
|
671
|
+
nestedWrites?: boolean;
|
|
547
672
|
/**
|
|
548
673
|
* Makes `where` non-null on the plural `update<Table>` / `delete<Table>` mutations, and
|
|
549
674
|
* rejects a `where` that collapses to no filters (e.g. `where: {}`), so a schema can rule
|
|
@@ -774,6 +899,56 @@ type BuildSchemaConfig = {
|
|
|
774
899
|
* @default true
|
|
775
900
|
*/
|
|
776
901
|
eagerLoadRelations?: boolean | ((tableName: string, relationName: string) => boolean);
|
|
902
|
+
/**
|
|
903
|
+
* Declarative per-table, per-column scalar overrides — replaces the GraphQL type built-in
|
|
904
|
+
* detection would pick for a column with the scalar you provide, everywhere that column's
|
|
905
|
+
* type surfaces: the object type, create/update inputs, filter operands (in a filter type
|
|
906
|
+
* named `${Scalar}Filter`), and aggregate min/max fields.
|
|
907
|
+
*
|
|
908
|
+
* Keys are the Drizzle schema keys: the table's key in your schema object and the column's
|
|
909
|
+
* property name. The value is either one scalar for both directions, or `{ output, input }`
|
|
910
|
+
* to type outputs and inputs differently (either side may be omitted to keep the default).
|
|
911
|
+
*
|
|
912
|
+
* ```ts
|
|
913
|
+
* buildSchema(db, {
|
|
914
|
+
* scalars: {
|
|
915
|
+
* users: {
|
|
916
|
+
* balance: GraphQLBigIntString, // both directions
|
|
917
|
+
* settings: { output: PrettyJSON }, // output only, input stays default
|
|
918
|
+
* },
|
|
919
|
+
* },
|
|
920
|
+
* });
|
|
921
|
+
* ```
|
|
922
|
+
*
|
|
923
|
+
* Validation and coercion become the scalar's job: for an overridden column the generated
|
|
924
|
+
* resolvers pass values through untouched — `parseValue`/`parseLiteral` results go to the
|
|
925
|
+
* database driver as-is, and raw driver values go to `serialize` as-is — so the scalar must
|
|
926
|
+
* accept what the driver produces and produce what the driver accepts.
|
|
927
|
+
*
|
|
928
|
+
* A declarative entry fully decides its column and wins over {@link mapColumnType}.
|
|
929
|
+
*/
|
|
930
|
+
scalars?: ScalarOverridesConfig;
|
|
931
|
+
/**
|
|
932
|
+
* Rule-based scalar mapping, called once per column at build time — the tool for applying
|
|
933
|
+
* a convention across many columns (e.g. "every `numeric` column is `Money`") or for typing
|
|
934
|
+
* custom column types the built-in detection does not know.
|
|
935
|
+
*
|
|
936
|
+
* Return a scalar (or `{ output, input }` pair) to override the column, or `undefined` to
|
|
937
|
+
* keep the default. `info` carries the table/column schema keys and the types built-in
|
|
938
|
+
* detection would use (`defaultType` / `defaultInputType`), so rules can key off either the
|
|
939
|
+
* Drizzle column or the default GraphQL type.
|
|
940
|
+
*
|
|
941
|
+
* ```ts
|
|
942
|
+
* buildSchema(db, {
|
|
943
|
+
* mapColumnType: (column, { columnName }) =>
|
|
944
|
+
* column.columnType === 'PgNumeric' ? MoneyScalar : undefined,
|
|
945
|
+
* });
|
|
946
|
+
* ```
|
|
947
|
+
*
|
|
948
|
+
* Same semantics as {@link scalars} otherwise; a column matched by both is decided by
|
|
949
|
+
* `scalars` alone.
|
|
950
|
+
*/
|
|
951
|
+
mapColumnType?: ColumnTypeMapper;
|
|
777
952
|
/**
|
|
778
953
|
* Called for every error thrown by a generated resolver, before it reaches the client.
|
|
779
954
|
*
|
|
@@ -798,6 +973,94 @@ type BuildSchemaConfig = {
|
|
|
798
973
|
* ```
|
|
799
974
|
*/
|
|
800
975
|
onError?: (error: unknown) => unknown;
|
|
976
|
+
/**
|
|
977
|
+
* Supplies the GraphQL `description` for a column, everywhere that column becomes a field:
|
|
978
|
+
* the object type, the create/update inputs, the filter input, and the aggregate
|
|
979
|
+
* `min`/`max`/`group` fields.
|
|
980
|
+
*
|
|
981
|
+
* Nothing is generated by default. The library used to emit the column's own type name
|
|
982
|
+
* ("DateTime", "JSON") as its description, which documented nothing a reader could not see
|
|
983
|
+
* from the type — that is gone, and this hook is what puts real prose in its place. Drizzle
|
|
984
|
+
* carries no column-comment metadata to read, so the text has to come from here.
|
|
985
|
+
*
|
|
986
|
+
* ```ts
|
|
987
|
+
* const columnDocs = { Users: { email: 'Primary contact address. Unique, case-insensitive.' } };
|
|
988
|
+
*
|
|
989
|
+
* buildSchema(db, {
|
|
990
|
+
* describeColumn: (_column, { tableName, columnName }) => columnDocs[tableName]?.[columnName],
|
|
991
|
+
* });
|
|
992
|
+
* ```
|
|
993
|
+
*
|
|
994
|
+
* `tableName` and `columnName` are the Drizzle schema keys. Return `undefined` to leave the
|
|
995
|
+
* field undocumented.
|
|
996
|
+
*/
|
|
997
|
+
describeColumn?: ColumnDescriber;
|
|
998
|
+
/**
|
|
999
|
+
* Supplies the GraphQL `description` for a table's object type.
|
|
1000
|
+
*
|
|
1001
|
+
* ```ts
|
|
1002
|
+
* buildSchema(db, { describeTable: (tableName) => tableDocs[tableName] });
|
|
1003
|
+
* ```
|
|
1004
|
+
*/
|
|
1005
|
+
describeTable?: TableDescriber;
|
|
1006
|
+
/**
|
|
1007
|
+
* Supplies the GraphQL `description` for a relation field on a table's object type.
|
|
1008
|
+
*
|
|
1009
|
+
* ```ts
|
|
1010
|
+
* buildSchema(db, {
|
|
1011
|
+
* describeRelation: (tableName, relationName) =>
|
|
1012
|
+
* tableName === 'Users' && relationName === 'posts' ? 'Posts this user authored.' : undefined,
|
|
1013
|
+
* });
|
|
1014
|
+
* ```
|
|
1015
|
+
*
|
|
1016
|
+
* The generated `<relation>Aggregate` companion fields are not covered — they are derived
|
|
1017
|
+
* fields rather than the relation itself.
|
|
1018
|
+
*/
|
|
1019
|
+
describeRelation?: RelationDescriber;
|
|
1020
|
+
/**
|
|
1021
|
+
* Supplies the GraphQL `deprecationReason` for a column, marking it `@deprecated` on the
|
|
1022
|
+
* object type and on the create/update inputs.
|
|
1023
|
+
*
|
|
1024
|
+
* ```ts
|
|
1025
|
+
* buildSchema(db, {
|
|
1026
|
+
* deprecateColumn: (_column, { columnName }) =>
|
|
1027
|
+
* columnName === 'legacyFlag' ? 'Use `status` instead.' : undefined,
|
|
1028
|
+
* });
|
|
1029
|
+
* ```
|
|
1030
|
+
*
|
|
1031
|
+
* A required input field cannot be deprecated — GraphQL rejects the schema, since a client
|
|
1032
|
+
* has no way to stop sending it — so the reason is dropped on non-null input fields and
|
|
1033
|
+
* kept everywhere else. Filter and orderBy fields are never deprecated either: filtering on
|
|
1034
|
+
* a deprecated column is how a caller finds the rows that still use it.
|
|
1035
|
+
*/
|
|
1036
|
+
deprecateColumn?: ColumnDeprecator;
|
|
1037
|
+
/**
|
|
1038
|
+
* Names the GraphQL enum types generated for enum columns.
|
|
1039
|
+
*
|
|
1040
|
+
* By default a column declared with a named `pgEnum` gets one shared type named after the
|
|
1041
|
+
* enum (`pgEnum('status', …)` → `StatusEnum`), reused by every column declared with that
|
|
1042
|
+
* same `pgEnum` — the database column is the same type, so a client variable typed
|
|
1043
|
+
* `StatusEnum!` is passable to any of them. A column with an inline value list
|
|
1044
|
+
* (`text({ enum: [...] })`, `mysqlEnum(...)`) keeps a per-column type named for its table
|
|
1045
|
+
* and column (`UsersRoleTextEnum`), because its values are shared with nothing.
|
|
1046
|
+
*
|
|
1047
|
+
* This hook overrides the name either way — for lining the schema up with another schema it
|
|
1048
|
+
* is stitched into, or for opting a specific column back into a type of its own:
|
|
1049
|
+
*
|
|
1050
|
+
* ```ts
|
|
1051
|
+
* buildSchema(db, {
|
|
1052
|
+
* enumNameMapper: (info) => (info.enumName === 'status' ? 'PublicationStatus' : undefined),
|
|
1053
|
+
* });
|
|
1054
|
+
* ```
|
|
1055
|
+
*
|
|
1056
|
+
* Two columns the mapper sends to the same name share one type when their values match —
|
|
1057
|
+
* the way to unify inline enums declared separately that mean the same thing. Sending two
|
|
1058
|
+
* *different* value lists to one name throws at build time rather than producing an
|
|
1059
|
+
* invalid schema.
|
|
1060
|
+
*
|
|
1061
|
+
* Return `undefined` to keep the default name.
|
|
1062
|
+
*/
|
|
1063
|
+
enumNameMapper?: EnumNameMapper;
|
|
801
1064
|
};
|
|
802
1065
|
|
|
803
1066
|
/**
|
|
@@ -817,4 +1080,4 @@ declare const GraphQLDecimalString: GraphQLScalarType<string, string>;
|
|
|
817
1080
|
|
|
818
1081
|
declare const buildSchema: <TDbClient extends AnyDrizzleDB<any>>(db: TDbClient, config?: BuildSchemaConfig) => GeneratedData<TDbClient>;
|
|
819
1082
|
|
|
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 };
|
|
1083
|
+
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,103 @@
|
|
|
1
|
-
import {
|
|
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,
|
|
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
|
+
/** Everything an {@link EnumNameMapper} needs to name — or opt a column out of — a generated enum type. */
|
|
44
|
+
type EnumNameInfo = {
|
|
45
|
+
/**
|
|
46
|
+
* The name the enum type was declared with (`pgEnum('status', …)`), shared by every column
|
|
47
|
+
* that uses it. `undefined` for an inline value list (`text({ enum: [...] })`,
|
|
48
|
+
* `mysqlEnum(...)`), which belongs to the one column that declares it.
|
|
49
|
+
*/
|
|
50
|
+
enumName: string | undefined;
|
|
51
|
+
/** The Postgres schema the named enum was declared in, when it declares one. */
|
|
52
|
+
schema: string | undefined;
|
|
53
|
+
/** The table's key in the Drizzle schema object. */
|
|
54
|
+
tableName: string;
|
|
55
|
+
/** The column's property name on the table object. */
|
|
56
|
+
columnName: string;
|
|
57
|
+
/** The enum's values, in declaration order. */
|
|
58
|
+
values: readonly string[];
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Names a generated GraphQL enum type. Return `undefined` to keep the default name. See
|
|
62
|
+
* `BuildSchemaConfig.enumNameMapper`.
|
|
63
|
+
*/
|
|
64
|
+
type EnumNameMapper = (info: EnumNameInfo) => string | undefined;
|
|
65
|
+
/** Context handed to the documentation and deprecation hooks alongside the column itself. */
|
|
66
|
+
type ColumnDocInfo = {
|
|
67
|
+
/** The table's key in the Drizzle schema object. */
|
|
68
|
+
tableName: string;
|
|
69
|
+
/** The column's property name on the table object. */
|
|
70
|
+
columnName: string;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Supplies the GraphQL `description` for a generated column field. See
|
|
74
|
+
* `BuildSchemaConfig.describeColumn`.
|
|
75
|
+
*/
|
|
76
|
+
type ColumnDescriber = (column: Column, info: ColumnDocInfo) => string | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Supplies the GraphQL `deprecationReason` for a generated column field. See
|
|
79
|
+
* `BuildSchemaConfig.deprecateColumn`.
|
|
80
|
+
*/
|
|
81
|
+
type ColumnDeprecator = (column: Column, info: ColumnDocInfo) => string | undefined;
|
|
82
|
+
/** Supplies the GraphQL `description` for a table's object type. See `BuildSchemaConfig.describeTable`. */
|
|
83
|
+
type TableDescriber = (tableName: string) => string | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Supplies the GraphQL `description` for a relation field. See
|
|
86
|
+
* `BuildSchemaConfig.describeRelation`.
|
|
87
|
+
*/
|
|
88
|
+
type RelationDescriber = (tableName: string, relationName: string) => string | undefined;
|
|
89
|
+
/**
|
|
90
|
+
* The documentation hooks a build was configured with, resolved once and threaded through
|
|
91
|
+
* type generation. Every member is optional; a build with no hooks generates fields with no
|
|
92
|
+
* descriptions at all.
|
|
93
|
+
*/
|
|
94
|
+
type SchemaDocs = {
|
|
95
|
+
describeColumn?: ColumnDescriber;
|
|
96
|
+
describeTable?: TableDescriber;
|
|
97
|
+
describeRelation?: RelationDescriber;
|
|
98
|
+
deprecateColumn?: ColumnDeprecator;
|
|
99
|
+
};
|
|
100
|
+
|
|
8
101
|
type TableNamedRelations = {
|
|
9
102
|
relation: Relation;
|
|
10
103
|
targetTableName: string;
|
|
@@ -544,6 +637,38 @@ type SchemaFeatures = {
|
|
|
544
637
|
* @default false
|
|
545
638
|
*/
|
|
546
639
|
upsert?: boolean;
|
|
640
|
+
/**
|
|
641
|
+
* Relation fields on `Create<Table>Input` and `Update<Table>Input`, so a parent row and
|
|
642
|
+
* the rows it is related to can be written in one mutation. Off unless asked for: it adds
|
|
643
|
+
* a field per writable relation to every create and update input.
|
|
644
|
+
*
|
|
645
|
+
* ```graphql
|
|
646
|
+
* createPostsSingle(values: {
|
|
647
|
+
* title: "Hello"
|
|
648
|
+
* author: { connect: { id: { eq: "a1" } } }
|
|
649
|
+
* tags: { create: [{ name: "drizzle" }] }
|
|
650
|
+
* }) { id }
|
|
651
|
+
* ```
|
|
652
|
+
*
|
|
653
|
+
* Each relation field offers `create` and `connect`; the update input adds `disconnect`
|
|
654
|
+
* and, for a to-many relation, `set` (replace the whole set). `disconnect` and `set` are
|
|
655
|
+
* generated only when the foreign key is nullable — there is no way to detach a row whose
|
|
656
|
+
* key is NOT NULL — and many-to-many (`.through()`) relations are not written through at
|
|
657
|
+
* all. Nesting is one level deep: the row a nested `create` inserts takes columns only.
|
|
658
|
+
*
|
|
659
|
+
* The whole tree runs in one transaction (a savepoint when the request already carries
|
|
660
|
+
* one), and a column a relation fills in (`authorId`, when `author: { create: … }` is
|
|
661
|
+
* offered) becomes nullable on the create input, since the relation is the other way to
|
|
662
|
+
* supply it.
|
|
663
|
+
*
|
|
664
|
+
* PostgreSQL and SQLite only. MySQL cannot return the rows it just wrote, which is how a
|
|
665
|
+
* nested write learns the parent's key, so `buildSchema` rejects the flag there. On SQLite
|
|
666
|
+
* the driver must be asynchronous (libsql, D1, …): a synchronous one commits before an
|
|
667
|
+
* awaited statement runs, so `buildSchema` rejects the combination outright.
|
|
668
|
+
*
|
|
669
|
+
* @default false
|
|
670
|
+
*/
|
|
671
|
+
nestedWrites?: boolean;
|
|
547
672
|
/**
|
|
548
673
|
* Makes `where` non-null on the plural `update<Table>` / `delete<Table>` mutations, and
|
|
549
674
|
* rejects a `where` that collapses to no filters (e.g. `where: {}`), so a schema can rule
|
|
@@ -774,6 +899,56 @@ type BuildSchemaConfig = {
|
|
|
774
899
|
* @default true
|
|
775
900
|
*/
|
|
776
901
|
eagerLoadRelations?: boolean | ((tableName: string, relationName: string) => boolean);
|
|
902
|
+
/**
|
|
903
|
+
* Declarative per-table, per-column scalar overrides — replaces the GraphQL type built-in
|
|
904
|
+
* detection would pick for a column with the scalar you provide, everywhere that column's
|
|
905
|
+
* type surfaces: the object type, create/update inputs, filter operands (in a filter type
|
|
906
|
+
* named `${Scalar}Filter`), and aggregate min/max fields.
|
|
907
|
+
*
|
|
908
|
+
* Keys are the Drizzle schema keys: the table's key in your schema object and the column's
|
|
909
|
+
* property name. The value is either one scalar for both directions, or `{ output, input }`
|
|
910
|
+
* to type outputs and inputs differently (either side may be omitted to keep the default).
|
|
911
|
+
*
|
|
912
|
+
* ```ts
|
|
913
|
+
* buildSchema(db, {
|
|
914
|
+
* scalars: {
|
|
915
|
+
* users: {
|
|
916
|
+
* balance: GraphQLBigIntString, // both directions
|
|
917
|
+
* settings: { output: PrettyJSON }, // output only, input stays default
|
|
918
|
+
* },
|
|
919
|
+
* },
|
|
920
|
+
* });
|
|
921
|
+
* ```
|
|
922
|
+
*
|
|
923
|
+
* Validation and coercion become the scalar's job: for an overridden column the generated
|
|
924
|
+
* resolvers pass values through untouched — `parseValue`/`parseLiteral` results go to the
|
|
925
|
+
* database driver as-is, and raw driver values go to `serialize` as-is — so the scalar must
|
|
926
|
+
* accept what the driver produces and produce what the driver accepts.
|
|
927
|
+
*
|
|
928
|
+
* A declarative entry fully decides its column and wins over {@link mapColumnType}.
|
|
929
|
+
*/
|
|
930
|
+
scalars?: ScalarOverridesConfig;
|
|
931
|
+
/**
|
|
932
|
+
* Rule-based scalar mapping, called once per column at build time — the tool for applying
|
|
933
|
+
* a convention across many columns (e.g. "every `numeric` column is `Money`") or for typing
|
|
934
|
+
* custom column types the built-in detection does not know.
|
|
935
|
+
*
|
|
936
|
+
* Return a scalar (or `{ output, input }` pair) to override the column, or `undefined` to
|
|
937
|
+
* keep the default. `info` carries the table/column schema keys and the types built-in
|
|
938
|
+
* detection would use (`defaultType` / `defaultInputType`), so rules can key off either the
|
|
939
|
+
* Drizzle column or the default GraphQL type.
|
|
940
|
+
*
|
|
941
|
+
* ```ts
|
|
942
|
+
* buildSchema(db, {
|
|
943
|
+
* mapColumnType: (column, { columnName }) =>
|
|
944
|
+
* column.columnType === 'PgNumeric' ? MoneyScalar : undefined,
|
|
945
|
+
* });
|
|
946
|
+
* ```
|
|
947
|
+
*
|
|
948
|
+
* Same semantics as {@link scalars} otherwise; a column matched by both is decided by
|
|
949
|
+
* `scalars` alone.
|
|
950
|
+
*/
|
|
951
|
+
mapColumnType?: ColumnTypeMapper;
|
|
777
952
|
/**
|
|
778
953
|
* Called for every error thrown by a generated resolver, before it reaches the client.
|
|
779
954
|
*
|
|
@@ -798,6 +973,94 @@ type BuildSchemaConfig = {
|
|
|
798
973
|
* ```
|
|
799
974
|
*/
|
|
800
975
|
onError?: (error: unknown) => unknown;
|
|
976
|
+
/**
|
|
977
|
+
* Supplies the GraphQL `description` for a column, everywhere that column becomes a field:
|
|
978
|
+
* the object type, the create/update inputs, the filter input, and the aggregate
|
|
979
|
+
* `min`/`max`/`group` fields.
|
|
980
|
+
*
|
|
981
|
+
* Nothing is generated by default. The library used to emit the column's own type name
|
|
982
|
+
* ("DateTime", "JSON") as its description, which documented nothing a reader could not see
|
|
983
|
+
* from the type — that is gone, and this hook is what puts real prose in its place. Drizzle
|
|
984
|
+
* carries no column-comment metadata to read, so the text has to come from here.
|
|
985
|
+
*
|
|
986
|
+
* ```ts
|
|
987
|
+
* const columnDocs = { Users: { email: 'Primary contact address. Unique, case-insensitive.' } };
|
|
988
|
+
*
|
|
989
|
+
* buildSchema(db, {
|
|
990
|
+
* describeColumn: (_column, { tableName, columnName }) => columnDocs[tableName]?.[columnName],
|
|
991
|
+
* });
|
|
992
|
+
* ```
|
|
993
|
+
*
|
|
994
|
+
* `tableName` and `columnName` are the Drizzle schema keys. Return `undefined` to leave the
|
|
995
|
+
* field undocumented.
|
|
996
|
+
*/
|
|
997
|
+
describeColumn?: ColumnDescriber;
|
|
998
|
+
/**
|
|
999
|
+
* Supplies the GraphQL `description` for a table's object type.
|
|
1000
|
+
*
|
|
1001
|
+
* ```ts
|
|
1002
|
+
* buildSchema(db, { describeTable: (tableName) => tableDocs[tableName] });
|
|
1003
|
+
* ```
|
|
1004
|
+
*/
|
|
1005
|
+
describeTable?: TableDescriber;
|
|
1006
|
+
/**
|
|
1007
|
+
* Supplies the GraphQL `description` for a relation field on a table's object type.
|
|
1008
|
+
*
|
|
1009
|
+
* ```ts
|
|
1010
|
+
* buildSchema(db, {
|
|
1011
|
+
* describeRelation: (tableName, relationName) =>
|
|
1012
|
+
* tableName === 'Users' && relationName === 'posts' ? 'Posts this user authored.' : undefined,
|
|
1013
|
+
* });
|
|
1014
|
+
* ```
|
|
1015
|
+
*
|
|
1016
|
+
* The generated `<relation>Aggregate` companion fields are not covered — they are derived
|
|
1017
|
+
* fields rather than the relation itself.
|
|
1018
|
+
*/
|
|
1019
|
+
describeRelation?: RelationDescriber;
|
|
1020
|
+
/**
|
|
1021
|
+
* Supplies the GraphQL `deprecationReason` for a column, marking it `@deprecated` on the
|
|
1022
|
+
* object type and on the create/update inputs.
|
|
1023
|
+
*
|
|
1024
|
+
* ```ts
|
|
1025
|
+
* buildSchema(db, {
|
|
1026
|
+
* deprecateColumn: (_column, { columnName }) =>
|
|
1027
|
+
* columnName === 'legacyFlag' ? 'Use `status` instead.' : undefined,
|
|
1028
|
+
* });
|
|
1029
|
+
* ```
|
|
1030
|
+
*
|
|
1031
|
+
* A required input field cannot be deprecated — GraphQL rejects the schema, since a client
|
|
1032
|
+
* has no way to stop sending it — so the reason is dropped on non-null input fields and
|
|
1033
|
+
* kept everywhere else. Filter and orderBy fields are never deprecated either: filtering on
|
|
1034
|
+
* a deprecated column is how a caller finds the rows that still use it.
|
|
1035
|
+
*/
|
|
1036
|
+
deprecateColumn?: ColumnDeprecator;
|
|
1037
|
+
/**
|
|
1038
|
+
* Names the GraphQL enum types generated for enum columns.
|
|
1039
|
+
*
|
|
1040
|
+
* By default a column declared with a named `pgEnum` gets one shared type named after the
|
|
1041
|
+
* enum (`pgEnum('status', …)` → `StatusEnum`), reused by every column declared with that
|
|
1042
|
+
* same `pgEnum` — the database column is the same type, so a client variable typed
|
|
1043
|
+
* `StatusEnum!` is passable to any of them. A column with an inline value list
|
|
1044
|
+
* (`text({ enum: [...] })`, `mysqlEnum(...)`) keeps a per-column type named for its table
|
|
1045
|
+
* and column (`UsersRoleTextEnum`), because its values are shared with nothing.
|
|
1046
|
+
*
|
|
1047
|
+
* This hook overrides the name either way — for lining the schema up with another schema it
|
|
1048
|
+
* is stitched into, or for opting a specific column back into a type of its own:
|
|
1049
|
+
*
|
|
1050
|
+
* ```ts
|
|
1051
|
+
* buildSchema(db, {
|
|
1052
|
+
* enumNameMapper: (info) => (info.enumName === 'status' ? 'PublicationStatus' : undefined),
|
|
1053
|
+
* });
|
|
1054
|
+
* ```
|
|
1055
|
+
*
|
|
1056
|
+
* Two columns the mapper sends to the same name share one type when their values match —
|
|
1057
|
+
* the way to unify inline enums declared separately that mean the same thing. Sending two
|
|
1058
|
+
* *different* value lists to one name throws at build time rather than producing an
|
|
1059
|
+
* invalid schema.
|
|
1060
|
+
*
|
|
1061
|
+
* Return `undefined` to keep the default name.
|
|
1062
|
+
*/
|
|
1063
|
+
enumNameMapper?: EnumNameMapper;
|
|
801
1064
|
};
|
|
802
1065
|
|
|
803
1066
|
/**
|
|
@@ -817,4 +1080,4 @@ declare const GraphQLDecimalString: GraphQLScalarType<string, string>;
|
|
|
817
1080
|
|
|
818
1081
|
declare const buildSchema: <TDbClient extends AnyDrizzleDB<any>>(db: TDbClient, config?: BuildSchemaConfig) => GeneratedData<TDbClient>;
|
|
819
1082
|
|
|
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 };
|
|
1083
|
+
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 };
|