@constructive-io/graphql-codegen 2.20.1 → 2.21.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/__tests__/codegen/react-query-optional.test.d.ts +1 -0
- package/__tests__/codegen/react-query-optional.test.js +292 -0
- package/cli/codegen/custom-mutations.d.ts +7 -1
- package/cli/codegen/custom-mutations.js +11 -3
- package/cli/codegen/custom-queries.d.ts +4 -0
- package/cli/codegen/custom-queries.js +48 -38
- package/cli/codegen/index.js +5 -2
- package/cli/codegen/mutations.d.ts +12 -4
- package/cli/codegen/mutations.js +29 -7
- package/cli/codegen/queries.d.ts +7 -3
- package/cli/codegen/queries.js +154 -136
- package/esm/__tests__/codegen/react-query-optional.test.d.ts +1 -0
- package/esm/__tests__/codegen/react-query-optional.test.js +290 -0
- package/esm/cli/codegen/custom-mutations.d.ts +7 -1
- package/esm/cli/codegen/custom-mutations.js +11 -3
- package/esm/cli/codegen/custom-queries.d.ts +4 -0
- package/esm/cli/codegen/custom-queries.js +48 -38
- package/esm/cli/codegen/index.js +5 -2
- package/esm/cli/codegen/mutations.d.ts +12 -4
- package/esm/cli/codegen/mutations.js +29 -7
- package/esm/cli/codegen/queries.d.ts +7 -3
- package/esm/cli/codegen/queries.js +154 -136
- package/esm/types/config.d.ts +16 -1
- package/esm/types/config.js +6 -0
- package/package.json +2 -2
- package/types/config.d.ts +16 -1
- package/types/config.js +6 -0
|
@@ -11,15 +11,19 @@ export interface GeneratedQueryFile {
|
|
|
11
11
|
fileName: string;
|
|
12
12
|
content: string;
|
|
13
13
|
}
|
|
14
|
+
export interface QueryGeneratorOptions {
|
|
15
|
+
/** Whether to generate React Query hooks (default: true for backwards compatibility) */
|
|
16
|
+
reactQueryEnabled?: boolean;
|
|
17
|
+
}
|
|
14
18
|
/**
|
|
15
19
|
* Generate list query hook file content using AST
|
|
16
20
|
*/
|
|
17
|
-
export declare function generateListQueryHook(table: CleanTable): GeneratedQueryFile;
|
|
21
|
+
export declare function generateListQueryHook(table: CleanTable, options?: QueryGeneratorOptions): GeneratedQueryFile;
|
|
18
22
|
/**
|
|
19
23
|
* Generate single item query hook file content using AST
|
|
20
24
|
*/
|
|
21
|
-
export declare function generateSingleQueryHook(table: CleanTable): GeneratedQueryFile;
|
|
25
|
+
export declare function generateSingleQueryHook(table: CleanTable, options?: QueryGeneratorOptions): GeneratedQueryFile;
|
|
22
26
|
/**
|
|
23
27
|
* Generate all query hook files for all tables
|
|
24
28
|
*/
|
|
25
|
-
export declare function generateAllQueryHooks(tables: CleanTable[]): GeneratedQueryFile[];
|
|
29
|
+
export declare function generateAllQueryHooks(tables: CleanTable[], options?: QueryGeneratorOptions): GeneratedQueryFile[];
|
|
@@ -7,7 +7,8 @@ import { getTableNames, getListQueryHookName, getSingleQueryHookName, getListQue
|
|
|
7
7
|
/**
|
|
8
8
|
* Generate list query hook file content using AST
|
|
9
9
|
*/
|
|
10
|
-
export function generateListQueryHook(table) {
|
|
10
|
+
export function generateListQueryHook(table, options = {}) {
|
|
11
|
+
const { reactQueryEnabled = true } = options;
|
|
11
12
|
const project = createProject();
|
|
12
13
|
const { typeName, pluralName } = getTableNames(table);
|
|
13
14
|
const hookName = getListQueryHookName(table);
|
|
@@ -20,7 +21,10 @@ export function generateListQueryHook(table) {
|
|
|
20
21
|
const queryDocument = printGraphQL(queryAST);
|
|
21
22
|
const sourceFile = createSourceFile(project, getListQueryFileName(table));
|
|
22
23
|
// Add file header as leading comment
|
|
23
|
-
|
|
24
|
+
const headerText = reactQueryEnabled
|
|
25
|
+
? `List query hook for ${typeName}`
|
|
26
|
+
: `List query functions for ${typeName}`;
|
|
27
|
+
sourceFile.insertText(0, createFileHeader(headerText) + '\n\n');
|
|
24
28
|
// Collect all filter types used by this table's fields
|
|
25
29
|
const filterTypesUsed = new Set();
|
|
26
30
|
for (const field of scalarFields) {
|
|
@@ -29,23 +33,24 @@ export function generateListQueryHook(table) {
|
|
|
29
33
|
filterTypesUsed.add(filterType);
|
|
30
34
|
}
|
|
31
35
|
}
|
|
32
|
-
// Add imports
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
// Add imports - conditionally include React Query imports
|
|
37
|
+
const imports = [];
|
|
38
|
+
if (reactQueryEnabled) {
|
|
39
|
+
imports.push(createImport({
|
|
35
40
|
moduleSpecifier: '@tanstack/react-query',
|
|
36
41
|
namedImports: ['useQuery'],
|
|
37
42
|
typeOnlyNamedImports: ['UseQueryOptions', 'QueryClient'],
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
imports.push(createImport({
|
|
46
|
+
moduleSpecifier: '../client',
|
|
47
|
+
namedImports: ['execute'],
|
|
48
|
+
typeOnlyNamedImports: ['ExecuteOptions'],
|
|
49
|
+
}), createImport({
|
|
50
|
+
moduleSpecifier: '../types',
|
|
51
|
+
typeOnlyNamedImports: [typeName, ...Array.from(filterTypesUsed)],
|
|
52
|
+
}));
|
|
53
|
+
sourceFile.addImportDeclarations(imports);
|
|
49
54
|
// Re-export entity type
|
|
50
55
|
sourceFile.addStatements(`\n// Re-export entity type for convenience\nexport type { ${typeName} };\n`);
|
|
51
56
|
// Add section comment
|
|
@@ -109,27 +114,28 @@ export function generateListQueryHook(table) {
|
|
|
109
114
|
// Query key factory
|
|
110
115
|
sourceFile.addVariableStatement(createConst(`${queryName}QueryKey`, `(variables?: ${ucFirst(pluralName)}QueryVariables) =>
|
|
111
116
|
['${typeName.toLowerCase()}', 'list', variables] as const`));
|
|
112
|
-
// Add section
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
117
|
+
// Add React Query hook section (only if enabled)
|
|
118
|
+
if (reactQueryEnabled) {
|
|
119
|
+
sourceFile.addStatements('\n// ============================================================================');
|
|
120
|
+
sourceFile.addStatements('// Hook');
|
|
121
|
+
sourceFile.addStatements('// ============================================================================\n');
|
|
122
|
+
// Hook function
|
|
123
|
+
sourceFile.addFunction({
|
|
124
|
+
name: hookName,
|
|
125
|
+
isExported: true,
|
|
126
|
+
parameters: [
|
|
127
|
+
{
|
|
128
|
+
name: 'variables',
|
|
129
|
+
type: `${ucFirst(pluralName)}QueryVariables`,
|
|
130
|
+
hasQuestionToken: true,
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
name: 'options',
|
|
134
|
+
type: `Omit<UseQueryOptions<${ucFirst(pluralName)}QueryResult, Error>, 'queryKey' | 'queryFn'>`,
|
|
135
|
+
hasQuestionToken: true,
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
statements: `return useQuery({
|
|
133
139
|
queryKey: ${queryName}QueryKey(variables),
|
|
134
140
|
queryFn: () => execute<${ucFirst(pluralName)}QueryResult, ${ucFirst(pluralName)}QueryVariables>(
|
|
135
141
|
${queryName}QueryDocument,
|
|
@@ -137,9 +143,9 @@ export function generateListQueryHook(table) {
|
|
|
137
143
|
),
|
|
138
144
|
...options,
|
|
139
145
|
});`,
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
146
|
+
docs: [
|
|
147
|
+
{
|
|
148
|
+
description: `Query hook for fetching ${typeName} list
|
|
143
149
|
|
|
144
150
|
@example
|
|
145
151
|
\`\`\`tsx
|
|
@@ -149,9 +155,10 @@ const { data, isLoading } = ${hookName}({
|
|
|
149
155
|
orderBy: ['CREATED_AT_DESC'],
|
|
150
156
|
});
|
|
151
157
|
\`\`\``,
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
});
|
|
161
|
+
}
|
|
155
162
|
// Add section comment for standalone functions
|
|
156
163
|
sourceFile.addStatements('\n// ============================================================================');
|
|
157
164
|
sourceFile.addStatements('// Standalone Functions (non-React)');
|
|
@@ -197,29 +204,30 @@ const data = await queryClient.fetchQuery({
|
|
|
197
204
|
},
|
|
198
205
|
],
|
|
199
206
|
});
|
|
200
|
-
// Prefetch function (for SSR/QueryClient)
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
207
|
+
// Prefetch function (for SSR/QueryClient) - only if React Query is enabled
|
|
208
|
+
if (reactQueryEnabled) {
|
|
209
|
+
sourceFile.addFunction({
|
|
210
|
+
name: `prefetch${ucFirst(pluralName)}Query`,
|
|
211
|
+
isExported: true,
|
|
212
|
+
isAsync: true,
|
|
213
|
+
parameters: [
|
|
214
|
+
{
|
|
215
|
+
name: 'queryClient',
|
|
216
|
+
type: 'QueryClient',
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
name: 'variables',
|
|
220
|
+
type: `${ucFirst(pluralName)}QueryVariables`,
|
|
221
|
+
hasQuestionToken: true,
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
name: 'options',
|
|
225
|
+
type: 'ExecuteOptions',
|
|
226
|
+
hasQuestionToken: true,
|
|
227
|
+
},
|
|
228
|
+
],
|
|
229
|
+
returnType: 'Promise<void>',
|
|
230
|
+
statements: `await queryClient.prefetchQuery({
|
|
223
231
|
queryKey: ${queryName}QueryKey(variables),
|
|
224
232
|
queryFn: () => execute<${ucFirst(pluralName)}QueryResult, ${ucFirst(pluralName)}QueryVariables>(
|
|
225
233
|
${queryName}QueryDocument,
|
|
@@ -227,17 +235,18 @@ const data = await queryClient.fetchQuery({
|
|
|
227
235
|
options
|
|
228
236
|
),
|
|
229
237
|
});`,
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
238
|
+
docs: [
|
|
239
|
+
{
|
|
240
|
+
description: `Prefetch ${typeName} list for SSR or cache warming
|
|
233
241
|
|
|
234
242
|
@example
|
|
235
243
|
\`\`\`ts
|
|
236
244
|
await prefetch${ucFirst(pluralName)}Query(queryClient, { first: 10 });
|
|
237
245
|
\`\`\``,
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
246
|
+
},
|
|
247
|
+
],
|
|
248
|
+
});
|
|
249
|
+
}
|
|
241
250
|
return {
|
|
242
251
|
fileName: getListQueryFileName(table),
|
|
243
252
|
content: getFormattedOutput(sourceFile),
|
|
@@ -249,7 +258,8 @@ await prefetch${ucFirst(pluralName)}Query(queryClient, { first: 10 });
|
|
|
249
258
|
/**
|
|
250
259
|
* Generate single item query hook file content using AST
|
|
251
260
|
*/
|
|
252
|
-
export function generateSingleQueryHook(table) {
|
|
261
|
+
export function generateSingleQueryHook(table, options = {}) {
|
|
262
|
+
const { reactQueryEnabled = true } = options;
|
|
253
263
|
const project = createProject();
|
|
254
264
|
const { typeName, singularName } = getTableNames(table);
|
|
255
265
|
const hookName = getSingleQueryHookName(table);
|
|
@@ -259,24 +269,28 @@ export function generateSingleQueryHook(table) {
|
|
|
259
269
|
const queryDocument = printGraphQL(queryAST);
|
|
260
270
|
const sourceFile = createSourceFile(project, getSingleQueryFileName(table));
|
|
261
271
|
// Add file header
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
272
|
+
const headerText = reactQueryEnabled
|
|
273
|
+
? `Single item query hook for ${typeName}`
|
|
274
|
+
: `Single item query functions for ${typeName}`;
|
|
275
|
+
sourceFile.insertText(0, createFileHeader(headerText) + '\n\n');
|
|
276
|
+
// Add imports - conditionally include React Query imports
|
|
277
|
+
const imports = [];
|
|
278
|
+
if (reactQueryEnabled) {
|
|
279
|
+
imports.push(createImport({
|
|
266
280
|
moduleSpecifier: '@tanstack/react-query',
|
|
267
281
|
namedImports: ['useQuery'],
|
|
268
282
|
typeOnlyNamedImports: ['UseQueryOptions', 'QueryClient'],
|
|
269
|
-
})
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
283
|
+
}));
|
|
284
|
+
}
|
|
285
|
+
imports.push(createImport({
|
|
286
|
+
moduleSpecifier: '../client',
|
|
287
|
+
namedImports: ['execute'],
|
|
288
|
+
typeOnlyNamedImports: ['ExecuteOptions'],
|
|
289
|
+
}), createImport({
|
|
290
|
+
moduleSpecifier: '../types',
|
|
291
|
+
typeOnlyNamedImports: [typeName],
|
|
292
|
+
}));
|
|
293
|
+
sourceFile.addImportDeclarations(imports);
|
|
280
294
|
// Re-export entity type
|
|
281
295
|
sourceFile.addStatements(`\n// Re-export entity type for convenience\nexport type { ${typeName} };\n`);
|
|
282
296
|
// Add section comment
|
|
@@ -304,23 +318,24 @@ export function generateSingleQueryHook(table) {
|
|
|
304
318
|
// Query key factory
|
|
305
319
|
sourceFile.addVariableStatement(createConst(`${queryName}QueryKey`, `(id: string) =>
|
|
306
320
|
['${typeName.toLowerCase()}', 'detail', id] as const`));
|
|
307
|
-
// Add section
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
321
|
+
// Add React Query hook section (only if enabled)
|
|
322
|
+
if (reactQueryEnabled) {
|
|
323
|
+
sourceFile.addStatements('\n// ============================================================================');
|
|
324
|
+
sourceFile.addStatements('// Hook');
|
|
325
|
+
sourceFile.addStatements('// ============================================================================\n');
|
|
326
|
+
// Hook function
|
|
327
|
+
sourceFile.addFunction({
|
|
328
|
+
name: hookName,
|
|
329
|
+
isExported: true,
|
|
330
|
+
parameters: [
|
|
331
|
+
{ name: 'id', type: 'string' },
|
|
332
|
+
{
|
|
333
|
+
name: 'options',
|
|
334
|
+
type: `Omit<UseQueryOptions<${ucFirst(singularName)}QueryResult, Error>, 'queryKey' | 'queryFn'>`,
|
|
335
|
+
hasQuestionToken: true,
|
|
336
|
+
},
|
|
337
|
+
],
|
|
338
|
+
statements: `return useQuery({
|
|
324
339
|
queryKey: ${queryName}QueryKey(id),
|
|
325
340
|
queryFn: () => execute<${ucFirst(singularName)}QueryResult, ${ucFirst(singularName)}QueryVariables>(
|
|
326
341
|
${queryName}QueryDocument,
|
|
@@ -329,9 +344,9 @@ export function generateSingleQueryHook(table) {
|
|
|
329
344
|
enabled: !!id && (options?.enabled !== false),
|
|
330
345
|
...options,
|
|
331
346
|
});`,
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
347
|
+
docs: [
|
|
348
|
+
{
|
|
349
|
+
description: `Query hook for fetching a single ${typeName} by ID
|
|
335
350
|
|
|
336
351
|
@example
|
|
337
352
|
\`\`\`tsx
|
|
@@ -341,9 +356,10 @@ if (data?.${queryName}) {
|
|
|
341
356
|
console.log(data.${queryName}.id);
|
|
342
357
|
}
|
|
343
358
|
\`\`\``,
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
359
|
+
},
|
|
360
|
+
],
|
|
361
|
+
});
|
|
362
|
+
}
|
|
347
363
|
// Add section comment for standalone functions
|
|
348
364
|
sourceFile.addStatements('\n// ============================================================================');
|
|
349
365
|
sourceFile.addStatements('// Standalone Functions (non-React)');
|
|
@@ -378,22 +394,23 @@ const data = await fetch${ucFirst(singularName)}Query('uuid-here');
|
|
|
378
394
|
},
|
|
379
395
|
],
|
|
380
396
|
});
|
|
381
|
-
// Prefetch function (for SSR/QueryClient)
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
+
// Prefetch function (for SSR/QueryClient) - only if React Query is enabled
|
|
398
|
+
if (reactQueryEnabled) {
|
|
399
|
+
sourceFile.addFunction({
|
|
400
|
+
name: `prefetch${ucFirst(singularName)}Query`,
|
|
401
|
+
isExported: true,
|
|
402
|
+
isAsync: true,
|
|
403
|
+
parameters: [
|
|
404
|
+
{ name: 'queryClient', type: 'QueryClient' },
|
|
405
|
+
{ name: 'id', type: 'string' },
|
|
406
|
+
{
|
|
407
|
+
name: 'options',
|
|
408
|
+
type: 'ExecuteOptions',
|
|
409
|
+
hasQuestionToken: true,
|
|
410
|
+
},
|
|
411
|
+
],
|
|
412
|
+
returnType: 'Promise<void>',
|
|
413
|
+
statements: `await queryClient.prefetchQuery({
|
|
397
414
|
queryKey: ${queryName}QueryKey(id),
|
|
398
415
|
queryFn: () => execute<${ucFirst(singularName)}QueryResult, ${ucFirst(singularName)}QueryVariables>(
|
|
399
416
|
${queryName}QueryDocument,
|
|
@@ -401,17 +418,18 @@ const data = await fetch${ucFirst(singularName)}Query('uuid-here');
|
|
|
401
418
|
options
|
|
402
419
|
),
|
|
403
420
|
});`,
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
421
|
+
docs: [
|
|
422
|
+
{
|
|
423
|
+
description: `Prefetch a single ${typeName} for SSR or cache warming
|
|
407
424
|
|
|
408
425
|
@example
|
|
409
426
|
\`\`\`ts
|
|
410
427
|
await prefetch${ucFirst(singularName)}Query(queryClient, 'uuid-here');
|
|
411
428
|
\`\`\``,
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
429
|
+
},
|
|
430
|
+
],
|
|
431
|
+
});
|
|
432
|
+
}
|
|
415
433
|
return {
|
|
416
434
|
fileName: getSingleQueryFileName(table),
|
|
417
435
|
content: getFormattedOutput(sourceFile),
|
|
@@ -423,11 +441,11 @@ await prefetch${ucFirst(singularName)}Query(queryClient, 'uuid-here');
|
|
|
423
441
|
/**
|
|
424
442
|
* Generate all query hook files for all tables
|
|
425
443
|
*/
|
|
426
|
-
export function generateAllQueryHooks(tables) {
|
|
444
|
+
export function generateAllQueryHooks(tables, options = {}) {
|
|
427
445
|
const files = [];
|
|
428
446
|
for (const table of tables) {
|
|
429
|
-
files.push(generateListQueryHook(table));
|
|
430
|
-
files.push(generateSingleQueryHook(table));
|
|
447
|
+
files.push(generateListQueryHook(table, options));
|
|
448
|
+
files.push(generateSingleQueryHook(table, options));
|
|
431
449
|
}
|
|
432
450
|
return files;
|
|
433
451
|
}
|
package/esm/types/config.d.ts
CHANGED
|
@@ -95,6 +95,18 @@ export interface GraphQLSDKConfig {
|
|
|
95
95
|
*/
|
|
96
96
|
useSharedTypes?: boolean;
|
|
97
97
|
};
|
|
98
|
+
/**
|
|
99
|
+
* React Query integration options
|
|
100
|
+
* Controls whether React Query hooks are generated
|
|
101
|
+
*/
|
|
102
|
+
reactQuery?: {
|
|
103
|
+
/**
|
|
104
|
+
* Whether to generate React Query hooks (useQuery, useMutation)
|
|
105
|
+
* When false, only standalone fetch functions are generated (no React dependency)
|
|
106
|
+
* @default false
|
|
107
|
+
*/
|
|
108
|
+
enabled?: boolean;
|
|
109
|
+
};
|
|
98
110
|
/**
|
|
99
111
|
* Watch mode configuration (dev-only feature)
|
|
100
112
|
* When enabled via CLI --watch flag, the CLI will poll the endpoint for schema changes
|
|
@@ -142,7 +154,7 @@ export interface ResolvedWatchConfig {
|
|
|
142
154
|
/**
|
|
143
155
|
* Resolved configuration with defaults applied
|
|
144
156
|
*/
|
|
145
|
-
export interface ResolvedConfig extends Required<Omit<GraphQLSDKConfig, 'headers' | 'tables' | 'queries' | 'mutations' | 'hooks' | 'postgraphile' | 'codegen' | 'orm' | 'watch'>> {
|
|
157
|
+
export interface ResolvedConfig extends Required<Omit<GraphQLSDKConfig, 'headers' | 'tables' | 'queries' | 'mutations' | 'hooks' | 'postgraphile' | 'codegen' | 'orm' | 'reactQuery' | 'watch'>> {
|
|
146
158
|
headers: Record<string, string>;
|
|
147
159
|
tables: {
|
|
148
160
|
include: string[];
|
|
@@ -172,6 +184,9 @@ export interface ResolvedConfig extends Required<Omit<GraphQLSDKConfig, 'headers
|
|
|
172
184
|
output: string;
|
|
173
185
|
useSharedTypes: boolean;
|
|
174
186
|
} | null;
|
|
187
|
+
reactQuery: {
|
|
188
|
+
enabled: boolean;
|
|
189
|
+
};
|
|
175
190
|
watch: ResolvedWatchConfig;
|
|
176
191
|
}
|
|
177
192
|
/**
|
package/esm/types/config.js
CHANGED
|
@@ -42,6 +42,9 @@ export const DEFAULT_CONFIG = {
|
|
|
42
42
|
skipQueryField: true,
|
|
43
43
|
},
|
|
44
44
|
orm: null, // ORM generation disabled by default
|
|
45
|
+
reactQuery: {
|
|
46
|
+
enabled: false, // React Query hooks disabled by default
|
|
47
|
+
},
|
|
45
48
|
watch: DEFAULT_WATCH_CONFIG,
|
|
46
49
|
};
|
|
47
50
|
/**
|
|
@@ -96,6 +99,9 @@ export function resolveConfig(config) {
|
|
|
96
99
|
useSharedTypes: config.orm.useSharedTypes ?? DEFAULT_ORM_CONFIG.useSharedTypes,
|
|
97
100
|
}
|
|
98
101
|
: null,
|
|
102
|
+
reactQuery: {
|
|
103
|
+
enabled: config.reactQuery?.enabled ?? DEFAULT_CONFIG.reactQuery.enabled,
|
|
104
|
+
},
|
|
99
105
|
watch: {
|
|
100
106
|
pollInterval: config.watch?.pollInterval ?? DEFAULT_WATCH_CONFIG.pollInterval,
|
|
101
107
|
debounce: config.watch?.debounce ?? DEFAULT_WATCH_CONFIG.debounce,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constructive-io/graphql-codegen",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.21.0",
|
|
4
4
|
"description": "CLI-based GraphQL SDK generator for PostGraphile endpoints with React Query hooks",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graphql",
|
|
@@ -78,5 +78,5 @@
|
|
|
78
78
|
"ts-jest": "^29.2.5",
|
|
79
79
|
"typescript": "^5.9.3"
|
|
80
80
|
},
|
|
81
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "a8a6f2cf22eb610f385bfba63d5e6e40e0a47e50"
|
|
82
82
|
}
|
package/types/config.d.ts
CHANGED
|
@@ -95,6 +95,18 @@ export interface GraphQLSDKConfig {
|
|
|
95
95
|
*/
|
|
96
96
|
useSharedTypes?: boolean;
|
|
97
97
|
};
|
|
98
|
+
/**
|
|
99
|
+
* React Query integration options
|
|
100
|
+
* Controls whether React Query hooks are generated
|
|
101
|
+
*/
|
|
102
|
+
reactQuery?: {
|
|
103
|
+
/**
|
|
104
|
+
* Whether to generate React Query hooks (useQuery, useMutation)
|
|
105
|
+
* When false, only standalone fetch functions are generated (no React dependency)
|
|
106
|
+
* @default false
|
|
107
|
+
*/
|
|
108
|
+
enabled?: boolean;
|
|
109
|
+
};
|
|
98
110
|
/**
|
|
99
111
|
* Watch mode configuration (dev-only feature)
|
|
100
112
|
* When enabled via CLI --watch flag, the CLI will poll the endpoint for schema changes
|
|
@@ -142,7 +154,7 @@ export interface ResolvedWatchConfig {
|
|
|
142
154
|
/**
|
|
143
155
|
* Resolved configuration with defaults applied
|
|
144
156
|
*/
|
|
145
|
-
export interface ResolvedConfig extends Required<Omit<GraphQLSDKConfig, 'headers' | 'tables' | 'queries' | 'mutations' | 'hooks' | 'postgraphile' | 'codegen' | 'orm' | 'watch'>> {
|
|
157
|
+
export interface ResolvedConfig extends Required<Omit<GraphQLSDKConfig, 'headers' | 'tables' | 'queries' | 'mutations' | 'hooks' | 'postgraphile' | 'codegen' | 'orm' | 'reactQuery' | 'watch'>> {
|
|
146
158
|
headers: Record<string, string>;
|
|
147
159
|
tables: {
|
|
148
160
|
include: string[];
|
|
@@ -172,6 +184,9 @@ export interface ResolvedConfig extends Required<Omit<GraphQLSDKConfig, 'headers
|
|
|
172
184
|
output: string;
|
|
173
185
|
useSharedTypes: boolean;
|
|
174
186
|
} | null;
|
|
187
|
+
reactQuery: {
|
|
188
|
+
enabled: boolean;
|
|
189
|
+
};
|
|
175
190
|
watch: ResolvedWatchConfig;
|
|
176
191
|
}
|
|
177
192
|
/**
|
package/types/config.js
CHANGED
|
@@ -47,6 +47,9 @@ exports.DEFAULT_CONFIG = {
|
|
|
47
47
|
skipQueryField: true,
|
|
48
48
|
},
|
|
49
49
|
orm: null, // ORM generation disabled by default
|
|
50
|
+
reactQuery: {
|
|
51
|
+
enabled: false, // React Query hooks disabled by default
|
|
52
|
+
},
|
|
50
53
|
watch: exports.DEFAULT_WATCH_CONFIG,
|
|
51
54
|
};
|
|
52
55
|
/**
|
|
@@ -101,6 +104,9 @@ function resolveConfig(config) {
|
|
|
101
104
|
useSharedTypes: config.orm.useSharedTypes ?? exports.DEFAULT_ORM_CONFIG.useSharedTypes,
|
|
102
105
|
}
|
|
103
106
|
: null,
|
|
107
|
+
reactQuery: {
|
|
108
|
+
enabled: config.reactQuery?.enabled ?? exports.DEFAULT_CONFIG.reactQuery.enabled,
|
|
109
|
+
},
|
|
104
110
|
watch: {
|
|
105
111
|
pollInterval: config.watch?.pollInterval ?? exports.DEFAULT_WATCH_CONFIG.pollInterval,
|
|
106
112
|
debounce: config.watch?.debounce ?? exports.DEFAULT_WATCH_CONFIG.debounce,
|