@constructive-io/graphql-codegen 2.22.1 → 2.23.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.
- package/cli/codegen/barrel.d.ts +5 -1
- package/cli/codegen/barrel.js +13 -11
- package/cli/codegen/index.d.ts +3 -3
- package/cli/codegen/index.js +15 -9
- package/cli/codegen/orm/client-generator.js +3 -2
- package/cli/codegen/orm/custom-ops-generator.js +17 -4
- package/cli/codegen/orm/input-types-generator.js +129 -18
- package/cli/codegen/orm/model-generator.js +2 -1
- package/cli/codegen/orm/query-builder.d.ts +1 -1
- package/cli/codegen/orm/query-builder.js +2 -2
- package/cli/codegen/schema-types-generator.js +5 -5
- package/cli/codegen/utils.d.ts +6 -1
- package/cli/codegen/utils.js +23 -8
- package/cli/commands/generate-orm.d.ts +5 -3
- package/cli/commands/generate-orm.js +65 -84
- package/cli/commands/generate.d.ts +2 -0
- package/cli/commands/generate.js +66 -87
- package/cli/commands/shared.d.ts +74 -0
- package/cli/commands/shared.js +88 -0
- package/cli/index.js +75 -45
- package/cli/introspect/index.d.ts +8 -5
- package/cli/introspect/index.js +19 -7
- package/cli/introspect/infer-tables.d.ts +51 -0
- package/cli/introspect/infer-tables.js +550 -0
- package/cli/introspect/source/endpoint.d.ts +34 -0
- package/cli/introspect/source/endpoint.js +35 -0
- package/cli/introspect/source/file.d.ts +20 -0
- package/cli/introspect/source/file.js +103 -0
- package/cli/introspect/source/index.d.ts +48 -0
- package/cli/introspect/source/index.js +72 -0
- package/cli/introspect/source/types.d.ts +58 -0
- package/cli/introspect/source/types.js +27 -0
- package/cli/introspect/transform.d.ts +5 -6
- package/cli/introspect/transform.js +0 -173
- package/cli/watch/cache.d.ts +3 -4
- package/cli/watch/cache.js +6 -10
- package/cli/watch/poller.d.ts +1 -2
- package/cli/watch/poller.js +27 -45
- package/cli/watch/types.d.ts +0 -3
- package/core/ast.js +4 -4
- package/core/query-builder.js +12 -12
- package/esm/cli/codegen/barrel.d.ts +5 -1
- package/esm/cli/codegen/barrel.js +13 -11
- package/esm/cli/codegen/index.d.ts +3 -3
- package/esm/cli/codegen/index.js +18 -12
- package/esm/cli/codegen/orm/client-generator.js +3 -2
- package/esm/cli/codegen/orm/custom-ops-generator.js +18 -5
- package/esm/cli/codegen/orm/input-types-generator.js +130 -19
- package/esm/cli/codegen/orm/model-generator.js +3 -2
- package/esm/cli/codegen/orm/query-builder.d.ts +1 -1
- package/esm/cli/codegen/orm/query-builder.js +2 -2
- package/esm/cli/codegen/schema-types-generator.js +6 -6
- package/esm/cli/codegen/utils.d.ts +6 -1
- package/esm/cli/codegen/utils.js +22 -8
- package/esm/cli/commands/generate-orm.d.ts +5 -3
- package/esm/cli/commands/generate-orm.js +65 -84
- package/esm/cli/commands/generate.d.ts +2 -0
- package/esm/cli/commands/generate.js +66 -87
- package/esm/cli/commands/shared.d.ts +74 -0
- package/esm/cli/commands/shared.js +84 -0
- package/esm/cli/index.js +76 -46
- package/esm/cli/introspect/index.d.ts +8 -5
- package/esm/cli/introspect/index.js +10 -3
- package/esm/cli/introspect/infer-tables.d.ts +51 -0
- package/esm/cli/introspect/infer-tables.js +547 -0
- package/esm/cli/introspect/source/endpoint.d.ts +34 -0
- package/esm/cli/introspect/source/endpoint.js +31 -0
- package/esm/cli/introspect/source/file.d.ts +20 -0
- package/esm/cli/introspect/source/file.js +66 -0
- package/esm/cli/introspect/source/index.d.ts +48 -0
- package/esm/cli/introspect/source/index.js +54 -0
- package/esm/cli/introspect/source/types.d.ts +58 -0
- package/esm/cli/introspect/source/types.js +23 -0
- package/esm/cli/introspect/transform.d.ts +5 -6
- package/esm/cli/introspect/transform.js +0 -172
- package/esm/cli/watch/cache.d.ts +3 -4
- package/esm/cli/watch/cache.js +7 -11
- package/esm/cli/watch/poller.d.ts +1 -2
- package/esm/cli/watch/poller.js +28 -46
- package/esm/cli/watch/types.d.ts +0 -3
- package/esm/core/ast.js +4 -4
- package/esm/core/query-builder.js +12 -12
- package/esm/generators/mutations.js +3 -3
- package/esm/generators/select.js +7 -7
- package/esm/types/config.d.ts +21 -5
- package/esm/types/config.js +2 -1
- package/generators/mutations.js +3 -3
- package/generators/select.js +7 -7
- package/package.json +5 -3
- package/types/config.d.ts +21 -5
- package/types/config.js +2 -1
- package/cli/introspect/fetch-meta.d.ts +0 -31
- package/cli/introspect/fetch-meta.js +0 -108
- package/cli/introspect/meta-query.d.ts +0 -111
- package/cli/introspect/meta-query.js +0 -191
- package/esm/cli/introspect/fetch-meta.d.ts +0 -31
- package/esm/cli/introspect/fetch-meta.js +0 -104
- package/esm/cli/introspect/meta-query.d.ts +0 -111
- package/esm/cli/introspect/meta-query.js +0 -188
package/cli/watch/poller.js
CHANGED
|
@@ -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 {
|
|
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
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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(
|
|
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,
|
|
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,
|
|
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
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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 &&
|
|
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(
|
|
200
|
-
|
|
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
|
}
|
package/cli/watch/types.d.ts
CHANGED
|
@@ -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
|
}
|
package/core/ast.js
CHANGED
|
@@ -36,7 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.deleteOne = exports.patchOne = exports.createOne = exports.getOne = exports.getMany = exports.getCount = exports.getAll = void 0;
|
|
37
37
|
exports.getSelections = getSelections;
|
|
38
38
|
const t = __importStar(require("gql-ast"));
|
|
39
|
-
const
|
|
39
|
+
const inflekt_1 = require("inflekt");
|
|
40
40
|
const custom_ast_1 = require("./custom-ast");
|
|
41
41
|
const NON_MUTABLE_PROPS = ['createdAt', 'createdBy', 'updatedAt', 'updatedBy'];
|
|
42
42
|
const objectToArray = (obj) => Object.keys(obj).map((k) => ({
|
|
@@ -320,7 +320,7 @@ const createOne = ({ mutationName, operationName, mutation, selection, }) => {
|
|
|
320
320
|
if (!mutation.properties?.input?.properties) {
|
|
321
321
|
throw new Error(`No input field for mutation: ${mutationName}`);
|
|
322
322
|
}
|
|
323
|
-
const modelName =
|
|
323
|
+
const modelName = (0, inflekt_1.camelize)([(0, inflekt_1.singularize)(mutation.model)].join('_'), true);
|
|
324
324
|
const inputProperties = mutation.properties.input
|
|
325
325
|
.properties;
|
|
326
326
|
const modelProperties = inputProperties[modelName];
|
|
@@ -366,7 +366,7 @@ const patchOne = ({ mutationName, operationName, mutation, selection, }) => {
|
|
|
366
366
|
if (!mutation.properties?.input?.properties) {
|
|
367
367
|
throw new Error(`No input field for mutation: ${mutationName}`);
|
|
368
368
|
}
|
|
369
|
-
const modelName =
|
|
369
|
+
const modelName = (0, inflekt_1.camelize)([(0, inflekt_1.singularize)(mutation.model)].join('_'), true);
|
|
370
370
|
const inputProperties = mutation.properties.input
|
|
371
371
|
.properties;
|
|
372
372
|
const patchProperties = inputProperties['patch'];
|
|
@@ -419,7 +419,7 @@ const deleteOne = ({ mutationName, operationName, mutation, }) => {
|
|
|
419
419
|
if (!mutation.properties?.input?.properties) {
|
|
420
420
|
throw new Error(`No input field for mutation: ${mutationName}`);
|
|
421
421
|
}
|
|
422
|
-
const modelName =
|
|
422
|
+
const modelName = (0, inflekt_1.camelize)([(0, inflekt_1.singularize)(mutation.model)].join('_'), true);
|
|
423
423
|
const inputProperties = mutation.properties.input
|
|
424
424
|
.properties;
|
|
425
425
|
const deleteAttrs = objectToArray(inputProperties);
|
package/core/query-builder.js
CHANGED
|
@@ -35,7 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.QueryBuilder = exports.MetaObject = void 0;
|
|
37
37
|
const graphql_1 = require("graphql");
|
|
38
|
-
const
|
|
38
|
+
const inflekt_1 = require("inflekt");
|
|
39
39
|
const ast_1 = require("./ast");
|
|
40
40
|
const meta_object_1 = require("./meta-object");
|
|
41
41
|
exports.MetaObject = __importStar(require("./meta-object"));
|
|
@@ -124,13 +124,13 @@ class QueryBuilder {
|
|
|
124
124
|
const getInputName = (mutationType) => {
|
|
125
125
|
switch (mutationType) {
|
|
126
126
|
case 'delete': {
|
|
127
|
-
return `Delete${
|
|
127
|
+
return `Delete${(0, inflekt_1.camelize)(this._model)}Input`;
|
|
128
128
|
}
|
|
129
129
|
case 'create': {
|
|
130
|
-
return `Create${
|
|
130
|
+
return `Create${(0, inflekt_1.camelize)(this._model)}Input`;
|
|
131
131
|
}
|
|
132
132
|
case 'patch': {
|
|
133
|
-
return `Update${
|
|
133
|
+
return `Update${(0, inflekt_1.camelize)(this._model)}Input`;
|
|
134
134
|
}
|
|
135
135
|
default:
|
|
136
136
|
throw new Error('Unhandled mutation type' + mutationType);
|
|
@@ -159,7 +159,7 @@ class QueryBuilder {
|
|
|
159
159
|
getMany({ select } = {}) {
|
|
160
160
|
this._op = 'getMany';
|
|
161
161
|
this._key = this._findQuery();
|
|
162
|
-
this.queryName(
|
|
162
|
+
this.queryName((0, inflekt_1.camelize)(['get', (0, inflekt_1.underscore)(this._key), 'query'].join('_'), true));
|
|
163
163
|
const defn = this._introspection[this._key];
|
|
164
164
|
this.select(select);
|
|
165
165
|
this._ast = (0, ast_1.getMany)({
|
|
@@ -174,7 +174,7 @@ class QueryBuilder {
|
|
|
174
174
|
all({ select } = {}) {
|
|
175
175
|
this._op = 'getMany';
|
|
176
176
|
this._key = this._findQuery();
|
|
177
|
-
this.queryName(
|
|
177
|
+
this.queryName((0, inflekt_1.camelize)(['get', (0, inflekt_1.underscore)(this._key), 'query', 'all'].join('_'), true));
|
|
178
178
|
const defn = this._introspection[this._key];
|
|
179
179
|
this.select(select);
|
|
180
180
|
this._ast = (0, ast_1.getAll)({
|
|
@@ -188,7 +188,7 @@ class QueryBuilder {
|
|
|
188
188
|
count() {
|
|
189
189
|
this._op = 'getMany';
|
|
190
190
|
this._key = this._findQuery();
|
|
191
|
-
this.queryName(
|
|
191
|
+
this.queryName((0, inflekt_1.camelize)(['get', (0, inflekt_1.underscore)(this._key), 'count', 'query'].join('_'), true));
|
|
192
192
|
const defn = this._introspection[this._key];
|
|
193
193
|
this._ast = (0, ast_1.getCount)({
|
|
194
194
|
queryName: this._queryName,
|
|
@@ -200,7 +200,7 @@ class QueryBuilder {
|
|
|
200
200
|
getOne({ select } = {}) {
|
|
201
201
|
this._op = 'getOne';
|
|
202
202
|
this._key = this._findQuery();
|
|
203
|
-
this.queryName(
|
|
203
|
+
this.queryName((0, inflekt_1.camelize)(['get', (0, inflekt_1.underscore)(this._key), 'query'].join('_'), true));
|
|
204
204
|
const defn = this._introspection[this._key];
|
|
205
205
|
this.select(select);
|
|
206
206
|
this._ast = (0, ast_1.getOne)({
|
|
@@ -216,7 +216,7 @@ class QueryBuilder {
|
|
|
216
216
|
this._op = 'mutation';
|
|
217
217
|
this._mutation = 'create';
|
|
218
218
|
this._key = this._findMutation();
|
|
219
|
-
this.queryName(
|
|
219
|
+
this.queryName((0, inflekt_1.camelize)([(0, inflekt_1.underscore)(this._key), 'mutation'].join('_'), true));
|
|
220
220
|
const defn = this._introspection[this._key];
|
|
221
221
|
this.select(select);
|
|
222
222
|
this._ast = (0, ast_1.createOne)({
|
|
@@ -231,7 +231,7 @@ class QueryBuilder {
|
|
|
231
231
|
this._op = 'mutation';
|
|
232
232
|
this._mutation = 'delete';
|
|
233
233
|
this._key = this._findMutation();
|
|
234
|
-
this.queryName(
|
|
234
|
+
this.queryName((0, inflekt_1.camelize)([(0, inflekt_1.underscore)(this._key), 'mutation'].join('_'), true));
|
|
235
235
|
const defn = this._introspection[this._key];
|
|
236
236
|
this.select(select);
|
|
237
237
|
this._ast = (0, ast_1.deleteOne)({
|
|
@@ -245,7 +245,7 @@ class QueryBuilder {
|
|
|
245
245
|
this._op = 'mutation';
|
|
246
246
|
this._mutation = 'patch';
|
|
247
247
|
this._key = this._findMutation();
|
|
248
|
-
this.queryName(
|
|
248
|
+
this.queryName((0, inflekt_1.camelize)([(0, inflekt_1.underscore)(this._key), 'mutation'].join('_'), true));
|
|
249
249
|
const defn = this._introspection[this._key];
|
|
250
250
|
this.select(select);
|
|
251
251
|
this._ast = (0, ast_1.patchOne)({
|
|
@@ -408,5 +408,5 @@ function isRelationalField(fieldName, modelMeta) {
|
|
|
408
408
|
// Get getMany op name from model
|
|
409
409
|
// ie. UserSetting => userSettings
|
|
410
410
|
function modelNameToGetMany(model) {
|
|
411
|
-
return
|
|
411
|
+
return (0, inflekt_1.camelize)((0, inflekt_1.pluralize)((0, inflekt_1.underscore)(model)), true);
|
|
412
412
|
}
|
|
@@ -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
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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';
|
package/esm/cli/codegen/index.js
CHANGED
|
@@ -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, {
|
|
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 (
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
:
|
|
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: [\${
|
|
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 &&
|
|
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([
|
|
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 = [
|
|
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 = [
|
|
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
|