@constructive-io/graphql-codegen 2.20.1 → 2.22.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/README.md +15 -3
- package/cli/codegen/barrel.d.ts +4 -1
- package/cli/codegen/barrel.js +18 -12
- package/cli/codegen/client.js +33 -0
- package/cli/codegen/custom-mutations.d.ts +11 -1
- package/cli/codegen/custom-mutations.js +49 -15
- package/cli/codegen/custom-queries.d.ts +8 -0
- package/cli/codegen/custom-queries.js +82 -47
- package/cli/codegen/gql-ast.js +9 -5
- package/cli/codegen/index.js +39 -8
- package/cli/codegen/mutations.d.ts +14 -4
- package/cli/codegen/mutations.js +114 -28
- package/cli/codegen/orm/barrel.js +4 -2
- package/cli/codegen/orm/index.js +17 -0
- package/cli/codegen/orm/input-types-generator.js +83 -29
- package/cli/codegen/orm/model-generator.js +6 -4
- package/cli/codegen/queries.d.ts +7 -3
- package/cli/codegen/queries.js +185 -158
- package/cli/codegen/scalars.d.ts +6 -4
- package/cli/codegen/scalars.js +17 -9
- package/cli/codegen/schema-types-generator.d.ts +26 -0
- package/cli/codegen/schema-types-generator.js +365 -0
- package/cli/codegen/ts-ast.d.ts +3 -1
- package/cli/codegen/ts-ast.js +2 -2
- package/cli/codegen/type-resolver.d.ts +52 -6
- package/cli/codegen/type-resolver.js +97 -19
- package/cli/codegen/types.d.ts +7 -4
- package/cli/codegen/types.js +94 -41
- package/cli/codegen/utils.d.ts +20 -2
- package/cli/codegen/utils.js +32 -7
- package/cli/commands/generate-orm.js +5 -5
- package/cli/commands/generate.d.ts +4 -1
- package/cli/commands/generate.js +27 -8
- package/cli/introspect/transform-schema.d.ts +33 -21
- package/cli/introspect/transform-schema.js +31 -21
- package/esm/cli/codegen/barrel.d.ts +4 -1
- package/esm/cli/codegen/barrel.js +18 -12
- package/esm/cli/codegen/client.js +33 -0
- package/esm/cli/codegen/custom-mutations.d.ts +11 -1
- package/esm/cli/codegen/custom-mutations.js +50 -16
- package/esm/cli/codegen/custom-queries.d.ts +8 -0
- package/esm/cli/codegen/custom-queries.js +83 -48
- package/esm/cli/codegen/gql-ast.js +10 -6
- package/esm/cli/codegen/index.js +39 -8
- package/esm/cli/codegen/mutations.d.ts +14 -4
- package/esm/cli/codegen/mutations.js +115 -29
- package/esm/cli/codegen/orm/barrel.js +4 -2
- package/esm/cli/codegen/orm/index.js +17 -0
- package/esm/cli/codegen/orm/input-types-generator.js +83 -29
- package/esm/cli/codegen/orm/model-generator.js +7 -5
- package/esm/cli/codegen/queries.d.ts +7 -3
- package/esm/cli/codegen/queries.js +186 -159
- package/esm/cli/codegen/scalars.d.ts +6 -4
- package/esm/cli/codegen/scalars.js +16 -8
- package/esm/cli/codegen/schema-types-generator.d.ts +26 -0
- package/esm/cli/codegen/schema-types-generator.js +362 -0
- package/esm/cli/codegen/ts-ast.d.ts +3 -1
- package/esm/cli/codegen/ts-ast.js +2 -2
- package/esm/cli/codegen/type-resolver.d.ts +52 -6
- package/esm/cli/codegen/type-resolver.js +97 -20
- package/esm/cli/codegen/types.d.ts +7 -4
- package/esm/cli/codegen/types.js +95 -41
- package/esm/cli/codegen/utils.d.ts +20 -2
- package/esm/cli/codegen/utils.js +31 -7
- package/esm/cli/commands/generate-orm.js +5 -5
- package/esm/cli/commands/generate.d.ts +4 -1
- package/esm/cli/commands/generate.js +27 -8
- package/esm/cli/introspect/transform-schema.d.ts +33 -21
- package/esm/cli/introspect/transform-schema.js +31 -21
- package/esm/types/config.d.ts +16 -1
- package/esm/types/config.js +6 -0
- package/esm/types/schema.d.ts +2 -0
- package/package.json +8 -6
- package/types/config.d.ts +16 -1
- package/types/config.js +6 -0
- package/types/schema.d.ts +2 -0
- package/__tests__/codegen/input-types-generator.test.d.ts +0 -1
- package/__tests__/codegen/input-types-generator.test.js +0 -635
- package/cli/codegen/filters.d.ts +0 -27
- package/cli/codegen/filters.js +0 -357
- package/cli/codegen/orm/input-types-generator.test.d.ts +0 -1
- package/cli/codegen/orm/input-types-generator.test.js +0 -75
- package/cli/codegen/orm/select-types.test.d.ts +0 -11
- package/cli/codegen/orm/select-types.test.js +0 -22
- package/cli/introspect/transform-schema.test.d.ts +0 -1
- package/cli/introspect/transform-schema.test.js +0 -67
- package/esm/__tests__/codegen/input-types-generator.test.d.ts +0 -1
- package/esm/__tests__/codegen/input-types-generator.test.js +0 -633
- package/esm/cli/codegen/filters.d.ts +0 -27
- package/esm/cli/codegen/filters.js +0 -351
- package/esm/cli/codegen/orm/input-types-generator.test.d.ts +0 -1
- package/esm/cli/codegen/orm/input-types-generator.test.js +0 -73
- package/esm/cli/codegen/orm/select-types.test.d.ts +0 -11
- package/esm/cli/codegen/orm/select-types.test.js +0 -21
- package/esm/cli/introspect/transform-schema.test.d.ts +0 -1
- package/esm/cli/introspect/transform-schema.test.js +0 -65
|
@@ -1,351 +0,0 @@
|
|
|
1
|
-
import { getFilterTypeName, getOrderByTypeName, getScalarFilterType, getScalarFields, toScreamingSnake, getGeneratedFileHeader, } from './utils';
|
|
2
|
-
// ============================================================================
|
|
3
|
-
// Base filter type definitions
|
|
4
|
-
// ============================================================================
|
|
5
|
-
/**
|
|
6
|
-
* Generate all base PostGraphile filter types
|
|
7
|
-
* These are shared across all tables
|
|
8
|
-
*/
|
|
9
|
-
export function generateBaseFilterTypes() {
|
|
10
|
-
return `${getGeneratedFileHeader('PostGraphile base filter types')}
|
|
11
|
-
|
|
12
|
-
// ============================================================================
|
|
13
|
-
// String filters
|
|
14
|
-
// ============================================================================
|
|
15
|
-
|
|
16
|
-
export interface StringFilter {
|
|
17
|
-
isNull?: boolean;
|
|
18
|
-
equalTo?: string;
|
|
19
|
-
notEqualTo?: string;
|
|
20
|
-
distinctFrom?: string;
|
|
21
|
-
notDistinctFrom?: string;
|
|
22
|
-
in?: string[];
|
|
23
|
-
notIn?: string[];
|
|
24
|
-
lessThan?: string;
|
|
25
|
-
lessThanOrEqualTo?: string;
|
|
26
|
-
greaterThan?: string;
|
|
27
|
-
greaterThanOrEqualTo?: string;
|
|
28
|
-
includes?: string;
|
|
29
|
-
notIncludes?: string;
|
|
30
|
-
includesInsensitive?: string;
|
|
31
|
-
notIncludesInsensitive?: string;
|
|
32
|
-
startsWith?: string;
|
|
33
|
-
notStartsWith?: string;
|
|
34
|
-
startsWithInsensitive?: string;
|
|
35
|
-
notStartsWithInsensitive?: string;
|
|
36
|
-
endsWith?: string;
|
|
37
|
-
notEndsWith?: string;
|
|
38
|
-
endsWithInsensitive?: string;
|
|
39
|
-
notEndsWithInsensitive?: string;
|
|
40
|
-
like?: string;
|
|
41
|
-
notLike?: string;
|
|
42
|
-
likeInsensitive?: string;
|
|
43
|
-
notLikeInsensitive?: string;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export interface StringListFilter {
|
|
47
|
-
isNull?: boolean;
|
|
48
|
-
equalTo?: string[];
|
|
49
|
-
notEqualTo?: string[];
|
|
50
|
-
distinctFrom?: string[];
|
|
51
|
-
notDistinctFrom?: string[];
|
|
52
|
-
lessThan?: string[];
|
|
53
|
-
lessThanOrEqualTo?: string[];
|
|
54
|
-
greaterThan?: string[];
|
|
55
|
-
greaterThanOrEqualTo?: string[];
|
|
56
|
-
contains?: string[];
|
|
57
|
-
containedBy?: string[];
|
|
58
|
-
overlaps?: string[];
|
|
59
|
-
anyEqualTo?: string;
|
|
60
|
-
anyNotEqualTo?: string;
|
|
61
|
-
anyLessThan?: string;
|
|
62
|
-
anyLessThanOrEqualTo?: string;
|
|
63
|
-
anyGreaterThan?: string;
|
|
64
|
-
anyGreaterThanOrEqualTo?: string;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// ============================================================================
|
|
68
|
-
// Numeric filters
|
|
69
|
-
// ============================================================================
|
|
70
|
-
|
|
71
|
-
export interface IntFilter {
|
|
72
|
-
isNull?: boolean;
|
|
73
|
-
equalTo?: number;
|
|
74
|
-
notEqualTo?: number;
|
|
75
|
-
distinctFrom?: number;
|
|
76
|
-
notDistinctFrom?: number;
|
|
77
|
-
in?: number[];
|
|
78
|
-
notIn?: number[];
|
|
79
|
-
lessThan?: number;
|
|
80
|
-
lessThanOrEqualTo?: number;
|
|
81
|
-
greaterThan?: number;
|
|
82
|
-
greaterThanOrEqualTo?: number;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export interface IntListFilter {
|
|
86
|
-
isNull?: boolean;
|
|
87
|
-
equalTo?: number[];
|
|
88
|
-
notEqualTo?: number[];
|
|
89
|
-
distinctFrom?: number[];
|
|
90
|
-
notDistinctFrom?: number[];
|
|
91
|
-
lessThan?: number[];
|
|
92
|
-
lessThanOrEqualTo?: number[];
|
|
93
|
-
greaterThan?: number[];
|
|
94
|
-
greaterThanOrEqualTo?: number[];
|
|
95
|
-
contains?: number[];
|
|
96
|
-
containedBy?: number[];
|
|
97
|
-
overlaps?: number[];
|
|
98
|
-
anyEqualTo?: number;
|
|
99
|
-
anyNotEqualTo?: number;
|
|
100
|
-
anyLessThan?: number;
|
|
101
|
-
anyLessThanOrEqualTo?: number;
|
|
102
|
-
anyGreaterThan?: number;
|
|
103
|
-
anyGreaterThanOrEqualTo?: number;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export interface FloatFilter {
|
|
107
|
-
isNull?: boolean;
|
|
108
|
-
equalTo?: number;
|
|
109
|
-
notEqualTo?: number;
|
|
110
|
-
distinctFrom?: number;
|
|
111
|
-
notDistinctFrom?: number;
|
|
112
|
-
in?: number[];
|
|
113
|
-
notIn?: number[];
|
|
114
|
-
lessThan?: number;
|
|
115
|
-
lessThanOrEqualTo?: number;
|
|
116
|
-
greaterThan?: number;
|
|
117
|
-
greaterThanOrEqualTo?: number;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export interface BigIntFilter {
|
|
121
|
-
isNull?: boolean;
|
|
122
|
-
equalTo?: string;
|
|
123
|
-
notEqualTo?: string;
|
|
124
|
-
distinctFrom?: string;
|
|
125
|
-
notDistinctFrom?: string;
|
|
126
|
-
in?: string[];
|
|
127
|
-
notIn?: string[];
|
|
128
|
-
lessThan?: string;
|
|
129
|
-
lessThanOrEqualTo?: string;
|
|
130
|
-
greaterThan?: string;
|
|
131
|
-
greaterThanOrEqualTo?: string;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export interface BigFloatFilter {
|
|
135
|
-
isNull?: boolean;
|
|
136
|
-
equalTo?: string;
|
|
137
|
-
notEqualTo?: string;
|
|
138
|
-
distinctFrom?: string;
|
|
139
|
-
notDistinctFrom?: string;
|
|
140
|
-
in?: string[];
|
|
141
|
-
notIn?: string[];
|
|
142
|
-
lessThan?: string;
|
|
143
|
-
lessThanOrEqualTo?: string;
|
|
144
|
-
greaterThan?: string;
|
|
145
|
-
greaterThanOrEqualTo?: string;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// ============================================================================
|
|
149
|
-
// Boolean filter
|
|
150
|
-
// ============================================================================
|
|
151
|
-
|
|
152
|
-
export interface BooleanFilter {
|
|
153
|
-
isNull?: boolean;
|
|
154
|
-
equalTo?: boolean;
|
|
155
|
-
notEqualTo?: boolean;
|
|
156
|
-
distinctFrom?: boolean;
|
|
157
|
-
notDistinctFrom?: boolean;
|
|
158
|
-
in?: boolean[];
|
|
159
|
-
notIn?: boolean[];
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// ============================================================================
|
|
163
|
-
// UUID filter
|
|
164
|
-
// ============================================================================
|
|
165
|
-
|
|
166
|
-
export interface UUIDFilter {
|
|
167
|
-
isNull?: boolean;
|
|
168
|
-
equalTo?: string;
|
|
169
|
-
notEqualTo?: string;
|
|
170
|
-
distinctFrom?: string;
|
|
171
|
-
notDistinctFrom?: string;
|
|
172
|
-
in?: string[];
|
|
173
|
-
notIn?: string[];
|
|
174
|
-
lessThan?: string;
|
|
175
|
-
lessThanOrEqualTo?: string;
|
|
176
|
-
greaterThan?: string;
|
|
177
|
-
greaterThanOrEqualTo?: string;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export interface UUIDListFilter {
|
|
181
|
-
isNull?: boolean;
|
|
182
|
-
equalTo?: string[];
|
|
183
|
-
notEqualTo?: string[];
|
|
184
|
-
distinctFrom?: string[];
|
|
185
|
-
notDistinctFrom?: string[];
|
|
186
|
-
lessThan?: string[];
|
|
187
|
-
lessThanOrEqualTo?: string[];
|
|
188
|
-
greaterThan?: string[];
|
|
189
|
-
greaterThanOrEqualTo?: string[];
|
|
190
|
-
contains?: string[];
|
|
191
|
-
containedBy?: string[];
|
|
192
|
-
overlaps?: string[];
|
|
193
|
-
anyEqualTo?: string;
|
|
194
|
-
anyNotEqualTo?: string;
|
|
195
|
-
anyLessThan?: string;
|
|
196
|
-
anyLessThanOrEqualTo?: string;
|
|
197
|
-
anyGreaterThan?: string;
|
|
198
|
-
anyGreaterThanOrEqualTo?: string;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// ============================================================================
|
|
202
|
-
// Date/Time filters
|
|
203
|
-
// ============================================================================
|
|
204
|
-
|
|
205
|
-
export interface DatetimeFilter {
|
|
206
|
-
isNull?: boolean;
|
|
207
|
-
equalTo?: string;
|
|
208
|
-
notEqualTo?: string;
|
|
209
|
-
distinctFrom?: string;
|
|
210
|
-
notDistinctFrom?: string;
|
|
211
|
-
in?: string[];
|
|
212
|
-
notIn?: string[];
|
|
213
|
-
lessThan?: string;
|
|
214
|
-
lessThanOrEqualTo?: string;
|
|
215
|
-
greaterThan?: string;
|
|
216
|
-
greaterThanOrEqualTo?: string;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
export interface DateFilter {
|
|
220
|
-
isNull?: boolean;
|
|
221
|
-
equalTo?: string;
|
|
222
|
-
notEqualTo?: string;
|
|
223
|
-
distinctFrom?: string;
|
|
224
|
-
notDistinctFrom?: string;
|
|
225
|
-
in?: string[];
|
|
226
|
-
notIn?: string[];
|
|
227
|
-
lessThan?: string;
|
|
228
|
-
lessThanOrEqualTo?: string;
|
|
229
|
-
greaterThan?: string;
|
|
230
|
-
greaterThanOrEqualTo?: string;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
export interface TimeFilter {
|
|
234
|
-
isNull?: boolean;
|
|
235
|
-
equalTo?: string;
|
|
236
|
-
notEqualTo?: string;
|
|
237
|
-
distinctFrom?: string;
|
|
238
|
-
notDistinctFrom?: string;
|
|
239
|
-
in?: string[];
|
|
240
|
-
notIn?: string[];
|
|
241
|
-
lessThan?: string;
|
|
242
|
-
lessThanOrEqualTo?: string;
|
|
243
|
-
greaterThan?: string;
|
|
244
|
-
greaterThanOrEqualTo?: string;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
// ============================================================================
|
|
248
|
-
// JSON filter
|
|
249
|
-
// ============================================================================
|
|
250
|
-
|
|
251
|
-
export interface JSONFilter {
|
|
252
|
-
isNull?: boolean;
|
|
253
|
-
equalTo?: unknown;
|
|
254
|
-
notEqualTo?: unknown;
|
|
255
|
-
distinctFrom?: unknown;
|
|
256
|
-
notDistinctFrom?: unknown;
|
|
257
|
-
in?: unknown[];
|
|
258
|
-
notIn?: unknown[];
|
|
259
|
-
contains?: unknown;
|
|
260
|
-
containedBy?: unknown;
|
|
261
|
-
containsKey?: string;
|
|
262
|
-
containsAllKeys?: string[];
|
|
263
|
-
containsAnyKeys?: string[];
|
|
264
|
-
}
|
|
265
|
-
`;
|
|
266
|
-
}
|
|
267
|
-
// ============================================================================
|
|
268
|
-
// Table-specific filter generators
|
|
269
|
-
// ============================================================================
|
|
270
|
-
/**
|
|
271
|
-
* Generate filter interface for a specific table
|
|
272
|
-
*/
|
|
273
|
-
export function generateTableFilter(table) {
|
|
274
|
-
const filterTypeName = getFilterTypeName(table);
|
|
275
|
-
const scalarFields = getScalarFields(table);
|
|
276
|
-
const fieldFilters = scalarFields
|
|
277
|
-
.map((field) => {
|
|
278
|
-
const filterType = getFieldFilterType(field);
|
|
279
|
-
if (!filterType)
|
|
280
|
-
return null;
|
|
281
|
-
return ` ${field.name}?: ${filterType};`;
|
|
282
|
-
})
|
|
283
|
-
.filter(Boolean)
|
|
284
|
-
.join('\n');
|
|
285
|
-
return `export interface ${filterTypeName} {
|
|
286
|
-
${fieldFilters}
|
|
287
|
-
/** Logical AND */
|
|
288
|
-
and?: ${filterTypeName}[];
|
|
289
|
-
/** Logical OR */
|
|
290
|
-
or?: ${filterTypeName}[];
|
|
291
|
-
/** Logical NOT */
|
|
292
|
-
not?: ${filterTypeName};
|
|
293
|
-
}`;
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* Get the filter type for a specific field
|
|
297
|
-
*/
|
|
298
|
-
function getFieldFilterType(field) {
|
|
299
|
-
const { gqlType, isArray } = field.type;
|
|
300
|
-
// Handle array types
|
|
301
|
-
if (isArray) {
|
|
302
|
-
const cleanType = gqlType.replace(/!/g, '');
|
|
303
|
-
switch (cleanType) {
|
|
304
|
-
case 'String':
|
|
305
|
-
return 'StringListFilter';
|
|
306
|
-
case 'Int':
|
|
307
|
-
return 'IntListFilter';
|
|
308
|
-
case 'UUID':
|
|
309
|
-
return 'UUIDListFilter';
|
|
310
|
-
default:
|
|
311
|
-
return null;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
return getScalarFilterType(gqlType);
|
|
315
|
-
}
|
|
316
|
-
// ============================================================================
|
|
317
|
-
// OrderBy enum generators
|
|
318
|
-
// ============================================================================
|
|
319
|
-
/**
|
|
320
|
-
* Generate OrderBy type for a specific table
|
|
321
|
-
*/
|
|
322
|
-
export function generateTableOrderBy(table) {
|
|
323
|
-
const orderByTypeName = getOrderByTypeName(table);
|
|
324
|
-
const scalarFields = getScalarFields(table);
|
|
325
|
-
const fieldOrderBys = scalarFields.flatMap((field) => {
|
|
326
|
-
const screamingName = toScreamingSnake(field.name);
|
|
327
|
-
return [`'${screamingName}_ASC'`, `'${screamingName}_DESC'`];
|
|
328
|
-
});
|
|
329
|
-
// Add standard PostGraphile order options
|
|
330
|
-
const standardOrderBys = [
|
|
331
|
-
"'NATURAL'",
|
|
332
|
-
"'PRIMARY_KEY_ASC'",
|
|
333
|
-
"'PRIMARY_KEY_DESC'",
|
|
334
|
-
];
|
|
335
|
-
const allOrderBys = [...fieldOrderBys, ...standardOrderBys];
|
|
336
|
-
return `export type ${orderByTypeName} = ${allOrderBys.join(' | ')};`;
|
|
337
|
-
}
|
|
338
|
-
// ============================================================================
|
|
339
|
-
// Combined generators for hook files
|
|
340
|
-
// ============================================================================
|
|
341
|
-
/**
|
|
342
|
-
* Generate inline filter and orderBy types for a query hook file
|
|
343
|
-
* These are embedded directly in the hook file for self-containment
|
|
344
|
-
*/
|
|
345
|
-
export function generateInlineFilterTypes(table) {
|
|
346
|
-
const filterDef = generateTableFilter(table);
|
|
347
|
-
const orderByDef = generateTableOrderBy(table);
|
|
348
|
-
return `${filterDef}
|
|
349
|
-
|
|
350
|
-
${orderByDef}`;
|
|
351
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
// Jest globals - no import needed
|
|
2
|
-
import { generateInputTypesFile } from './input-types-generator';
|
|
3
|
-
const uuidType = { gqlType: 'UUID', isArray: false };
|
|
4
|
-
const stringType = { gqlType: 'String', isArray: false };
|
|
5
|
-
function createTable(table) {
|
|
6
|
-
return {
|
|
7
|
-
name: table.name,
|
|
8
|
-
fields: table.fields ?? [],
|
|
9
|
-
relations: table.relations ?? {
|
|
10
|
-
belongsTo: [],
|
|
11
|
-
hasOne: [],
|
|
12
|
-
hasMany: [],
|
|
13
|
-
manyToMany: [],
|
|
14
|
-
},
|
|
15
|
-
query: table.query,
|
|
16
|
-
inflection: table.inflection,
|
|
17
|
-
constraints: table.constraints,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
describe('input-types-generator', () => {
|
|
21
|
-
it('emits relation helpers and select types with related names', () => {
|
|
22
|
-
const userTable = createTable({
|
|
23
|
-
name: 'User',
|
|
24
|
-
fields: [
|
|
25
|
-
{ name: 'id', type: uuidType },
|
|
26
|
-
{ name: 'name', type: stringType },
|
|
27
|
-
],
|
|
28
|
-
relations: {
|
|
29
|
-
belongsTo: [],
|
|
30
|
-
hasOne: [],
|
|
31
|
-
hasMany: [
|
|
32
|
-
{
|
|
33
|
-
fieldName: 'posts',
|
|
34
|
-
isUnique: false,
|
|
35
|
-
referencedByTable: 'Post',
|
|
36
|
-
type: null,
|
|
37
|
-
keys: [],
|
|
38
|
-
},
|
|
39
|
-
],
|
|
40
|
-
manyToMany: [],
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
const postTable = createTable({
|
|
44
|
-
name: 'Post',
|
|
45
|
-
fields: [
|
|
46
|
-
{ name: 'id', type: uuidType },
|
|
47
|
-
{ name: 'title', type: stringType },
|
|
48
|
-
],
|
|
49
|
-
relations: {
|
|
50
|
-
belongsTo: [
|
|
51
|
-
{
|
|
52
|
-
fieldName: 'author',
|
|
53
|
-
isUnique: false,
|
|
54
|
-
referencesTable: 'User',
|
|
55
|
-
type: null,
|
|
56
|
-
keys: [],
|
|
57
|
-
},
|
|
58
|
-
],
|
|
59
|
-
hasOne: [],
|
|
60
|
-
hasMany: [],
|
|
61
|
-
manyToMany: [],
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
const result = generateInputTypesFile(new Map(), new Set(), [userTable, postTable]);
|
|
65
|
-
expect(result.content).toContain('export interface ConnectionResult<T>');
|
|
66
|
-
expect(result.content).toContain('export interface UserRelations');
|
|
67
|
-
expect(result.content).toContain('posts?: ConnectionResult<Post>');
|
|
68
|
-
expect(result.content).toContain('export type UserWithRelations = User & UserRelations;');
|
|
69
|
-
expect(result.content).toContain('posts?: boolean | {');
|
|
70
|
-
expect(result.content).toContain('orderBy?: PostsOrderBy[];');
|
|
71
|
-
expect(result.content).toContain('author?: boolean | { select?: UserSelect };');
|
|
72
|
-
});
|
|
73
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type-level tests for select-types.ts
|
|
3
|
-
*
|
|
4
|
-
* These tests verify the compile-time type inference behavior.
|
|
5
|
-
* The TypeScript compiler validates these types during build.
|
|
6
|
-
*
|
|
7
|
-
* Note: Type-only tests using expectTypeOf have been removed as they
|
|
8
|
-
* are not compatible with Jest. The TypeScript compiler validates
|
|
9
|
-
* these types at compile time via the type assertions below.
|
|
10
|
-
*/
|
|
11
|
-
export {};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type-level tests for select-types.ts
|
|
3
|
-
*
|
|
4
|
-
* These tests verify the compile-time type inference behavior.
|
|
5
|
-
* The TypeScript compiler validates these types during build.
|
|
6
|
-
*
|
|
7
|
-
* Note: Type-only tests using expectTypeOf have been removed as they
|
|
8
|
-
* are not compatible with Jest. The TypeScript compiler validates
|
|
9
|
-
* these types at compile time via the type assertions below.
|
|
10
|
-
*/
|
|
11
|
-
// Compile-time type check: verify the inferred type matches expected structure
|
|
12
|
-
const _typeCheck = {};
|
|
13
|
-
const _excludedTypeCheck = {};
|
|
14
|
-
// Dummy test to satisfy Jest
|
|
15
|
-
describe('InferSelectResult', () => {
|
|
16
|
-
it('type assertions compile correctly', () => {
|
|
17
|
-
// If this file compiles, the type tests pass
|
|
18
|
-
expect(true).toBe(true);
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
// Jest globals - no import needed
|
|
2
|
-
import { getTableOperationNames, getCustomOperations, isTableOperation, } from './transform-schema';
|
|
3
|
-
describe('transform-schema table operation filtering', () => {
|
|
4
|
-
const dummyReturnType = { kind: 'SCALAR', name: 'String' };
|
|
5
|
-
it('detects table operations and update/delete patterns', () => {
|
|
6
|
-
const tableOps = getTableOperationNames([
|
|
7
|
-
{
|
|
8
|
-
name: 'User',
|
|
9
|
-
query: {
|
|
10
|
-
all: 'users',
|
|
11
|
-
one: 'user',
|
|
12
|
-
create: 'createUser',
|
|
13
|
-
update: 'updateUser',
|
|
14
|
-
delete: 'deleteUser',
|
|
15
|
-
},
|
|
16
|
-
inflection: { tableType: 'User' },
|
|
17
|
-
},
|
|
18
|
-
]);
|
|
19
|
-
const updateByEmail = {
|
|
20
|
-
name: 'updateUserByEmail',
|
|
21
|
-
kind: 'mutation',
|
|
22
|
-
args: [],
|
|
23
|
-
returnType: dummyReturnType,
|
|
24
|
-
};
|
|
25
|
-
const login = {
|
|
26
|
-
name: 'login',
|
|
27
|
-
kind: 'mutation',
|
|
28
|
-
args: [],
|
|
29
|
-
returnType: dummyReturnType,
|
|
30
|
-
};
|
|
31
|
-
expect(isTableOperation(updateByEmail, tableOps)).toBe(true);
|
|
32
|
-
expect(isTableOperation(login, tableOps)).toBe(false);
|
|
33
|
-
});
|
|
34
|
-
it('filters out table operations from custom list', () => {
|
|
35
|
-
const tableOps = getTableOperationNames([
|
|
36
|
-
{
|
|
37
|
-
name: 'User',
|
|
38
|
-
query: {
|
|
39
|
-
all: 'users',
|
|
40
|
-
one: 'user',
|
|
41
|
-
create: 'createUser',
|
|
42
|
-
update: 'updateUser',
|
|
43
|
-
delete: 'deleteUser',
|
|
44
|
-
},
|
|
45
|
-
inflection: { tableType: 'User' },
|
|
46
|
-
},
|
|
47
|
-
]);
|
|
48
|
-
const operations = [
|
|
49
|
-
{
|
|
50
|
-
name: 'users',
|
|
51
|
-
kind: 'query',
|
|
52
|
-
args: [],
|
|
53
|
-
returnType: dummyReturnType,
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
name: 'login',
|
|
57
|
-
kind: 'mutation',
|
|
58
|
-
args: [],
|
|
59
|
-
returnType: dummyReturnType,
|
|
60
|
-
},
|
|
61
|
-
];
|
|
62
|
-
const customOps = getCustomOperations(operations, tableOps);
|
|
63
|
-
expect(customOps.map((op) => op.name)).toEqual(['login']);
|
|
64
|
-
});
|
|
65
|
-
});
|