@pothos/plugin-drizzle 0.8.1 → 0.10.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.
Files changed (122) hide show
  1. package/CHANGELOG.md +102 -0
  2. package/TODO.md +25 -4
  3. package/dts/connection-helpers.d.ts +34 -0
  4. package/dts/connection-helpers.d.ts.map +1 -0
  5. package/dts/drizzle-field-builder.d.ts +18 -53
  6. package/dts/drizzle-field-builder.d.ts.map +1 -1
  7. package/dts/global-types.d.ts +22 -41
  8. package/dts/global-types.d.ts.map +1 -1
  9. package/dts/index.d.ts +5 -2
  10. package/dts/index.d.ts.map +1 -1
  11. package/dts/interface-ref.d.ts +3 -2
  12. package/dts/interface-ref.d.ts.map +1 -1
  13. package/dts/model-loader.d.ts +3 -2
  14. package/dts/model-loader.d.ts.map +1 -1
  15. package/dts/node-ref.d.ts +1 -1
  16. package/dts/node-ref.d.ts.map +1 -1
  17. package/dts/object-ref.d.ts +2 -2
  18. package/dts/object-ref.d.ts.map +1 -1
  19. package/dts/types.d.ts +61 -41
  20. package/dts/types.d.ts.map +1 -1
  21. package/dts/utils/config.d.ts +4 -3
  22. package/dts/utils/config.d.ts.map +1 -1
  23. package/dts/utils/cursors.d.ts +13 -7
  24. package/dts/utils/cursors.d.ts.map +1 -1
  25. package/dts/utils/drizzle-graphql.d.ts +0 -17
  26. package/dts/utils/drizzle-graphql.d.ts.map +1 -1
  27. package/dts/utils/map-query.d.ts.map +1 -1
  28. package/dts/utils/selections.d.ts +5 -5
  29. package/dts/utils/selections.d.ts.map +1 -1
  30. package/esm/connection-helpers.d.ts +36 -0
  31. package/esm/connection-helpers.d.ts.map +1 -0
  32. package/esm/connection-helpers.js +82 -0
  33. package/esm/connection-helpers.js.map +1 -0
  34. package/esm/drizzle-field-builder.d.ts +18 -73
  35. package/esm/drizzle-field-builder.d.ts.map +1 -1
  36. package/esm/drizzle-field-builder.js +25 -14
  37. package/esm/drizzle-field-builder.js.map +1 -1
  38. package/esm/field-builder.js +2 -3
  39. package/esm/field-builder.js.map +1 -1
  40. package/esm/global-types.d.ts +35 -60
  41. package/esm/global-types.d.ts.map +1 -1
  42. package/esm/global-types.js.map +1 -1
  43. package/esm/index.d.ts +5 -2
  44. package/esm/index.d.ts.map +1 -1
  45. package/esm/index.js +71 -61
  46. package/esm/index.js.map +1 -1
  47. package/esm/interface-ref.d.ts +3 -2
  48. package/esm/interface-ref.d.ts.map +1 -1
  49. package/esm/interface-ref.js.map +1 -1
  50. package/esm/model-loader.d.ts +3 -2
  51. package/esm/model-loader.d.ts.map +1 -1
  52. package/esm/model-loader.js +17 -10
  53. package/esm/model-loader.js.map +1 -1
  54. package/esm/node-ref.d.ts +1 -1
  55. package/esm/node-ref.d.ts.map +1 -1
  56. package/esm/object-ref.d.ts +2 -2
  57. package/esm/object-ref.d.ts.map +1 -1
  58. package/esm/schema-builder.js +113 -67
  59. package/esm/schema-builder.js.map +1 -1
  60. package/esm/types.d.ts +61 -41
  61. package/esm/types.d.ts.map +1 -1
  62. package/esm/types.js.map +1 -1
  63. package/esm/utils/config.d.ts +4 -3
  64. package/esm/utils/config.d.ts.map +1 -1
  65. package/esm/utils/config.js +32 -15
  66. package/esm/utils/config.js.map +1 -1
  67. package/esm/utils/cursors.d.ts +13 -7
  68. package/esm/utils/cursors.d.ts.map +1 -1
  69. package/esm/utils/cursors.js +137 -63
  70. package/esm/utils/cursors.js.map +1 -1
  71. package/esm/utils/drizzle-graphql.d.ts +0 -17
  72. package/esm/utils/drizzle-graphql.d.ts.map +1 -1
  73. package/esm/utils/drizzle-graphql.js +230 -198
  74. package/esm/utils/drizzle-graphql.js.map +1 -1
  75. package/esm/utils/map-query.d.ts.map +1 -1
  76. package/esm/utils/map-query.js +10 -6
  77. package/esm/utils/map-query.js.map +1 -1
  78. package/esm/utils/selections.d.ts +5 -5
  79. package/esm/utils/selections.d.ts.map +1 -1
  80. package/esm/utils/selections.js +19 -18
  81. package/esm/utils/selections.js.map +1 -1
  82. package/lib/connection-helpers.js +93 -0
  83. package/lib/connection-helpers.js.map +1 -0
  84. package/lib/drizzle-field-builder.js +24 -13
  85. package/lib/drizzle-field-builder.js.map +1 -1
  86. package/lib/field-builder.js +2 -3
  87. package/lib/field-builder.js.map +1 -1
  88. package/lib/index.js +79 -60
  89. package/lib/index.js.map +1 -1
  90. package/lib/interface-ref.js.map +1 -1
  91. package/lib/model-loader.js +17 -10
  92. package/lib/model-loader.js.map +1 -1
  93. package/lib/schema-builder.js +113 -67
  94. package/lib/schema-builder.js.map +1 -1
  95. package/lib/types.js.map +1 -1
  96. package/lib/utils/config.js +31 -14
  97. package/lib/utils/config.js.map +1 -1
  98. package/lib/utils/cursors.js +135 -63
  99. package/lib/utils/cursors.js.map +1 -1
  100. package/lib/utils/drizzle-graphql.js +230 -221
  101. package/lib/utils/drizzle-graphql.js.map +1 -1
  102. package/lib/utils/map-query.js +10 -6
  103. package/lib/utils/map-query.js.map +1 -1
  104. package/lib/utils/selections.js +18 -17
  105. package/lib/utils/selections.js.map +1 -1
  106. package/package.json +14 -14
  107. package/src/connection-helpers.ts +206 -0
  108. package/src/drizzle-field-builder.ts +30 -26
  109. package/src/field-builder.ts +4 -7
  110. package/src/global-types.ts +112 -119
  111. package/src/index.ts +91 -70
  112. package/src/interface-ref.ts +7 -3
  113. package/src/model-loader.ts +32 -17
  114. package/src/node-ref.ts +1 -1
  115. package/src/object-ref.ts +2 -2
  116. package/src/schema-builder.ts +116 -113
  117. package/src/types.ts +95 -62
  118. package/src/utils/config.ts +39 -30
  119. package/src/utils/cursors.ts +134 -101
  120. package/src/utils/drizzle-graphql.ts +273 -274
  121. package/src/utils/map-query.ts +20 -8
  122. package/src/utils/selections.ts +34 -28
@@ -13,13 +13,14 @@ import type {
13
13
  TypeParam,
14
14
  } from '@pothos/core';
15
15
  import type {
16
- AnyTable,
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
- DrizzleSchema: Record<string, unknown>;
62
- DrizzleRelationSchema: Record<string, TableRelationalConfig>;
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
- DrizzleSchema: PartialTypes['DrizzleSchema'] & {};
68
- DrizzleRelationSchema: ExtractTablesWithRelations<PartialTypes['DrizzleSchema'] & {}>;
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['DrizzleRelationSchema'],
75
+ Table extends keyof Types['DrizzleRelations']['tables'],
78
76
  Selection extends
79
77
  | DBQueryConfig<
80
78
  'one',
81
- false,
82
- Types['DrizzleRelationSchema'],
83
- Types['DrizzleRelationSchema'][Table]
79
+ Types['DrizzleRelationsConfig'],
80
+ Types['DrizzleRelationsConfig'][Table]
84
81
  >
85
82
  | true,
86
83
  Shape = BuildQueryResult<
87
- Types['DrizzleRelationSchema'],
88
- Types['DrizzleRelationSchema'][Table],
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['DrizzleRelationSchema'],
95
+ Table extends keyof Types['DrizzleRelationsConfig'],
99
96
  Selection extends
100
97
  | DBQueryConfig<
101
98
  'one',
102
- false,
103
- Types['DrizzleRelationSchema'],
104
- Types['DrizzleRelationSchema'][Table]
99
+ Types['DrizzleRelationsConfig'],
100
+ Types['DrizzleRelationsConfig'][Table]
105
101
  >
106
102
  | true,
107
103
  Shape = BuildQueryResult<
108
- Types['DrizzleRelationSchema'],
109
- Types['DrizzleRelationSchema'][Table],
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['DrizzleRelationSchema'],
116
+ Table extends keyof Types['DrizzleRelationsConfig'],
121
117
  Selection extends
122
118
  | DBQueryConfig<
123
119
  'one',
124
- false,
125
- Types['DrizzleRelationSchema'],
126
- Types['DrizzleRelationSchema'][Table]
120
+ Types['DrizzleRelationsConfig'],
121
+ Types['DrizzleRelationsConfig'][Table]
127
122
  >
128
123
  | true,
129
- IDColumn extends Column,
124
+ IDColumns,
130
125
  Shape = BuildQueryResult<
131
- Types['DrizzleRelationSchema'],
132
- Types['DrizzleRelationSchema'][Table],
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, IDColumn>,
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['DrizzleRelationSchema'],
137
+ Type extends DrizzleObjectRef<Types> | keyof Types['DrizzleRelationsConfig'],
150
138
  TableConfig extends TableRelationalConfig = Type extends DrizzleObjectRef<Types>
151
139
  ? Type[typeof drizzleTableKey]
152
- : Types['DrizzleRelationSchema'][Type & keyof Types['DrizzleRelationSchema']],
140
+ : Types['DrizzleRelationsConfig'][Type & keyof Types['DrizzleRelationsConfig']],
153
141
  Shape extends {} = Type extends DrizzleObjectRef<
154
142
  Types,
155
- keyof Types['DrizzleRelationSchema'],
143
+ keyof Types['DrizzleRelationsConfig'],
156
144
  infer S
157
145
  >
158
146
  ? S & { [drizzleTableName]?: TableConfig['tsName'] }
159
- : BuildQueryResult<Types['DrizzleRelationSchema'], TableConfig, true> & {
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['DrizzleRelationSchema'],
157
+ Type extends DrizzleInterfaceRef<Types> | keyof Types['DrizzleRelationsConfig'],
170
158
  TableConfig extends TableRelationalConfig = Type extends DrizzleObjectRef<Types>
171
159
  ? Type[typeof drizzleTableKey]
172
- : Types['DrizzleRelationSchema'][Type & keyof Types['DrizzleRelationSchema']],
160
+ : Types['DrizzleRelationsConfig'][Type & keyof Types['DrizzleRelationsConfig']],
173
161
  Shape extends {} = Type extends DrizzleInterfaceRef<
174
162
  Types,
175
- keyof Types['DrizzleRelationSchema'],
163
+ keyof Types['DrizzleRelationsConfig'],
176
164
  infer S
177
165
  >
178
166
  ? S & { [drizzleTableName]?: TableConfig['tsName'] }
179
- : BuildQueryResult<Types['DrizzleRelationSchema'], TableConfig, true> & {
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['DrizzleRelationSchema'],
177
+ Type extends DrizzleObjectRef<Types> | keyof Types['DrizzleRelationsConfig'],
190
178
  TableConfig extends TableRelationalConfig = Type extends DrizzleObjectRef<Types>
191
179
  ? Type[typeof drizzleTableKey]
192
- : Types['DrizzleRelationSchema'][Type & keyof Types['DrizzleRelationSchema']],
180
+ : Types['DrizzleRelationsConfig'][Type & keyof Types['DrizzleRelationsConfig']],
193
181
  Shape extends {} = Type extends DrizzleObjectRef<
194
182
  Types,
195
- keyof Types['DrizzleRelationSchema'],
183
+ keyof Types['DrizzleRelationsConfig'],
196
184
  infer S
197
185
  >
198
186
  ? S & { [drizzleTableName]?: TableConfig['tsName'] }
199
- : BuildQueryResult<Types['DrizzleRelationSchema'], TableConfig, true> & {
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['DrizzleRelationSchema'],
196
+ Type extends DrizzleInterfaceRef<Types> | keyof Types['DrizzleRelationsConfig'],
209
197
  TableConfig extends TableRelationalConfig = Type extends DrizzleObjectRef<Types>
210
198
  ? Type[typeof drizzleTableKey]
211
- : Types['DrizzleRelationSchema'][Type & keyof Types['DrizzleRelationSchema']],
199
+ : Types['DrizzleRelationsConfig'][Type & keyof Types['DrizzleRelationsConfig']],
212
200
  Shape extends {} = Type extends DrizzleInterfaceRef<
213
201
  Types,
214
- keyof Types['DrizzleRelationSchema'],
202
+ keyof Types['DrizzleRelationsConfig'],
215
203
  infer S
216
204
  >
217
205
  ? S & { [drizzleTableName]?: TableConfig['tsName'] }
218
- : BuildQueryResult<Types['DrizzleRelationSchema'], TableConfig, true> & {
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
- ? <Table extends keyof Types['DrizzleRelationSchema']>(
228
- table: Table,
229
- type: GraphQLInputObjectType,
230
- ...args: NormalizeArgs<[options: AddGraphQLInputTypeOptions<Types, {}>]>
231
- ) => InputObjectRef<Types, SQL | SQL[]>
232
- : '@pothos/plugin-add-graphql is required to use this method';
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
- ? <Table extends keyof Types['DrizzleRelationSchema']>(
236
- table: Table,
237
- type: GraphQLInputObjectType,
238
- ...args: NormalizeArgs<[options: AddGraphQLInputTypeOptions<Types, {}>]>
239
- ) => InputObjectRef<Types, SQL>
240
- : '@pothos/plugin-add-graphql is required to use this method';
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
- ? <Table extends keyof Types['DrizzleRelationSchema']>(
244
- table: Table,
245
- type: GraphQLInputObjectType,
246
- ...args: NormalizeArgs<[options: AddGraphQLInputTypeOptions<Types, {}>]>
247
- ) => InputObjectRef<Types, Record<string, unknown>>
248
- : '@pothos/plugin-add-graphql is required to use this method';
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
- ? <Table extends keyof Types['DrizzleRelationSchema']>(
252
- table: Table,
253
- type: GraphQLInputObjectType,
254
- ...args: NormalizeArgs<[options: AddGraphQLInputTypeOptions<Types, {}>]>
255
- ) => InputObjectRef<Types, Record<string, unknown>>
256
- : '@pothos/plugin-add-graphql is required to use this method';
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['DrizzleRelationSchema']
292
- | [keyof Types['DrizzleRelationSchema']]
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['DrizzleRelationSchema'] = Param extends keyof Types['DrizzleRelationSchema']
289
+ keyof Types['DrizzleRelationsConfig'] = Param extends keyof Types['DrizzleRelationsConfig']
302
290
  ? Param
303
- : Param extends [keyof Types['DrizzleRelationSchema']]
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['DrizzleRelationSchema']
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['DrizzleRelationSchema']
298
+ ? T & keyof Types['DrizzleRelationsConfig']
311
299
  : never,
312
- Type extends TypeParam<Types> = Param extends [unknown]
313
- ? [
314
- ObjectRef<
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['DrizzleRelationSchema'],
318
- Types['DrizzleRelationSchema'][Table],
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['DrizzleRelationSchema']>
350
- | keyof Types['DrizzleRelationSchema'],
339
+ | DrizzleRef<any, keyof Types['DrizzleRelationsConfig']>
340
+ | keyof Types['DrizzleRelationsConfig'],
351
341
  Nullable extends boolean,
352
342
  ResolveReturnShape,
353
343
  Args extends InputFieldMap = {},
354
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
355
- Shape = Type extends DrizzleRef<any, keyof Types['DrizzleRelationSchema'], infer S>
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['DrizzleRelationSchema'],
359
- Types['DrizzleRelationSchema'][Type & keyof Types['DrizzleRelationSchema']],
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['DrizzleRelationSchema'][Type extends DrizzleRef<any, infer K>
364
+ Types['DrizzleRelationsConfig'][Type extends DrizzleRef<any, infer K>
371
365
  ? K
372
- : Type & keyof Types['DrizzleRelationSchema']],
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['DrizzleRelationSchema']
419
- | [keyof Types['DrizzleRelationSchema']]
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['DrizzleRelationSchema'] = Param extends keyof Types['DrizzleRelationSchema']
425
+ keyof Types['DrizzleRelationsConfig'] = Param extends keyof Types['DrizzleRelationsConfig']
433
426
  ? Param
434
- : Param extends [keyof Types['DrizzleRelationSchema']]
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['DrizzleRelationSchema']
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['DrizzleRelationSchema']
434
+ ? T & keyof Types['DrizzleRelationsConfig']
442
435
  : never,
443
436
  Type extends TypeParam<Types> = ObjectRef<
444
437
  Types,
445
438
  BuildQueryResult<
446
- Types['DrizzleRelationSchema'],
447
- Types['DrizzleRelationSchema'][Table],
439
+ Types['DrizzleRelationsConfig'],
440
+ Types['DrizzleRelationsConfig'][Table],
448
441
  true
449
442
  >
450
443
  >,
package/src/index.ts CHANGED
@@ -3,85 +3,117 @@ import './field-builder';
3
3
  import './schema-builder';
4
4
  import SchemaBuilder, {
5
5
  BasePlugin,
6
- createInputValueMapper,
7
- type InputTypeFieldsMapping,
8
- mapInputFields,
9
6
  type PothosOutputFieldConfig,
7
+ PothosSchemaError,
8
+ type PothosTypeConfig,
10
9
  type SchemaTypes,
11
10
  } from '@pothos/core';
12
11
  import type { GraphQLFieldResolver } from 'graphql';
13
12
  import type { ModelLoader } from './model-loader';
14
- import type { DrizzleGraphQLInputExtensions } from './types';
15
- import {
16
- extractFilters,
17
- extractOrderBy,
18
- remapFromGraphQLSingleInput,
19
- } from './utils/drizzle-graphql';
20
13
  import { getLoaderMapping, setLoaderMappings } from './utils/loader-map';
14
+ export { DrizzleObjectFieldBuilder } from './drizzle-field-builder';
21
15
  export { drizzleClientCache } from './utils/config';
16
+ export { drizzleConnectionHelpers } from './connection-helpers';
22
17
 
23
18
  export * from './types';
24
19
 
20
+ export { drizzleTableName } from './types';
21
+
25
22
  const pluginName = 'drizzle';
26
23
 
27
24
  export default pluginName;
28
25
 
29
26
  export class PothosDrizzlePlugin<Types extends SchemaTypes> extends BasePlugin<Types> {
30
- private mappingCache = new Map<
31
- string,
32
- InputTypeFieldsMapping<Types, DrizzleGraphQLInputExtensions>
33
- >();
34
- override onOutputFieldConfig(
35
- fieldConfig: PothosOutputFieldConfig<Types>,
36
- ): PothosOutputFieldConfig<Types> | null {
37
- const argMappings = mapInputFields<Types, DrizzleGraphQLInputExtensions>(
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
- );
27
+ // private mappingCache = new Map<
28
+ // string,
29
+ // InputTypeFieldsMapping<Types, DrizzleGraphQLInputExtensions>
30
+ // >();
31
+ override onTypeConfig(typeConfig: PothosTypeConfig): PothosTypeConfig {
32
+ if (typeConfig.kind !== 'Object' && typeConfig.kind !== 'Interface') {
33
+ return typeConfig;
34
+ }
51
35
 
52
- const argMapper = argMappings
53
- ? createInputValueMapper(argMappings, (input, mappings) => {
54
- if (!mappings.value) {
55
- return input;
56
- }
36
+ let model = typeConfig.extensions?.pothosDrizzleModel as string | undefined;
57
37
 
58
- const { table, tableConfig, inputType } = mappings.value;
38
+ for (const iface of typeConfig.interfaces) {
39
+ const interfaceModel = this.buildCache.getTypeConfig(iface, 'Interface').extensions
40
+ ?.pothosDrizzleModel as string | undefined;
59
41
 
60
- switch (inputType) {
61
- case 'orderBy':
62
- return extractOrderBy(tableConfig, input as never);
63
- case 'filters':
64
- return extractFilters(tableConfig, table, input as never);
65
- case 'insert':
66
- return remapFromGraphQLSingleInput(input as never, tableConfig);
67
- case 'update':
68
- return remapFromGraphQLSingleInput(input as never, tableConfig);
42
+ if (interfaceModel) {
43
+ if (model && model !== interfaceModel) {
44
+ throw new PothosSchemaError(
45
+ `DrizzleObjects must be based on the same prisma model as any DrizzleInterfaces they extend. ${typeConfig.name} uses ${model} and ${iface.name} uses ${interfaceModel}`,
46
+ );
47
+ }
69
48
 
70
- default:
71
- throw new Error(`Unknown drizzle input type: ${inputType}`);
72
- }
73
- })
74
- : null;
49
+ model = interfaceModel;
50
+ }
51
+ }
75
52
 
76
- const argMappers: typeof fieldConfig.argMappers = argMapper
77
- ? [...(fieldConfig.argMappers ?? []), (args) => argMapper(args, undefined)]
78
- : fieldConfig.argMappers;
53
+ return {
54
+ ...typeConfig,
55
+ extensions: {
56
+ ...typeConfig.extensions,
57
+ pothosDrizzleModel: model,
58
+ },
59
+ };
60
+ }
79
61
 
80
- if (fieldConfig.kind === 'DrizzleObject' && fieldConfig.pothosOptions.select) {
62
+ override onOutputFieldConfig(
63
+ fieldConfig: PothosOutputFieldConfig<Types>,
64
+ ): PothosOutputFieldConfig<Types> | null {
65
+ // const argMappings = mapInputFields<Types, DrizzleGraphQLInputExtensions>(
66
+ // fieldConfig.args,
67
+ // this.buildCache,
68
+ // (inputField) => {
69
+ // if (inputField.type.kind === 'InputObject') {
70
+ // const config = this.buildCache.getTypeConfig(inputField.type.ref);
71
+
72
+ // return (config.extensions?.drizzleGraphQL as DrizzleGraphQLInputExtensions) ?? null;
73
+ // }
74
+
75
+ // return null;
76
+ // },
77
+ // this.mappingCache,
78
+ // );
79
+
80
+ // const argMapper = argMappings
81
+ // ? createInputValueMapper(argMappings, (input, mappings) => {
82
+ // if (!mappings.value) {
83
+ // return input;
84
+ // }
85
+
86
+ // const { table, tableConfig, inputType } = mappings.value;
87
+
88
+ // switch (inputType) {
89
+ // case 'orderBy':
90
+ // return extractOrderBy(tableConfig, input as never);
91
+ // case 'filters':
92
+ // return extractFilters(tableConfig, table, input as never);
93
+ // case 'insert':
94
+ // return remapFromGraphQLSingleInput(input as never, tableConfig);
95
+ // case 'update':
96
+ // return remapFromGraphQLSingleInput(input as never, tableConfig);
97
+
98
+ // default:
99
+ // throw new Error(`Unknown drizzle input type: ${inputType}`);
100
+ // }
101
+ // })
102
+ // : null;
103
+
104
+ // const argMappers: typeof fieldConfig.argMappers = argMapper
105
+ // ? [...(fieldConfig.argMappers ?? []), (args) => argMapper(args, undefined)]
106
+ // : fieldConfig.argMappers;
107
+
108
+ if (
109
+ fieldConfig.kind === 'DrizzleObject' &&
110
+ fieldConfig.pothosOptions.select &&
111
+ !fieldConfig.extensions?.pothosDrizzleSelect
112
+ ) {
81
113
  const { select } = fieldConfig.pothosOptions;
82
114
  return {
83
115
  ...fieldConfig,
84
- argMappers,
116
+ // argMappers,
85
117
  extensions: {
86
118
  ...fieldConfig.extensions,
87
119
  pothosDrizzleSelect:
@@ -90,13 +122,12 @@ export class PothosDrizzlePlugin<Types extends SchemaTypes> extends BasePlugin<T
90
122
  args: {},
91
123
  ctx: Types['Context'],
92
124
  nestedQuery: (query: unknown, path?: string[]) => never,
93
- ) => ({
94
- select: (select as (args: unknown, ctx: unknown, nestedQuery: unknown) => {})(
125
+ ) =>
126
+ (select as (args: unknown, ctx: unknown, nestedQuery: unknown) => {})(
95
127
  args,
96
128
  ctx,
97
129
  nestedQuery,
98
- ),
99
- })
130
+ )
100
131
  : select,
101
132
  },
102
133
  };
@@ -104,7 +135,7 @@ export class PothosDrizzlePlugin<Types extends SchemaTypes> extends BasePlugin<T
104
135
 
105
136
  return {
106
137
  ...fieldConfig,
107
- argMappers,
138
+ // argMappers,
108
139
  };
109
140
  }
110
141
 
@@ -155,16 +186,6 @@ export class PothosDrizzlePlugin<Types extends SchemaTypes> extends BasePlugin<T
155
186
  return resolver(parent, args, context, info);
156
187
  }
157
188
 
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
189
  return modelLoader(context)
169
190
  .loadSelection(info, parent as object)
170
191
  .then((result) => resolver(result, args, context, info));