@constructive-io/graphql-codegen 2.22.0 → 2.23.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.
Files changed (95) hide show
  1. package/cli/codegen/barrel.d.ts +5 -1
  2. package/cli/codegen/barrel.js +13 -11
  3. package/cli/codegen/index.d.ts +3 -3
  4. package/cli/codegen/index.js +15 -9
  5. package/cli/codegen/orm/client-generator.js +3 -2
  6. package/cli/codegen/orm/custom-ops-generator.js +17 -4
  7. package/cli/codegen/orm/input-types-generator.js +129 -18
  8. package/cli/codegen/orm/model-generator.js +2 -1
  9. package/cli/codegen/orm/query-builder.d.ts +1 -1
  10. package/cli/codegen/orm/query-builder.js +2 -2
  11. package/cli/codegen/schema-types-generator.js +5 -5
  12. package/cli/codegen/utils.d.ts +6 -1
  13. package/cli/codegen/utils.js +23 -8
  14. package/cli/commands/generate-orm.d.ts +5 -3
  15. package/cli/commands/generate-orm.js +65 -84
  16. package/cli/commands/generate.d.ts +2 -0
  17. package/cli/commands/generate.js +66 -87
  18. package/cli/commands/shared.d.ts +74 -0
  19. package/cli/commands/shared.js +88 -0
  20. package/cli/index.js +75 -45
  21. package/cli/introspect/index.d.ts +8 -5
  22. package/cli/introspect/index.js +19 -7
  23. package/cli/introspect/infer-tables.d.ts +51 -0
  24. package/cli/introspect/infer-tables.js +550 -0
  25. package/cli/introspect/pluralize.d.ts +30 -0
  26. package/cli/introspect/pluralize.js +124 -0
  27. package/cli/introspect/source/endpoint.d.ts +34 -0
  28. package/cli/introspect/source/endpoint.js +35 -0
  29. package/cli/introspect/source/file.d.ts +20 -0
  30. package/cli/introspect/source/file.js +103 -0
  31. package/cli/introspect/source/index.d.ts +48 -0
  32. package/cli/introspect/source/index.js +72 -0
  33. package/cli/introspect/source/types.d.ts +58 -0
  34. package/cli/introspect/source/types.js +27 -0
  35. package/cli/introspect/transform.d.ts +5 -6
  36. package/cli/introspect/transform.js +0 -173
  37. package/cli/watch/cache.d.ts +3 -4
  38. package/cli/watch/cache.js +6 -10
  39. package/cli/watch/poller.d.ts +1 -2
  40. package/cli/watch/poller.js +27 -45
  41. package/cli/watch/types.d.ts +0 -3
  42. package/esm/cli/codegen/barrel.d.ts +5 -1
  43. package/esm/cli/codegen/barrel.js +13 -11
  44. package/esm/cli/codegen/index.d.ts +3 -3
  45. package/esm/cli/codegen/index.js +18 -12
  46. package/esm/cli/codegen/orm/client-generator.js +3 -2
  47. package/esm/cli/codegen/orm/custom-ops-generator.js +18 -5
  48. package/esm/cli/codegen/orm/input-types-generator.js +130 -19
  49. package/esm/cli/codegen/orm/model-generator.js +3 -2
  50. package/esm/cli/codegen/orm/query-builder.d.ts +1 -1
  51. package/esm/cli/codegen/orm/query-builder.js +2 -2
  52. package/esm/cli/codegen/schema-types-generator.js +6 -6
  53. package/esm/cli/codegen/utils.d.ts +6 -1
  54. package/esm/cli/codegen/utils.js +22 -8
  55. package/esm/cli/commands/generate-orm.d.ts +5 -3
  56. package/esm/cli/commands/generate-orm.js +65 -84
  57. package/esm/cli/commands/generate.d.ts +2 -0
  58. package/esm/cli/commands/generate.js +66 -87
  59. package/esm/cli/commands/shared.d.ts +74 -0
  60. package/esm/cli/commands/shared.js +84 -0
  61. package/esm/cli/index.js +76 -46
  62. package/esm/cli/introspect/index.d.ts +8 -5
  63. package/esm/cli/introspect/index.js +10 -3
  64. package/esm/cli/introspect/infer-tables.d.ts +51 -0
  65. package/esm/cli/introspect/infer-tables.js +547 -0
  66. package/esm/cli/introspect/pluralize.d.ts +30 -0
  67. package/esm/cli/introspect/pluralize.js +83 -0
  68. package/esm/cli/introspect/source/endpoint.d.ts +34 -0
  69. package/esm/cli/introspect/source/endpoint.js +31 -0
  70. package/esm/cli/introspect/source/file.d.ts +20 -0
  71. package/esm/cli/introspect/source/file.js +66 -0
  72. package/esm/cli/introspect/source/index.d.ts +48 -0
  73. package/esm/cli/introspect/source/index.js +54 -0
  74. package/esm/cli/introspect/source/types.d.ts +58 -0
  75. package/esm/cli/introspect/source/types.js +23 -0
  76. package/esm/cli/introspect/transform.d.ts +5 -6
  77. package/esm/cli/introspect/transform.js +0 -172
  78. package/esm/cli/watch/cache.d.ts +3 -4
  79. package/esm/cli/watch/cache.js +7 -11
  80. package/esm/cli/watch/poller.d.ts +1 -2
  81. package/esm/cli/watch/poller.js +28 -46
  82. package/esm/cli/watch/types.d.ts +0 -3
  83. package/esm/types/config.d.ts +21 -5
  84. package/esm/types/config.js +2 -1
  85. package/package.json +4 -3
  86. package/types/config.d.ts +21 -5
  87. package/types/config.js +2 -1
  88. package/cli/introspect/fetch-meta.d.ts +0 -31
  89. package/cli/introspect/fetch-meta.js +0 -108
  90. package/cli/introspect/meta-query.d.ts +0 -111
  91. package/cli/introspect/meta-query.js +0 -191
  92. package/esm/cli/introspect/fetch-meta.d.ts +0 -31
  93. package/esm/cli/introspect/fetch-meta.js +0 -104
  94. package/esm/cli/introspect/meta-query.d.ts +0 -111
  95. package/esm/cli/introspect/meta-query.js +0 -188
@@ -1,181 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.transformMetaToCleanTables = transformMetaToCleanTables;
4
3
  exports.getTableNames = getTableNames;
5
4
  exports.findTable = findTable;
6
5
  exports.filterTables = filterTables;
7
- /**
8
- * Transform _meta response to CleanTable array
9
- */
10
- function transformMetaToCleanTables(metaResponse) {
11
- const { tables } = metaResponse._meta;
12
- return tables.map((table) => transformTable(table));
13
- }
14
- /**
15
- * Transform a single MetaTable to CleanTable
16
- */
17
- function transformTable(table) {
18
- return {
19
- name: table.name,
20
- fields: transformFields(table.fields),
21
- relations: transformRelations(table.relations),
22
- inflection: transformInflection(table.inflection),
23
- query: transformQuery(table.query),
24
- constraints: transformConstraints(table),
25
- };
26
- }
27
- /**
28
- * Transform MetaField[] to CleanField[]
29
- */
30
- function transformFields(fields) {
31
- return fields.map((field) => ({
32
- name: field.name,
33
- type: transformFieldType(field.type),
34
- }));
35
- }
36
- /**
37
- * Transform MetaFieldType to CleanFieldType
38
- */
39
- function transformFieldType(type) {
40
- return {
41
- gqlType: type.gqlType,
42
- isArray: type.isArray,
43
- modifier: type.modifier,
44
- pgAlias: type.pgAlias,
45
- pgType: type.pgType,
46
- subtype: type.subtype,
47
- typmod: type.typmod,
48
- };
49
- }
50
- /**
51
- * Transform table relations
52
- */
53
- function transformRelations(relations) {
54
- return {
55
- belongsTo: relations.belongsTo.map(transformBelongsTo),
56
- hasOne: relations.hasOne.map(transformHasOne),
57
- hasMany: relations.hasMany.map(transformHasMany),
58
- manyToMany: relations.manyToMany.map(transformManyToMany),
59
- };
60
- }
61
- /**
62
- * Transform belongsTo relation
63
- */
64
- function transformBelongsTo(rel) {
65
- return {
66
- fieldName: rel.fieldName,
67
- isUnique: rel.isUnique,
68
- referencesTable: rel.references.name,
69
- type: rel.type,
70
- keys: transformFields(rel.keys),
71
- };
72
- }
73
- /**
74
- * Transform hasOne relation
75
- */
76
- function transformHasOne(rel) {
77
- return {
78
- fieldName: rel.fieldName,
79
- isUnique: rel.isUnique,
80
- referencedByTable: rel.referencedBy.name,
81
- type: rel.type,
82
- keys: transformFields(rel.keys),
83
- };
84
- }
85
- /**
86
- * Transform hasMany relation
87
- */
88
- function transformHasMany(rel) {
89
- return {
90
- fieldName: rel.fieldName,
91
- isUnique: rel.isUnique,
92
- referencedByTable: rel.referencedBy.name,
93
- type: rel.type,
94
- keys: transformFields(rel.keys),
95
- };
96
- }
97
- /**
98
- * Transform manyToMany relation
99
- */
100
- function transformManyToMany(rel) {
101
- return {
102
- fieldName: rel.fieldName,
103
- rightTable: rel.rightTable.name,
104
- junctionTable: rel.junctionTable.name,
105
- type: rel.type,
106
- };
107
- }
108
- /**
109
- * Transform inflection data
110
- */
111
- function transformInflection(inflection) {
112
- return {
113
- allRows: inflection.allRows,
114
- allRowsSimple: inflection.allRowsSimple,
115
- conditionType: inflection.conditionType,
116
- connection: inflection.connection,
117
- createField: inflection.createField,
118
- createInputType: inflection.createInputType,
119
- createPayloadType: inflection.createPayloadType,
120
- deleteByPrimaryKey: inflection.deleteByPrimaryKey,
121
- deletePayloadType: inflection.deletePayloadType,
122
- edge: inflection.edge,
123
- edgeField: inflection.edgeField,
124
- enumType: inflection.enumType,
125
- filterType: inflection.filterType,
126
- inputType: inflection.inputType,
127
- orderByType: inflection.orderByType,
128
- patchField: inflection.patchField,
129
- patchType: inflection.patchType,
130
- tableFieldName: inflection.tableFieldName,
131
- tableType: inflection.tableType,
132
- typeName: inflection.typeName,
133
- updateByPrimaryKey: inflection.updateByPrimaryKey,
134
- updatePayloadType: inflection.updatePayloadType,
135
- };
136
- }
137
- /**
138
- * Transform query names
139
- */
140
- function transformQuery(query) {
141
- return {
142
- all: query.all,
143
- one: query.one,
144
- create: query.create,
145
- update: query.update,
146
- delete: query.delete,
147
- };
148
- }
149
- /**
150
- * Transform constraints
151
- */
152
- function transformConstraints(table) {
153
- return {
154
- primaryKey: table.primaryKeyConstraints.map(transformConstraint),
155
- foreignKey: table.foreignKeyConstraints.map(transformForeignKeyConstraint),
156
- unique: table.uniqueConstraints.map(transformConstraint),
157
- };
158
- }
159
- /**
160
- * Transform a basic constraint
161
- */
162
- function transformConstraint(constraint) {
163
- return {
164
- name: constraint.name,
165
- fields: transformFields(constraint.fields),
166
- };
167
- }
168
- /**
169
- * Transform a foreign key constraint
170
- */
171
- function transformForeignKeyConstraint(constraint) {
172
- return {
173
- name: constraint.name,
174
- fields: transformFields(constraint.fields),
175
- refTable: constraint.refTable.name,
176
- refFields: transformFields(constraint.refFields),
177
- };
178
- }
179
6
  /**
180
7
  * Get table names from CleanTable array
181
8
  */
@@ -4,11 +4,10 @@
4
4
  * Only stores the hash in memory - no file I/O during normal operation.
5
5
  * Touch file feature is optional and only writes when explicitly configured.
6
6
  */
7
- import type { MetaQueryResponse } from '../introspect/meta-query';
8
7
  import type { IntrospectionQueryResponse } from '../../types/introspection';
9
8
  /**
10
9
  * Lightweight in-memory schema cache
11
- * Only stores the combined hash string to detect changes
10
+ * Only stores the schema hash string to detect changes
12
11
  */
13
12
  export declare class SchemaCache {
14
13
  /** Current schema hash (in-memory only) */
@@ -17,7 +16,7 @@ export declare class SchemaCache {
17
16
  * Check if schema has changed by comparing hashes
18
17
  * This is the hot path - must be efficient
19
18
  */
20
- hasChanged(meta: MetaQueryResponse, schema: IntrospectionQueryResponse): Promise<{
19
+ hasChanged(schema: IntrospectionQueryResponse): Promise<{
21
20
  changed: boolean;
22
21
  newHash: string;
23
22
  }>;
@@ -34,7 +33,7 @@ export declare class SchemaCache {
34
33
  */
35
34
  clear(): void;
36
35
  /**
37
- * Compute hash from meta and schema responses
36
+ * Compute hash from schema response
38
37
  */
39
38
  private computeHash;
40
39
  }
@@ -46,7 +46,7 @@ const path = __importStar(require("node:path"));
46
46
  const hash_1 = require("./hash");
47
47
  /**
48
48
  * Lightweight in-memory schema cache
49
- * Only stores the combined hash string to detect changes
49
+ * Only stores the schema hash string to detect changes
50
50
  */
51
51
  class SchemaCache {
52
52
  /** Current schema hash (in-memory only) */
@@ -55,8 +55,8 @@ class SchemaCache {
55
55
  * Check if schema has changed by comparing hashes
56
56
  * This is the hot path - must be efficient
57
57
  */
58
- async hasChanged(meta, schema) {
59
- const newHash = await this.computeHash(meta, schema);
58
+ async hasChanged(schema) {
59
+ const newHash = await this.computeHash(schema);
60
60
  const changed = this.currentHash === null || this.currentHash !== newHash;
61
61
  return { changed, newHash };
62
62
  }
@@ -79,14 +79,10 @@ class SchemaCache {
79
79
  this.currentHash = null;
80
80
  }
81
81
  /**
82
- * Compute hash from meta and schema responses
82
+ * Compute hash from schema response
83
83
  */
84
- async computeHash(meta, schema) {
85
- // Hash each response separately then combine
86
- // This is more efficient than stringifying both together
87
- const metaHash = await (0, hash_1.hashObject)(meta);
88
- const schemaHash = await (0, hash_1.hashObject)(schema);
89
- return (0, hash_1.combineHashes)(metaHash, schemaHash);
84
+ async computeHash(schema) {
85
+ return (0, hash_1.hashObject)(schema);
90
86
  }
91
87
  }
92
88
  exports.SchemaCache = SchemaCache;
@@ -5,7 +5,6 @@
5
5
  * No file I/O during normal polling - only touchFile is optional file write.
6
6
  */
7
7
  import { EventEmitter } from 'node:events';
8
- import type { MetaQueryResponse } from '../introspect/meta-query';
9
8
  import type { IntrospectionQueryResponse } from '../../types/introspection';
10
9
  import { SchemaCache } from './cache';
11
10
  import type { PollResult, WatchOptions } from './types';
@@ -62,4 +61,4 @@ export declare class SchemaPoller extends EventEmitter {
62
61
  /**
63
62
  * Utility to compute schema hash without full poll
64
63
  */
65
- export declare function computeSchemaHash(meta: MetaQueryResponse, schema: IntrospectionQueryResponse): Promise<string>;
64
+ export declare function computeSchemaHash(schema: IntrospectionQueryResponse): Promise<string>;
@@ -9,7 +9,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.SchemaPoller = void 0;
10
10
  exports.computeSchemaHash = computeSchemaHash;
11
11
  const node_events_1 = require("node:events");
12
- const fetch_meta_1 = require("../introspect/fetch-meta");
13
12
  const fetch_schema_1 = require("../introspect/fetch-schema");
14
13
  const cache_1 = require("./cache");
15
14
  const hash_1 = require("./hash");
@@ -60,39 +59,31 @@ class SchemaPoller extends node_events_1.EventEmitter {
60
59
  async poll() {
61
60
  // Prevent concurrent polls
62
61
  if (this.isPolling) {
63
- return { success: false, changed: false, error: 'Poll already in progress' };
62
+ return {
63
+ success: false,
64
+ changed: false,
65
+ error: 'Poll already in progress',
66
+ };
64
67
  }
65
68
  this.isPolling = true;
66
69
  const startTime = Date.now();
67
70
  this.emit('poll-start', this.createEvent('poll-start'));
68
71
  try {
69
- // Fetch both _meta and __schema
70
- const [metaResult, schemaResult] = await Promise.all([
71
- (0, fetch_meta_1.fetchMeta)({
72
- endpoint: this.options.endpoint,
73
- authorization: this.options.authorization,
74
- headers: this.options.headers,
75
- timeout: 30000,
76
- }),
77
- (0, fetch_schema_1.fetchSchema)({
78
- endpoint: this.options.endpoint,
79
- authorization: this.options.authorization,
80
- headers: this.options.headers,
81
- timeout: 30000,
82
- }),
83
- ]);
72
+ // Fetch __schema via standard introspection
73
+ const schemaResult = await (0, fetch_schema_1.fetchSchema)({
74
+ endpoint: this.options.endpoint,
75
+ authorization: this.options.authorization,
76
+ headers: this.options.headers,
77
+ timeout: 30000,
78
+ });
84
79
  const duration = Date.now() - startTime;
85
80
  // Check for errors
86
- if (!metaResult.success) {
87
- return this.handleError(`_meta fetch failed: ${metaResult.error}`, duration);
88
- }
89
81
  if (!schemaResult.success) {
90
82
  return this.handleError(`__schema fetch failed: ${schemaResult.error}`, duration);
91
83
  }
92
- const meta = metaResult.data;
93
84
  const schema = schemaResult.data;
94
85
  // Check if schema changed
95
- const { changed, newHash } = await this.cache.hasChanged(meta, schema);
86
+ const { changed, newHash } = await this.cache.hasChanged(schema);
96
87
  // Reset error counter on success
97
88
  this.consecutiveErrors = 0;
98
89
  if (changed) {
@@ -103,11 +94,11 @@ class SchemaPoller extends node_events_1.EventEmitter {
103
94
  (0, cache_1.touchFile)(this.options.touchFile);
104
95
  }
105
96
  this.emit('schema-changed', this.createEvent('schema-changed', { hash: newHash, duration }));
106
- return { success: true, changed: true, hash: newHash, meta, schema };
97
+ return { success: true, changed: true, hash: newHash, schema };
107
98
  }
108
99
  this.emit('schema-unchanged', this.createEvent('schema-unchanged', { duration }));
109
100
  this.emit('poll-success', this.createEvent('poll-success', { duration }));
110
- return { success: true, changed: false, hash: newHash, meta, schema };
101
+ return { success: true, changed: false, hash: newHash, schema };
111
102
  }
112
103
  catch (err) {
113
104
  const duration = Date.now() - startTime;
@@ -130,22 +121,14 @@ class SchemaPoller extends node_events_1.EventEmitter {
130
121
  */
131
122
  async seedCache() {
132
123
  try {
133
- const [metaResult, schemaResult] = await Promise.all([
134
- (0, fetch_meta_1.fetchMeta)({
135
- endpoint: this.options.endpoint,
136
- authorization: this.options.authorization,
137
- headers: this.options.headers,
138
- timeout: 30000,
139
- }),
140
- (0, fetch_schema_1.fetchSchema)({
141
- endpoint: this.options.endpoint,
142
- authorization: this.options.authorization,
143
- headers: this.options.headers,
144
- timeout: 30000,
145
- }),
146
- ]);
147
- if (metaResult.success && schemaResult.success) {
148
- const { newHash } = await this.cache.hasChanged(metaResult.data, schemaResult.data);
124
+ const schemaResult = await (0, fetch_schema_1.fetchSchema)({
125
+ endpoint: this.options.endpoint,
126
+ authorization: this.options.authorization,
127
+ headers: this.options.headers,
128
+ timeout: 30000,
129
+ });
130
+ if (schemaResult.success) {
131
+ const { newHash } = await this.cache.hasChanged(schemaResult.data);
149
132
  this.cache.updateHash(newHash);
150
133
  }
151
134
  }
@@ -175,7 +158,8 @@ class SchemaPoller extends node_events_1.EventEmitter {
175
158
  this.consecutiveErrors++;
176
159
  this.emit('poll-error', this.createEvent('poll-error', { error, duration }));
177
160
  // Slow down polling after multiple consecutive errors
178
- if (this.consecutiveErrors >= this.MAX_CONSECUTIVE_ERRORS && this.pollTimer) {
161
+ if (this.consecutiveErrors >= this.MAX_CONSECUTIVE_ERRORS &&
162
+ this.pollTimer) {
179
163
  this.stop();
180
164
  const newInterval = this.options.pollInterval * 2;
181
165
  this.pollTimer = setInterval(() => {
@@ -196,8 +180,6 @@ exports.SchemaPoller = SchemaPoller;
196
180
  /**
197
181
  * Utility to compute schema hash without full poll
198
182
  */
199
- async function computeSchemaHash(meta, schema) {
200
- const metaHash = await (0, hash_1.hashObject)(meta);
201
- const schemaHash = await (0, hash_1.hashObject)(schema);
202
- return (0, hash_1.combineHashes)(metaHash, schemaHash);
183
+ async function computeSchemaHash(schema) {
184
+ return (0, hash_1.hashObject)(schema);
203
185
  }
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * Watch mode types
3
3
  */
4
- import type { MetaQueryResponse } from '../introspect/meta-query';
5
4
  import type { IntrospectionQueryResponse } from '../../types/introspection';
6
5
  /**
7
6
  * Result of a schema poll operation
@@ -14,8 +13,6 @@ export interface PollResult {
14
13
  error?: string;
15
14
  /** The new hash if successful */
16
15
  hash?: string;
17
- /** Meta response if successful */
18
- meta?: MetaQueryResponse;
19
16
  /** Schema response if successful */
20
17
  schema?: IntrospectionQueryResponse;
21
18
  }
@@ -19,7 +19,11 @@ export declare function generateMutationsBarrel(tables: CleanTable[]): string;
19
19
  * @param tables - The tables to include in the SDK
20
20
  * @param hasSchemaTypes - Whether schema-types.ts was generated
21
21
  */
22
- export declare function generateMainBarrel(tables: CleanTable[], hasSchemaTypes?: boolean): string;
22
+ export interface MainBarrelOptions {
23
+ hasSchemaTypes?: boolean;
24
+ hasMutations?: boolean;
25
+ }
26
+ export declare function generateMainBarrel(tables: CleanTable[], options?: MainBarrelOptions | boolean): string;
23
27
  /**
24
28
  * Generate queries barrel including custom query operations
25
29
  */
@@ -39,18 +39,23 @@ export function generateMutationsBarrel(tables) {
39
39
  }
40
40
  return lines.join('\n') + '\n';
41
41
  }
42
- /**
43
- * Generate the main index.ts barrel file
44
- *
45
- * @param tables - The tables to include in the SDK
46
- * @param hasSchemaTypes - Whether schema-types.ts was generated
47
- */
48
- export function generateMainBarrel(tables, hasSchemaTypes = false) {
42
+ export function generateMainBarrel(tables, options = {}) {
43
+ // Support legacy signature where second arg was just hasSchemaTypes boolean
44
+ const opts = typeof options === 'boolean'
45
+ ? { hasSchemaTypes: options, hasMutations: true }
46
+ : options;
47
+ const { hasSchemaTypes = false, hasMutations = true } = opts;
49
48
  const tableNames = tables.map((t) => t.name).join(', ');
50
49
  const schemaTypesExport = hasSchemaTypes
51
50
  ? `
52
51
  // Schema types (input, payload, enum types)
53
52
  export * from './schema-types';
53
+ `
54
+ : '';
55
+ const mutationsExport = hasMutations
56
+ ? `
57
+ // Mutation hooks
58
+ export * from './mutations';
54
59
  `
55
60
  : '';
56
61
  return `/**
@@ -91,10 +96,7 @@ export * from './types';
91
96
  ${schemaTypesExport}
92
97
  // Query hooks
93
98
  export * from './queries';
94
-
95
- // Mutation hooks
96
- export * from './mutations';
97
- `;
99
+ ${mutationsExport}`;
98
100
  }
99
101
  // ============================================================================
100
102
  // Custom operation barrels (includes both table and custom hooks)
@@ -64,8 +64,8 @@ export declare function generateAllFiles(tables: CleanTable[], config: ResolvedC
64
64
  export declare function generate(options: GenerateOptions): GenerateResult;
65
65
  export { generateClientFile } from './client';
66
66
  export { generateTypesFile } from './types';
67
- export { generateAllQueryHooks, generateListQueryHook, generateSingleQueryHook } from './queries';
67
+ export { generateAllQueryHooks, generateListQueryHook, generateSingleQueryHook, } from './queries';
68
68
  export { generateAllMutationHooks, generateCreateMutationHook, generateUpdateMutationHook, generateDeleteMutationHook, } from './mutations';
69
- export { generateAllCustomQueryHooks, generateCustomQueryHook } from './custom-queries';
70
- export { generateAllCustomMutationHooks, generateCustomMutationHook } from './custom-mutations';
69
+ export { generateAllCustomQueryHooks, generateCustomQueryHook, } from './custom-queries';
70
+ export { generateAllCustomMutationHooks, generateCustomMutationHook, } from './custom-mutations';
71
71
  export { generateQueriesBarrel, generateMutationsBarrel, generateMainBarrel, generateCustomQueriesBarrel, generateCustomMutationsBarrel, } from './barrel';
@@ -55,7 +55,9 @@ export function generate(options) {
55
55
  // 3. Generate types.ts (can now import enums from schema-types)
56
56
  files.push({
57
57
  path: 'types.ts',
58
- content: generateTypesFile(tables, { enumsFromSchemaTypes: generatedEnumNames }),
58
+ content: generateTypesFile(tables, {
59
+ enumsFromSchemaTypes: generatedEnumNames,
60
+ }),
59
61
  });
60
62
  // 4. Generate table-based query hooks (queries/*.ts)
61
63
  const queryHooks = generateAllQueryHooks(tables, { reactQueryEnabled });
@@ -119,17 +121,21 @@ export function generate(options) {
119
121
  });
120
122
  }
121
123
  }
122
- // 8. Generate mutations/index.ts barrel (includes both table and custom mutations)
123
- files.push({
124
- path: 'mutations/index.ts',
125
- content: customMutationHooks.length > 0
126
- ? generateCustomMutationsBarrel(tables, customMutationHooks.map((h) => h.operationName))
127
- : generateMutationsBarrel(tables),
128
- });
124
+ // 8. Generate mutations/index.ts barrel (only if React Query is enabled)
125
+ // When reactQuery is disabled, no mutation hooks are generated, so skip the barrel
126
+ const hasMutations = mutationHooks.length > 0 || customMutationHooks.length > 0;
127
+ if (hasMutations) {
128
+ files.push({
129
+ path: 'mutations/index.ts',
130
+ content: customMutationHooks.length > 0
131
+ ? generateCustomMutationsBarrel(tables, customMutationHooks.map((h) => h.operationName))
132
+ : generateMutationsBarrel(tables),
133
+ });
134
+ }
129
135
  // 9. Generate main index.ts barrel (with schema-types if present)
130
136
  files.push({
131
137
  path: 'index.ts',
132
- content: generateMainBarrel(tables, hasSchemaTypes),
138
+ content: generateMainBarrel(tables, { hasSchemaTypes, hasMutations }),
133
139
  });
134
140
  return {
135
141
  files,
@@ -148,8 +154,8 @@ export function generate(options) {
148
154
  // ============================================================================
149
155
  export { generateClientFile } from './client';
150
156
  export { generateTypesFile } from './types';
151
- export { generateAllQueryHooks, generateListQueryHook, generateSingleQueryHook } from './queries';
157
+ export { generateAllQueryHooks, generateListQueryHook, generateSingleQueryHook, } from './queries';
152
158
  export { generateAllMutationHooks, generateCreateMutationHook, generateUpdateMutationHook, generateDeleteMutationHook, } from './mutations';
153
- export { generateAllCustomQueryHooks, generateCustomQueryHook } from './custom-queries';
154
- export { generateAllCustomMutationHooks, generateCustomMutationHook } from './custom-mutations';
159
+ export { generateAllCustomQueryHooks, generateCustomQueryHook, } from './custom-queries';
160
+ export { generateAllCustomMutationHooks, generateCustomMutationHook, } from './custom-mutations';
155
161
  export { generateQueriesBarrel, generateMutationsBarrel, generateMainBarrel, generateCustomQueriesBarrel, generateCustomMutationsBarrel, } from './barrel';
@@ -276,7 +276,8 @@ export function buildFindManyDocument<TSelect, TWhere>(
276
276
  before?: string;
277
277
  offset?: number;
278
278
  },
279
- filterTypeName: string
279
+ filterTypeName: string,
280
+ orderByTypeName: string
280
281
  ): { document: string; variables: Record<string, unknown> } {
281
282
  const selections = select ? buildSelections(select) : 'id';
282
283
 
@@ -290,7 +291,7 @@ export function buildFindManyDocument<TSelect, TWhere>(
290
291
  variables.where = args.where;
291
292
  }
292
293
  if (args.orderBy?.length) {
293
- varDefs.push(\`$orderBy: [\${operationName}sOrderBy!]\`);
294
+ varDefs.push(\`$orderBy: [\${orderByTypeName}!]\`);
294
295
  queryArgs.push('orderBy: $orderBy');
295
296
  variables.orderBy = args.orderBy;
296
297
  }
@@ -1,16 +1,21 @@
1
1
  import { createProject, createSourceFile, getFormattedOutput, createFileHeader, createImport, } from '../ts-ast';
2
2
  import { ucFirst } from '../utils';
3
- import { typeRefToTsType, isTypeRequired, getTypeBaseName } from '../type-resolver';
3
+ import { typeRefToTsType, isTypeRequired, getTypeBaseName, } from '../type-resolver';
4
4
  import { SCALAR_NAMES } from '../scalars';
5
5
  /**
6
6
  * Collect all input type names used by operations
7
+ * Includes Input, Filter, OrderBy, and Condition types
7
8
  */
8
9
  function collectInputTypeNamesFromOps(operations) {
9
10
  const inputTypes = new Set();
10
11
  for (const op of operations) {
11
12
  for (const arg of op.args) {
12
13
  const baseName = getTypeBaseName(arg.type);
13
- if (baseName && (baseName.endsWith('Input') || baseName.endsWith('Filter'))) {
14
+ if (baseName &&
15
+ (baseName.endsWith('Input') ||
16
+ baseName.endsWith('Filter') ||
17
+ baseName.endsWith('OrderBy') ||
18
+ baseName.endsWith('Condition'))) {
14
19
  inputTypes.add(baseName);
15
20
  }
16
21
  }
@@ -18,7 +23,11 @@ function collectInputTypeNamesFromOps(operations) {
18
23
  return Array.from(inputTypes);
19
24
  }
20
25
  // Types that don't need Select types
21
- const NON_SELECT_TYPES = new Set([...SCALAR_NAMES, 'Query', 'Mutation']);
26
+ const NON_SELECT_TYPES = new Set([
27
+ ...SCALAR_NAMES,
28
+ 'Query',
29
+ 'Mutation',
30
+ ]);
22
31
  /**
23
32
  * Collect all payload/return type names from operations (for Select types)
24
33
  * Filters out scalar types
@@ -64,7 +73,9 @@ export function generateCustomQueryOpsFile(operations) {
64
73
  // Generate Select type names for payloads
65
74
  const selectTypeNames = payloadTypeNames.map((p) => `${p}Select`);
66
75
  // Combine all type imports
67
- const allTypeImports = [...new Set([...inputTypeNames, ...payloadTypeNames, ...selectTypeNames])];
76
+ const allTypeImports = [
77
+ ...new Set([...inputTypeNames, ...payloadTypeNames, ...selectTypeNames]),
78
+ ];
68
79
  // Add file header
69
80
  sourceFile.insertText(0, createFileHeader('Custom query operations') + '\n\n');
70
81
  // Add imports
@@ -197,7 +208,9 @@ export function generateCustomMutationOpsFile(operations) {
197
208
  // Generate Select type names for payloads
198
209
  const selectTypeNames = payloadTypeNames.map((p) => `${p}Select`);
199
210
  // Combine all type imports
200
- const allTypeImports = [...new Set([...inputTypeNames, ...payloadTypeNames, ...selectTypeNames])];
211
+ const allTypeImports = [
212
+ ...new Set([...inputTypeNames, ...payloadTypeNames, ...selectTypeNames]),
213
+ ];
201
214
  // Add file header
202
215
  sourceFile.insertText(0, createFileHeader('Custom mutation operations') + '\n\n');
203
216
  // Add imports