@pothos/plugin-drizzle 0.8.0 → 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 +98 -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 +18 -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 +18 -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 +33 -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
|
@@ -1,274 +1,273 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from '
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
//
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
};
|
|
1
|
+
// import {
|
|
2
|
+
// type Column,
|
|
3
|
+
// type SQL,
|
|
4
|
+
// type TableRelationalConfig,
|
|
5
|
+
// asc,
|
|
6
|
+
// desc,
|
|
7
|
+
// operators as ops,
|
|
8
|
+
// } from 'drizzle-orm';
|
|
9
|
+
// import { GraphQLError } from 'graphql';
|
|
10
|
+
|
|
11
|
+
// // biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
12
|
+
// export const remapFromGraphQLCore = (value: any, column: Column, columnName: string) => {
|
|
13
|
+
// switch (column.dataType) {
|
|
14
|
+
// case 'date': {
|
|
15
|
+
// const formatted = new Date(value);
|
|
16
|
+
// if (Number.isNaN(formatted.getTime())) {
|
|
17
|
+
// throw new GraphQLError(`Field '${columnName}' is not a valid date!`);
|
|
18
|
+
// }
|
|
19
|
+
|
|
20
|
+
// return formatted;
|
|
21
|
+
// }
|
|
22
|
+
|
|
23
|
+
// case 'buffer': {
|
|
24
|
+
// if (!Array.isArray(value)) {
|
|
25
|
+
// throw new GraphQLError(`Field '${columnName}' is not an array!`);
|
|
26
|
+
// }
|
|
27
|
+
|
|
28
|
+
// return Buffer.from(value);
|
|
29
|
+
// }
|
|
30
|
+
|
|
31
|
+
// case 'json': {
|
|
32
|
+
// if (column.columnType === 'PgGeometryObject') {
|
|
33
|
+
// return value;
|
|
34
|
+
// }
|
|
35
|
+
|
|
36
|
+
// try {
|
|
37
|
+
// return JSON.parse(value);
|
|
38
|
+
// } catch (e) {
|
|
39
|
+
// throw new GraphQLError(
|
|
40
|
+
// `Invalid JSON in field '${columnName}':\n${e instanceof Error ? e.message : 'Unknown error'}`,
|
|
41
|
+
// );
|
|
42
|
+
// }
|
|
43
|
+
// }
|
|
44
|
+
|
|
45
|
+
// case 'array': {
|
|
46
|
+
// if (!Array.isArray(value)) {
|
|
47
|
+
// throw new GraphQLError(`Field '${columnName}' is not an array!`);
|
|
48
|
+
// }
|
|
49
|
+
|
|
50
|
+
// if (column.columnType === 'PgGeometry' && value.length !== 2) {
|
|
51
|
+
// throw new GraphQLError(
|
|
52
|
+
// `Invalid float tuple in field '${columnName}': expected array with length of 2, received ${value.length}`,
|
|
53
|
+
// );
|
|
54
|
+
// }
|
|
55
|
+
|
|
56
|
+
// return value;
|
|
57
|
+
// }
|
|
58
|
+
|
|
59
|
+
// case 'bigint': {
|
|
60
|
+
// try {
|
|
61
|
+
// return BigInt(value);
|
|
62
|
+
// } catch (_error) {
|
|
63
|
+
// throw new GraphQLError(`Field '${columnName}' is not a BigInt!`);
|
|
64
|
+
// }
|
|
65
|
+
// }
|
|
66
|
+
|
|
67
|
+
// default: {
|
|
68
|
+
// return value;
|
|
69
|
+
// }
|
|
70
|
+
// }
|
|
71
|
+
// };
|
|
72
|
+
|
|
73
|
+
// export const remapFromGraphQLSingleInput = (
|
|
74
|
+
// // biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
75
|
+
// queryInput: Record<string, any>,
|
|
76
|
+
// table: TableRelationalConfig,
|
|
77
|
+
// ) => {
|
|
78
|
+
// for (const [key, value] of Object.entries(queryInput)) {
|
|
79
|
+
// if (value === undefined) {
|
|
80
|
+
// delete queryInput[key];
|
|
81
|
+
// } else {
|
|
82
|
+
// const column = table.columns[key];
|
|
83
|
+
// if (!column) {
|
|
84
|
+
// throw new GraphQLError(`Unknown column: ${key}`);
|
|
85
|
+
// }
|
|
86
|
+
|
|
87
|
+
// if (value === null && (column as Column).notNull) {
|
|
88
|
+
// delete queryInput[key];
|
|
89
|
+
// continue;
|
|
90
|
+
// }
|
|
91
|
+
|
|
92
|
+
// queryInput[key] = remapFromGraphQLCore(value, column as Column, key);
|
|
93
|
+
// }
|
|
94
|
+
// }
|
|
95
|
+
|
|
96
|
+
// return queryInput;
|
|
97
|
+
// };
|
|
98
|
+
|
|
99
|
+
// export const remapFromGraphQLArrayInput = (
|
|
100
|
+
// // biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
101
|
+
// queryInput: Record<string, any>[],
|
|
102
|
+
// table: TableRelationalConfig,
|
|
103
|
+
// ) => {
|
|
104
|
+
// for (const entry of queryInput) {
|
|
105
|
+
// remapFromGraphQLSingleInput(entry, table);
|
|
106
|
+
// }
|
|
107
|
+
|
|
108
|
+
// return queryInput;
|
|
109
|
+
// };
|
|
110
|
+
|
|
111
|
+
// export type OrderByArgs<TTable extends TableRelationalConfig> = {
|
|
112
|
+
// [Key in keyof TTable['columns']]?: {
|
|
113
|
+
// direction: 'asc' | 'desc';
|
|
114
|
+
// priority: number;
|
|
115
|
+
// };
|
|
116
|
+
// };
|
|
117
|
+
|
|
118
|
+
// export const extractOrderBy = <
|
|
119
|
+
// TTable extends TableRelationalConfig,
|
|
120
|
+
// // biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
121
|
+
// TArgs extends OrderByArgs<any> = OrderByArgs<TTable>,
|
|
122
|
+
// >(
|
|
123
|
+
// table: TTable,
|
|
124
|
+
// orderArgs: TArgs,
|
|
125
|
+
// ): SQL[] => {
|
|
126
|
+
// const res = [] as SQL[];
|
|
127
|
+
|
|
128
|
+
// for (const [column, config] of Object.entries(orderArgs).sort(
|
|
129
|
+
// (a, b) => (b[1]?.priority ?? 0) - (a[1]?.priority ?? 0),
|
|
130
|
+
// )) {
|
|
131
|
+
// if (!config) {
|
|
132
|
+
// continue;
|
|
133
|
+
// }
|
|
134
|
+
// const { direction } = config;
|
|
135
|
+
|
|
136
|
+
// res.push(direction === 'asc' ? asc(table.columns[column]!) : desc(table.columns[column]!));
|
|
137
|
+
// }
|
|
138
|
+
|
|
139
|
+
// return res;
|
|
140
|
+
// };
|
|
141
|
+
|
|
142
|
+
// export const extractFiltersColumn = <TColumn extends Column>(
|
|
143
|
+
// column: TColumn,
|
|
144
|
+
// columnName: string,
|
|
145
|
+
// operators: Record<string, unknown> & { OR?: Record<string, unknown>[] },
|
|
146
|
+
// ): SQL | undefined => {
|
|
147
|
+
// if (!operators.OR?.length) {
|
|
148
|
+
// // biome-ignore lint/performance/noDelete: <explanation>
|
|
149
|
+
// delete operators.OR;
|
|
150
|
+
// }
|
|
151
|
+
|
|
152
|
+
// const entries = Object.entries(operators);
|
|
153
|
+
|
|
154
|
+
// if (operators.OR) {
|
|
155
|
+
// if (entries.length > 1) {
|
|
156
|
+
// throw new GraphQLError(
|
|
157
|
+
// `WHERE ${columnName}: Cannot specify both fields and 'OR' in column operators!`,
|
|
158
|
+
// );
|
|
159
|
+
// }
|
|
160
|
+
|
|
161
|
+
// const variants = [] as SQL[];
|
|
162
|
+
|
|
163
|
+
// for (const variant of operators.OR) {
|
|
164
|
+
// const extracted = extractFiltersColumn(column, columnName, variant);
|
|
165
|
+
|
|
166
|
+
// // biome-ignore lint/style/useBlockStatements: <explanation>
|
|
167
|
+
// if (extracted) variants.push(extracted);
|
|
168
|
+
// }
|
|
169
|
+
|
|
170
|
+
// return variants.length ? (variants.length > 1 ? ops.or(...variants) : variants[0]) : undefined;
|
|
171
|
+
// }
|
|
172
|
+
|
|
173
|
+
// const variants = [] as SQL[];
|
|
174
|
+
// for (const [operatorName, operatorValue] of entries) {
|
|
175
|
+
// // biome-ignore lint/style/useBlockStatements: <explanation>
|
|
176
|
+
// if (operatorValue === null || operatorValue === false) continue;
|
|
177
|
+
|
|
178
|
+
// switch (operatorName) {
|
|
179
|
+
// case 'eq':
|
|
180
|
+
// case 'ne':
|
|
181
|
+
// case 'gt':
|
|
182
|
+
// case 'gte':
|
|
183
|
+
// case 'lt':
|
|
184
|
+
// case 'lte': {
|
|
185
|
+
// const singleValue = remapFromGraphQLCore(operatorValue, column, columnName);
|
|
186
|
+
// variants.push(ops[operatorName](column, singleValue));
|
|
187
|
+
|
|
188
|
+
// break;
|
|
189
|
+
// }
|
|
190
|
+
// case 'like':
|
|
191
|
+
// case 'notLike':
|
|
192
|
+
// case 'ilike':
|
|
193
|
+
// case 'notIlike':
|
|
194
|
+
// variants.push(ops[operatorName](column, operatorValue as string));
|
|
195
|
+
// break;
|
|
196
|
+
// case 'inArray':
|
|
197
|
+
// case 'notInArray': {
|
|
198
|
+
// // biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
199
|
+
// if (!(operatorValue as any[]).length) {
|
|
200
|
+
// throw new GraphQLError(
|
|
201
|
+
// `WHERE ${columnName}: Unable to use operator ${operatorName} with an empty array!`,
|
|
202
|
+
// );
|
|
203
|
+
// }
|
|
204
|
+
// // biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
205
|
+
// const arrayValue = (operatorValue as any[]).map((val) =>
|
|
206
|
+
// remapFromGraphQLCore(val, column, columnName),
|
|
207
|
+
// );
|
|
208
|
+
|
|
209
|
+
// variants.push(ops[operatorName](column, arrayValue));
|
|
210
|
+
// break;
|
|
211
|
+
// }
|
|
212
|
+
// case 'isNull':
|
|
213
|
+
// case 'isNotNull':
|
|
214
|
+
// variants.push(ops[operatorName](column));
|
|
215
|
+
// break;
|
|
216
|
+
// default:
|
|
217
|
+
// throw new GraphQLError(`Unknown operator: ${operatorName}`);
|
|
218
|
+
// }
|
|
219
|
+
// }
|
|
220
|
+
|
|
221
|
+
// return variants.length ? (variants.length > 1 ? ops.and(...variants) : variants[0]) : undefined;
|
|
222
|
+
// };
|
|
223
|
+
|
|
224
|
+
// export const extractFilters = <TTable extends TableRelationalConfig>(
|
|
225
|
+
// table: TTable,
|
|
226
|
+
// tableName: string,
|
|
227
|
+
// filters: Record<string, unknown> & {
|
|
228
|
+
// OR?: Record<string, unknown>[];
|
|
229
|
+
// },
|
|
230
|
+
// ): SQL | undefined => {
|
|
231
|
+
// if (!filters.OR?.length) {
|
|
232
|
+
// // biome-ignore lint/performance/noDelete: <explanation>
|
|
233
|
+
// delete filters.OR;
|
|
234
|
+
// }
|
|
235
|
+
|
|
236
|
+
// const entries = Object.entries(filters);
|
|
237
|
+
// if (!entries.length) {
|
|
238
|
+
// return;
|
|
239
|
+
// }
|
|
240
|
+
|
|
241
|
+
// if (filters.OR) {
|
|
242
|
+
// if (entries.length > 1) {
|
|
243
|
+
// throw new GraphQLError(
|
|
244
|
+
// `WHERE ${tableName}: Cannot specify both fields and 'OR' in table filters!`,
|
|
245
|
+
// );
|
|
246
|
+
// }
|
|
247
|
+
|
|
248
|
+
// const variants = [] as SQL[];
|
|
249
|
+
|
|
250
|
+
// for (const variant of filters.OR) {
|
|
251
|
+
// const extracted = extractFilters(table, tableName, variant);
|
|
252
|
+
// if (extracted) {
|
|
253
|
+
// variants.push(extracted);
|
|
254
|
+
// }
|
|
255
|
+
// }
|
|
256
|
+
|
|
257
|
+
// return variants.length ? (variants.length > 1 ? ops.or(...variants) : variants[0]) : undefined;
|
|
258
|
+
// }
|
|
259
|
+
|
|
260
|
+
// const variants = [] as SQL[];
|
|
261
|
+
// for (const [columnName, operators] of entries) {
|
|
262
|
+
// if (operators === null) {
|
|
263
|
+
// continue;
|
|
264
|
+
// }
|
|
265
|
+
|
|
266
|
+
// const column = table.columns[columnName]!;
|
|
267
|
+
// variants.push(
|
|
268
|
+
// extractFiltersColumn(column as Column, columnName, operators as Record<string, unknown>)!,
|
|
269
|
+
// );
|
|
270
|
+
// }
|
|
271
|
+
|
|
272
|
+
// return variants.length ? (variants.length > 1 ? ops.and(...variants) : variants[0]) : undefined;
|
|
273
|
+
// };
|
package/src/utils/map-query.ts
CHANGED
|
@@ -54,7 +54,7 @@ function addTypeSelectionsForField(
|
|
|
54
54
|
|
|
55
55
|
const { pothosDrizzleSelect, pothosIndirectInclude } = (type.extensions ?? {}) as {
|
|
56
56
|
pothosIndirectInclude?: IndirectInclude;
|
|
57
|
-
pothosDrizzleSelect?: DBQueryConfig<'one'
|
|
57
|
+
pothosDrizzleSelect?: DBQueryConfig<'one'>;
|
|
58
58
|
};
|
|
59
59
|
|
|
60
60
|
if (
|
|
@@ -316,7 +316,7 @@ function addFieldSelection(
|
|
|
316
316
|
|
|
317
317
|
const fieldSelect = field.extensions?.pothosDrizzleSelect as DrizzleFieldSelection | undefined;
|
|
318
318
|
|
|
319
|
-
let fieldSelectionMap: DBQueryConfig<'one'
|
|
319
|
+
let fieldSelectionMap: DBQueryConfig<'one'> | undefined;
|
|
320
320
|
let mappings: LoaderMappings = {};
|
|
321
321
|
if (typeof fieldSelect === 'function') {
|
|
322
322
|
const args = getMappedArgumentValues(field, selection, context, info) as Record<
|
|
@@ -375,7 +375,7 @@ function addFieldSelection(
|
|
|
375
375
|
}
|
|
376
376
|
addTypeSelectionsForField(config, returnType, context, info, fieldState, selection, []);
|
|
377
377
|
mappings = fieldState.mappings;
|
|
378
|
-
return selectionToQuery(fieldState);
|
|
378
|
+
return selectionToQuery(config, fieldState);
|
|
379
379
|
},
|
|
380
380
|
(path) => {
|
|
381
381
|
const returnType = getNamedType(field.type);
|
|
@@ -429,7 +429,7 @@ export function queryFromInfo<T extends SelectionMap>({
|
|
|
429
429
|
|
|
430
430
|
setLoaderMappings(options.context, options.info, state.mappings);
|
|
431
431
|
|
|
432
|
-
const query = selectionToQuery(state) as T;
|
|
432
|
+
const query = selectionToQuery(options.config, state) as T;
|
|
433
433
|
|
|
434
434
|
return withUsageCheck ? wrapWithUsageCheck(query) : query;
|
|
435
435
|
}
|
|
@@ -445,6 +445,12 @@ export function stateFromInfo<T extends SelectionMap>({
|
|
|
445
445
|
}: QueryFromInfoOptions<T>) {
|
|
446
446
|
const returnType = getNamedType(info.returnType);
|
|
447
447
|
const type = typeName ? info.schema.getTypeMap()[typeName] : returnType;
|
|
448
|
+
const initialSelection = select
|
|
449
|
+
? {
|
|
450
|
+
columns: {},
|
|
451
|
+
...select,
|
|
452
|
+
}
|
|
453
|
+
: undefined;
|
|
448
454
|
|
|
449
455
|
let state: SelectionState | undefined;
|
|
450
456
|
|
|
@@ -470,7 +476,13 @@ export function stateFromInfo<T extends SelectionMap>({
|
|
|
470
476
|
: [path.map((n) => (typeof n === 'string' ? { name: n } : n))],
|
|
471
477
|
subPath,
|
|
472
478
|
(resolvedType, resolvedField, nested, deferred) => {
|
|
473
|
-
state = createStateForSelection(
|
|
479
|
+
state = createStateForSelection(
|
|
480
|
+
config,
|
|
481
|
+
info,
|
|
482
|
+
resolvedType,
|
|
483
|
+
undefined,
|
|
484
|
+
initialSelection,
|
|
485
|
+
);
|
|
474
486
|
|
|
475
487
|
addTypeSelectionsForField(
|
|
476
488
|
config,
|
|
@@ -488,13 +500,13 @@ export function stateFromInfo<T extends SelectionMap>({
|
|
|
488
500
|
},
|
|
489
501
|
);
|
|
490
502
|
} else {
|
|
491
|
-
state = createStateForSelection(config, info, type, undefined,
|
|
503
|
+
state = createStateForSelection(config, info, type, undefined, initialSelection);
|
|
492
504
|
|
|
493
505
|
addTypeSelectionsForField(config, type, context, info, state, info.fieldNodes[0], []);
|
|
494
506
|
}
|
|
495
507
|
|
|
496
508
|
if (!state) {
|
|
497
|
-
state = createStateForSelection(config, info, type, undefined,
|
|
509
|
+
state = createStateForSelection(config, info, type, undefined, initialSelection);
|
|
498
510
|
}
|
|
499
511
|
|
|
500
512
|
return state;
|