@constructive-io/graphql-codegen 3.2.1 → 3.3.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/cli/index.js +36 -43
- package/cli/shared.d.ts +15 -19
- package/cli/shared.js +104 -25
- package/client/error.js +31 -9
- package/client/execute.js +2 -2
- package/client/index.d.ts +3 -3
- package/client/index.js +6 -6
- package/core/ast.d.ts +1 -1
- package/core/ast.js +1 -1
- package/core/codegen/babel-ast.d.ts +1 -1
- package/core/codegen/babel-ast.js +2 -2
- package/core/codegen/barrel.d.ts +0 -6
- package/core/codegen/barrel.js +22 -19
- package/core/codegen/client.d.ts +2 -12
- package/core/codegen/client.js +7 -21
- package/core/codegen/custom-mutations.d.ts +0 -14
- package/core/codegen/custom-mutations.js +139 -88
- package/core/codegen/custom-queries.d.ts +0 -14
- package/core/codegen/custom-queries.js +483 -193
- package/core/codegen/hooks-ast.d.ts +75 -0
- package/core/codegen/hooks-ast.js +522 -0
- package/core/codegen/index.d.ts +16 -18
- package/core/codegen/index.js +42 -88
- package/core/codegen/invalidation.d.ts +1 -7
- package/core/codegen/invalidation.js +50 -16
- package/core/codegen/mutation-keys.d.ts +1 -10
- package/core/codegen/mutation-keys.js +22 -8
- package/core/codegen/mutations.d.ts +0 -13
- package/core/codegen/mutations.js +301 -366
- package/core/codegen/orm/barrel.d.ts +0 -5
- package/core/codegen/orm/barrel.js +5 -0
- package/core/codegen/orm/client-generator.d.ts +0 -5
- package/core/codegen/orm/client-generator.js +7 -2
- package/core/codegen/orm/client.js +3 -1
- package/core/codegen/orm/custom-ops-generator.d.ts +0 -6
- package/core/codegen/orm/custom-ops-generator.js +104 -51
- package/core/codegen/orm/index.d.ts +4 -4
- package/core/codegen/orm/index.js +28 -15
- package/core/codegen/orm/input-types-generator.d.ts +1 -13
- package/core/codegen/orm/input-types-generator.js +85 -23
- package/core/codegen/orm/model-generator.d.ts +0 -5
- package/core/codegen/orm/model-generator.js +309 -131
- package/core/codegen/orm/select-types.d.ts +19 -14
- package/core/codegen/queries.d.ts +0 -8
- package/core/codegen/queries.js +360 -559
- package/core/codegen/query-keys.d.ts +1 -1
- package/core/codegen/query-keys.js +37 -23
- package/core/codegen/scalars.js +3 -1
- package/core/codegen/schema-types-generator.d.ts +1 -1
- package/core/codegen/schema-types-generator.js +17 -2
- package/core/codegen/select-helpers.d.ts +19 -0
- package/core/codegen/select-helpers.js +40 -0
- package/core/codegen/selection.d.ts +4 -0
- package/core/codegen/selection.js +65 -0
- package/core/codegen/shared/index.d.ts +2 -15
- package/core/codegen/shared/index.js +17 -4
- package/core/codegen/templates/hooks-client.ts +49 -0
- package/core/codegen/templates/hooks-selection.ts +58 -0
- package/core/codegen/templates/orm-client.ts +8 -6
- package/core/codegen/templates/query-builder.ts +250 -46
- package/core/codegen/templates/select-types.ts +31 -14
- package/core/codegen/type-resolver.d.ts +1 -5
- package/core/codegen/type-resolver.js +0 -22
- package/core/codegen/types.d.ts +0 -3
- package/core/codegen/types.js +71 -14
- package/core/codegen/utils.d.ts +1 -4
- package/core/codegen/utils.js +4 -1
- package/core/config/index.d.ts +1 -1
- package/core/config/resolver.js +1 -3
- package/core/generate.js +38 -50
- package/core/index.d.ts +3 -3
- package/core/index.js +3 -4
- package/core/introspect/index.d.ts +6 -6
- package/core/introspect/index.js +5 -8
- package/core/introspect/infer-tables.d.ts +0 -14
- package/core/introspect/infer-tables.js +15 -1
- package/core/introspect/source/database.js +1 -1
- package/core/introspect/source/endpoint.d.ts +0 -6
- package/core/introspect/source/endpoint.js +7 -1
- package/core/introspect/source/index.d.ts +4 -4
- package/core/introspect/source/index.js +5 -9
- package/core/introspect/source/pgpm-module.js +3 -3
- package/core/introspect/transform-schema.d.ts +2 -2
- package/core/introspect/transform-schema.js +2 -2
- package/core/output/index.d.ts +1 -1
- package/core/output/index.js +2 -2
- package/core/output/writer.d.ts +3 -0
- package/core/output/writer.js +20 -1
- package/core/pipeline/index.d.ts +2 -2
- package/core/query-builder.d.ts +2 -2
- package/core/query-builder.js +1 -1
- package/core/watch/index.d.ts +4 -4
- package/core/watch/index.js +9 -9
- package/core/watch/orchestrator.js +5 -3
- package/esm/cli/index.js +37 -44
- package/esm/cli/shared.d.ts +15 -19
- package/esm/cli/shared.js +94 -23
- package/esm/client/error.js +31 -9
- package/esm/client/execute.js +2 -2
- package/esm/client/index.d.ts +3 -3
- package/esm/client/index.js +3 -3
- package/esm/core/ast.d.ts +1 -1
- package/esm/core/ast.js +1 -1
- package/esm/core/codegen/babel-ast.d.ts +1 -1
- package/esm/core/codegen/babel-ast.js +2 -2
- package/esm/core/codegen/barrel.d.ts +0 -6
- package/esm/core/codegen/barrel.js +23 -20
- package/esm/core/codegen/client.d.ts +2 -12
- package/esm/core/codegen/client.js +7 -21
- package/esm/core/codegen/custom-mutations.d.ts +0 -14
- package/esm/core/codegen/custom-mutations.js +141 -90
- package/esm/core/codegen/custom-queries.d.ts +0 -14
- package/esm/core/codegen/custom-queries.js +486 -196
- package/esm/core/codegen/hooks-ast.d.ts +75 -0
- package/esm/core/codegen/hooks-ast.js +424 -0
- package/esm/core/codegen/index.d.ts +16 -18
- package/esm/core/codegen/index.js +26 -71
- package/esm/core/codegen/invalidation.d.ts +1 -7
- package/esm/core/codegen/invalidation.js +51 -17
- package/esm/core/codegen/mutation-keys.d.ts +1 -10
- package/esm/core/codegen/mutation-keys.js +23 -9
- package/esm/core/codegen/mutations.d.ts +0 -13
- package/esm/core/codegen/mutations.js +302 -367
- package/esm/core/codegen/orm/barrel.d.ts +0 -5
- package/esm/core/codegen/orm/barrel.js +6 -1
- package/esm/core/codegen/orm/client-generator.d.ts +0 -5
- package/esm/core/codegen/orm/client-generator.js +7 -2
- package/esm/core/codegen/orm/client.js +3 -1
- package/esm/core/codegen/orm/custom-ops-generator.d.ts +0 -6
- package/esm/core/codegen/orm/custom-ops-generator.js +103 -50
- package/esm/core/codegen/orm/index.d.ts +4 -4
- package/esm/core/codegen/orm/index.js +25 -12
- package/esm/core/codegen/orm/input-types-generator.d.ts +1 -13
- package/esm/core/codegen/orm/input-types-generator.js +85 -23
- package/esm/core/codegen/orm/model-generator.d.ts +0 -5
- package/esm/core/codegen/orm/model-generator.js +310 -132
- package/esm/core/codegen/orm/select-types.d.ts +19 -14
- package/esm/core/codegen/queries.d.ts +0 -8
- package/esm/core/codegen/queries.js +362 -561
- package/esm/core/codegen/query-keys.d.ts +1 -1
- package/esm/core/codegen/query-keys.js +38 -24
- package/esm/core/codegen/scalars.js +3 -1
- package/esm/core/codegen/schema-types-generator.d.ts +1 -1
- package/esm/core/codegen/schema-types-generator.js +17 -2
- package/esm/core/codegen/select-helpers.d.ts +19 -0
- package/esm/core/codegen/select-helpers.js +35 -0
- package/esm/core/codegen/selection.d.ts +4 -0
- package/esm/core/codegen/selection.js +29 -0
- package/esm/core/codegen/shared/index.d.ts +2 -15
- package/esm/core/codegen/shared/index.js +16 -3
- package/esm/core/codegen/type-resolver.d.ts +1 -5
- package/esm/core/codegen/type-resolver.js +1 -22
- package/esm/core/codegen/types.d.ts +0 -3
- package/esm/core/codegen/types.js +72 -15
- package/esm/core/codegen/utils.d.ts +1 -4
- package/esm/core/codegen/utils.js +4 -1
- package/esm/core/config/index.d.ts +1 -1
- package/esm/core/config/resolver.js +2 -4
- package/esm/core/generate.js +38 -50
- package/esm/core/index.d.ts +3 -3
- package/esm/core/index.js +2 -3
- package/esm/core/introspect/index.d.ts +6 -6
- package/esm/core/introspect/index.js +3 -6
- package/esm/core/introspect/infer-tables.d.ts +0 -14
- package/esm/core/introspect/infer-tables.js +16 -2
- package/esm/core/introspect/source/database.js +2 -2
- package/esm/core/introspect/source/endpoint.d.ts +0 -6
- package/esm/core/introspect/source/endpoint.js +7 -1
- package/esm/core/introspect/source/index.d.ts +4 -4
- package/esm/core/introspect/source/index.js +6 -10
- package/esm/core/introspect/source/pgpm-module.js +3 -3
- package/esm/core/introspect/transform-schema.d.ts +2 -2
- package/esm/core/introspect/transform-schema.js +2 -2
- package/esm/core/output/index.d.ts +1 -1
- package/esm/core/output/index.js +1 -1
- package/esm/core/output/writer.d.ts +3 -0
- package/esm/core/output/writer.js +20 -1
- package/esm/core/pipeline/index.d.ts +2 -2
- package/esm/core/pipeline/index.js +2 -2
- package/esm/core/query-builder.d.ts +2 -2
- package/esm/core/query-builder.js +2 -2
- package/esm/core/watch/index.d.ts +4 -4
- package/esm/core/watch/index.js +3 -3
- package/esm/core/watch/orchestrator.js +5 -3
- package/esm/generators/index.d.ts +3 -3
- package/esm/generators/index.js +3 -3
- package/esm/generators/mutations.d.ts +1 -1
- package/esm/generators/select.d.ts +1 -1
- package/esm/index.d.ts +3 -3
- package/esm/index.js +1 -4
- package/esm/types/config.d.ts +0 -10
- package/esm/types/config.js +0 -2
- package/esm/types/index.d.ts +6 -6
- package/esm/types/index.js +1 -1
- package/generators/index.d.ts +3 -3
- package/generators/index.js +8 -8
- package/generators/mutations.d.ts +1 -1
- package/generators/select.d.ts +1 -1
- package/index.d.ts +3 -3
- package/index.js +11 -6
- package/package.json +10 -10
- package/types/config.d.ts +0 -10
- package/types/config.js +0 -2
- package/types/index.d.ts +6 -6
- package/types/index.js +2 -2
- package/core/codegen/gql-ast.d.ts +0 -41
- package/core/codegen/gql-ast.js +0 -353
- package/core/codegen/schema-gql-ast.d.ts +0 -51
- package/core/codegen/schema-gql-ast.js +0 -385
- package/core/codegen/templates/client.browser.ts +0 -271
- package/core/codegen/templates/client.node.ts +0 -337
- package/esm/core/codegen/gql-ast.d.ts +0 -41
- package/esm/core/codegen/gql-ast.js +0 -312
- package/esm/core/codegen/schema-gql-ast.d.ts +0 -51
- package/esm/core/codegen/schema-gql-ast.js +0 -343
|
@@ -35,6 +35,11 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.generateModelsBarrel = generateModelsBarrel;
|
|
37
37
|
exports.generateTypesBarrel = generateTypesBarrel;
|
|
38
|
+
/**
|
|
39
|
+
* Barrel file generators for ORM client (Babel AST-based)
|
|
40
|
+
*
|
|
41
|
+
* Generates index.ts files that re-export all models and operations.
|
|
42
|
+
*/
|
|
38
43
|
const t = __importStar(require("@babel/types"));
|
|
39
44
|
const babel_ast_1 = require("../babel-ast");
|
|
40
45
|
const utils_1 = require("../utils");
|
|
@@ -37,11 +37,16 @@ exports.generateOrmClientFile = generateOrmClientFile;
|
|
|
37
37
|
exports.generateQueryBuilderFile = generateQueryBuilderFile;
|
|
38
38
|
exports.generateSelectTypesFile = generateSelectTypesFile;
|
|
39
39
|
exports.generateCreateClientFile = generateCreateClientFile;
|
|
40
|
+
/**
|
|
41
|
+
* ORM Client generator (Babel AST-based)
|
|
42
|
+
*
|
|
43
|
+
* Generates the createClient() factory function and main client file.
|
|
44
|
+
*/
|
|
40
45
|
const t = __importStar(require("@babel/types"));
|
|
41
|
-
const babel_ast_1 = require("../babel-ast");
|
|
42
|
-
const utils_1 = require("../utils");
|
|
43
46
|
const fs = __importStar(require("fs"));
|
|
44
47
|
const path = __importStar(require("path"));
|
|
48
|
+
const babel_ast_1 = require("../babel-ast");
|
|
49
|
+
const utils_1 = require("../utils");
|
|
45
50
|
/**
|
|
46
51
|
* Find a template file path.
|
|
47
52
|
* Templates are at ../templates/ relative to this file in both src/ and dist/.
|
|
@@ -37,7 +37,9 @@ class FetchAdapter {
|
|
|
37
37
|
return {
|
|
38
38
|
ok: false,
|
|
39
39
|
data: null,
|
|
40
|
-
errors: [
|
|
40
|
+
errors: [
|
|
41
|
+
{ message: `HTTP ${response.status}: ${response.statusText}` },
|
|
42
|
+
],
|
|
41
43
|
};
|
|
42
44
|
}
|
|
43
45
|
const json = (await response.json());
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Custom operations generator for ORM client (Babel AST-based)
|
|
3
|
-
*
|
|
4
|
-
* Generates db.query.* and db.mutation.* namespaces for non-table operations
|
|
5
|
-
* like login, register, currentUser, etc.
|
|
6
|
-
*/
|
|
7
1
|
import type { CleanOperation } from '../../../types/schema';
|
|
8
2
|
export interface GeneratedCustomOpsFile {
|
|
9
3
|
fileName: string;
|
|
@@ -35,11 +35,17 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.generateCustomQueryOpsFile = generateCustomQueryOpsFile;
|
|
37
37
|
exports.generateCustomMutationOpsFile = generateCustomMutationOpsFile;
|
|
38
|
+
/**
|
|
39
|
+
* Custom operations generator for ORM client (Babel AST-based)
|
|
40
|
+
*
|
|
41
|
+
* Generates db.query.* and db.mutation.* namespaces for non-table operations
|
|
42
|
+
* like login, register, currentUser, etc.
|
|
43
|
+
*/
|
|
38
44
|
const t = __importStar(require("@babel/types"));
|
|
39
45
|
const babel_ast_1 = require("../babel-ast");
|
|
40
|
-
const
|
|
46
|
+
const select_helpers_1 = require("../select-helpers");
|
|
41
47
|
const type_resolver_1 = require("../type-resolver");
|
|
42
|
-
const
|
|
48
|
+
const utils_1 = require("../utils");
|
|
43
49
|
/**
|
|
44
50
|
* Collect all input type names used by operations
|
|
45
51
|
* Includes Input, Filter, OrderBy, and Condition types
|
|
@@ -60,12 +66,6 @@ function collectInputTypeNamesFromOps(operations) {
|
|
|
60
66
|
}
|
|
61
67
|
return Array.from(inputTypes);
|
|
62
68
|
}
|
|
63
|
-
// Types that don't need Select types
|
|
64
|
-
const NON_SELECT_TYPES = new Set([
|
|
65
|
-
...scalars_1.SCALAR_NAMES,
|
|
66
|
-
'Query',
|
|
67
|
-
'Mutation',
|
|
68
|
-
]);
|
|
69
69
|
/**
|
|
70
70
|
* Collect all payload/return type names from operations (for Select types)
|
|
71
71
|
* Filters out scalar types
|
|
@@ -76,28 +76,27 @@ function collectPayloadTypeNamesFromOps(operations) {
|
|
|
76
76
|
const baseName = (0, type_resolver_1.getTypeBaseName)(op.returnType);
|
|
77
77
|
if (baseName &&
|
|
78
78
|
!baseName.endsWith('Connection') &&
|
|
79
|
-
baseName
|
|
80
|
-
baseName !== 'Mutation' &&
|
|
81
|
-
!NON_SELECT_TYPES.has(baseName)) {
|
|
79
|
+
!select_helpers_1.NON_SELECT_TYPES.has(baseName)) {
|
|
82
80
|
payloadTypes.add(baseName);
|
|
83
81
|
}
|
|
84
82
|
}
|
|
85
83
|
return Array.from(payloadTypes);
|
|
86
84
|
}
|
|
87
85
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
86
|
+
* Collect Connection and other non-scalar return type names that need importing
|
|
87
|
+
* (for typing QueryBuilder results on scalar/Connection operations)
|
|
90
88
|
*/
|
|
91
|
-
function
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
baseName
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
89
|
+
function collectRawReturnTypeNames(operations) {
|
|
90
|
+
const types = new Set();
|
|
91
|
+
for (const op of operations) {
|
|
92
|
+
const baseName = (0, type_resolver_1.getTypeBaseName)(op.returnType);
|
|
93
|
+
if (baseName &&
|
|
94
|
+
!select_helpers_1.NON_SELECT_TYPES.has(baseName) &&
|
|
95
|
+
baseName.endsWith('Connection')) {
|
|
96
|
+
types.add(baseName);
|
|
97
|
+
}
|
|
99
98
|
}
|
|
100
|
-
return
|
|
99
|
+
return Array.from(types);
|
|
101
100
|
}
|
|
102
101
|
function createImportDeclaration(moduleSpecifier, namedImports, typeOnly = false) {
|
|
103
102
|
const specifiers = namedImports.map((name) => t.importSpecifier(t.identifier(name), t.identifier(name)));
|
|
@@ -132,7 +131,9 @@ function parseTypeAnnotation(typeStr) {
|
|
|
132
131
|
if (typeStr === 'unknown')
|
|
133
132
|
return t.tsUnknownKeyword();
|
|
134
133
|
if (typeStr.includes(' | ')) {
|
|
135
|
-
const parts = typeStr
|
|
134
|
+
const parts = typeStr
|
|
135
|
+
.split(' | ')
|
|
136
|
+
.map((p) => parseTypeAnnotation(p.trim()));
|
|
136
137
|
return t.tsUnionType(parts);
|
|
137
138
|
}
|
|
138
139
|
if (typeStr.endsWith('[]')) {
|
|
@@ -140,6 +141,18 @@ function parseTypeAnnotation(typeStr) {
|
|
|
140
141
|
}
|
|
141
142
|
return t.tsTypeReference(t.identifier(typeStr));
|
|
142
143
|
}
|
|
144
|
+
function buildSelectedResultTsType(typeRef, payloadTypeName) {
|
|
145
|
+
if (typeRef.kind === 'NON_NULL' && typeRef.ofType) {
|
|
146
|
+
return buildSelectedResultTsType(typeRef.ofType, payloadTypeName);
|
|
147
|
+
}
|
|
148
|
+
if (typeRef.kind === 'LIST' && typeRef.ofType) {
|
|
149
|
+
return t.tsArrayType(buildSelectedResultTsType(typeRef.ofType, payloadTypeName));
|
|
150
|
+
}
|
|
151
|
+
return t.tsTypeReference(t.identifier('InferSelectResult'), t.tsTypeParameterInstantiation([
|
|
152
|
+
t.tsTypeReference(t.identifier(payloadTypeName)),
|
|
153
|
+
t.tsTypeReference(t.identifier('S')),
|
|
154
|
+
]));
|
|
155
|
+
}
|
|
143
156
|
function buildOperationMethod(op, operationType) {
|
|
144
157
|
const hasArgs = op.args.length > 0;
|
|
145
158
|
const varTypeName = `${(0, utils_1.ucFirst)(op.name)}Variables`;
|
|
@@ -147,7 +160,7 @@ function buildOperationMethod(op, operationType) {
|
|
|
147
160
|
name: arg.name,
|
|
148
161
|
type: formatGraphQLType(arg.type),
|
|
149
162
|
}));
|
|
150
|
-
const selectTypeName = getSelectTypeName(op.returnType);
|
|
163
|
+
const selectTypeName = (0, select_helpers_1.getSelectTypeName)(op.returnType);
|
|
151
164
|
const payloadTypeName = (0, type_resolver_1.getTypeBaseName)(op.returnType);
|
|
152
165
|
// Build the arrow function parameters
|
|
153
166
|
const params = [];
|
|
@@ -157,25 +170,25 @@ function buildOperationMethod(op, operationType) {
|
|
|
157
170
|
params.push(argsParam);
|
|
158
171
|
}
|
|
159
172
|
const optionsParam = t.identifier('options');
|
|
160
|
-
optionsParam.optional =
|
|
173
|
+
optionsParam.optional = !selectTypeName;
|
|
161
174
|
if (selectTypeName) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
optionsParam.typeAnnotation = t.tsTypeAnnotation(t.
|
|
165
|
-
(
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
prop.optional = true;
|
|
171
|
-
return prop;
|
|
172
|
-
})(),
|
|
175
|
+
const selectProp = t.tsPropertySignature(t.identifier('select'), t.tsTypeAnnotation(t.tsTypeReference(t.identifier('S'))));
|
|
176
|
+
selectProp.optional = false;
|
|
177
|
+
optionsParam.typeAnnotation = t.tsTypeAnnotation(t.tsIntersectionType([
|
|
178
|
+
t.tsTypeLiteral([selectProp]),
|
|
179
|
+
t.tsTypeReference(t.identifier('StrictSelect'), t.tsTypeParameterInstantiation([
|
|
180
|
+
t.tsTypeReference(t.identifier('S')),
|
|
181
|
+
t.tsTypeReference(t.identifier(selectTypeName)),
|
|
182
|
+
])),
|
|
173
183
|
]));
|
|
174
184
|
}
|
|
175
185
|
else {
|
|
176
186
|
optionsParam.typeAnnotation = t.tsTypeAnnotation(t.tsTypeLiteral([
|
|
177
187
|
(() => {
|
|
178
|
-
const prop = t.tsPropertySignature(t.identifier('select'), t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Record'), t.tsTypeParameterInstantiation([
|
|
188
|
+
const prop = t.tsPropertySignature(t.identifier('select'), t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Record'), t.tsTypeParameterInstantiation([
|
|
189
|
+
t.tsStringKeyword(),
|
|
190
|
+
t.tsUnknownKeyword(),
|
|
191
|
+
]))));
|
|
179
192
|
prop.optional = true;
|
|
180
193
|
return prop;
|
|
181
194
|
})(),
|
|
@@ -183,6 +196,12 @@ function buildOperationMethod(op, operationType) {
|
|
|
183
196
|
}
|
|
184
197
|
params.push(optionsParam);
|
|
185
198
|
// Build the QueryBuilder call
|
|
199
|
+
const selectExpr = selectTypeName
|
|
200
|
+
? t.memberExpression(t.identifier('options'), t.identifier('select'))
|
|
201
|
+
: t.optionalMemberExpression(t.identifier('options'), t.identifier('select'), false, true);
|
|
202
|
+
const entityTypeExpr = selectTypeName && payloadTypeName
|
|
203
|
+
? t.stringLiteral(payloadTypeName)
|
|
204
|
+
: t.identifier('undefined');
|
|
186
205
|
const queryBuilderArgs = t.objectExpression([
|
|
187
206
|
t.objectProperty(t.identifier('client'), t.identifier('client'), false, true),
|
|
188
207
|
t.objectProperty(t.identifier('operation'), t.stringLiteral(operationType)),
|
|
@@ -192,23 +211,34 @@ function buildOperationMethod(op, operationType) {
|
|
|
192
211
|
t.stringLiteral(operationType),
|
|
193
212
|
t.stringLiteral((0, utils_1.ucFirst)(op.name)),
|
|
194
213
|
t.stringLiteral(op.name),
|
|
195
|
-
|
|
214
|
+
selectExpr,
|
|
196
215
|
hasArgs ? t.identifier('args') : t.identifier('undefined'),
|
|
197
216
|
t.arrayExpression(varDefs.map((v) => t.objectExpression([
|
|
198
217
|
t.objectProperty(t.identifier('name'), t.stringLiteral(v.name)),
|
|
199
218
|
t.objectProperty(t.identifier('type'), t.stringLiteral(v.type)),
|
|
200
219
|
]))),
|
|
220
|
+
t.identifier('connectionFieldsMap'),
|
|
221
|
+
entityTypeExpr,
|
|
201
222
|
])),
|
|
202
223
|
]);
|
|
203
|
-
const newExpr = t.newExpression(t.identifier('QueryBuilder'), [
|
|
204
|
-
|
|
224
|
+
const newExpr = t.newExpression(t.identifier('QueryBuilder'), [
|
|
225
|
+
queryBuilderArgs,
|
|
226
|
+
]);
|
|
227
|
+
// Add type parameter to QueryBuilder for typed .unwrap() results
|
|
205
228
|
if (selectTypeName && payloadTypeName) {
|
|
229
|
+
// Select-based type: use InferSelectResult<PayloadType, S>
|
|
230
|
+
newExpr.typeParameters = t.tsTypeParameterInstantiation([
|
|
231
|
+
t.tsTypeLiteral([
|
|
232
|
+
t.tsPropertySignature(t.identifier(op.name), t.tsTypeAnnotation(buildSelectedResultTsType(op.returnType, payloadTypeName))),
|
|
233
|
+
]),
|
|
234
|
+
]);
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
// Scalar/Connection type: use raw TS type directly
|
|
238
|
+
const rawTsType = (0, type_resolver_1.typeRefToTsType)(op.returnType);
|
|
206
239
|
newExpr.typeParameters = t.tsTypeParameterInstantiation([
|
|
207
240
|
t.tsTypeLiteral([
|
|
208
|
-
t.tsPropertySignature(t.identifier(op.name), t.tsTypeAnnotation(
|
|
209
|
-
t.tsTypeReference(t.identifier(payloadTypeName)),
|
|
210
|
-
t.tsTypeReference(t.identifier('S')),
|
|
211
|
-
])))),
|
|
241
|
+
t.tsPropertySignature(t.identifier(op.name), t.tsTypeAnnotation(parseTypeAnnotation(rawTsType))),
|
|
212
242
|
]),
|
|
213
243
|
]);
|
|
214
244
|
}
|
|
@@ -216,7 +246,6 @@ function buildOperationMethod(op, operationType) {
|
|
|
216
246
|
// Add type parameters to arrow function if we have a select type
|
|
217
247
|
if (selectTypeName) {
|
|
218
248
|
const typeParam = t.tsTypeParameter(t.tsTypeReference(t.identifier(selectTypeName)), null, 'S');
|
|
219
|
-
typeParam.const = true;
|
|
220
249
|
arrowFunc.typeParameters = t.tsTypeParameterDeclaration([typeParam]);
|
|
221
250
|
}
|
|
222
251
|
return t.objectProperty(t.identifier(op.name), arrowFunc);
|
|
@@ -230,14 +259,26 @@ function generateCustomQueryOpsFile(operations) {
|
|
|
230
259
|
const inputTypeNames = collectInputTypeNamesFromOps(operations);
|
|
231
260
|
const payloadTypeNames = collectPayloadTypeNamesFromOps(operations);
|
|
232
261
|
const selectTypeNames = payloadTypeNames.map((p) => `${p}Select`);
|
|
233
|
-
const
|
|
262
|
+
const rawReturnTypeNames = collectRawReturnTypeNames(operations);
|
|
263
|
+
const allTypeImports = [
|
|
264
|
+
...new Set([
|
|
265
|
+
...inputTypeNames,
|
|
266
|
+
...payloadTypeNames,
|
|
267
|
+
...selectTypeNames,
|
|
268
|
+
...rawReturnTypeNames,
|
|
269
|
+
]),
|
|
270
|
+
];
|
|
234
271
|
// Add imports
|
|
235
272
|
statements.push(createImportDeclaration('../client', ['OrmClient']));
|
|
236
|
-
statements.push(createImportDeclaration('../query-builder', [
|
|
237
|
-
|
|
273
|
+
statements.push(createImportDeclaration('../query-builder', [
|
|
274
|
+
'QueryBuilder',
|
|
275
|
+
'buildCustomDocument',
|
|
276
|
+
]));
|
|
277
|
+
statements.push(createImportDeclaration('../select-types', ['InferSelectResult', 'StrictSelect'], true));
|
|
238
278
|
if (allTypeImports.length > 0) {
|
|
239
279
|
statements.push(createImportDeclaration('../input-types', allTypeImports, true));
|
|
240
280
|
}
|
|
281
|
+
statements.push(createImportDeclaration('../input-types', ['connectionFieldsMap']));
|
|
241
282
|
// Generate variable interfaces
|
|
242
283
|
for (const op of operations) {
|
|
243
284
|
const varInterface = createVariablesInterface(op);
|
|
@@ -268,14 +309,26 @@ function generateCustomMutationOpsFile(operations) {
|
|
|
268
309
|
const inputTypeNames = collectInputTypeNamesFromOps(operations);
|
|
269
310
|
const payloadTypeNames = collectPayloadTypeNamesFromOps(operations);
|
|
270
311
|
const selectTypeNames = payloadTypeNames.map((p) => `${p}Select`);
|
|
271
|
-
const
|
|
312
|
+
const rawReturnTypeNames = collectRawReturnTypeNames(operations);
|
|
313
|
+
const allTypeImports = [
|
|
314
|
+
...new Set([
|
|
315
|
+
...inputTypeNames,
|
|
316
|
+
...payloadTypeNames,
|
|
317
|
+
...selectTypeNames,
|
|
318
|
+
...rawReturnTypeNames,
|
|
319
|
+
]),
|
|
320
|
+
];
|
|
272
321
|
// Add imports
|
|
273
322
|
statements.push(createImportDeclaration('../client', ['OrmClient']));
|
|
274
|
-
statements.push(createImportDeclaration('../query-builder', [
|
|
275
|
-
|
|
323
|
+
statements.push(createImportDeclaration('../query-builder', [
|
|
324
|
+
'QueryBuilder',
|
|
325
|
+
'buildCustomDocument',
|
|
326
|
+
]));
|
|
327
|
+
statements.push(createImportDeclaration('../select-types', ['InferSelectResult', 'StrictSelect'], true));
|
|
276
328
|
if (allTypeImports.length > 0) {
|
|
277
329
|
statements.push(createImportDeclaration('../input-types', allTypeImports, true));
|
|
278
330
|
}
|
|
331
|
+
statements.push(createImportDeclaration('../input-types', ['connectionFieldsMap']));
|
|
279
332
|
// Generate variable interfaces
|
|
280
333
|
for (const op of operations) {
|
|
281
334
|
const varInterface = createVariablesInterface(op);
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* Main entry point for ORM code generation. Coordinates all generators
|
|
5
5
|
* and produces the complete ORM client output.
|
|
6
6
|
*/
|
|
7
|
-
import type { CleanTable, CleanOperation, TypeRegistry } from '../../../types/schema';
|
|
8
7
|
import type { GraphQLSDKConfigTarget } from '../../../types/config';
|
|
8
|
+
import type { CleanOperation, CleanTable, TypeRegistry } from '../../../types/schema';
|
|
9
9
|
export interface GeneratedFile {
|
|
10
10
|
path: string;
|
|
11
11
|
content: string;
|
|
@@ -39,7 +39,7 @@ export interface GenerateOrmResult {
|
|
|
39
39
|
* Generate all ORM client files
|
|
40
40
|
*/
|
|
41
41
|
export declare function generateOrm(options: GenerateOrmOptions): GenerateOrmResult;
|
|
42
|
-
export { generateOrmClientFile, generateQueryBuilderFile, generateSelectTypesFile, } from './client-generator';
|
|
43
|
-
export { generateModelFile, generateAllModelFiles } from './model-generator';
|
|
44
|
-
export { generateCustomQueryOpsFile, generateCustomMutationOpsFile } from './custom-ops-generator';
|
|
45
42
|
export { generateModelsBarrel, generateTypesBarrel } from './barrel';
|
|
43
|
+
export { generateOrmClientFile, generateQueryBuilderFile, generateSelectTypesFile, } from './client-generator';
|
|
44
|
+
export { generateCustomMutationOpsFile, generateCustomQueryOpsFile, } from './custom-ops-generator';
|
|
45
|
+
export { generateAllModelFiles, generateModelFile } from './model-generator';
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.generateModelFile = exports.generateAllModelFiles = exports.generateCustomQueryOpsFile = exports.generateCustomMutationOpsFile = exports.generateSelectTypesFile = exports.generateQueryBuilderFile = exports.generateOrmClientFile = exports.generateTypesBarrel = exports.generateModelsBarrel = void 0;
|
|
4
4
|
exports.generateOrm = generateOrm;
|
|
5
|
+
const barrel_1 = require("./barrel");
|
|
5
6
|
const client_generator_1 = require("./client-generator");
|
|
6
|
-
const model_generator_1 = require("./model-generator");
|
|
7
7
|
const custom_ops_generator_1 = require("./custom-ops-generator");
|
|
8
|
-
const barrel_1 = require("./barrel");
|
|
9
8
|
const input_types_generator_1 = require("./input-types-generator");
|
|
9
|
+
const model_generator_1 = require("./model-generator");
|
|
10
10
|
/**
|
|
11
11
|
* Generate all ORM client files
|
|
12
12
|
*/
|
|
@@ -22,9 +22,15 @@ function generateOrm(options) {
|
|
|
22
22
|
const clientFile = (0, client_generator_1.generateOrmClientFile)();
|
|
23
23
|
files.push({ path: clientFile.fileName, content: clientFile.content });
|
|
24
24
|
const queryBuilderFile = (0, client_generator_1.generateQueryBuilderFile)();
|
|
25
|
-
files.push({
|
|
25
|
+
files.push({
|
|
26
|
+
path: queryBuilderFile.fileName,
|
|
27
|
+
content: queryBuilderFile.content,
|
|
28
|
+
});
|
|
26
29
|
const selectTypesFile = (0, client_generator_1.generateSelectTypesFile)();
|
|
27
|
-
files.push({
|
|
30
|
+
files.push({
|
|
31
|
+
path: selectTypesFile.fileName,
|
|
32
|
+
content: selectTypesFile.content,
|
|
33
|
+
});
|
|
28
34
|
// 2. Generate model files
|
|
29
35
|
const modelFiles = (0, model_generator_1.generateAllModelFiles)(tables, useSharedTypes);
|
|
30
36
|
for (const modelFile of modelFiles) {
|
|
@@ -38,7 +44,8 @@ function generateOrm(options) {
|
|
|
38
44
|
files.push({ path: modelsBarrel.fileName, content: modelsBarrel.content });
|
|
39
45
|
// 4. Generate comprehensive input types (entities, filters, orderBy, CRUD inputs, custom inputs, payload types)
|
|
40
46
|
// Always generate if we have tables or custom operations
|
|
41
|
-
if (tables.length > 0 ||
|
|
47
|
+
if (tables.length > 0 ||
|
|
48
|
+
(typeRegistry && (hasCustomQueries || hasCustomMutations))) {
|
|
42
49
|
const allOps = [
|
|
43
50
|
...(customOperations?.queries ?? []),
|
|
44
51
|
...(customOperations?.mutations ?? []),
|
|
@@ -63,7 +70,10 @@ function generateOrm(options) {
|
|
|
63
70
|
}
|
|
64
71
|
}
|
|
65
72
|
const inputTypesFile = (0, input_types_generator_1.generateInputTypesFile)(typeRegistry ?? new Map(), usedInputTypes, tables, usedPayloadTypes);
|
|
66
|
-
files.push({
|
|
73
|
+
files.push({
|
|
74
|
+
path: inputTypesFile.fileName,
|
|
75
|
+
content: inputTypesFile.content,
|
|
76
|
+
});
|
|
67
77
|
}
|
|
68
78
|
// 5. Generate custom operations (if any)
|
|
69
79
|
if (hasCustomQueries && customOperations?.queries) {
|
|
@@ -72,7 +82,10 @@ function generateOrm(options) {
|
|
|
72
82
|
}
|
|
73
83
|
if (hasCustomMutations && customOperations?.mutations) {
|
|
74
84
|
const mutationOpsFile = (0, custom_ops_generator_1.generateCustomMutationOpsFile)(customOperations.mutations);
|
|
75
|
-
files.push({
|
|
85
|
+
files.push({
|
|
86
|
+
path: mutationOpsFile.fileName,
|
|
87
|
+
content: mutationOpsFile.content,
|
|
88
|
+
});
|
|
76
89
|
}
|
|
77
90
|
// 6. Generate types barrel
|
|
78
91
|
const typesBarrel = (0, barrel_1.generateTypesBarrel)(useSharedTypes);
|
|
@@ -91,16 +104,16 @@ function generateOrm(options) {
|
|
|
91
104
|
};
|
|
92
105
|
}
|
|
93
106
|
// Re-export generators for direct use
|
|
107
|
+
var barrel_2 = require("./barrel");
|
|
108
|
+
Object.defineProperty(exports, "generateModelsBarrel", { enumerable: true, get: function () { return barrel_2.generateModelsBarrel; } });
|
|
109
|
+
Object.defineProperty(exports, "generateTypesBarrel", { enumerable: true, get: function () { return barrel_2.generateTypesBarrel; } });
|
|
94
110
|
var client_generator_2 = require("./client-generator");
|
|
95
111
|
Object.defineProperty(exports, "generateOrmClientFile", { enumerable: true, get: function () { return client_generator_2.generateOrmClientFile; } });
|
|
96
112
|
Object.defineProperty(exports, "generateQueryBuilderFile", { enumerable: true, get: function () { return client_generator_2.generateQueryBuilderFile; } });
|
|
97
113
|
Object.defineProperty(exports, "generateSelectTypesFile", { enumerable: true, get: function () { return client_generator_2.generateSelectTypesFile; } });
|
|
98
|
-
var model_generator_2 = require("./model-generator");
|
|
99
|
-
Object.defineProperty(exports, "generateModelFile", { enumerable: true, get: function () { return model_generator_2.generateModelFile; } });
|
|
100
|
-
Object.defineProperty(exports, "generateAllModelFiles", { enumerable: true, get: function () { return model_generator_2.generateAllModelFiles; } });
|
|
101
114
|
var custom_ops_generator_2 = require("./custom-ops-generator");
|
|
102
|
-
Object.defineProperty(exports, "generateCustomQueryOpsFile", { enumerable: true, get: function () { return custom_ops_generator_2.generateCustomQueryOpsFile; } });
|
|
103
115
|
Object.defineProperty(exports, "generateCustomMutationOpsFile", { enumerable: true, get: function () { return custom_ops_generator_2.generateCustomMutationOpsFile; } });
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
Object.defineProperty(exports, "
|
|
116
|
+
Object.defineProperty(exports, "generateCustomQueryOpsFile", { enumerable: true, get: function () { return custom_ops_generator_2.generateCustomQueryOpsFile; } });
|
|
117
|
+
var model_generator_2 = require("./model-generator");
|
|
118
|
+
Object.defineProperty(exports, "generateAllModelFiles", { enumerable: true, get: function () { return model_generator_2.generateAllModelFiles; } });
|
|
119
|
+
Object.defineProperty(exports, "generateModelFile", { enumerable: true, get: function () { return model_generator_2.generateModelFile; } });
|
|
@@ -1,16 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* Input types generator for ORM client (Babel AST-based)
|
|
3
|
-
*
|
|
4
|
-
* Generates TypeScript interfaces for:
|
|
5
|
-
* 1. Scalar filter types (StringFilter, IntFilter, UUIDFilter, etc.)
|
|
6
|
-
* 2. Entity interfaces (User, Order, etc.)
|
|
7
|
-
* 3. Table filter types (UserFilter, OrderFilter, etc.)
|
|
8
|
-
* 4. OrderBy enums (UsersOrderBy, OrdersOrderBy, etc.)
|
|
9
|
-
* 5. Input types (LoginInput, CreateUserInput, etc.)
|
|
10
|
-
*
|
|
11
|
-
* Uses Babel AST for robust code generation.
|
|
12
|
-
*/
|
|
13
|
-
import type { TypeRegistry, CleanArgument, CleanTable } from '../../../types/schema';
|
|
1
|
+
import type { CleanArgument, CleanTable, TypeRegistry } from '../../../types/schema';
|
|
14
2
|
export interface GeneratedInputTypesFile {
|
|
15
3
|
fileName: string;
|
|
16
4
|
content: string;
|