@constructive-io/graphql-codegen 2.21.0 → 2.22.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.
Files changed (93) hide show
  1. package/cli/codegen/barrel.d.ts +4 -1
  2. package/cli/codegen/barrel.js +18 -12
  3. package/cli/codegen/client.js +33 -0
  4. package/cli/codegen/custom-mutations.d.ts +4 -0
  5. package/cli/codegen/custom-mutations.js +39 -13
  6. package/cli/codegen/custom-queries.d.ts +4 -0
  7. package/cli/codegen/custom-queries.js +36 -11
  8. package/cli/codegen/gql-ast.js +9 -5
  9. package/cli/codegen/index.js +35 -7
  10. package/cli/codegen/mutations.d.ts +2 -0
  11. package/cli/codegen/mutations.js +87 -23
  12. package/cli/codegen/orm/barrel.js +4 -2
  13. package/cli/codegen/orm/index.js +17 -0
  14. package/cli/codegen/orm/input-types-generator.js +83 -29
  15. package/cli/codegen/orm/model-generator.js +6 -4
  16. package/cli/codegen/queries.js +36 -27
  17. package/cli/codegen/scalars.d.ts +6 -4
  18. package/cli/codegen/scalars.js +17 -9
  19. package/cli/codegen/schema-types-generator.d.ts +26 -0
  20. package/cli/codegen/schema-types-generator.js +365 -0
  21. package/cli/codegen/ts-ast.d.ts +3 -1
  22. package/cli/codegen/ts-ast.js +2 -2
  23. package/cli/codegen/type-resolver.d.ts +52 -6
  24. package/cli/codegen/type-resolver.js +97 -19
  25. package/cli/codegen/types.d.ts +7 -4
  26. package/cli/codegen/types.js +94 -41
  27. package/cli/codegen/utils.d.ts +20 -2
  28. package/cli/codegen/utils.js +32 -7
  29. package/cli/commands/generate-orm.js +5 -5
  30. package/cli/commands/generate.d.ts +4 -1
  31. package/cli/commands/generate.js +27 -8
  32. package/cli/introspect/transform-schema.d.ts +33 -21
  33. package/cli/introspect/transform-schema.js +31 -21
  34. package/esm/cli/codegen/barrel.d.ts +4 -1
  35. package/esm/cli/codegen/barrel.js +18 -12
  36. package/esm/cli/codegen/client.js +33 -0
  37. package/esm/cli/codegen/custom-mutations.d.ts +4 -0
  38. package/esm/cli/codegen/custom-mutations.js +40 -14
  39. package/esm/cli/codegen/custom-queries.d.ts +4 -0
  40. package/esm/cli/codegen/custom-queries.js +37 -12
  41. package/esm/cli/codegen/gql-ast.js +10 -6
  42. package/esm/cli/codegen/index.js +35 -7
  43. package/esm/cli/codegen/mutations.d.ts +2 -0
  44. package/esm/cli/codegen/mutations.js +88 -24
  45. package/esm/cli/codegen/orm/barrel.js +4 -2
  46. package/esm/cli/codegen/orm/index.js +17 -0
  47. package/esm/cli/codegen/orm/input-types-generator.js +83 -29
  48. package/esm/cli/codegen/orm/model-generator.js +7 -5
  49. package/esm/cli/codegen/queries.js +37 -28
  50. package/esm/cli/codegen/scalars.d.ts +6 -4
  51. package/esm/cli/codegen/scalars.js +16 -8
  52. package/esm/cli/codegen/schema-types-generator.d.ts +26 -0
  53. package/esm/cli/codegen/schema-types-generator.js +362 -0
  54. package/esm/cli/codegen/ts-ast.d.ts +3 -1
  55. package/esm/cli/codegen/ts-ast.js +2 -2
  56. package/esm/cli/codegen/type-resolver.d.ts +52 -6
  57. package/esm/cli/codegen/type-resolver.js +97 -20
  58. package/esm/cli/codegen/types.d.ts +7 -4
  59. package/esm/cli/codegen/types.js +95 -41
  60. package/esm/cli/codegen/utils.d.ts +20 -2
  61. package/esm/cli/codegen/utils.js +31 -7
  62. package/esm/cli/commands/generate-orm.js +5 -5
  63. package/esm/cli/commands/generate.d.ts +4 -1
  64. package/esm/cli/commands/generate.js +27 -8
  65. package/esm/cli/introspect/transform-schema.d.ts +33 -21
  66. package/esm/cli/introspect/transform-schema.js +31 -21
  67. package/esm/types/schema.d.ts +2 -0
  68. package/package.json +8 -7
  69. package/types/schema.d.ts +2 -0
  70. package/__tests__/codegen/input-types-generator.test.d.ts +0 -1
  71. package/__tests__/codegen/input-types-generator.test.js +0 -635
  72. package/__tests__/codegen/react-query-optional.test.d.ts +0 -1
  73. package/__tests__/codegen/react-query-optional.test.js +0 -292
  74. package/cli/codegen/filters.d.ts +0 -27
  75. package/cli/codegen/filters.js +0 -357
  76. package/cli/codegen/orm/input-types-generator.test.d.ts +0 -1
  77. package/cli/codegen/orm/input-types-generator.test.js +0 -75
  78. package/cli/codegen/orm/select-types.test.d.ts +0 -11
  79. package/cli/codegen/orm/select-types.test.js +0 -22
  80. package/cli/introspect/transform-schema.test.d.ts +0 -1
  81. package/cli/introspect/transform-schema.test.js +0 -67
  82. package/esm/__tests__/codegen/input-types-generator.test.d.ts +0 -1
  83. package/esm/__tests__/codegen/input-types-generator.test.js +0 -633
  84. package/esm/__tests__/codegen/react-query-optional.test.d.ts +0 -1
  85. package/esm/__tests__/codegen/react-query-optional.test.js +0 -290
  86. package/esm/cli/codegen/filters.d.ts +0 -27
  87. package/esm/cli/codegen/filters.js +0 -351
  88. package/esm/cli/codegen/orm/input-types-generator.test.d.ts +0 -1
  89. package/esm/cli/codegen/orm/input-types-generator.test.js +0 -73
  90. package/esm/cli/codegen/orm/select-types.test.d.ts +0 -11
  91. package/esm/cli/codegen/orm/select-types.test.js +0 -21
  92. package/esm/cli/introspect/transform-schema.test.d.ts +0 -1
  93. package/esm/cli/introspect/transform-schema.test.js +0 -65
@@ -1,292 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /**
4
- * Tests for React Query optional flag in code generators
5
- *
6
- * Verifies that when reactQueryEnabled is false:
7
- * - Query generators skip React Query imports and hooks
8
- * - Mutation generators return null (since they require React Query)
9
- * - Standalone fetch functions are still generated for queries
10
- */
11
- const queries_1 = require("../../cli/codegen/queries");
12
- const mutations_1 = require("../../cli/codegen/mutations");
13
- const custom_queries_1 = require("../../cli/codegen/custom-queries");
14
- const custom_mutations_1 = require("../../cli/codegen/custom-mutations");
15
- // ============================================================================
16
- // Test Fixtures
17
- // ============================================================================
18
- const fieldTypes = {
19
- uuid: { gqlType: 'UUID', isArray: false },
20
- string: { gqlType: 'String', isArray: false },
21
- int: { gqlType: 'Int', isArray: false },
22
- datetime: { gqlType: 'Datetime', isArray: false },
23
- };
24
- const emptyRelations = {
25
- belongsTo: [],
26
- hasOne: [],
27
- hasMany: [],
28
- manyToMany: [],
29
- };
30
- function createTable(partial) {
31
- return {
32
- name: partial.name,
33
- fields: partial.fields ?? [],
34
- relations: partial.relations ?? emptyRelations,
35
- query: partial.query,
36
- inflection: partial.inflection,
37
- constraints: partial.constraints,
38
- };
39
- }
40
- const userTable = createTable({
41
- name: 'User',
42
- fields: [
43
- { name: 'id', type: fieldTypes.uuid },
44
- { name: 'email', type: fieldTypes.string },
45
- { name: 'name', type: fieldTypes.string },
46
- { name: 'createdAt', type: fieldTypes.datetime },
47
- ],
48
- query: {
49
- all: 'users',
50
- one: 'user',
51
- create: 'createUser',
52
- update: 'updateUser',
53
- delete: 'deleteUser',
54
- },
55
- });
56
- function createTypeRef(kind, name, ofType) {
57
- return { kind, name, ofType };
58
- }
59
- const sampleQueryOperation = {
60
- name: 'currentUser',
61
- kind: 'query',
62
- args: [],
63
- returnType: createTypeRef('OBJECT', 'User'),
64
- description: 'Get the current authenticated user',
65
- };
66
- const sampleMutationOperation = {
67
- name: 'login',
68
- kind: 'mutation',
69
- args: [
70
- { name: 'email', type: createTypeRef('NON_NULL', null, createTypeRef('SCALAR', 'String')) },
71
- { name: 'password', type: createTypeRef('NON_NULL', null, createTypeRef('SCALAR', 'String')) },
72
- ],
73
- returnType: createTypeRef('OBJECT', 'LoginPayload'),
74
- description: 'Authenticate user',
75
- };
76
- const emptyTypeRegistry = new Map();
77
- // ============================================================================
78
- // Tests - Query Generators with reactQueryEnabled: false
79
- // ============================================================================
80
- describe('Query generators with reactQueryEnabled: false', () => {
81
- describe('generateListQueryHook', () => {
82
- it('should not include React Query imports when disabled', () => {
83
- const result = (0, queries_1.generateListQueryHook)(userTable, { reactQueryEnabled: false });
84
- expect(result.content).not.toContain('@tanstack/react-query');
85
- expect(result.content).not.toContain('useQuery');
86
- expect(result.content).not.toContain('UseQueryOptions');
87
- });
88
- it('should not include useXxxQuery hook when disabled', () => {
89
- const result = (0, queries_1.generateListQueryHook)(userTable, { reactQueryEnabled: false });
90
- expect(result.content).not.toContain('export function useUsersQuery');
91
- });
92
- it('should not include prefetch function when disabled', () => {
93
- const result = (0, queries_1.generateListQueryHook)(userTable, { reactQueryEnabled: false });
94
- expect(result.content).not.toContain('export async function prefetchUsersQuery');
95
- });
96
- it('should still include standalone fetch function when disabled', () => {
97
- const result = (0, queries_1.generateListQueryHook)(userTable, { reactQueryEnabled: false });
98
- expect(result.content).toContain('export async function fetchUsersQuery');
99
- });
100
- it('should still include GraphQL document when disabled', () => {
101
- const result = (0, queries_1.generateListQueryHook)(userTable, { reactQueryEnabled: false });
102
- expect(result.content).toContain('usersQueryDocument');
103
- });
104
- it('should still include query key factory when disabled', () => {
105
- const result = (0, queries_1.generateListQueryHook)(userTable, { reactQueryEnabled: false });
106
- expect(result.content).toContain('usersQueryKey');
107
- });
108
- it('should update file header when disabled', () => {
109
- const result = (0, queries_1.generateListQueryHook)(userTable, { reactQueryEnabled: false });
110
- expect(result.content).toContain('List query functions for User');
111
- });
112
- });
113
- describe('generateSingleQueryHook', () => {
114
- it('should not include React Query imports when disabled', () => {
115
- const result = (0, queries_1.generateSingleQueryHook)(userTable, { reactQueryEnabled: false });
116
- expect(result.content).not.toContain('@tanstack/react-query');
117
- expect(result.content).not.toContain('useQuery');
118
- });
119
- it('should not include useXxxQuery hook when disabled', () => {
120
- const result = (0, queries_1.generateSingleQueryHook)(userTable, { reactQueryEnabled: false });
121
- expect(result.content).not.toContain('export function useUserQuery');
122
- });
123
- it('should still include standalone fetch function when disabled', () => {
124
- const result = (0, queries_1.generateSingleQueryHook)(userTable, { reactQueryEnabled: false });
125
- expect(result.content).toContain('export async function fetchUserQuery');
126
- });
127
- });
128
- describe('generateAllQueryHooks', () => {
129
- it('should generate files without React Query when disabled', () => {
130
- const results = (0, queries_1.generateAllQueryHooks)([userTable], { reactQueryEnabled: false });
131
- expect(results.length).toBe(2); // list + single
132
- for (const result of results) {
133
- expect(result.content).not.toContain('@tanstack/react-query');
134
- expect(result.content).not.toContain('useQuery');
135
- }
136
- });
137
- });
138
- });
139
- // ============================================================================
140
- // Tests - Query Generators with reactQueryEnabled: true (default)
141
- // ============================================================================
142
- describe('Query generators with reactQueryEnabled: true (default)', () => {
143
- describe('generateListQueryHook', () => {
144
- it('should include React Query imports by default', () => {
145
- const result = (0, queries_1.generateListQueryHook)(userTable);
146
- expect(result.content).toContain('@tanstack/react-query');
147
- expect(result.content).toContain('useQuery');
148
- });
149
- it('should include useXxxQuery hook by default', () => {
150
- const result = (0, queries_1.generateListQueryHook)(userTable);
151
- expect(result.content).toContain('export function useUsersQuery');
152
- });
153
- it('should include prefetch function by default', () => {
154
- const result = (0, queries_1.generateListQueryHook)(userTable);
155
- expect(result.content).toContain('export async function prefetchUsersQuery');
156
- });
157
- it('should include standalone fetch function by default', () => {
158
- const result = (0, queries_1.generateListQueryHook)(userTable);
159
- expect(result.content).toContain('export async function fetchUsersQuery');
160
- });
161
- });
162
- });
163
- // ============================================================================
164
- // Tests - Mutation Generators with reactQueryEnabled: false
165
- // ============================================================================
166
- describe('Mutation generators with reactQueryEnabled: false', () => {
167
- describe('generateCreateMutationHook', () => {
168
- it('should return null when disabled', () => {
169
- const result = (0, mutations_1.generateCreateMutationHook)(userTable, { reactQueryEnabled: false });
170
- expect(result).toBeNull();
171
- });
172
- });
173
- describe('generateUpdateMutationHook', () => {
174
- it('should return null when disabled', () => {
175
- const result = (0, mutations_1.generateUpdateMutationHook)(userTable, { reactQueryEnabled: false });
176
- expect(result).toBeNull();
177
- });
178
- });
179
- describe('generateDeleteMutationHook', () => {
180
- it('should return null when disabled', () => {
181
- const result = (0, mutations_1.generateDeleteMutationHook)(userTable, { reactQueryEnabled: false });
182
- expect(result).toBeNull();
183
- });
184
- });
185
- describe('generateAllMutationHooks', () => {
186
- it('should return empty array when disabled', () => {
187
- const results = (0, mutations_1.generateAllMutationHooks)([userTable], { reactQueryEnabled: false });
188
- expect(results).toEqual([]);
189
- });
190
- });
191
- });
192
- // ============================================================================
193
- // Tests - Mutation Generators with reactQueryEnabled: true (default)
194
- // ============================================================================
195
- describe('Mutation generators with reactQueryEnabled: true (default)', () => {
196
- describe('generateCreateMutationHook', () => {
197
- it('should return mutation file by default', () => {
198
- const result = (0, mutations_1.generateCreateMutationHook)(userTable);
199
- expect(result).not.toBeNull();
200
- expect(result.content).toContain('useMutation');
201
- });
202
- });
203
- describe('generateAllMutationHooks', () => {
204
- it('should return mutation files by default', () => {
205
- const results = (0, mutations_1.generateAllMutationHooks)([userTable]);
206
- expect(results.length).toBeGreaterThan(0);
207
- });
208
- });
209
- });
210
- // ============================================================================
211
- // Tests - Custom Query Generators with reactQueryEnabled: false
212
- // ============================================================================
213
- describe('Custom query generators with reactQueryEnabled: false', () => {
214
- describe('generateCustomQueryHook', () => {
215
- it('should not include React Query imports when disabled', () => {
216
- const result = (0, custom_queries_1.generateCustomQueryHook)({
217
- operation: sampleQueryOperation,
218
- typeRegistry: emptyTypeRegistry,
219
- reactQueryEnabled: false,
220
- });
221
- expect(result.content).not.toContain('@tanstack/react-query');
222
- expect(result.content).not.toContain('useQuery');
223
- });
224
- it('should not include useXxxQuery hook when disabled', () => {
225
- const result = (0, custom_queries_1.generateCustomQueryHook)({
226
- operation: sampleQueryOperation,
227
- typeRegistry: emptyTypeRegistry,
228
- reactQueryEnabled: false,
229
- });
230
- expect(result.content).not.toContain('export function useCurrentUserQuery');
231
- });
232
- it('should still include standalone fetch function when disabled', () => {
233
- const result = (0, custom_queries_1.generateCustomQueryHook)({
234
- operation: sampleQueryOperation,
235
- typeRegistry: emptyTypeRegistry,
236
- reactQueryEnabled: false,
237
- });
238
- expect(result.content).toContain('export async function fetchCurrentUserQuery');
239
- });
240
- });
241
- describe('generateAllCustomQueryHooks', () => {
242
- it('should generate files without React Query when disabled', () => {
243
- const results = (0, custom_queries_1.generateAllCustomQueryHooks)({
244
- operations: [sampleQueryOperation],
245
- typeRegistry: emptyTypeRegistry,
246
- reactQueryEnabled: false,
247
- });
248
- expect(results.length).toBe(1);
249
- expect(results[0].content).not.toContain('@tanstack/react-query');
250
- });
251
- });
252
- });
253
- // ============================================================================
254
- // Tests - Custom Mutation Generators with reactQueryEnabled: false
255
- // ============================================================================
256
- describe('Custom mutation generators with reactQueryEnabled: false', () => {
257
- describe('generateCustomMutationHook', () => {
258
- it('should return null when disabled', () => {
259
- const result = (0, custom_mutations_1.generateCustomMutationHook)({
260
- operation: sampleMutationOperation,
261
- typeRegistry: emptyTypeRegistry,
262
- reactQueryEnabled: false,
263
- });
264
- expect(result).toBeNull();
265
- });
266
- });
267
- describe('generateAllCustomMutationHooks', () => {
268
- it('should return empty array when disabled', () => {
269
- const results = (0, custom_mutations_1.generateAllCustomMutationHooks)({
270
- operations: [sampleMutationOperation],
271
- typeRegistry: emptyTypeRegistry,
272
- reactQueryEnabled: false,
273
- });
274
- expect(results).toEqual([]);
275
- });
276
- });
277
- });
278
- // ============================================================================
279
- // Tests - Custom Mutation Generators with reactQueryEnabled: true (default)
280
- // ============================================================================
281
- describe('Custom mutation generators with reactQueryEnabled: true (default)', () => {
282
- describe('generateCustomMutationHook', () => {
283
- it('should return mutation file by default', () => {
284
- const result = (0, custom_mutations_1.generateCustomMutationHook)({
285
- operation: sampleMutationOperation,
286
- typeRegistry: emptyTypeRegistry,
287
- });
288
- expect(result).not.toBeNull();
289
- expect(result.content).toContain('useMutation');
290
- });
291
- });
292
- });
@@ -1,27 +0,0 @@
1
- /**
2
- * PostGraphile filter type generators
3
- *
4
- * Generates TypeScript interfaces for PostGraphile filter types:
5
- * - Base scalar filters (StringFilter, IntFilter, etc.)
6
- * - Table-specific filters (CarFilter, UserFilter, etc.)
7
- * - OrderBy enum types
8
- */
9
- import type { CleanTable } from '../../types/schema';
10
- /**
11
- * Generate all base PostGraphile filter types
12
- * These are shared across all tables
13
- */
14
- export declare function generateBaseFilterTypes(): string;
15
- /**
16
- * Generate filter interface for a specific table
17
- */
18
- export declare function generateTableFilter(table: CleanTable): string;
19
- /**
20
- * Generate OrderBy type for a specific table
21
- */
22
- export declare function generateTableOrderBy(table: CleanTable): string;
23
- /**
24
- * Generate inline filter and orderBy types for a query hook file
25
- * These are embedded directly in the hook file for self-containment
26
- */
27
- export declare function generateInlineFilterTypes(table: CleanTable): string;
@@ -1,357 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateBaseFilterTypes = generateBaseFilterTypes;
4
- exports.generateTableFilter = generateTableFilter;
5
- exports.generateTableOrderBy = generateTableOrderBy;
6
- exports.generateInlineFilterTypes = generateInlineFilterTypes;
7
- const utils_1 = require("./utils");
8
- // ============================================================================
9
- // Base filter type definitions
10
- // ============================================================================
11
- /**
12
- * Generate all base PostGraphile filter types
13
- * These are shared across all tables
14
- */
15
- function generateBaseFilterTypes() {
16
- return `${(0, utils_1.getGeneratedFileHeader)('PostGraphile base filter types')}
17
-
18
- // ============================================================================
19
- // String filters
20
- // ============================================================================
21
-
22
- export interface StringFilter {
23
- isNull?: boolean;
24
- equalTo?: string;
25
- notEqualTo?: string;
26
- distinctFrom?: string;
27
- notDistinctFrom?: string;
28
- in?: string[];
29
- notIn?: string[];
30
- lessThan?: string;
31
- lessThanOrEqualTo?: string;
32
- greaterThan?: string;
33
- greaterThanOrEqualTo?: string;
34
- includes?: string;
35
- notIncludes?: string;
36
- includesInsensitive?: string;
37
- notIncludesInsensitive?: string;
38
- startsWith?: string;
39
- notStartsWith?: string;
40
- startsWithInsensitive?: string;
41
- notStartsWithInsensitive?: string;
42
- endsWith?: string;
43
- notEndsWith?: string;
44
- endsWithInsensitive?: string;
45
- notEndsWithInsensitive?: string;
46
- like?: string;
47
- notLike?: string;
48
- likeInsensitive?: string;
49
- notLikeInsensitive?: string;
50
- }
51
-
52
- export interface StringListFilter {
53
- isNull?: boolean;
54
- equalTo?: string[];
55
- notEqualTo?: string[];
56
- distinctFrom?: string[];
57
- notDistinctFrom?: string[];
58
- lessThan?: string[];
59
- lessThanOrEqualTo?: string[];
60
- greaterThan?: string[];
61
- greaterThanOrEqualTo?: string[];
62
- contains?: string[];
63
- containedBy?: string[];
64
- overlaps?: string[];
65
- anyEqualTo?: string;
66
- anyNotEqualTo?: string;
67
- anyLessThan?: string;
68
- anyLessThanOrEqualTo?: string;
69
- anyGreaterThan?: string;
70
- anyGreaterThanOrEqualTo?: string;
71
- }
72
-
73
- // ============================================================================
74
- // Numeric filters
75
- // ============================================================================
76
-
77
- export interface IntFilter {
78
- isNull?: boolean;
79
- equalTo?: number;
80
- notEqualTo?: number;
81
- distinctFrom?: number;
82
- notDistinctFrom?: number;
83
- in?: number[];
84
- notIn?: number[];
85
- lessThan?: number;
86
- lessThanOrEqualTo?: number;
87
- greaterThan?: number;
88
- greaterThanOrEqualTo?: number;
89
- }
90
-
91
- export interface IntListFilter {
92
- isNull?: boolean;
93
- equalTo?: number[];
94
- notEqualTo?: number[];
95
- distinctFrom?: number[];
96
- notDistinctFrom?: number[];
97
- lessThan?: number[];
98
- lessThanOrEqualTo?: number[];
99
- greaterThan?: number[];
100
- greaterThanOrEqualTo?: number[];
101
- contains?: number[];
102
- containedBy?: number[];
103
- overlaps?: number[];
104
- anyEqualTo?: number;
105
- anyNotEqualTo?: number;
106
- anyLessThan?: number;
107
- anyLessThanOrEqualTo?: number;
108
- anyGreaterThan?: number;
109
- anyGreaterThanOrEqualTo?: number;
110
- }
111
-
112
- export interface FloatFilter {
113
- isNull?: boolean;
114
- equalTo?: number;
115
- notEqualTo?: number;
116
- distinctFrom?: number;
117
- notDistinctFrom?: number;
118
- in?: number[];
119
- notIn?: number[];
120
- lessThan?: number;
121
- lessThanOrEqualTo?: number;
122
- greaterThan?: number;
123
- greaterThanOrEqualTo?: number;
124
- }
125
-
126
- export interface BigIntFilter {
127
- isNull?: boolean;
128
- equalTo?: string;
129
- notEqualTo?: string;
130
- distinctFrom?: string;
131
- notDistinctFrom?: string;
132
- in?: string[];
133
- notIn?: string[];
134
- lessThan?: string;
135
- lessThanOrEqualTo?: string;
136
- greaterThan?: string;
137
- greaterThanOrEqualTo?: string;
138
- }
139
-
140
- export interface BigFloatFilter {
141
- isNull?: boolean;
142
- equalTo?: string;
143
- notEqualTo?: string;
144
- distinctFrom?: string;
145
- notDistinctFrom?: string;
146
- in?: string[];
147
- notIn?: string[];
148
- lessThan?: string;
149
- lessThanOrEqualTo?: string;
150
- greaterThan?: string;
151
- greaterThanOrEqualTo?: string;
152
- }
153
-
154
- // ============================================================================
155
- // Boolean filter
156
- // ============================================================================
157
-
158
- export interface BooleanFilter {
159
- isNull?: boolean;
160
- equalTo?: boolean;
161
- notEqualTo?: boolean;
162
- distinctFrom?: boolean;
163
- notDistinctFrom?: boolean;
164
- in?: boolean[];
165
- notIn?: boolean[];
166
- }
167
-
168
- // ============================================================================
169
- // UUID filter
170
- // ============================================================================
171
-
172
- export interface UUIDFilter {
173
- isNull?: boolean;
174
- equalTo?: string;
175
- notEqualTo?: string;
176
- distinctFrom?: string;
177
- notDistinctFrom?: string;
178
- in?: string[];
179
- notIn?: string[];
180
- lessThan?: string;
181
- lessThanOrEqualTo?: string;
182
- greaterThan?: string;
183
- greaterThanOrEqualTo?: string;
184
- }
185
-
186
- export interface UUIDListFilter {
187
- isNull?: boolean;
188
- equalTo?: string[];
189
- notEqualTo?: string[];
190
- distinctFrom?: string[];
191
- notDistinctFrom?: string[];
192
- lessThan?: string[];
193
- lessThanOrEqualTo?: string[];
194
- greaterThan?: string[];
195
- greaterThanOrEqualTo?: string[];
196
- contains?: string[];
197
- containedBy?: string[];
198
- overlaps?: string[];
199
- anyEqualTo?: string;
200
- anyNotEqualTo?: string;
201
- anyLessThan?: string;
202
- anyLessThanOrEqualTo?: string;
203
- anyGreaterThan?: string;
204
- anyGreaterThanOrEqualTo?: string;
205
- }
206
-
207
- // ============================================================================
208
- // Date/Time filters
209
- // ============================================================================
210
-
211
- export interface DatetimeFilter {
212
- isNull?: boolean;
213
- equalTo?: string;
214
- notEqualTo?: string;
215
- distinctFrom?: string;
216
- notDistinctFrom?: string;
217
- in?: string[];
218
- notIn?: string[];
219
- lessThan?: string;
220
- lessThanOrEqualTo?: string;
221
- greaterThan?: string;
222
- greaterThanOrEqualTo?: string;
223
- }
224
-
225
- export interface DateFilter {
226
- isNull?: boolean;
227
- equalTo?: string;
228
- notEqualTo?: string;
229
- distinctFrom?: string;
230
- notDistinctFrom?: string;
231
- in?: string[];
232
- notIn?: string[];
233
- lessThan?: string;
234
- lessThanOrEqualTo?: string;
235
- greaterThan?: string;
236
- greaterThanOrEqualTo?: string;
237
- }
238
-
239
- export interface TimeFilter {
240
- isNull?: boolean;
241
- equalTo?: string;
242
- notEqualTo?: string;
243
- distinctFrom?: string;
244
- notDistinctFrom?: string;
245
- in?: string[];
246
- notIn?: string[];
247
- lessThan?: string;
248
- lessThanOrEqualTo?: string;
249
- greaterThan?: string;
250
- greaterThanOrEqualTo?: string;
251
- }
252
-
253
- // ============================================================================
254
- // JSON filter
255
- // ============================================================================
256
-
257
- export interface JSONFilter {
258
- isNull?: boolean;
259
- equalTo?: unknown;
260
- notEqualTo?: unknown;
261
- distinctFrom?: unknown;
262
- notDistinctFrom?: unknown;
263
- in?: unknown[];
264
- notIn?: unknown[];
265
- contains?: unknown;
266
- containedBy?: unknown;
267
- containsKey?: string;
268
- containsAllKeys?: string[];
269
- containsAnyKeys?: string[];
270
- }
271
- `;
272
- }
273
- // ============================================================================
274
- // Table-specific filter generators
275
- // ============================================================================
276
- /**
277
- * Generate filter interface for a specific table
278
- */
279
- function generateTableFilter(table) {
280
- const filterTypeName = (0, utils_1.getFilterTypeName)(table);
281
- const scalarFields = (0, utils_1.getScalarFields)(table);
282
- const fieldFilters = scalarFields
283
- .map((field) => {
284
- const filterType = getFieldFilterType(field);
285
- if (!filterType)
286
- return null;
287
- return ` ${field.name}?: ${filterType};`;
288
- })
289
- .filter(Boolean)
290
- .join('\n');
291
- return `export interface ${filterTypeName} {
292
- ${fieldFilters}
293
- /** Logical AND */
294
- and?: ${filterTypeName}[];
295
- /** Logical OR */
296
- or?: ${filterTypeName}[];
297
- /** Logical NOT */
298
- not?: ${filterTypeName};
299
- }`;
300
- }
301
- /**
302
- * Get the filter type for a specific field
303
- */
304
- function getFieldFilterType(field) {
305
- const { gqlType, isArray } = field.type;
306
- // Handle array types
307
- if (isArray) {
308
- const cleanType = gqlType.replace(/!/g, '');
309
- switch (cleanType) {
310
- case 'String':
311
- return 'StringListFilter';
312
- case 'Int':
313
- return 'IntListFilter';
314
- case 'UUID':
315
- return 'UUIDListFilter';
316
- default:
317
- return null;
318
- }
319
- }
320
- return (0, utils_1.getScalarFilterType)(gqlType);
321
- }
322
- // ============================================================================
323
- // OrderBy enum generators
324
- // ============================================================================
325
- /**
326
- * Generate OrderBy type for a specific table
327
- */
328
- function generateTableOrderBy(table) {
329
- const orderByTypeName = (0, utils_1.getOrderByTypeName)(table);
330
- const scalarFields = (0, utils_1.getScalarFields)(table);
331
- const fieldOrderBys = scalarFields.flatMap((field) => {
332
- const screamingName = (0, utils_1.toScreamingSnake)(field.name);
333
- return [`'${screamingName}_ASC'`, `'${screamingName}_DESC'`];
334
- });
335
- // Add standard PostGraphile order options
336
- const standardOrderBys = [
337
- "'NATURAL'",
338
- "'PRIMARY_KEY_ASC'",
339
- "'PRIMARY_KEY_DESC'",
340
- ];
341
- const allOrderBys = [...fieldOrderBys, ...standardOrderBys];
342
- return `export type ${orderByTypeName} = ${allOrderBys.join(' | ')};`;
343
- }
344
- // ============================================================================
345
- // Combined generators for hook files
346
- // ============================================================================
347
- /**
348
- * Generate inline filter and orderBy types for a query hook file
349
- * These are embedded directly in the hook file for self-containment
350
- */
351
- function generateInlineFilterTypes(table) {
352
- const filterDef = generateTableFilter(table);
353
- const orderByDef = generateTableOrderBy(table);
354
- return `${filterDef}
355
-
356
- ${orderByDef}`;
357
- }
@@ -1 +0,0 @@
1
- export {};