@pothos/plugin-drizzle 0.0.1
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 +7 -0
- package/LICENSE +6 -0
- package/README.md +437 -0
- package/TODO.md +21 -0
- package/drizzle/meta/_journal.json +1 -0
- package/drizzle.config.ts +10 -0
- package/dts/drizzle-field-builder.d.ts +124 -0
- package/dts/drizzle-field-builder.d.ts.map +1 -0
- package/dts/field-builder.d.ts +2 -0
- package/dts/field-builder.d.ts.map +1 -0
- package/dts/global-types.d.ts +92 -0
- package/dts/global-types.d.ts.map +1 -0
- package/dts/index.d.ts +13 -0
- package/dts/index.d.ts.map +1 -0
- package/dts/interface-ref.d.ts +9 -0
- package/dts/interface-ref.d.ts.map +1 -0
- package/dts/model-loader.d.ts +44 -0
- package/dts/model-loader.d.ts.map +1 -0
- package/dts/node-ref.d.ts +5 -0
- package/dts/node-ref.d.ts.map +1 -0
- package/dts/object-ref.d.ts +14 -0
- package/dts/object-ref.d.ts.map +1 -0
- package/dts/schema-builder.d.ts +2 -0
- package/dts/schema-builder.d.ts.map +1 -0
- package/dts/types.d.ts +147 -0
- package/dts/types.d.ts.map +1 -0
- package/dts/utils/config.d.ts +7 -0
- package/dts/utils/config.d.ts.map +1 -0
- package/dts/utils/cursors.d.ts +58 -0
- package/dts/utils/cursors.d.ts.map +1 -0
- package/dts/utils/deep-equal.d.ts +2 -0
- package/dts/utils/deep-equal.d.ts.map +1 -0
- package/dts/utils/drizzle-graphql.d.ts +18 -0
- package/dts/utils/drizzle-graphql.d.ts.map +1 -0
- package/dts/utils/loader-map.d.ts +11 -0
- package/dts/utils/loader-map.d.ts.map +1 -0
- package/dts/utils/map-query.d.ts +30 -0
- package/dts/utils/map-query.d.ts.map +1 -0
- package/dts/utils/refs.d.ts +5 -0
- package/dts/utils/refs.d.ts.map +1 -0
- package/dts/utils/selections.d.ts +22 -0
- package/dts/utils/selections.d.ts.map +1 -0
- package/dts/utils/usage.d.ts +5 -0
- package/dts/utils/usage.d.ts.map +1 -0
- package/esm/drizzle-field-builder.d.ts +216 -0
- package/esm/drizzle-field-builder.d.ts.map +1 -0
- package/esm/field-builder.d.ts +2 -0
- package/esm/field-builder.d.ts.map +1 -0
- package/esm/global-types.d.ts +124 -0
- package/esm/global-types.d.ts.map +1 -0
- package/esm/index.d.ts +13 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/interface-ref.d.ts +9 -0
- package/esm/interface-ref.d.ts.map +1 -0
- package/esm/model-loader.d.ts +45 -0
- package/esm/model-loader.d.ts.map +1 -0
- package/esm/node-ref.d.ts +5 -0
- package/esm/node-ref.d.ts.map +1 -0
- package/esm/object-ref.d.ts +14 -0
- package/esm/object-ref.d.ts.map +1 -0
- package/esm/package.json +3 -0
- package/esm/schema-builder.d.ts +2 -0
- package/esm/schema-builder.d.ts.map +1 -0
- package/esm/src/drizzle-field-builder.js +215 -0
- package/esm/src/drizzle-field-builder.js.map +1 -0
- package/esm/src/field-builder.js +77 -0
- package/esm/src/field-builder.js.map +1 -0
- package/esm/src/global-types.js +2 -0
- package/esm/src/global-types.js.map +1 -0
- package/esm/src/index.js +107 -0
- package/esm/src/index.js.map +1 -0
- package/esm/src/interface-ref.js +26 -0
- package/esm/src/interface-ref.js.map +1 -0
- package/esm/src/model-loader.js +168 -0
- package/esm/src/model-loader.js.map +1 -0
- package/esm/src/node-ref.js +4 -0
- package/esm/src/node-ref.js.map +1 -0
- package/esm/src/object-ref.js +38 -0
- package/esm/src/object-ref.js.map +1 -0
- package/esm/src/schema-builder.js +190 -0
- package/esm/src/schema-builder.js.map +1 -0
- package/esm/src/types.js +2 -0
- package/esm/src/types.js.map +1 -0
- package/esm/src/utils/config.js +15 -0
- package/esm/src/utils/config.js.map +1 -0
- package/esm/src/utils/cursors.js +316 -0
- package/esm/src/utils/cursors.js.map +1 -0
- package/esm/src/utils/deep-equal.js +44 -0
- package/esm/src/utils/deep-equal.js.map +1 -0
- package/esm/src/utils/drizzle-graphql.js +176 -0
- package/esm/src/utils/drizzle-graphql.js.map +1 -0
- package/esm/src/utils/loader-map.js +35 -0
- package/esm/src/utils/loader-map.js.map +1 -0
- package/esm/src/utils/map-query.js +284 -0
- package/esm/src/utils/map-query.js.map +1 -0
- package/esm/src/utils/refs.js +14 -0
- package/esm/src/utils/refs.js.map +1 -0
- package/esm/src/utils/selections.js +136 -0
- package/esm/src/utils/selections.js.map +1 -0
- package/esm/src/utils/usage.js +59 -0
- package/esm/src/utils/usage.js.map +1 -0
- package/esm/types.d.ts +161 -0
- package/esm/types.d.ts.map +1 -0
- package/esm/utils/config.d.ts +7 -0
- package/esm/utils/config.d.ts.map +1 -0
- package/esm/utils/cursors.d.ts +58 -0
- package/esm/utils/cursors.d.ts.map +1 -0
- package/esm/utils/deep-equal.d.ts +2 -0
- package/esm/utils/deep-equal.d.ts.map +1 -0
- package/esm/utils/drizzle-graphql.d.ts +18 -0
- package/esm/utils/drizzle-graphql.d.ts.map +1 -0
- package/esm/utils/loader-map.d.ts +11 -0
- package/esm/utils/loader-map.d.ts.map +1 -0
- package/esm/utils/map-query.d.ts +30 -0
- package/esm/utils/map-query.d.ts.map +1 -0
- package/esm/utils/refs.d.ts +5 -0
- package/esm/utils/refs.d.ts.map +1 -0
- package/esm/utils/selections.d.ts +22 -0
- package/esm/utils/selections.d.ts.map +1 -0
- package/esm/utils/usage.d.ts +5 -0
- package/esm/utils/usage.d.ts.map +1 -0
- package/lib/src/drizzle-field-builder.js +225 -0
- package/lib/src/drizzle-field-builder.js.map +1 -0
- package/lib/src/field-builder.js +82 -0
- package/lib/src/field-builder.js.map +1 -0
- package/lib/src/global-types.js +6 -0
- package/lib/src/global-types.js.map +1 -0
- package/lib/src/index.js +180 -0
- package/lib/src/index.js.map +1 -0
- package/lib/src/interface-ref.js +36 -0
- package/lib/src/interface-ref.js.map +1 -0
- package/lib/src/model-loader.js +176 -0
- package/lib/src/model-loader.js.map +1 -0
- package/lib/src/node-ref.js +15 -0
- package/lib/src/node-ref.js.map +1 -0
- package/lib/src/object-ref.js +56 -0
- package/lib/src/object-ref.js.map +1 -0
- package/lib/src/schema-builder.js +236 -0
- package/lib/src/schema-builder.js.map +1 -0
- package/lib/src/types.js +13 -0
- package/lib/src/types.js.map +1 -0
- package/lib/src/utils/config.js +26 -0
- package/lib/src/utils/config.js.map +1 -0
- package/lib/src/utils/cursors.js +362 -0
- package/lib/src/utils/cursors.js.map +1 -0
- package/lib/src/utils/deep-equal.js +55 -0
- package/lib/src/utils/deep-equal.js.map +1 -0
- package/lib/src/utils/drizzle-graphql.js +192 -0
- package/lib/src/utils/drizzle-graphql.js.map +1 -0
- package/lib/src/utils/loader-map.js +57 -0
- package/lib/src/utils/loader-map.js.map +1 -0
- package/lib/src/utils/map-query.js +308 -0
- package/lib/src/utils/map-query.js.map +1 -0
- package/lib/src/utils/refs.js +33 -0
- package/lib/src/utils/refs.js.map +1 -0
- package/lib/src/utils/selections.js +163 -0
- package/lib/src/utils/selections.js.map +1 -0
- package/lib/src/utils/usage.js +84 -0
- package/lib/src/utils/usage.js.map +1 -0
- package/package.json +66 -0
- package/src/drizzle-field-builder.ts +500 -0
- package/src/field-builder.ts +168 -0
- package/src/global-types.ts +481 -0
- package/src/index.ts +175 -0
- package/src/interface-ref.ts +24 -0
- package/src/model-loader.ts +235 -0
- package/src/node-ref.ts +8 -0
- package/src/object-ref.ts +51 -0
- package/src/schema-builder.ts +299 -0
- package/src/types.ts +640 -0
- package/src/utils/config.ts +28 -0
- package/src/utils/cursors.ts +446 -0
- package/src/utils/deep-equal.ts +58 -0
- package/src/utils/drizzle-graphql.ts +235 -0
- package/src/utils/loader-map.ts +51 -0
- package/src/utils/map-query.ts +582 -0
- package/src/utils/refs.ts +25 -0
- package/src/utils/selections.ts +209 -0
- package/src/utils/usage.ts +64 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,640 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BuildQueryResult,
|
|
3
|
+
Column,
|
|
4
|
+
DBQueryConfig,
|
|
5
|
+
Many,
|
|
6
|
+
Relation,
|
|
7
|
+
RelationalSchemaConfig,
|
|
8
|
+
SQL,
|
|
9
|
+
TableRelationalConfig,
|
|
10
|
+
TablesRelationalConfig,
|
|
11
|
+
} from 'drizzle-orm';
|
|
12
|
+
import { FieldNode, GraphQLResolveInfo } from 'graphql';
|
|
13
|
+
import {
|
|
14
|
+
ArgumentRef,
|
|
15
|
+
FieldKind,
|
|
16
|
+
FieldMap,
|
|
17
|
+
FieldNullability,
|
|
18
|
+
FieldOptionsFromKind,
|
|
19
|
+
InferredFieldOptionKeys,
|
|
20
|
+
InferredFieldOptionsByKind,
|
|
21
|
+
InputFieldMap,
|
|
22
|
+
InputFieldsFromShape,
|
|
23
|
+
InputShapeFromFields,
|
|
24
|
+
InterfaceParam,
|
|
25
|
+
InterfaceRef,
|
|
26
|
+
InterfaceTypeOptions,
|
|
27
|
+
ListResolveValue,
|
|
28
|
+
MaybePromise,
|
|
29
|
+
Normalize,
|
|
30
|
+
ObjectRef,
|
|
31
|
+
ObjectTypeOptions,
|
|
32
|
+
OutputShape,
|
|
33
|
+
OutputType,
|
|
34
|
+
SchemaTypes,
|
|
35
|
+
ShapeFromTypeParam,
|
|
36
|
+
typeBrandKey,
|
|
37
|
+
TypeParam,
|
|
38
|
+
} from '@pothos/core';
|
|
39
|
+
import type { DrizzleObjectFieldBuilder } from './drizzle-field-builder';
|
|
40
|
+
import { type DrizzleRef } from './interface-ref';
|
|
41
|
+
import { IndirectInclude } from './utils/map-query';
|
|
42
|
+
import { SelectionMap } from './utils/selections';
|
|
43
|
+
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
45
|
+
export interface DrizzlePluginOptions<Types extends SchemaTypes> {
|
|
46
|
+
client: { _: Partial<RelationalSchemaConfig<TablesRelationalConfig>>; query: {} };
|
|
47
|
+
maxConnectionSize?: number;
|
|
48
|
+
defaultConnectionSize?: number;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const drizzleTableName = Symbol.for('Pothos.drizzleTableName');
|
|
52
|
+
|
|
53
|
+
type NameOrVariant =
|
|
54
|
+
| {
|
|
55
|
+
name?: never;
|
|
56
|
+
variant?: string;
|
|
57
|
+
}
|
|
58
|
+
| {
|
|
59
|
+
name?: string;
|
|
60
|
+
variant?: never;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export type DrizzleObjectOptions<
|
|
64
|
+
Types extends SchemaTypes,
|
|
65
|
+
Table extends keyof Types['DrizzleRelationSchema'],
|
|
66
|
+
Shape,
|
|
67
|
+
Selection,
|
|
68
|
+
Interfaces extends InterfaceParam<Types>[],
|
|
69
|
+
> = Omit<ObjectTypeOptions<Types, ObjectRef<Types, Shape>, Shape, Interfaces>, 'fields'> &
|
|
70
|
+
NameOrVariant & {
|
|
71
|
+
select?: Selection;
|
|
72
|
+
fields?: (
|
|
73
|
+
t: DrizzleObjectFieldBuilder<
|
|
74
|
+
Types,
|
|
75
|
+
Types['DrizzleRelationSchema'][Table],
|
|
76
|
+
Shape & { [drizzleTableName]?: Table }
|
|
77
|
+
>,
|
|
78
|
+
) => FieldMap;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export type DrizzleInterfaceOptions<
|
|
82
|
+
Types extends SchemaTypes,
|
|
83
|
+
Table extends keyof Types['DrizzleRelationSchema'],
|
|
84
|
+
Shape,
|
|
85
|
+
Selection,
|
|
86
|
+
Interfaces extends InterfaceParam<Types>[],
|
|
87
|
+
> = Omit<
|
|
88
|
+
InterfaceTypeOptions<Types, InterfaceRef<Types, Shape>, Shape, Interfaces> & {
|
|
89
|
+
name: string;
|
|
90
|
+
select?: Selection;
|
|
91
|
+
},
|
|
92
|
+
'fields'
|
|
93
|
+
> &
|
|
94
|
+
NameOrVariant & {
|
|
95
|
+
fields?: (
|
|
96
|
+
t: DrizzleObjectFieldBuilder<
|
|
97
|
+
Types,
|
|
98
|
+
Types['DrizzleRelationSchema'][Table],
|
|
99
|
+
Shape & { [drizzleTableName]?: Table }
|
|
100
|
+
>,
|
|
101
|
+
) => FieldMap;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export type DrizzleNodeOptions<
|
|
105
|
+
Types extends SchemaTypes,
|
|
106
|
+
Table extends keyof Types['DrizzleRelationSchema'],
|
|
107
|
+
Shape,
|
|
108
|
+
Selection,
|
|
109
|
+
Interfaces extends InterfaceParam<Types>[],
|
|
110
|
+
> = NameOrVariant &
|
|
111
|
+
Omit<
|
|
112
|
+
| PothosSchemaTypes.ObjectTypeOptions<Types, Shape>
|
|
113
|
+
| PothosSchemaTypes.ObjectTypeWithInterfaceOptions<Types, Shape, Interfaces>,
|
|
114
|
+
'fields' | 'isTypeOf'
|
|
115
|
+
> & {
|
|
116
|
+
id: Omit<
|
|
117
|
+
FieldOptionsFromKind<
|
|
118
|
+
Types,
|
|
119
|
+
Shape,
|
|
120
|
+
'ID',
|
|
121
|
+
false,
|
|
122
|
+
{},
|
|
123
|
+
'Object',
|
|
124
|
+
OutputShape<Types, 'ID'>,
|
|
125
|
+
MaybePromise<OutputShape<Types, 'ID'>>
|
|
126
|
+
>,
|
|
127
|
+
'args' | 'nullable' | 'type' | InferredFieldOptionKeys
|
|
128
|
+
> & {
|
|
129
|
+
column:
|
|
130
|
+
| Column
|
|
131
|
+
| Column[]
|
|
132
|
+
| ((columns: Types['DrizzleRelationSchema'][Table]['columns']) => Column | Column[]);
|
|
133
|
+
};
|
|
134
|
+
name: string;
|
|
135
|
+
select?: Selection;
|
|
136
|
+
fields?: (
|
|
137
|
+
t: DrizzleObjectFieldBuilder<
|
|
138
|
+
Types,
|
|
139
|
+
Types['DrizzleRelationSchema'][Table],
|
|
140
|
+
Shape & { [drizzleTableName]?: Table }
|
|
141
|
+
>,
|
|
142
|
+
) => FieldMap;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
export type DrizzleFieldOptions<
|
|
146
|
+
Types extends SchemaTypes,
|
|
147
|
+
ParentShape,
|
|
148
|
+
Table extends keyof Types['DrizzleRelationSchema'],
|
|
149
|
+
Type extends TypeParam<Types>,
|
|
150
|
+
Nullable extends FieldNullability<Type>,
|
|
151
|
+
Args extends InputFieldMap,
|
|
152
|
+
Kind extends FieldKind,
|
|
153
|
+
ResolveShape,
|
|
154
|
+
ResolveReturnShape,
|
|
155
|
+
Param,
|
|
156
|
+
> = Omit<
|
|
157
|
+
FieldOptionsFromKind<
|
|
158
|
+
Types,
|
|
159
|
+
ParentShape,
|
|
160
|
+
Type,
|
|
161
|
+
Nullable,
|
|
162
|
+
Args,
|
|
163
|
+
Kind,
|
|
164
|
+
ResolveShape,
|
|
165
|
+
ResolveReturnShape
|
|
166
|
+
>,
|
|
167
|
+
'resolve' | 'type'
|
|
168
|
+
> & {
|
|
169
|
+
type: Param;
|
|
170
|
+
resolve: (
|
|
171
|
+
query: <T extends QueryForDrizzleField<Types, Param, Table>>(selection?: T) => T,
|
|
172
|
+
parent: ParentShape,
|
|
173
|
+
args: InputShapeFromFields<Args>,
|
|
174
|
+
ctx: Types['Context'],
|
|
175
|
+
info: GraphQLResolveInfo,
|
|
176
|
+
) => MaybePromise<ShapeFromTypeParam<Types, Type, Nullable>>;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
export type DrizzleFieldWithInputOptions<
|
|
180
|
+
Types extends SchemaTypes,
|
|
181
|
+
ParentShape,
|
|
182
|
+
Table extends keyof Types['DrizzleRelationSchema'],
|
|
183
|
+
Type extends TypeParam<Types>,
|
|
184
|
+
Nullable extends FieldNullability<Type>,
|
|
185
|
+
Args extends InputFieldMap,
|
|
186
|
+
Kind extends FieldKind,
|
|
187
|
+
ResolveShape,
|
|
188
|
+
ResolveReturnShape,
|
|
189
|
+
Param,
|
|
190
|
+
InputName extends string,
|
|
191
|
+
Fields extends InputFieldMap,
|
|
192
|
+
ArgRequired extends boolean,
|
|
193
|
+
> = Omit<
|
|
194
|
+
DrizzleFieldOptions<
|
|
195
|
+
Types,
|
|
196
|
+
ParentShape,
|
|
197
|
+
Table,
|
|
198
|
+
Type,
|
|
199
|
+
Nullable,
|
|
200
|
+
Args & {
|
|
201
|
+
[K in InputName]: ArgumentRef<
|
|
202
|
+
Types,
|
|
203
|
+
InputShapeFromFields<Fields> | (true extends ArgRequired ? never : null | undefined)
|
|
204
|
+
>;
|
|
205
|
+
},
|
|
206
|
+
Kind,
|
|
207
|
+
ResolveShape,
|
|
208
|
+
ResolveReturnShape,
|
|
209
|
+
Param
|
|
210
|
+
>,
|
|
211
|
+
'args'
|
|
212
|
+
> &
|
|
213
|
+
PothosSchemaTypes.FieldWithInputBaseOptions<
|
|
214
|
+
Types,
|
|
215
|
+
Args & {
|
|
216
|
+
[K in InputName]: ArgumentRef<
|
|
217
|
+
Types,
|
|
218
|
+
InputShapeFromFields<Fields> | (true extends ArgRequired ? never : null | undefined)
|
|
219
|
+
>;
|
|
220
|
+
},
|
|
221
|
+
Fields,
|
|
222
|
+
InputName,
|
|
223
|
+
ArgRequired
|
|
224
|
+
>;
|
|
225
|
+
|
|
226
|
+
export type DrizzleObjectFieldOptions<
|
|
227
|
+
Types extends SchemaTypes,
|
|
228
|
+
ParentShape,
|
|
229
|
+
Type extends TypeParam<Types>,
|
|
230
|
+
Nullable extends FieldNullability<Type>,
|
|
231
|
+
Args extends InputFieldMap,
|
|
232
|
+
Select,
|
|
233
|
+
ResolveReturnShape,
|
|
234
|
+
ShapeWithSelection = Normalize<
|
|
235
|
+
Omit<
|
|
236
|
+
unknown extends Select
|
|
237
|
+
? ParentShape
|
|
238
|
+
: BuildQueryResult<
|
|
239
|
+
Types['DrizzleRelationSchema'],
|
|
240
|
+
ExtractTable<Types, ParentShape>,
|
|
241
|
+
Record<string, unknown> & (Select extends (...args: any[]) => infer R ? R : Select)
|
|
242
|
+
> &
|
|
243
|
+
ParentShape,
|
|
244
|
+
typeof drizzleTableName
|
|
245
|
+
>
|
|
246
|
+
>,
|
|
247
|
+
> = PothosSchemaTypes.ObjectFieldOptions<
|
|
248
|
+
Types,
|
|
249
|
+
ShapeWithSelection,
|
|
250
|
+
Type,
|
|
251
|
+
Nullable,
|
|
252
|
+
Args,
|
|
253
|
+
ResolveReturnShape
|
|
254
|
+
> &
|
|
255
|
+
InferredFieldOptionsByKind<
|
|
256
|
+
Types,
|
|
257
|
+
Types['InferredFieldOptionsKind'],
|
|
258
|
+
ShapeWithSelection,
|
|
259
|
+
Type,
|
|
260
|
+
Nullable,
|
|
261
|
+
Args,
|
|
262
|
+
ResolveReturnShape
|
|
263
|
+
> & {
|
|
264
|
+
select?: Select &
|
|
265
|
+
(
|
|
266
|
+
| DBQueryConfig<
|
|
267
|
+
'one',
|
|
268
|
+
false,
|
|
269
|
+
Types['DrizzleRelationSchema'],
|
|
270
|
+
ExtractTable<Types, ParentShape>
|
|
271
|
+
>
|
|
272
|
+
| ((
|
|
273
|
+
args: InputShapeFromFields<Args>,
|
|
274
|
+
ctx: Types['Context'],
|
|
275
|
+
nestedSelection: <Selection extends boolean | {}>(
|
|
276
|
+
selection?: Selection,
|
|
277
|
+
path?: string[],
|
|
278
|
+
) => Selection,
|
|
279
|
+
) => DBQueryConfig<
|
|
280
|
+
'one',
|
|
281
|
+
false,
|
|
282
|
+
Types['DrizzleRelationSchema'],
|
|
283
|
+
ExtractTable<Types, ParentShape>
|
|
284
|
+
>)
|
|
285
|
+
);
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
export type DrizzleFieldSelection =
|
|
289
|
+
| DBQueryConfig<'one', false>
|
|
290
|
+
| ((
|
|
291
|
+
args: {},
|
|
292
|
+
ctx: object,
|
|
293
|
+
mergeNestedSelection: (
|
|
294
|
+
selection:
|
|
295
|
+
| SelectionMap
|
|
296
|
+
| boolean
|
|
297
|
+
| ((args: object, context: object) => DBQueryConfig<'one', false>),
|
|
298
|
+
path?: IndirectInclude | string[],
|
|
299
|
+
type?: string,
|
|
300
|
+
) => DBQueryConfig<'one', false> | boolean,
|
|
301
|
+
resolveSelection: (path: string[]) => FieldNode | null,
|
|
302
|
+
) => SelectionMap);
|
|
303
|
+
|
|
304
|
+
export type ExtractTable<Types extends SchemaTypes, Shape> = Shape extends {
|
|
305
|
+
[drizzleTableName]?: keyof Types['DrizzleRelationSchema'];
|
|
306
|
+
}
|
|
307
|
+
? Types['DrizzleRelationSchema'][NonNullable<Shape[typeof drizzleTableName]>]
|
|
308
|
+
: never;
|
|
309
|
+
|
|
310
|
+
export type RelatedFieldOptions<
|
|
311
|
+
Types extends SchemaTypes,
|
|
312
|
+
Table extends TableRelationalConfig,
|
|
313
|
+
Field extends keyof Table['relations'],
|
|
314
|
+
Nullable extends boolean,
|
|
315
|
+
Args extends InputFieldMap,
|
|
316
|
+
ResolveReturnShape,
|
|
317
|
+
Shape,
|
|
318
|
+
> = Omit<
|
|
319
|
+
DrizzleObjectFieldOptions<
|
|
320
|
+
Types,
|
|
321
|
+
Shape,
|
|
322
|
+
RefForRelation<Types, Table['relations'][Field]>,
|
|
323
|
+
Nullable,
|
|
324
|
+
Args,
|
|
325
|
+
{
|
|
326
|
+
columns: {};
|
|
327
|
+
with: { [K in Field]: true };
|
|
328
|
+
},
|
|
329
|
+
ResolveReturnShape
|
|
330
|
+
>,
|
|
331
|
+
'description' | 'resolve' | 'select' | 'type'
|
|
332
|
+
> & {
|
|
333
|
+
description?: string | false;
|
|
334
|
+
type?: ObjectRef<Types, TypesForRelation<Types, Table['relations'][Field]>>;
|
|
335
|
+
query?: QueryForField<Types, Args, Table['relations'][Field]>;
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
export type VariantFieldOptions<
|
|
339
|
+
Types extends SchemaTypes,
|
|
340
|
+
Table extends keyof Types['DrizzleRelationSchema'],
|
|
341
|
+
Variant extends DrizzleRef<any, Table> | Table,
|
|
342
|
+
Args extends InputFieldMap,
|
|
343
|
+
isNull,
|
|
344
|
+
Shape,
|
|
345
|
+
ResolveShape,
|
|
346
|
+
ResolveReturnShape,
|
|
347
|
+
> = Omit<
|
|
348
|
+
FieldOptionsFromKind<
|
|
349
|
+
Types,
|
|
350
|
+
Shape,
|
|
351
|
+
Variant extends DrizzleRef<any> ? Variant : DrizzleRef<any, Table>,
|
|
352
|
+
unknown extends isNull ? false : true,
|
|
353
|
+
Args,
|
|
354
|
+
'DrizzleObject',
|
|
355
|
+
ResolveShape,
|
|
356
|
+
ResolveReturnShape
|
|
357
|
+
>,
|
|
358
|
+
InferredFieldOptionKeys | 'type'
|
|
359
|
+
> & {
|
|
360
|
+
isNull?: isNull &
|
|
361
|
+
((
|
|
362
|
+
parent: Normalize<
|
|
363
|
+
Omit<
|
|
364
|
+
unknown extends ResolveShape
|
|
365
|
+
? Shape
|
|
366
|
+
: BuildQueryResult<
|
|
367
|
+
Types['DrizzleRelationSchema'],
|
|
368
|
+
ExtractTable<Types, Shape>,
|
|
369
|
+
Record<string, unknown> &
|
|
370
|
+
(ResolveShape extends (...args: any[]) => infer R ? R : ResolveShape)
|
|
371
|
+
> &
|
|
372
|
+
Shape,
|
|
373
|
+
typeof drizzleTableName
|
|
374
|
+
>
|
|
375
|
+
>,
|
|
376
|
+
args: InputShapeFromFields<Args>,
|
|
377
|
+
context: Types['Context'],
|
|
378
|
+
info: GraphQLResolveInfo,
|
|
379
|
+
) => MaybePromise<boolean>);
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
export type RefForRelation<Types extends SchemaTypes, Rel extends Relation> = Rel extends {
|
|
383
|
+
$relationBrand: 'One';
|
|
384
|
+
}
|
|
385
|
+
? ObjectRef<Types, TypesForRelation<Types, Rel>>
|
|
386
|
+
: [ObjectRef<Types, TypesForRelation<Types, Rel>>];
|
|
387
|
+
|
|
388
|
+
export type TypesForRelation<Types extends SchemaTypes, Rel extends Relation> = BuildQueryResult<
|
|
389
|
+
Types['DrizzleRelationSchema'],
|
|
390
|
+
Types['DrizzleRelationSchema'][Rel['referencedTable']['_']['name']],
|
|
391
|
+
true
|
|
392
|
+
>;
|
|
393
|
+
|
|
394
|
+
export type QueryForField<
|
|
395
|
+
Types extends SchemaTypes,
|
|
396
|
+
Args extends InputFieldMap,
|
|
397
|
+
Rel extends Relation,
|
|
398
|
+
> = (
|
|
399
|
+
Rel extends {
|
|
400
|
+
$relationBrand: 'One';
|
|
401
|
+
}
|
|
402
|
+
? Omit<
|
|
403
|
+
DBQueryConfig<
|
|
404
|
+
'one',
|
|
405
|
+
false,
|
|
406
|
+
Types['DrizzleRelationSchema'],
|
|
407
|
+
Types['DrizzleRelationSchema'][Rel['referencedTable']['_']['name']]
|
|
408
|
+
>,
|
|
409
|
+
'columns' | 'extra' | 'with'
|
|
410
|
+
>
|
|
411
|
+
: Omit<
|
|
412
|
+
DBQueryConfig<
|
|
413
|
+
'many',
|
|
414
|
+
false,
|
|
415
|
+
Types['DrizzleRelationSchema'],
|
|
416
|
+
Types['DrizzleRelationSchema'][Rel['referencedTable']['_']['name']]
|
|
417
|
+
>,
|
|
418
|
+
'columns' | 'extra' | 'with'
|
|
419
|
+
>
|
|
420
|
+
) extends infer QueryConfig
|
|
421
|
+
? QueryConfig | ((args: InputShapeFromFields<Args>, context: Types['Context']) => QueryConfig)
|
|
422
|
+
: never;
|
|
423
|
+
|
|
424
|
+
export type QueryForDrizzleField<
|
|
425
|
+
Types extends SchemaTypes,
|
|
426
|
+
Param,
|
|
427
|
+
Table extends keyof Types['DrizzleRelationSchema'],
|
|
428
|
+
> = Omit<
|
|
429
|
+
DBQueryConfig<
|
|
430
|
+
'many',
|
|
431
|
+
true,
|
|
432
|
+
Types['DrizzleRelationSchema'],
|
|
433
|
+
Types['DrizzleRelationSchema'][Table]
|
|
434
|
+
>,
|
|
435
|
+
Param extends [unknown] ? never : 'limit'
|
|
436
|
+
>;
|
|
437
|
+
|
|
438
|
+
export type QueryForRelatedConnection<
|
|
439
|
+
Types extends SchemaTypes,
|
|
440
|
+
Table extends TableRelationalConfig,
|
|
441
|
+
Args,
|
|
442
|
+
> = Omit<
|
|
443
|
+
DBQueryConfig<'many', false, Types['DrizzleRelationSchema'], Table>,
|
|
444
|
+
'orderBy' | 'limit' | 'offset' | 'columns' | 'extra' | 'with'
|
|
445
|
+
> & {
|
|
446
|
+
orderBy?: ConnectionOrderBy | ((columns: Table['columns']) => ConnectionOrderBy);
|
|
447
|
+
} extends infer QueryConfig
|
|
448
|
+
? QueryConfig | ((args: Args, context: Types['Context']) => QueryConfig)
|
|
449
|
+
: never;
|
|
450
|
+
|
|
451
|
+
export type QueryForDrizzleConnection<
|
|
452
|
+
Types extends SchemaTypes,
|
|
453
|
+
Table extends TableRelationalConfig,
|
|
454
|
+
> = Omit<
|
|
455
|
+
DBQueryConfig<'many', false, Types['DrizzleRelationSchema'], Table>,
|
|
456
|
+
'orderBy' | 'limit' | 'offset'
|
|
457
|
+
> & {
|
|
458
|
+
orderBy?: ConnectionOrderBy | ((columns: Table['columns']) => ConnectionOrderBy);
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
export type ListRelation<T extends TableRelationalConfig> = {
|
|
462
|
+
[K in keyof T['relations']]: T['relations'][K] extends Many<string> ? K : never;
|
|
463
|
+
}[keyof T['relations']];
|
|
464
|
+
|
|
465
|
+
export type DrizzleConnectionFieldOptions<
|
|
466
|
+
Types extends SchemaTypes,
|
|
467
|
+
ParentShape,
|
|
468
|
+
Type extends
|
|
469
|
+
| DrizzleRef<any, keyof Types['DrizzleRelationSchema']>
|
|
470
|
+
| keyof Types['DrizzleRelationSchema'],
|
|
471
|
+
TableConfig extends TableRelationalConfig,
|
|
472
|
+
Param extends OutputType<Types>,
|
|
473
|
+
Nullable extends boolean,
|
|
474
|
+
Args extends InputFieldMap,
|
|
475
|
+
ResolveReturnShape,
|
|
476
|
+
Kind extends FieldKind,
|
|
477
|
+
// eslint-disable-next-line @typescript-eslint/sort-type-constituents
|
|
478
|
+
> = Omit<
|
|
479
|
+
FieldOptionsFromKind<
|
|
480
|
+
Types,
|
|
481
|
+
ParentShape,
|
|
482
|
+
Param,
|
|
483
|
+
Nullable,
|
|
484
|
+
InputFieldsFromShape<Types, PothosSchemaTypes.DefaultConnectionArguments, 'Arg'> &
|
|
485
|
+
(InputFieldMap extends Args ? {} : Args),
|
|
486
|
+
Kind,
|
|
487
|
+
ParentShape,
|
|
488
|
+
ResolveReturnShape
|
|
489
|
+
>,
|
|
490
|
+
'args' | 'resolve' | 'type'
|
|
491
|
+
> &
|
|
492
|
+
Omit<
|
|
493
|
+
PothosSchemaTypes.ConnectionFieldOptions<
|
|
494
|
+
Types,
|
|
495
|
+
ParentShape,
|
|
496
|
+
Param,
|
|
497
|
+
Nullable,
|
|
498
|
+
false,
|
|
499
|
+
false,
|
|
500
|
+
Args,
|
|
501
|
+
ResolveReturnShape
|
|
502
|
+
>,
|
|
503
|
+
'resolve' | 'type'
|
|
504
|
+
> &
|
|
505
|
+
(InputShapeFromFields<Args> &
|
|
506
|
+
PothosSchemaTypes.DefaultConnectionArguments extends infer ConnectionArgs
|
|
507
|
+
? {
|
|
508
|
+
type: Type;
|
|
509
|
+
defaultSize?: number | ((args: ConnectionArgs, ctx: Types['Context']) => number);
|
|
510
|
+
maxSize?: number | ((args: ConnectionArgs, ctx: Types['Context']) => number);
|
|
511
|
+
|
|
512
|
+
resolve: (
|
|
513
|
+
query: <
|
|
514
|
+
T extends QueryForRelatedConnection<
|
|
515
|
+
Types,
|
|
516
|
+
Types['DrizzleRelationSchema'][Type extends DrizzleRef<any, infer K>
|
|
517
|
+
? K
|
|
518
|
+
: Type & keyof Types['DrizzleRelationSchema']],
|
|
519
|
+
ConnectionArgs
|
|
520
|
+
>,
|
|
521
|
+
>(
|
|
522
|
+
selection?: T,
|
|
523
|
+
) => Omit<T, 'orderBy'> & { orderBy: SQL },
|
|
524
|
+
parent: ParentShape,
|
|
525
|
+
args: ConnectionArgs,
|
|
526
|
+
context: Types['Context'],
|
|
527
|
+
info: GraphQLResolveInfo,
|
|
528
|
+
) => ShapeFromTypeParam<Types, [Param], Nullable> extends infer Shape
|
|
529
|
+
? [Shape] extends [[readonly (infer Item)[] | null | undefined]]
|
|
530
|
+
? ListResolveValue<Shape, Item, ResolveReturnShape>
|
|
531
|
+
: MaybePromise<Shape>
|
|
532
|
+
: never;
|
|
533
|
+
}
|
|
534
|
+
: never);
|
|
535
|
+
|
|
536
|
+
export type RelatedConnectionOptions<
|
|
537
|
+
Types extends SchemaTypes,
|
|
538
|
+
Shape,
|
|
539
|
+
Table extends TableRelationalConfig,
|
|
540
|
+
Field extends keyof Table['relations'],
|
|
541
|
+
Nullable extends boolean,
|
|
542
|
+
Args extends InputFieldMap,
|
|
543
|
+
NodeTable extends
|
|
544
|
+
TableRelationalConfig = Types['DrizzleRelationSchema'][Table['relations'][Field]['referencedTable']['_']['name']],
|
|
545
|
+
// eslint-disable-next-line @typescript-eslint/sort-type-constituents
|
|
546
|
+
> = Omit<
|
|
547
|
+
PothosSchemaTypes.ObjectFieldOptions<
|
|
548
|
+
Types,
|
|
549
|
+
Shape,
|
|
550
|
+
ObjectRef<Types, unknown>,
|
|
551
|
+
Nullable,
|
|
552
|
+
InputFieldsFromShape<Types, PothosSchemaTypes.DefaultConnectionArguments, 'InputObject'> &
|
|
553
|
+
(InputFieldMap extends Args ? {} : Args),
|
|
554
|
+
unknown
|
|
555
|
+
>,
|
|
556
|
+
'args' | 'resolve' | 'type'
|
|
557
|
+
> &
|
|
558
|
+
Omit<
|
|
559
|
+
PothosSchemaTypes.ConnectionFieldOptions<
|
|
560
|
+
Types,
|
|
561
|
+
Shape,
|
|
562
|
+
ObjectRef<Types, unknown>,
|
|
563
|
+
false,
|
|
564
|
+
false,
|
|
565
|
+
Nullable,
|
|
566
|
+
Args,
|
|
567
|
+
unknown
|
|
568
|
+
>,
|
|
569
|
+
'resolve' | 'type'
|
|
570
|
+
> &
|
|
571
|
+
(InputShapeFromFields<Args> &
|
|
572
|
+
PothosSchemaTypes.DefaultConnectionArguments extends infer ConnectionArgs
|
|
573
|
+
? {
|
|
574
|
+
resolve?: (
|
|
575
|
+
parent: Shape,
|
|
576
|
+
args: ConnectionArgs,
|
|
577
|
+
context: Types['Context'],
|
|
578
|
+
info: GraphQLResolveInfo,
|
|
579
|
+
) => MaybePromise<
|
|
580
|
+
ShapeFromTypeParam<
|
|
581
|
+
Types,
|
|
582
|
+
[ObjectRef<Types, TypesForRelation<Types, Table['relations'][Field]>>],
|
|
583
|
+
Nullable
|
|
584
|
+
>
|
|
585
|
+
>;
|
|
586
|
+
query: QueryForRelatedConnection<Types, NodeTable, ConnectionArgs>;
|
|
587
|
+
type?: DrizzleRef<any, Table['relations'][Field]['referencedTable']['_']['name']>;
|
|
588
|
+
|
|
589
|
+
defaultSize?: number | ((args: ConnectionArgs, ctx: Types['Context']) => number);
|
|
590
|
+
maxSize?: number | ((args: ConnectionArgs, ctx: Types['Context']) => number);
|
|
591
|
+
// totalCount?: NeedsResolve extends false ? boolean : false;
|
|
592
|
+
}
|
|
593
|
+
: never);
|
|
594
|
+
|
|
595
|
+
export type ConnectionOrderBy =
|
|
596
|
+
| Column
|
|
597
|
+
| { asc: Column }
|
|
598
|
+
| { desc: Column }
|
|
599
|
+
| (Column | { asc: Column } | { desc: Column })[];
|
|
600
|
+
|
|
601
|
+
export type ShapeFromConnection<T> = T extends { shape: unknown } ? T['shape'] : never;
|
|
602
|
+
|
|
603
|
+
export type DrizzleConnectionShape<
|
|
604
|
+
Types extends SchemaTypes,
|
|
605
|
+
T,
|
|
606
|
+
Parent,
|
|
607
|
+
Args extends InputFieldMap,
|
|
608
|
+
> = (
|
|
609
|
+
ShapeFromConnection<PothosSchemaTypes.ConnectionShapeHelper<Types, T, false>> extends infer Shape
|
|
610
|
+
? Shape & {
|
|
611
|
+
parent: Parent;
|
|
612
|
+
args: InputShapeFromFields<Args> & PothosSchemaTypes.DefaultConnectionArguments;
|
|
613
|
+
}
|
|
614
|
+
: never
|
|
615
|
+
) extends infer C
|
|
616
|
+
? [C] extends [
|
|
617
|
+
{ edges: MaybePromise<readonly (infer Edge | null | undefined)[] | null | undefined> },
|
|
618
|
+
]
|
|
619
|
+
? Omit<C, 'edges'> & { edges: (Edge & { connection: C })[] }
|
|
620
|
+
: C
|
|
621
|
+
: never;
|
|
622
|
+
|
|
623
|
+
export type WithBrand<T> = T & { [typeBrandKey]: string };
|
|
624
|
+
|
|
625
|
+
export interface AddGraphQLInputTypeOptions<Types extends SchemaTypes, Shape extends {}>
|
|
626
|
+
extends Omit<
|
|
627
|
+
PothosSchemaTypes.InputObjectTypeOptions<
|
|
628
|
+
Types,
|
|
629
|
+
InputFieldsFromShape<Types, Shape, 'InputObject'>
|
|
630
|
+
>,
|
|
631
|
+
'fields'
|
|
632
|
+
> {
|
|
633
|
+
name?: string;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
export interface DrizzleGraphQLInputExtensions {
|
|
637
|
+
table: string;
|
|
638
|
+
tableConfig: TableRelationalConfig;
|
|
639
|
+
inputType: 'insert' | 'filters' | 'orderBy' | 'update';
|
|
640
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createContextCache, SchemaTypes } from '@pothos/core';
|
|
2
|
+
import { RelationalSchemaConfig, TableRelationalConfig, TablesRelationalConfig } from 'drizzle-orm';
|
|
3
|
+
|
|
4
|
+
export interface PothosDrizzleSchemaConfig extends RelationalSchemaConfig<TablesRelationalConfig> {
|
|
5
|
+
dbToSchema: Record<string, TableRelationalConfig>;
|
|
6
|
+
}
|
|
7
|
+
const cache = createContextCache(
|
|
8
|
+
(config: RelationalSchemaConfig<TablesRelationalConfig>): PothosDrizzleSchemaConfig => {
|
|
9
|
+
const dbToSchema = Object.values(config.schema).reduce<Record<string, TableRelationalConfig>>(
|
|
10
|
+
(acc, table) => {
|
|
11
|
+
acc[table.dbName] = table;
|
|
12
|
+
return acc;
|
|
13
|
+
},
|
|
14
|
+
{},
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
dbToSchema,
|
|
19
|
+
...config,
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
export function getSchemaConfig<Types extends SchemaTypes>(
|
|
25
|
+
builder: PothosSchemaTypes.SchemaBuilder<Types>,
|
|
26
|
+
) {
|
|
27
|
+
return cache(builder.options.drizzle.client._ as RelationalSchemaConfig<TablesRelationalConfig>);
|
|
28
|
+
}
|