@pothos/plugin-drizzle 0.8.1 → 0.9.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/CHANGELOG.md +92 -0
- package/TODO.md +25 -4
- package/dts/connection-helpers.d.ts +32 -0
- package/dts/connection-helpers.d.ts.map +1 -0
- package/dts/drizzle-field-builder.d.ts +18 -53
- package/dts/drizzle-field-builder.d.ts.map +1 -1
- package/dts/global-types.d.ts +22 -41
- package/dts/global-types.d.ts.map +1 -1
- package/dts/index.d.ts +4 -2
- package/dts/index.d.ts.map +1 -1
- package/dts/interface-ref.d.ts +3 -2
- package/dts/interface-ref.d.ts.map +1 -1
- package/dts/model-loader.d.ts +3 -2
- package/dts/model-loader.d.ts.map +1 -1
- package/dts/node-ref.d.ts +1 -1
- package/dts/node-ref.d.ts.map +1 -1
- package/dts/object-ref.d.ts +2 -2
- package/dts/object-ref.d.ts.map +1 -1
- package/dts/types.d.ts +61 -41
- package/dts/types.d.ts.map +1 -1
- package/dts/utils/config.d.ts +4 -3
- package/dts/utils/config.d.ts.map +1 -1
- package/dts/utils/cursors.d.ts +13 -7
- package/dts/utils/cursors.d.ts.map +1 -1
- package/dts/utils/drizzle-graphql.d.ts +0 -17
- package/dts/utils/drizzle-graphql.d.ts.map +1 -1
- package/dts/utils/map-query.d.ts.map +1 -1
- package/dts/utils/selections.d.ts +5 -5
- package/dts/utils/selections.d.ts.map +1 -1
- package/esm/connection-helpers.d.ts +34 -0
- package/esm/connection-helpers.d.ts.map +1 -0
- package/esm/connection-helpers.js +74 -0
- package/esm/connection-helpers.js.map +1 -0
- package/esm/drizzle-field-builder.d.ts +18 -73
- package/esm/drizzle-field-builder.d.ts.map +1 -1
- package/esm/drizzle-field-builder.js +25 -14
- package/esm/drizzle-field-builder.js.map +1 -1
- package/esm/field-builder.js +2 -3
- package/esm/field-builder.js.map +1 -1
- package/esm/global-types.d.ts +35 -60
- package/esm/global-types.d.ts.map +1 -1
- package/esm/global-types.js.map +1 -1
- package/esm/index.d.ts +4 -2
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +70 -61
- package/esm/index.js.map +1 -1
- package/esm/interface-ref.d.ts +3 -2
- package/esm/interface-ref.d.ts.map +1 -1
- package/esm/interface-ref.js.map +1 -1
- package/esm/model-loader.d.ts +3 -2
- package/esm/model-loader.d.ts.map +1 -1
- package/esm/model-loader.js +17 -10
- package/esm/model-loader.js.map +1 -1
- package/esm/node-ref.d.ts +1 -1
- package/esm/node-ref.d.ts.map +1 -1
- package/esm/object-ref.d.ts +2 -2
- package/esm/object-ref.d.ts.map +1 -1
- package/esm/schema-builder.js +111 -65
- package/esm/schema-builder.js.map +1 -1
- package/esm/types.d.ts +61 -41
- package/esm/types.d.ts.map +1 -1
- package/esm/types.js.map +1 -1
- package/esm/utils/config.d.ts +4 -3
- package/esm/utils/config.d.ts.map +1 -1
- package/esm/utils/config.js +32 -15
- package/esm/utils/config.js.map +1 -1
- package/esm/utils/cursors.d.ts +13 -7
- package/esm/utils/cursors.d.ts.map +1 -1
- package/esm/utils/cursors.js +137 -63
- package/esm/utils/cursors.js.map +1 -1
- package/esm/utils/drizzle-graphql.d.ts +0 -17
- package/esm/utils/drizzle-graphql.d.ts.map +1 -1
- package/esm/utils/drizzle-graphql.js +230 -198
- package/esm/utils/drizzle-graphql.js.map +1 -1
- package/esm/utils/map-query.d.ts.map +1 -1
- package/esm/utils/map-query.js +9 -5
- package/esm/utils/map-query.js.map +1 -1
- package/esm/utils/selections.d.ts +5 -5
- package/esm/utils/selections.d.ts.map +1 -1
- package/esm/utils/selections.js +19 -18
- package/esm/utils/selections.js.map +1 -1
- package/lib/connection-helpers.js +85 -0
- package/lib/connection-helpers.js.map +1 -0
- package/lib/drizzle-field-builder.js +24 -13
- package/lib/drizzle-field-builder.js.map +1 -1
- package/lib/field-builder.js +2 -3
- package/lib/field-builder.js.map +1 -1
- package/lib/index.js +75 -60
- package/lib/index.js.map +1 -1
- package/lib/interface-ref.js.map +1 -1
- package/lib/model-loader.js +17 -10
- package/lib/model-loader.js.map +1 -1
- package/lib/schema-builder.js +111 -65
- package/lib/schema-builder.js.map +1 -1
- package/lib/types.js.map +1 -1
- package/lib/utils/config.js +31 -14
- package/lib/utils/config.js.map +1 -1
- package/lib/utils/cursors.js +135 -63
- package/lib/utils/cursors.js.map +1 -1
- package/lib/utils/drizzle-graphql.js +230 -221
- package/lib/utils/drizzle-graphql.js.map +1 -1
- package/lib/utils/map-query.js +9 -5
- package/lib/utils/map-query.js.map +1 -1
- package/lib/utils/selections.js +18 -17
- package/lib/utils/selections.js.map +1 -1
- package/package.json +14 -14
- package/src/connection-helpers.ts +184 -0
- package/src/drizzle-field-builder.ts +30 -26
- package/src/field-builder.ts +4 -7
- package/src/global-types.ts +112 -119
- package/src/index.ts +90 -68
- package/src/interface-ref.ts +7 -3
- package/src/model-loader.ts +32 -17
- package/src/node-ref.ts +1 -1
- package/src/object-ref.ts +2 -2
- package/src/schema-builder.ts +114 -111
- package/src/types.ts +95 -62
- package/src/utils/config.ts +39 -30
- package/src/utils/cursors.ts +134 -101
- package/src/utils/drizzle-graphql.ts +273 -274
- package/src/utils/map-query.ts +19 -7
- package/src/utils/selections.ts +34 -28
package/src/global-types.ts
CHANGED
|
@@ -13,13 +13,14 @@ import type {
|
|
|
13
13
|
TypeParam,
|
|
14
14
|
} from '@pothos/core';
|
|
15
15
|
import type {
|
|
16
|
-
|
|
16
|
+
AnyRelations,
|
|
17
17
|
BuildQueryResult,
|
|
18
18
|
Column,
|
|
19
19
|
DBQueryConfig,
|
|
20
20
|
ExtractTablesWithRelations,
|
|
21
21
|
SQL,
|
|
22
22
|
TableRelationalConfig,
|
|
23
|
+
TablesRelationalConfig,
|
|
23
24
|
} from 'drizzle-orm';
|
|
24
25
|
import type { DrizzleObjectFieldBuilder } from './drizzle-field-builder';
|
|
25
26
|
import type { DrizzleInterfaceRef, DrizzleRef } from './interface-ref';
|
|
@@ -36,6 +37,7 @@ import type {
|
|
|
36
37
|
DrizzleObjectOptions,
|
|
37
38
|
DrizzlePluginOptions,
|
|
38
39
|
ShapeFromConnection,
|
|
40
|
+
ShapeFromIdColumns,
|
|
39
41
|
drizzleTableName,
|
|
40
42
|
} from './types';
|
|
41
43
|
|
|
@@ -58,34 +60,29 @@ declare global {
|
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
export interface UserSchemaTypes {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
DrizzleRelationSchemaByDbName: Record<string, TableRelationalConfig>;
|
|
63
|
+
DrizzleRelations: AnyRelations;
|
|
64
|
+
DrizzleRelationsConfig: TablesRelationalConfig;
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
export interface ExtendDefaultTypes<PartialTypes extends Partial<UserSchemaTypes>> {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
DrizzleRelationSchemaByDbName: MapToDbName<
|
|
70
|
-
ExtractTablesWithRelations<PartialTypes['DrizzleSchema'] & {}>
|
|
71
|
-
>;
|
|
68
|
+
DrizzleRelations: PartialTypes['DrizzleRelations'] & {};
|
|
69
|
+
DrizzleRelationsConfig: ExtractTablesWithRelations<PartialTypes['DrizzleRelations'] & {}>;
|
|
72
70
|
}
|
|
73
71
|
|
|
74
72
|
export interface SchemaBuilder<Types extends SchemaTypes> {
|
|
75
73
|
drizzleObject: <
|
|
76
74
|
const Interfaces extends InterfaceParam<Types>[],
|
|
77
|
-
Table extends keyof Types['
|
|
75
|
+
Table extends keyof Types['DrizzleRelations']['tables'],
|
|
78
76
|
Selection extends
|
|
79
77
|
| DBQueryConfig<
|
|
80
78
|
'one',
|
|
81
|
-
|
|
82
|
-
Types['
|
|
83
|
-
Types['DrizzleRelationSchema'][Table]
|
|
79
|
+
Types['DrizzleRelationsConfig'],
|
|
80
|
+
Types['DrizzleRelationsConfig'][Table]
|
|
84
81
|
>
|
|
85
82
|
| true,
|
|
86
83
|
Shape = BuildQueryResult<
|
|
87
|
-
Types['
|
|
88
|
-
Types['
|
|
84
|
+
Types['DrizzleRelationsConfig'],
|
|
85
|
+
Types['DrizzleRelationsConfig'][Table],
|
|
89
86
|
Selection
|
|
90
87
|
>,
|
|
91
88
|
>(
|
|
@@ -95,18 +92,17 @@ declare global {
|
|
|
95
92
|
|
|
96
93
|
drizzleInterface: <
|
|
97
94
|
const Interfaces extends InterfaceParam<Types>[],
|
|
98
|
-
Table extends keyof Types['
|
|
95
|
+
Table extends keyof Types['DrizzleRelationsConfig'],
|
|
99
96
|
Selection extends
|
|
100
97
|
| DBQueryConfig<
|
|
101
98
|
'one',
|
|
102
|
-
|
|
103
|
-
Types['
|
|
104
|
-
Types['DrizzleRelationSchema'][Table]
|
|
99
|
+
Types['DrizzleRelationsConfig'],
|
|
100
|
+
Types['DrizzleRelationsConfig'][Table]
|
|
105
101
|
>
|
|
106
102
|
| true,
|
|
107
103
|
Shape = BuildQueryResult<
|
|
108
|
-
Types['
|
|
109
|
-
Types['
|
|
104
|
+
Types['DrizzleRelationsConfig'],
|
|
105
|
+
Types['DrizzleRelationsConfig'][Table],
|
|
110
106
|
Selection
|
|
111
107
|
>,
|
|
112
108
|
>(
|
|
@@ -117,46 +113,38 @@ declare global {
|
|
|
117
113
|
drizzleNode: 'relay' extends PluginName
|
|
118
114
|
? <
|
|
119
115
|
const Interfaces extends InterfaceParam<Types>[],
|
|
120
|
-
Table extends keyof Types['
|
|
116
|
+
Table extends keyof Types['DrizzleRelationsConfig'],
|
|
121
117
|
Selection extends
|
|
122
118
|
| DBQueryConfig<
|
|
123
119
|
'one',
|
|
124
|
-
|
|
125
|
-
Types['
|
|
126
|
-
Types['DrizzleRelationSchema'][Table]
|
|
120
|
+
Types['DrizzleRelationsConfig'],
|
|
121
|
+
Types['DrizzleRelationsConfig'][Table]
|
|
127
122
|
>
|
|
128
123
|
| true,
|
|
129
|
-
|
|
124
|
+
IDColumns,
|
|
130
125
|
Shape = BuildQueryResult<
|
|
131
|
-
Types['
|
|
132
|
-
Types['
|
|
126
|
+
Types['DrizzleRelationsConfig'],
|
|
127
|
+
Types['DrizzleRelationsConfig'][Table],
|
|
133
128
|
Selection
|
|
134
129
|
>,
|
|
135
130
|
>(
|
|
136
131
|
table: Table,
|
|
137
|
-
options: DrizzleNodeOptions<Types, Table, Shape, Selection, Interfaces,
|
|
138
|
-
) => DrizzleNodeRef<
|
|
139
|
-
Types,
|
|
140
|
-
Table,
|
|
141
|
-
Shape,
|
|
142
|
-
{
|
|
143
|
-
[K in IDColumn['_']['name']]: Extract<IDColumn, { _: { name: K } }>['_']['data'];
|
|
144
|
-
}
|
|
145
|
-
>
|
|
132
|
+
options: DrizzleNodeOptions<Types, Table, Shape, Selection, Interfaces, IDColumns>,
|
|
133
|
+
) => DrizzleNodeRef<Types, Table, Shape, ShapeFromIdColumns<Types, Table, IDColumns>>
|
|
146
134
|
: '@pothos/plugin-relay is required to use this method';
|
|
147
135
|
|
|
148
136
|
drizzleObjectField: <
|
|
149
|
-
Type extends DrizzleObjectRef<Types> | keyof Types['
|
|
137
|
+
Type extends DrizzleObjectRef<Types> | keyof Types['DrizzleRelationsConfig'],
|
|
150
138
|
TableConfig extends TableRelationalConfig = Type extends DrizzleObjectRef<Types>
|
|
151
139
|
? Type[typeof drizzleTableKey]
|
|
152
|
-
: Types['
|
|
140
|
+
: Types['DrizzleRelationsConfig'][Type & keyof Types['DrizzleRelationsConfig']],
|
|
153
141
|
Shape extends {} = Type extends DrizzleObjectRef<
|
|
154
142
|
Types,
|
|
155
|
-
keyof Types['
|
|
143
|
+
keyof Types['DrizzleRelationsConfig'],
|
|
156
144
|
infer S
|
|
157
145
|
>
|
|
158
146
|
? S & { [drizzleTableName]?: TableConfig['tsName'] }
|
|
159
|
-
: BuildQueryResult<Types['
|
|
147
|
+
: BuildQueryResult<Types['DrizzleRelationsConfig'], TableConfig, true> & {
|
|
160
148
|
[drizzleTableName]?: Type;
|
|
161
149
|
},
|
|
162
150
|
>(
|
|
@@ -166,17 +154,17 @@ declare global {
|
|
|
166
154
|
) => void;
|
|
167
155
|
|
|
168
156
|
drizzleInterfaceField: <
|
|
169
|
-
Type extends DrizzleInterfaceRef<Types> | keyof Types['
|
|
157
|
+
Type extends DrizzleInterfaceRef<Types> | keyof Types['DrizzleRelationsConfig'],
|
|
170
158
|
TableConfig extends TableRelationalConfig = Type extends DrizzleObjectRef<Types>
|
|
171
159
|
? Type[typeof drizzleTableKey]
|
|
172
|
-
: Types['
|
|
160
|
+
: Types['DrizzleRelationsConfig'][Type & keyof Types['DrizzleRelationsConfig']],
|
|
173
161
|
Shape extends {} = Type extends DrizzleInterfaceRef<
|
|
174
162
|
Types,
|
|
175
|
-
keyof Types['
|
|
163
|
+
keyof Types['DrizzleRelationsConfig'],
|
|
176
164
|
infer S
|
|
177
165
|
>
|
|
178
166
|
? S & { [drizzleTableName]?: TableConfig['tsName'] }
|
|
179
|
-
: BuildQueryResult<Types['
|
|
167
|
+
: BuildQueryResult<Types['DrizzleRelationsConfig'], TableConfig, true> & {
|
|
180
168
|
[drizzleTableName]?: Type;
|
|
181
169
|
},
|
|
182
170
|
>(
|
|
@@ -186,17 +174,17 @@ declare global {
|
|
|
186
174
|
) => void;
|
|
187
175
|
|
|
188
176
|
drizzleObjectFields: <
|
|
189
|
-
Type extends DrizzleObjectRef<Types> | keyof Types['
|
|
177
|
+
Type extends DrizzleObjectRef<Types> | keyof Types['DrizzleRelationsConfig'],
|
|
190
178
|
TableConfig extends TableRelationalConfig = Type extends DrizzleObjectRef<Types>
|
|
191
179
|
? Type[typeof drizzleTableKey]
|
|
192
|
-
: Types['
|
|
180
|
+
: Types['DrizzleRelationsConfig'][Type & keyof Types['DrizzleRelationsConfig']],
|
|
193
181
|
Shape extends {} = Type extends DrizzleObjectRef<
|
|
194
182
|
Types,
|
|
195
|
-
keyof Types['
|
|
183
|
+
keyof Types['DrizzleRelationsConfig'],
|
|
196
184
|
infer S
|
|
197
185
|
>
|
|
198
186
|
? S & { [drizzleTableName]?: TableConfig['tsName'] }
|
|
199
|
-
: BuildQueryResult<Types['
|
|
187
|
+
: BuildQueryResult<Types['DrizzleRelationsConfig'], TableConfig, true> & {
|
|
200
188
|
[drizzleTableName]?: Type;
|
|
201
189
|
},
|
|
202
190
|
>(
|
|
@@ -205,17 +193,17 @@ declare global {
|
|
|
205
193
|
) => void;
|
|
206
194
|
|
|
207
195
|
drizzleInterfaceFields: <
|
|
208
|
-
Type extends DrizzleInterfaceRef<Types> | keyof Types['
|
|
196
|
+
Type extends DrizzleInterfaceRef<Types> | keyof Types['DrizzleRelationsConfig'],
|
|
209
197
|
TableConfig extends TableRelationalConfig = Type extends DrizzleObjectRef<Types>
|
|
210
198
|
? Type[typeof drizzleTableKey]
|
|
211
|
-
: Types['
|
|
199
|
+
: Types['DrizzleRelationsConfig'][Type & keyof Types['DrizzleRelationsConfig']],
|
|
212
200
|
Shape extends {} = Type extends DrizzleInterfaceRef<
|
|
213
201
|
Types,
|
|
214
|
-
keyof Types['
|
|
202
|
+
keyof Types['DrizzleRelationsConfig'],
|
|
215
203
|
infer S
|
|
216
204
|
>
|
|
217
205
|
? S & { [drizzleTableName]?: TableConfig['tsName'] }
|
|
218
|
-
: BuildQueryResult<Types['
|
|
206
|
+
: BuildQueryResult<Types['DrizzleRelationsConfig'], TableConfig, true> & {
|
|
219
207
|
[drizzleTableName]?: Type;
|
|
220
208
|
},
|
|
221
209
|
>(
|
|
@@ -223,37 +211,37 @@ declare global {
|
|
|
223
211
|
fields: (t: DrizzleObjectFieldBuilder<Types, TableConfig, false, Shape>) => FieldMap,
|
|
224
212
|
) => void;
|
|
225
213
|
|
|
226
|
-
drizzleGraphQLOrderBy: 'addGraphQL' extends PluginName
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
214
|
+
// drizzleGraphQLOrderBy: 'addGraphQL' extends PluginName
|
|
215
|
+
// ? <Table extends keyof Types['DrizzleRelationsConfig']>(
|
|
216
|
+
// table: Table,
|
|
217
|
+
// type: GraphQLInputObjectType,
|
|
218
|
+
// ...args: NormalizeArgs<[options: AddGraphQLInputTypeOptions<Types, {}>]>
|
|
219
|
+
// ) => InputObjectRef<Types, SQL | SQL[]>
|
|
220
|
+
// : '@pothos/plugin-add-graphql is required to use this method';
|
|
233
221
|
|
|
234
|
-
drizzleGraphQLFilters: 'addGraphQL' extends PluginName
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
222
|
+
// drizzleGraphQLFilters: 'addGraphQL' extends PluginName
|
|
223
|
+
// ? <Table extends keyof Types['DrizzleRelationsConfig']>(
|
|
224
|
+
// table: Table,
|
|
225
|
+
// type: GraphQLInputObjectType,
|
|
226
|
+
// ...args: NormalizeArgs<[options: AddGraphQLInputTypeOptions<Types, {}>]>
|
|
227
|
+
// ) => InputObjectRef<Types, SQL>
|
|
228
|
+
// : '@pothos/plugin-add-graphql is required to use this method';
|
|
241
229
|
|
|
242
|
-
drizzleGraphQLInsert: 'addGraphQL' extends PluginName
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
230
|
+
// drizzleGraphQLInsert: 'addGraphQL' extends PluginName
|
|
231
|
+
// ? <Table extends keyof Types['DrizzleRelationsConfig']>(
|
|
232
|
+
// table: Table,
|
|
233
|
+
// type: GraphQLInputObjectType,
|
|
234
|
+
// ...args: NormalizeArgs<[options: AddGraphQLInputTypeOptions<Types, {}>]>
|
|
235
|
+
// ) => InputObjectRef<Types, Record<string, unknown>>
|
|
236
|
+
// : '@pothos/plugin-add-graphql is required to use this method';
|
|
249
237
|
|
|
250
|
-
drizzleGraphQLUpdate: 'addGraphQL' extends PluginName
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
238
|
+
// drizzleGraphQLUpdate: 'addGraphQL' extends PluginName
|
|
239
|
+
// ? <Table extends keyof Types['DrizzleRelationsConfig']>(
|
|
240
|
+
// table: Table,
|
|
241
|
+
// type: GraphQLInputObjectType,
|
|
242
|
+
// ...args: NormalizeArgs<[options: AddGraphQLInputTypeOptions<Types, {}>]>
|
|
243
|
+
// ) => InputObjectRef<Types, Record<string, unknown>>
|
|
244
|
+
// : '@pothos/plugin-add-graphql is required to use this method';
|
|
257
245
|
}
|
|
258
246
|
|
|
259
247
|
export interface PothosKindToGraphQLType {
|
|
@@ -288,8 +276,8 @@ declare global {
|
|
|
288
276
|
drizzleField: <
|
|
289
277
|
Args extends InputFieldMap,
|
|
290
278
|
Param extends
|
|
291
|
-
| keyof Types['
|
|
292
|
-
| [keyof Types['
|
|
279
|
+
| keyof Types['DrizzleRelationsConfig']
|
|
280
|
+
| [keyof Types['DrizzleRelationsConfig']]
|
|
293
281
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
294
282
|
| DrizzleRef<any>
|
|
295
283
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
@@ -298,36 +286,39 @@ declare global {
|
|
|
298
286
|
ResolveShape,
|
|
299
287
|
ResolveReturnShape,
|
|
300
288
|
Table extends
|
|
301
|
-
keyof Types['
|
|
289
|
+
keyof Types['DrizzleRelationsConfig'] = Param extends keyof Types['DrizzleRelationsConfig']
|
|
302
290
|
? Param
|
|
303
|
-
: Param extends [keyof Types['
|
|
291
|
+
: Param extends [keyof Types['DrizzleRelationsConfig']]
|
|
304
292
|
? Param[0]
|
|
305
293
|
: // biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
306
294
|
Param extends DrizzleRef<any, infer T>
|
|
307
|
-
? T & keyof Types['
|
|
295
|
+
? T & keyof Types['DrizzleRelationsConfig']
|
|
308
296
|
: // biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
309
297
|
Param extends [DrizzleRef<any, infer T>]
|
|
310
|
-
? T & keyof Types['
|
|
298
|
+
? T & keyof Types['DrizzleRelationsConfig']
|
|
311
299
|
: never,
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
300
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
301
|
+
Type extends TypeParam<Types> = Param extends DrizzleRef<any> | [DrizzleRef<any>]
|
|
302
|
+
? Param
|
|
303
|
+
: Param extends [unknown]
|
|
304
|
+
? [
|
|
305
|
+
ObjectRef<
|
|
306
|
+
Types,
|
|
307
|
+
BuildQueryResult<
|
|
308
|
+
Types['DrizzleRelationsConfig'],
|
|
309
|
+
Types['DrizzleRelationsConfig'][Table],
|
|
310
|
+
true
|
|
311
|
+
>
|
|
312
|
+
>,
|
|
313
|
+
]
|
|
314
|
+
: ObjectRef<
|
|
315
315
|
Types,
|
|
316
316
|
BuildQueryResult<
|
|
317
|
-
Types['
|
|
318
|
-
Types['
|
|
317
|
+
Types['DrizzleRelationsConfig'],
|
|
318
|
+
Types['DrizzleRelationsConfig'][Table],
|
|
319
319
|
true
|
|
320
320
|
>
|
|
321
321
|
>,
|
|
322
|
-
]
|
|
323
|
-
: ObjectRef<
|
|
324
|
-
Types,
|
|
325
|
-
BuildQueryResult<
|
|
326
|
-
Types['DrizzleRelationSchema'],
|
|
327
|
-
Types['DrizzleRelationSchema'][Table],
|
|
328
|
-
true
|
|
329
|
-
>
|
|
330
|
-
>,
|
|
331
322
|
>(
|
|
332
323
|
options: DrizzleFieldOptions<
|
|
333
324
|
Types,
|
|
@@ -342,21 +333,24 @@ declare global {
|
|
|
342
333
|
Param
|
|
343
334
|
>,
|
|
344
335
|
) => FieldRef<Types, ShapeFromTypeParam<Types, Type, Nullable>>;
|
|
345
|
-
|
|
346
336
|
drizzleConnection: 'relay' extends PluginName
|
|
347
337
|
? <
|
|
348
338
|
Type extends // biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
349
|
-
| DrizzleRef<any, keyof Types['
|
|
350
|
-
| keyof Types['
|
|
339
|
+
| DrizzleRef<any, keyof Types['DrizzleRelationsConfig']>
|
|
340
|
+
| keyof Types['DrizzleRelationsConfig'],
|
|
351
341
|
Nullable extends boolean,
|
|
352
342
|
ResolveReturnShape,
|
|
353
343
|
Args extends InputFieldMap = {},
|
|
354
|
-
|
|
355
|
-
|
|
344
|
+
Shape = Type extends DrizzleRef<
|
|
345
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
346
|
+
any,
|
|
347
|
+
keyof Types['DrizzleRelationsConfig'],
|
|
348
|
+
infer S
|
|
349
|
+
>
|
|
356
350
|
? S
|
|
357
351
|
: BuildQueryResult<
|
|
358
|
-
Types['
|
|
359
|
-
Types['
|
|
352
|
+
Types['DrizzleRelationsConfig'],
|
|
353
|
+
Types['DrizzleRelationsConfig'][Type & keyof Types['DrizzleRelationsConfig']],
|
|
360
354
|
true
|
|
361
355
|
>,
|
|
362
356
|
const ConnectionInterfaces extends InterfaceParam<Types>[] = [],
|
|
@@ -367,9 +361,9 @@ declare global {
|
|
|
367
361
|
ParentShape,
|
|
368
362
|
Type,
|
|
369
363
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
370
|
-
Types['
|
|
364
|
+
Types['DrizzleRelationsConfig'][Type extends DrizzleRef<any, infer K>
|
|
371
365
|
? K
|
|
372
|
-
: Type & keyof Types['
|
|
366
|
+
: Type & keyof Types['DrizzleRelationsConfig']],
|
|
373
367
|
ObjectRef<Types, Shape>,
|
|
374
368
|
Nullable,
|
|
375
369
|
Args,
|
|
@@ -411,12 +405,11 @@ declare global {
|
|
|
411
405
|
>
|
|
412
406
|
) => FieldRef<Types, ShapeFromConnection<ConnectionShapeHelper<Types, Shape, Nullable>>>
|
|
413
407
|
: '@pothos/plugin-relay is required to use this method';
|
|
414
|
-
|
|
415
408
|
drizzleFieldWithInput: 'withInput' extends PluginName
|
|
416
409
|
? <
|
|
417
410
|
Param extends
|
|
418
|
-
| keyof Types['
|
|
419
|
-
| [keyof Types['
|
|
411
|
+
| keyof Types['DrizzleRelationsConfig']
|
|
412
|
+
| [keyof Types['DrizzleRelationsConfig']]
|
|
420
413
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
421
414
|
| DrizzleRef<any>
|
|
422
415
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
@@ -429,22 +422,22 @@ declare global {
|
|
|
429
422
|
Args extends InputFieldMap = {},
|
|
430
423
|
InputName extends string = 'input',
|
|
431
424
|
Table extends
|
|
432
|
-
keyof Types['
|
|
425
|
+
keyof Types['DrizzleRelationsConfig'] = Param extends keyof Types['DrizzleRelationsConfig']
|
|
433
426
|
? Param
|
|
434
|
-
: Param extends [keyof Types['
|
|
427
|
+
: Param extends [keyof Types['DrizzleRelationsConfig']]
|
|
435
428
|
? Param[0]
|
|
436
429
|
: // biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
437
430
|
Param extends DrizzleRef<any, infer T>
|
|
438
|
-
? T & keyof Types['
|
|
431
|
+
? T & keyof Types['DrizzleRelationsConfig']
|
|
439
432
|
: // biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
440
433
|
Param extends [DrizzleRef<any, infer T>]
|
|
441
|
-
? T & keyof Types['
|
|
434
|
+
? T & keyof Types['DrizzleRelationsConfig']
|
|
442
435
|
: never,
|
|
443
436
|
Type extends TypeParam<Types> = ObjectRef<
|
|
444
437
|
Types,
|
|
445
438
|
BuildQueryResult<
|
|
446
|
-
Types['
|
|
447
|
-
Types['
|
|
439
|
+
Types['DrizzleRelationsConfig'],
|
|
440
|
+
Types['DrizzleRelationsConfig'][Table],
|
|
448
441
|
true
|
|
449
442
|
>
|
|
450
443
|
>,
|
package/src/index.ts
CHANGED
|
@@ -3,85 +3,118 @@ import './field-builder';
|
|
|
3
3
|
import './schema-builder';
|
|
4
4
|
import SchemaBuilder, {
|
|
5
5
|
BasePlugin,
|
|
6
|
-
createInputValueMapper,
|
|
7
6
|
type InputTypeFieldsMapping,
|
|
8
|
-
mapInputFields,
|
|
9
7
|
type PothosOutputFieldConfig,
|
|
8
|
+
PothosSchemaError,
|
|
9
|
+
type PothosTypeConfig,
|
|
10
10
|
type SchemaTypes,
|
|
11
11
|
} from '@pothos/core';
|
|
12
12
|
import type { GraphQLFieldResolver } from 'graphql';
|
|
13
13
|
import type { ModelLoader } from './model-loader';
|
|
14
14
|
import type { DrizzleGraphQLInputExtensions } from './types';
|
|
15
|
-
import {
|
|
16
|
-
extractFilters,
|
|
17
|
-
extractOrderBy,
|
|
18
|
-
remapFromGraphQLSingleInput,
|
|
19
|
-
} from './utils/drizzle-graphql';
|
|
20
15
|
import { getLoaderMapping, setLoaderMappings } from './utils/loader-map';
|
|
21
16
|
export { drizzleClientCache } from './utils/config';
|
|
17
|
+
export { drizzleConnectionHelpers } from './connection-helpers';
|
|
22
18
|
|
|
23
19
|
export * from './types';
|
|
24
20
|
|
|
21
|
+
export { drizzleTableName } from './types';
|
|
22
|
+
|
|
25
23
|
const pluginName = 'drizzle';
|
|
26
24
|
|
|
27
25
|
export default pluginName;
|
|
28
26
|
|
|
29
27
|
export class PothosDrizzlePlugin<Types extends SchemaTypes> extends BasePlugin<Types> {
|
|
30
|
-
private mappingCache = new Map<
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
>();
|
|
34
|
-
override
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
fieldConfig.args,
|
|
39
|
-
this.buildCache,
|
|
40
|
-
(inputField) => {
|
|
41
|
-
if (inputField.type.kind === 'InputObject') {
|
|
42
|
-
const config = this.buildCache.getTypeConfig(inputField.type.ref);
|
|
43
|
-
|
|
44
|
-
return (config.extensions?.drizzleGraphQL as DrizzleGraphQLInputExtensions) ?? null;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return null;
|
|
48
|
-
},
|
|
49
|
-
this.mappingCache,
|
|
50
|
-
);
|
|
28
|
+
// private mappingCache = new Map<
|
|
29
|
+
// string,
|
|
30
|
+
// InputTypeFieldsMapping<Types, DrizzleGraphQLInputExtensions>
|
|
31
|
+
// >();
|
|
32
|
+
override onTypeConfig(typeConfig: PothosTypeConfig): PothosTypeConfig {
|
|
33
|
+
if (typeConfig.kind !== 'Object' && typeConfig.kind !== 'Interface') {
|
|
34
|
+
return typeConfig;
|
|
35
|
+
}
|
|
51
36
|
|
|
52
|
-
|
|
53
|
-
? createInputValueMapper(argMappings, (input, mappings) => {
|
|
54
|
-
if (!mappings.value) {
|
|
55
|
-
return input;
|
|
56
|
-
}
|
|
37
|
+
let model = typeConfig.extensions?.pothosDrizzleModel as string | undefined;
|
|
57
38
|
|
|
58
|
-
|
|
39
|
+
for (const iface of typeConfig.interfaces) {
|
|
40
|
+
const interfaceModel = this.buildCache.getTypeConfig(iface, 'Interface').extensions
|
|
41
|
+
?.pothosDrizzleModel as string | undefined;
|
|
59
42
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return remapFromGraphQLSingleInput(input as never, tableConfig);
|
|
67
|
-
case 'update':
|
|
68
|
-
return remapFromGraphQLSingleInput(input as never, tableConfig);
|
|
43
|
+
if (interfaceModel) {
|
|
44
|
+
if (model && model !== interfaceModel) {
|
|
45
|
+
throw new PothosSchemaError(
|
|
46
|
+
`DrizzleObjects must be based on the same prisma model as any DrizzleInterfaces they extend. ${typeConfig.name} uses ${model} and ${iface.name} uses ${interfaceModel}`,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
69
49
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
})
|
|
74
|
-
: null;
|
|
50
|
+
model = interfaceModel;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
75
53
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
:
|
|
54
|
+
return {
|
|
55
|
+
...typeConfig,
|
|
56
|
+
extensions: {
|
|
57
|
+
...typeConfig.extensions,
|
|
58
|
+
pothosDrizzleModel: model,
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
79
62
|
|
|
80
|
-
|
|
63
|
+
override onOutputFieldConfig(
|
|
64
|
+
fieldConfig: PothosOutputFieldConfig<Types>,
|
|
65
|
+
): PothosOutputFieldConfig<Types> | null {
|
|
66
|
+
// const argMappings = mapInputFields<Types, DrizzleGraphQLInputExtensions>(
|
|
67
|
+
// fieldConfig.args,
|
|
68
|
+
// this.buildCache,
|
|
69
|
+
// (inputField) => {
|
|
70
|
+
// if (inputField.type.kind === 'InputObject') {
|
|
71
|
+
// const config = this.buildCache.getTypeConfig(inputField.type.ref);
|
|
72
|
+
|
|
73
|
+
// return (config.extensions?.drizzleGraphQL as DrizzleGraphQLInputExtensions) ?? null;
|
|
74
|
+
// }
|
|
75
|
+
|
|
76
|
+
// return null;
|
|
77
|
+
// },
|
|
78
|
+
// this.mappingCache,
|
|
79
|
+
// );
|
|
80
|
+
|
|
81
|
+
// const argMapper = argMappings
|
|
82
|
+
// ? createInputValueMapper(argMappings, (input, mappings) => {
|
|
83
|
+
// if (!mappings.value) {
|
|
84
|
+
// return input;
|
|
85
|
+
// }
|
|
86
|
+
|
|
87
|
+
// const { table, tableConfig, inputType } = mappings.value;
|
|
88
|
+
|
|
89
|
+
// switch (inputType) {
|
|
90
|
+
// case 'orderBy':
|
|
91
|
+
// return extractOrderBy(tableConfig, input as never);
|
|
92
|
+
// case 'filters':
|
|
93
|
+
// return extractFilters(tableConfig, table, input as never);
|
|
94
|
+
// case 'insert':
|
|
95
|
+
// return remapFromGraphQLSingleInput(input as never, tableConfig);
|
|
96
|
+
// case 'update':
|
|
97
|
+
// return remapFromGraphQLSingleInput(input as never, tableConfig);
|
|
98
|
+
|
|
99
|
+
// default:
|
|
100
|
+
// throw new Error(`Unknown drizzle input type: ${inputType}`);
|
|
101
|
+
// }
|
|
102
|
+
// })
|
|
103
|
+
// : null;
|
|
104
|
+
|
|
105
|
+
// const argMappers: typeof fieldConfig.argMappers = argMapper
|
|
106
|
+
// ? [...(fieldConfig.argMappers ?? []), (args) => argMapper(args, undefined)]
|
|
107
|
+
// : fieldConfig.argMappers;
|
|
108
|
+
|
|
109
|
+
if (
|
|
110
|
+
fieldConfig.kind === 'DrizzleObject' &&
|
|
111
|
+
fieldConfig.pothosOptions.select &&
|
|
112
|
+
!fieldConfig.extensions?.pothosDrizzleSelect
|
|
113
|
+
) {
|
|
81
114
|
const { select } = fieldConfig.pothosOptions;
|
|
82
115
|
return {
|
|
83
116
|
...fieldConfig,
|
|
84
|
-
argMappers,
|
|
117
|
+
// argMappers,
|
|
85
118
|
extensions: {
|
|
86
119
|
...fieldConfig.extensions,
|
|
87
120
|
pothosDrizzleSelect:
|
|
@@ -90,13 +123,12 @@ export class PothosDrizzlePlugin<Types extends SchemaTypes> extends BasePlugin<T
|
|
|
90
123
|
args: {},
|
|
91
124
|
ctx: Types['Context'],
|
|
92
125
|
nestedQuery: (query: unknown, path?: string[]) => never,
|
|
93
|
-
) =>
|
|
94
|
-
|
|
126
|
+
) =>
|
|
127
|
+
(select as (args: unknown, ctx: unknown, nestedQuery: unknown) => {})(
|
|
95
128
|
args,
|
|
96
129
|
ctx,
|
|
97
130
|
nestedQuery,
|
|
98
|
-
)
|
|
99
|
-
})
|
|
131
|
+
)
|
|
100
132
|
: select,
|
|
101
133
|
},
|
|
102
134
|
};
|
|
@@ -104,7 +136,7 @@ export class PothosDrizzlePlugin<Types extends SchemaTypes> extends BasePlugin<T
|
|
|
104
136
|
|
|
105
137
|
return {
|
|
106
138
|
...fieldConfig,
|
|
107
|
-
argMappers,
|
|
139
|
+
// argMappers,
|
|
108
140
|
};
|
|
109
141
|
}
|
|
110
142
|
|
|
@@ -155,16 +187,6 @@ export class PothosDrizzlePlugin<Types extends SchemaTypes> extends BasePlugin<T
|
|
|
155
187
|
return resolver(parent, args, context, info);
|
|
156
188
|
}
|
|
157
189
|
|
|
158
|
-
const primaryKeys = (
|
|
159
|
-
parentConfig.extensions!.pothosDrizzleTable as { primaryKey?: { name: string }[] }
|
|
160
|
-
).primaryKey;
|
|
161
|
-
|
|
162
|
-
if (!primaryKeys || primaryKeys.length === 0) {
|
|
163
|
-
throw new Error(
|
|
164
|
-
`Field ${fieldConfig.name} not resolved in initial query and no primary key found for type ${parentConfig.name}`,
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
190
|
return modelLoader(context)
|
|
169
191
|
.loadSelection(info, parent as object)
|
|
170
192
|
.then((result) => resolver(result, args, context, info));
|