drizzle-graphql-plus 0.8.6 → 0.8.8
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/package.json +3 -3
- package/src/types.ts +478 -360
- package/src/util/builders/common.ts +2 -0
- package/src/util/builders/mysql.ts +534 -449
- package/src/util/builders/pg.ts +583 -484
- package/src/util/builders/sqlite.ts +589 -491
- package/src/util/builders/types.ts +261 -175
|
@@ -1,35 +1,39 @@
|
|
|
1
|
-
import type { Column, Relation, SQL, Table } from
|
|
2
|
-
import type { PgArray } from
|
|
1
|
+
import type { Column, Relation, SQL, Table } from "drizzle-orm";
|
|
2
|
+
import type { PgArray } from "drizzle-orm/pg-core";
|
|
3
3
|
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
GraphQLFieldConfigArgumentMap,
|
|
5
|
+
GraphQLFieldResolver,
|
|
6
|
+
GraphQLInputObjectType,
|
|
7
|
+
GraphQLInterfaceType,
|
|
8
|
+
GraphQLList,
|
|
9
|
+
GraphQLNonNull,
|
|
10
|
+
GraphQLObjectType,
|
|
11
|
+
GraphQLScalarType,
|
|
12
|
+
} from "graphql";
|
|
13
|
+
import type {
|
|
14
|
+
ConvertedColumn,
|
|
15
|
+
ConvertedRelationColumnWithArgs,
|
|
16
|
+
} from "../type-converter";
|
|
13
17
|
|
|
14
18
|
export type TableNamedRelations = {
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
relation: Relation;
|
|
20
|
+
targetTableName: string;
|
|
17
21
|
};
|
|
18
22
|
|
|
19
23
|
export type TableSelectArgs = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
offset: number;
|
|
25
|
+
limit: number;
|
|
26
|
+
where: Filters<Table>;
|
|
27
|
+
orderBy: OrderByArgs<Table>;
|
|
24
28
|
};
|
|
25
29
|
|
|
26
30
|
export type ProcessedTableSelectArgs = {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
columns: Record<string, true>;
|
|
32
|
+
offset: number;
|
|
33
|
+
limit: number;
|
|
34
|
+
where: SQL;
|
|
35
|
+
orderBy: SQL[];
|
|
36
|
+
with?: Record<string, Partial<ProcessedTableSelectArgs>>;
|
|
33
37
|
};
|
|
34
38
|
|
|
35
39
|
export type SelectedColumnsRaw = [string, true][];
|
|
@@ -37,195 +41,277 @@ export type SelectedColumnsRaw = [string, true][];
|
|
|
37
41
|
export type SelectedSQLColumns = [string, Column][];
|
|
38
42
|
|
|
39
43
|
export type SelectedColumns = {
|
|
40
|
-
|
|
44
|
+
[columnName in keyof Table["_"]["columns"]]: true;
|
|
41
45
|
};
|
|
42
46
|
|
|
43
47
|
export type CreatedResolver = {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
name: string;
|
|
49
|
+
resolver: GraphQLFieldResolver<any, any>;
|
|
50
|
+
args: GraphQLFieldConfigArgumentMap;
|
|
47
51
|
};
|
|
48
52
|
|
|
49
53
|
export type ArgMapToArgsType<TArgMap extends GraphQLFieldConfigArgumentMap> = {
|
|
50
|
-
|
|
54
|
+
[Key in keyof TArgMap]?: TArgMap[Key] extends {
|
|
55
|
+
type: GraphQLScalarType<infer R, any>;
|
|
56
|
+
}
|
|
57
|
+
? R
|
|
58
|
+
: never;
|
|
51
59
|
};
|
|
52
60
|
|
|
53
|
-
export type ColTypeIsNull<
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
export type
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
61
|
+
export type ColTypeIsNull<
|
|
62
|
+
TColumn extends Column,
|
|
63
|
+
TColType
|
|
64
|
+
> = TColumn["_"]["notNull"] extends true ? TColType : TColType | null;
|
|
65
|
+
|
|
66
|
+
export type ColTypeIsNullOrUndefined<
|
|
67
|
+
TColumn extends Column,
|
|
68
|
+
TColType
|
|
69
|
+
> = TColumn["_"]["notNull"] extends true
|
|
70
|
+
? TColType
|
|
71
|
+
: TColType | null | undefined;
|
|
72
|
+
|
|
73
|
+
export type ColTypeIsNullOrUndefinedWithDefault<
|
|
74
|
+
TColumn extends Column,
|
|
75
|
+
TColType
|
|
76
|
+
> = TColumn["_"]["notNull"] extends true
|
|
77
|
+
? TColumn["_"]["hasDefault"] extends true
|
|
78
|
+
? TColType | null | undefined
|
|
79
|
+
: TColumn["defaultFn"] extends undefined
|
|
80
|
+
? TColType
|
|
81
|
+
: TColType | null | undefined
|
|
82
|
+
: TColType | null | undefined;
|
|
83
|
+
|
|
84
|
+
export type GetColumnGqlDataType<TColumn extends Column> =
|
|
85
|
+
TColumn["dataType"] extends "boolean"
|
|
86
|
+
? ColTypeIsNull<TColumn, boolean>
|
|
87
|
+
: TColumn["dataType"] extends "json"
|
|
88
|
+
? TColumn["_"]["columnType"] extends "PgGeometryObject"
|
|
89
|
+
? ColTypeIsNull<
|
|
90
|
+
TColumn,
|
|
91
|
+
{
|
|
92
|
+
x: number;
|
|
93
|
+
y: number;
|
|
94
|
+
}
|
|
95
|
+
>
|
|
96
|
+
: ColTypeIsNull<TColumn, string>
|
|
97
|
+
: TColumn["dataType"] extends "date" | "string" | "bigint"
|
|
98
|
+
? TColumn["enumValues"] extends [string, ...string[]]
|
|
99
|
+
? ColTypeIsNull<TColumn, TColumn["enumValues"][number]>
|
|
100
|
+
: ColTypeIsNull<TColumn, string>
|
|
101
|
+
: TColumn["dataType"] extends "number"
|
|
102
|
+
? ColTypeIsNull<TColumn, number>
|
|
103
|
+
: TColumn["dataType"] extends "buffer"
|
|
104
|
+
? ColTypeIsNull<TColumn, number[]>
|
|
105
|
+
: TColumn["dataType"] extends "array"
|
|
106
|
+
? TColumn["columnType"] extends "PgVector"
|
|
107
|
+
? ColTypeIsNull<TColumn, number[]>
|
|
108
|
+
: TColumn["columnType"] extends "PgGeometry"
|
|
109
|
+
? ColTypeIsNullOrUndefinedWithDefault<TColumn, [number, number]>
|
|
110
|
+
: ColTypeIsNull<
|
|
111
|
+
TColumn,
|
|
112
|
+
Array<
|
|
113
|
+
GetColumnGqlDataType<
|
|
114
|
+
TColumn extends { baseColumn: Column }
|
|
115
|
+
? TColumn["baseColumn"]
|
|
116
|
+
: never
|
|
117
|
+
> extends infer InnerColType
|
|
118
|
+
? InnerColType extends null | undefined
|
|
119
|
+
? never
|
|
120
|
+
: InnerColType
|
|
121
|
+
: never
|
|
122
|
+
>
|
|
123
|
+
>
|
|
124
|
+
: never;
|
|
125
|
+
|
|
126
|
+
export type GetColumnGqlInsertDataType<TColumn extends Column> =
|
|
127
|
+
TColumn["dataType"] extends "boolean"
|
|
128
|
+
? ColTypeIsNullOrUndefinedWithDefault<TColumn, boolean>
|
|
129
|
+
: TColumn["dataType"] extends "json"
|
|
130
|
+
? TColumn["_"]["columnType"] extends "PgGeometryObject"
|
|
131
|
+
? ColTypeIsNullOrUndefinedWithDefault<
|
|
132
|
+
TColumn,
|
|
133
|
+
{
|
|
134
|
+
x: number;
|
|
135
|
+
y: number;
|
|
136
|
+
}
|
|
137
|
+
>
|
|
138
|
+
: ColTypeIsNullOrUndefinedWithDefault<TColumn, string>
|
|
139
|
+
: TColumn["dataType"] extends "date" | "string" | "bigint"
|
|
140
|
+
? TColumn["enumValues"] extends [string, ...string[]]
|
|
141
|
+
? ColTypeIsNullOrUndefinedWithDefault<
|
|
142
|
+
TColumn,
|
|
143
|
+
TColumn["enumValues"][number]
|
|
144
|
+
>
|
|
145
|
+
: ColTypeIsNullOrUndefinedWithDefault<TColumn, string>
|
|
146
|
+
: TColumn["dataType"] extends "number"
|
|
147
|
+
? ColTypeIsNullOrUndefinedWithDefault<TColumn, number>
|
|
148
|
+
: TColumn["dataType"] extends "buffer"
|
|
149
|
+
? ColTypeIsNullOrUndefinedWithDefault<TColumn, number[]>
|
|
150
|
+
: TColumn["dataType"] extends "array"
|
|
151
|
+
? TColumn["columnType"] extends "PgVector"
|
|
152
|
+
? ColTypeIsNullOrUndefinedWithDefault<TColumn, number[]>
|
|
153
|
+
: TColumn["columnType"] extends "PgGeometry"
|
|
154
|
+
? ColTypeIsNullOrUndefinedWithDefault<TColumn, [number, number]>
|
|
155
|
+
: ColTypeIsNullOrUndefinedWithDefault<
|
|
156
|
+
TColumn,
|
|
157
|
+
Array<
|
|
158
|
+
GetColumnGqlDataType<
|
|
159
|
+
TColumn extends { baseColumn: Column }
|
|
160
|
+
? TColumn["baseColumn"]
|
|
161
|
+
: never
|
|
162
|
+
> extends infer InnerColType
|
|
163
|
+
? InnerColType extends null | undefined
|
|
164
|
+
? never
|
|
165
|
+
: InnerColType
|
|
166
|
+
: never
|
|
167
|
+
>
|
|
168
|
+
>
|
|
169
|
+
: never;
|
|
170
|
+
|
|
171
|
+
export type GetColumnGqlUpdateDataType<TColumn extends Column> =
|
|
172
|
+
TColumn["dataType"] extends "boolean"
|
|
173
|
+
? boolean | null | undefined
|
|
174
|
+
: TColumn["dataType"] extends "json"
|
|
175
|
+
? TColumn["_"]["columnType"] extends "PgGeometryObject"
|
|
176
|
+
?
|
|
177
|
+
| {
|
|
178
|
+
x: number;
|
|
179
|
+
y: number;
|
|
180
|
+
}
|
|
181
|
+
| null
|
|
182
|
+
| undefined
|
|
183
|
+
: string | null | undefined
|
|
184
|
+
: TColumn["dataType"] extends "date" | "string" | "bigint"
|
|
185
|
+
? TColumn["enumValues"] extends [string, ...string[]]
|
|
186
|
+
? TColumn["enumValues"][number] | null | undefined
|
|
187
|
+
: string | null | undefined
|
|
188
|
+
: TColumn["dataType"] extends "number"
|
|
189
|
+
? number | null | undefined
|
|
190
|
+
: TColumn["dataType"] extends "buffer"
|
|
191
|
+
? number[] | null | undefined
|
|
192
|
+
: TColumn["dataType"] extends "array"
|
|
193
|
+
? TColumn["columnType"] extends "PgVector"
|
|
194
|
+
? number[] | null | undefined
|
|
195
|
+
: TColumn["columnType"] extends "PgGeometry"
|
|
196
|
+
? [number, number] | null | undefined
|
|
197
|
+
:
|
|
198
|
+
| Array<
|
|
199
|
+
GetColumnGqlDataType<
|
|
200
|
+
TColumn extends { baseColumn: Column }
|
|
201
|
+
? TColumn["baseColumn"]
|
|
202
|
+
: never
|
|
203
|
+
> extends infer InnerColType
|
|
204
|
+
? InnerColType extends null | undefined
|
|
205
|
+
? never
|
|
206
|
+
: InnerColType
|
|
207
|
+
: never
|
|
208
|
+
>
|
|
209
|
+
| null
|
|
210
|
+
| undefined
|
|
211
|
+
: never;
|
|
146
212
|
|
|
147
213
|
export type GetRemappedTableDataType<
|
|
148
|
-
|
|
149
|
-
|
|
214
|
+
TTable extends Table,
|
|
215
|
+
TColumns extends TTable["_"]["columns"] = TTable["_"]["columns"]
|
|
150
216
|
> = {
|
|
151
|
-
|
|
217
|
+
[K in keyof TColumns]: GetColumnGqlDataType<TColumns[K]>;
|
|
152
218
|
};
|
|
153
219
|
|
|
154
220
|
export type GetRemappedTableInsertDataType<TTable extends Table> = {
|
|
155
|
-
|
|
221
|
+
[K in keyof TTable["_"]["columns"]]: GetColumnGqlInsertDataType<
|
|
222
|
+
TTable["_"]["columns"][K]
|
|
223
|
+
>;
|
|
156
224
|
};
|
|
157
225
|
|
|
158
226
|
export type GetRemappedTableUpdateDataType<TTable extends Table> = {
|
|
159
|
-
|
|
227
|
+
[K in keyof TTable["_"]["columns"]]: GetColumnGqlUpdateDataType<
|
|
228
|
+
TTable["_"]["columns"][K]
|
|
229
|
+
>;
|
|
160
230
|
};
|
|
161
231
|
|
|
162
|
-
export type FilterColumnOperatorsCore<
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
232
|
+
export type FilterColumnOperatorsCore<
|
|
233
|
+
TColumn extends Column,
|
|
234
|
+
TColType = GetColumnGqlDataType<TColumn>
|
|
235
|
+
> = Partial<{
|
|
236
|
+
eq: TColType;
|
|
237
|
+
ne: TColType;
|
|
238
|
+
lt: TColType;
|
|
239
|
+
lte: TColType;
|
|
240
|
+
gt: TColType;
|
|
241
|
+
gte: TColType;
|
|
242
|
+
like: string;
|
|
243
|
+
notLike: string;
|
|
244
|
+
ilike: string;
|
|
245
|
+
notIlike: string;
|
|
246
|
+
inArray: Array<TColType>;
|
|
247
|
+
notInArray: Array<TColType>;
|
|
248
|
+
isNull: boolean;
|
|
249
|
+
isNotNull: boolean;
|
|
177
250
|
}>;
|
|
178
251
|
|
|
179
252
|
export type FilterColumnOperators<
|
|
180
|
-
|
|
181
|
-
|
|
253
|
+
TColumn extends Column,
|
|
254
|
+
TOperators extends FilterColumnOperatorsCore<TColumn> = FilterColumnOperatorsCore<TColumn>
|
|
182
255
|
> = TOperators & {
|
|
183
|
-
|
|
256
|
+
OR?: TOperators[];
|
|
184
257
|
};
|
|
185
258
|
|
|
186
|
-
export type FiltersCore<TTable extends Table> = Partial<
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
>;
|
|
259
|
+
export type FiltersCore<TTable extends Table> = Partial<{
|
|
260
|
+
[Column in keyof TTable["_"]["columns"]]: FilterColumnOperatorsCore<
|
|
261
|
+
TTable["_"]["columns"][Column]
|
|
262
|
+
>;
|
|
263
|
+
}>;
|
|
191
264
|
|
|
192
|
-
export type Filters<
|
|
193
|
-
|
|
265
|
+
export type Filters<
|
|
266
|
+
TTable extends Table,
|
|
267
|
+
TFilterType = FiltersCore<TTable>
|
|
268
|
+
> = TFilterType & {
|
|
269
|
+
OR?: TFilterType[];
|
|
194
270
|
};
|
|
195
271
|
|
|
196
272
|
export type OrderByArgs<TTable extends Table> = {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
273
|
+
[Key in keyof TTable["_"]["columns"]]?: {
|
|
274
|
+
direction: "asc" | "desc";
|
|
275
|
+
priority: number;
|
|
276
|
+
};
|
|
201
277
|
};
|
|
202
278
|
|
|
203
279
|
export type GeneratedTableTypesInputs = {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
280
|
+
insertInput: GraphQLInputObjectType;
|
|
281
|
+
updateInput: GraphQLInputObjectType;
|
|
282
|
+
tableOrder: GraphQLInputObjectType;
|
|
283
|
+
tableFilters: GraphQLInputObjectType;
|
|
208
284
|
};
|
|
209
285
|
|
|
210
|
-
export type GeneratedTableTypesOutputs<WithReturning extends boolean> =
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
286
|
+
export type GeneratedTableTypesOutputs<WithReturning extends boolean> =
|
|
287
|
+
WithReturning extends true
|
|
288
|
+
? {
|
|
289
|
+
selectSingleOutput: GraphQLObjectType;
|
|
290
|
+
selectArrOutput: GraphQLNonNull<
|
|
291
|
+
GraphQLList<GraphQLNonNull<GraphQLObjectType>>
|
|
292
|
+
>;
|
|
293
|
+
singleTableItemOutput: GraphQLObjectType;
|
|
294
|
+
arrTableItemOutput: GraphQLNonNull<
|
|
295
|
+
GraphQLList<GraphQLNonNull<GraphQLObjectType>>
|
|
296
|
+
>;
|
|
297
|
+
tableFieldsInterface: GraphQLInterfaceType;
|
|
298
|
+
}
|
|
299
|
+
: {
|
|
300
|
+
selectSingleOutput: GraphQLObjectType;
|
|
301
|
+
selectArrOutput: GraphQLNonNull<
|
|
302
|
+
GraphQLList<GraphQLNonNull<GraphQLObjectType>>
|
|
303
|
+
>;
|
|
304
|
+
tableFieldsInterface: GraphQLInterfaceType;
|
|
305
|
+
};
|
|
220
306
|
|
|
221
307
|
export type GeneratedTableTypes<WithReturning extends boolean> = {
|
|
222
|
-
|
|
223
|
-
|
|
308
|
+
inputs: GeneratedTableTypesInputs;
|
|
309
|
+
outputs: GeneratedTableTypesOutputs<WithReturning>;
|
|
224
310
|
};
|
|
225
311
|
|
|
226
312
|
export type SelectData<TWithOrder extends boolean> = {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
313
|
+
filters: GraphQLInputObjectType;
|
|
314
|
+
tableFields: Record<string, ConvertedColumn>;
|
|
315
|
+
relationFields: Record<string, ConvertedRelationColumnWithArgs>;
|
|
316
|
+
order: TWithOrder extends true ? GraphQLInputObjectType : undefined;
|
|
231
317
|
};
|