@constructive-io/graphql-codegen 2.31.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +429 -1691
- package/cli/index.d.ts +5 -2
- package/cli/index.js +98 -581
- package/cli/shared.d.ts +35 -0
- package/cli/shared.js +106 -0
- package/{esm/cli → core}/codegen/barrel.d.ts +1 -1
- package/{cli → core}/codegen/barrel.js +1 -4
- package/{esm/cli → core}/codegen/index.d.ts +15 -5
- package/{cli → core}/codegen/index.js +44 -24
- package/{cli → core}/codegen/invalidation.d.ts +2 -2
- package/{esm/cli → core}/codegen/mutation-keys.d.ts +2 -2
- package/{cli → core}/codegen/orm/client-generator.js +2 -3
- package/{esm/cli → core}/codegen/orm/index.d.ts +9 -2
- package/{cli → core}/codegen/orm/index.js +3 -2
- package/{cli → core}/codegen/query-keys.d.ts +2 -2
- package/core/codegen/shared/index.d.ts +39 -0
- package/core/codegen/shared/index.js +118 -0
- package/core/config/index.d.ts +5 -0
- package/core/config/index.js +13 -0
- package/core/config/loader.d.ts +18 -0
- package/{cli/commands/init.js → core/config/loader.js} +7 -94
- package/core/config/resolver.d.ts +46 -0
- package/core/config/resolver.js +104 -0
- package/core/database/index.d.ts +43 -0
- package/core/database/index.js +85 -0
- package/core/generate.d.ts +22 -0
- package/core/generate.js +192 -0
- package/core/index.d.ts +13 -1
- package/core/index.js +22 -2
- package/{cli → core}/introspect/fetch-schema.js +58 -9
- package/core/introspect/source/api-schemas.d.ts +44 -0
- package/core/introspect/source/api-schemas.js +122 -0
- package/core/introspect/source/database.d.ts +32 -0
- package/core/introspect/source/database.js +91 -0
- package/core/introspect/source/index.d.ts +112 -0
- package/core/introspect/source/index.js +173 -0
- package/core/introspect/source/pgpm-module.d.ts +83 -0
- package/core/introspect/source/pgpm-module.js +200 -0
- package/core/output/index.d.ts +4 -0
- package/core/output/index.js +9 -0
- package/core/output/writer.d.ts +38 -0
- package/core/output/writer.js +156 -0
- package/{cli/commands/shared.d.ts → core/pipeline/index.d.ts} +5 -3
- package/{cli/commands/shared.js → core/pipeline/index.js} +12 -5
- package/{cli → core}/watch/orchestrator.d.ts +25 -3
- package/{cli → core}/watch/orchestrator.js +35 -27
- package/{cli → core}/watch/types.d.ts +1 -1
- package/esm/cli/index.d.ts +5 -2
- package/esm/cli/index.js +97 -547
- package/esm/cli/shared.d.ts +35 -0
- package/esm/cli/shared.js +101 -0
- package/{cli → esm/core}/codegen/barrel.d.ts +1 -1
- package/esm/{cli → core}/codegen/barrel.js +1 -4
- package/{cli → esm/core}/codegen/index.d.ts +15 -5
- package/esm/{cli → core}/codegen/index.js +44 -24
- package/esm/{cli → core}/codegen/invalidation.d.ts +2 -2
- package/{cli → esm/core}/codegen/mutation-keys.d.ts +2 -2
- package/esm/{cli → core}/codegen/orm/client-generator.js +2 -3
- package/{cli → esm/core}/codegen/orm/index.d.ts +9 -2
- package/esm/{cli → core}/codegen/orm/index.js +3 -2
- package/esm/{cli → core}/codegen/query-keys.d.ts +2 -2
- package/esm/core/codegen/shared/index.d.ts +39 -0
- package/esm/core/codegen/shared/index.js +79 -0
- package/esm/core/config/index.d.ts +5 -0
- package/esm/core/config/index.js +5 -0
- package/esm/core/config/loader.d.ts +18 -0
- package/esm/core/config/loader.js +71 -0
- package/esm/core/config/resolver.d.ts +46 -0
- package/esm/core/config/resolver.js +100 -0
- package/esm/core/database/index.d.ts +43 -0
- package/esm/core/database/index.js +48 -0
- package/esm/core/generate.d.ts +22 -0
- package/esm/core/generate.js +186 -0
- package/esm/core/index.d.ts +13 -1
- package/esm/core/index.js +20 -1
- package/esm/{cli → core}/introspect/fetch-schema.js +55 -9
- package/esm/core/introspect/source/api-schemas.d.ts +44 -0
- package/esm/core/introspect/source/api-schemas.js +117 -0
- package/esm/core/introspect/source/database.d.ts +32 -0
- package/esm/core/introspect/source/database.js +87 -0
- package/esm/core/introspect/source/index.d.ts +112 -0
- package/esm/core/introspect/source/index.js +154 -0
- package/esm/core/introspect/source/pgpm-module.d.ts +83 -0
- package/esm/core/introspect/source/pgpm-module.js +194 -0
- package/esm/core/output/index.d.ts +4 -0
- package/esm/core/output/index.js +4 -0
- package/esm/core/output/writer.d.ts +38 -0
- package/esm/core/output/writer.js +119 -0
- package/esm/{cli/commands/shared.d.ts → core/pipeline/index.d.ts} +5 -3
- package/esm/{cli/commands/shared.js → core/pipeline/index.js} +9 -5
- package/esm/{cli → core}/watch/orchestrator.d.ts +25 -3
- package/esm/{cli → core}/watch/orchestrator.js +35 -27
- package/esm/{cli → core}/watch/types.d.ts +1 -1
- package/esm/index.d.ts +8 -3
- package/esm/index.js +9 -3
- package/esm/types/config.d.ts +110 -136
- package/esm/types/config.js +23 -148
- package/esm/types/index.d.ts +2 -2
- package/esm/types/index.js +1 -1
- package/index.d.ts +8 -3
- package/index.js +18 -8
- package/package.json +19 -11
- package/types/config.d.ts +110 -136
- package/types/config.js +28 -152
- package/types/index.d.ts +2 -2
- package/types/index.js +3 -3
- package/cli/commands/generate-orm.d.ts +0 -53
- package/cli/commands/generate-orm.js +0 -292
- package/cli/commands/generate.d.ts +0 -66
- package/cli/commands/generate.js +0 -431
- package/cli/commands/index.d.ts +0 -9
- package/cli/commands/index.js +0 -14
- package/cli/commands/init.d.ts +0 -35
- package/cli/introspect/source/index.d.ts +0 -48
- package/cli/introspect/source/index.js +0 -72
- package/esm/cli/commands/generate-orm.d.ts +0 -53
- package/esm/cli/commands/generate-orm.js +0 -289
- package/esm/cli/commands/generate.d.ts +0 -66
- package/esm/cli/commands/generate.js +0 -393
- package/esm/cli/commands/index.d.ts +0 -9
- package/esm/cli/commands/index.js +0 -6
- package/esm/cli/commands/init.d.ts +0 -35
- package/esm/cli/commands/init.js +0 -158
- package/esm/cli/introspect/source/index.d.ts +0 -48
- package/esm/cli/introspect/source/index.js +0 -54
- /package/{cli → core}/codegen/babel-ast.d.ts +0 -0
- /package/{cli → core}/codegen/babel-ast.js +0 -0
- /package/{cli → core}/codegen/client.d.ts +0 -0
- /package/{cli → core}/codegen/client.js +0 -0
- /package/{cli → core}/codegen/custom-mutations.d.ts +0 -0
- /package/{cli → core}/codegen/custom-mutations.js +0 -0
- /package/{cli → core}/codegen/custom-queries.d.ts +0 -0
- /package/{cli → core}/codegen/custom-queries.js +0 -0
- /package/{cli → core}/codegen/gql-ast.d.ts +0 -0
- /package/{cli → core}/codegen/gql-ast.js +0 -0
- /package/{cli → core}/codegen/invalidation.js +0 -0
- /package/{cli → core}/codegen/mutation-keys.js +0 -0
- /package/{cli → core}/codegen/mutations.d.ts +0 -0
- /package/{cli → core}/codegen/mutations.js +0 -0
- /package/{cli → core}/codegen/orm/barrel.d.ts +0 -0
- /package/{cli → core}/codegen/orm/barrel.js +0 -0
- /package/{cli → core}/codegen/orm/client-generator.d.ts +0 -0
- /package/{cli → core}/codegen/orm/client.d.ts +0 -0
- /package/{cli → core}/codegen/orm/client.js +0 -0
- /package/{cli → core}/codegen/orm/custom-ops-generator.d.ts +0 -0
- /package/{cli → core}/codegen/orm/custom-ops-generator.js +0 -0
- /package/{cli → core}/codegen/orm/input-types-generator.d.ts +0 -0
- /package/{cli → core}/codegen/orm/input-types-generator.js +0 -0
- /package/{cli → core}/codegen/orm/model-generator.d.ts +0 -0
- /package/{cli → core}/codegen/orm/model-generator.js +0 -0
- /package/{cli → core}/codegen/orm/query-builder.d.ts +0 -0
- /package/{cli → core}/codegen/orm/query-builder.js +0 -0
- /package/{cli → core}/codegen/orm/query-builder.ts +0 -0
- /package/{cli → core}/codegen/orm/select-types.d.ts +0 -0
- /package/{cli → core}/codegen/orm/select-types.js +0 -0
- /package/{cli → core}/codegen/queries.d.ts +0 -0
- /package/{cli → core}/codegen/queries.js +0 -0
- /package/{cli → core}/codegen/query-keys.js +0 -0
- /package/{cli → core}/codegen/scalars.d.ts +0 -0
- /package/{cli → core}/codegen/scalars.js +0 -0
- /package/{cli → core}/codegen/schema-gql-ast.d.ts +0 -0
- /package/{cli → core}/codegen/schema-gql-ast.js +0 -0
- /package/{cli → core}/codegen/schema-types-generator.d.ts +0 -0
- /package/{cli → core}/codegen/schema-types-generator.js +0 -0
- /package/{cli → core}/codegen/type-resolver.d.ts +0 -0
- /package/{cli → core}/codegen/type-resolver.js +0 -0
- /package/{cli → core}/codegen/types.d.ts +0 -0
- /package/{cli → core}/codegen/types.js +0 -0
- /package/{cli → core}/codegen/utils.d.ts +0 -0
- /package/{cli → core}/codegen/utils.js +0 -0
- /package/{cli → core}/introspect/fetch-schema.d.ts +0 -0
- /package/{cli → core}/introspect/index.d.ts +0 -0
- /package/{cli → core}/introspect/index.js +0 -0
- /package/{cli → core}/introspect/infer-tables.d.ts +0 -0
- /package/{cli → core}/introspect/infer-tables.js +0 -0
- /package/{cli → core}/introspect/schema-query.d.ts +0 -0
- /package/{cli → core}/introspect/schema-query.js +0 -0
- /package/{cli → core}/introspect/source/endpoint.d.ts +0 -0
- /package/{cli → core}/introspect/source/endpoint.js +0 -0
- /package/{cli → core}/introspect/source/file.d.ts +0 -0
- /package/{cli → core}/introspect/source/file.js +0 -0
- /package/{cli → core}/introspect/source/types.d.ts +0 -0
- /package/{cli → core}/introspect/source/types.js +0 -0
- /package/{cli → core}/introspect/transform-schema.d.ts +0 -0
- /package/{cli → core}/introspect/transform-schema.js +0 -0
- /package/{cli → core}/introspect/transform.d.ts +0 -0
- /package/{cli → core}/introspect/transform.js +0 -0
- /package/{cli → core}/watch/cache.d.ts +0 -0
- /package/{cli → core}/watch/cache.js +0 -0
- /package/{cli → core}/watch/debounce.d.ts +0 -0
- /package/{cli → core}/watch/debounce.js +0 -0
- /package/{cli → core}/watch/hash.d.ts +0 -0
- /package/{cli → core}/watch/hash.js +0 -0
- /package/{cli → core}/watch/index.d.ts +0 -0
- /package/{cli → core}/watch/index.js +0 -0
- /package/{cli → core}/watch/poller.d.ts +0 -0
- /package/{cli → core}/watch/poller.js +0 -0
- /package/{cli → core}/watch/types.js +0 -0
- /package/esm/{cli → core}/codegen/babel-ast.d.ts +0 -0
- /package/esm/{cli → core}/codegen/babel-ast.js +0 -0
- /package/esm/{cli → core}/codegen/client.d.ts +0 -0
- /package/esm/{cli → core}/codegen/client.js +0 -0
- /package/esm/{cli → core}/codegen/custom-mutations.d.ts +0 -0
- /package/esm/{cli → core}/codegen/custom-mutations.js +0 -0
- /package/esm/{cli → core}/codegen/custom-queries.d.ts +0 -0
- /package/esm/{cli → core}/codegen/custom-queries.js +0 -0
- /package/esm/{cli → core}/codegen/gql-ast.d.ts +0 -0
- /package/esm/{cli → core}/codegen/gql-ast.js +0 -0
- /package/esm/{cli → core}/codegen/invalidation.js +0 -0
- /package/esm/{cli → core}/codegen/mutation-keys.js +0 -0
- /package/esm/{cli → core}/codegen/mutations.d.ts +0 -0
- /package/esm/{cli → core}/codegen/mutations.js +0 -0
- /package/esm/{cli → core}/codegen/orm/barrel.d.ts +0 -0
- /package/esm/{cli → core}/codegen/orm/barrel.js +0 -0
- /package/esm/{cli → core}/codegen/orm/client-generator.d.ts +0 -0
- /package/esm/{cli → core}/codegen/orm/client.d.ts +0 -0
- /package/esm/{cli → core}/codegen/orm/client.js +0 -0
- /package/esm/{cli → core}/codegen/orm/custom-ops-generator.d.ts +0 -0
- /package/esm/{cli → core}/codegen/orm/custom-ops-generator.js +0 -0
- /package/esm/{cli → core}/codegen/orm/input-types-generator.d.ts +0 -0
- /package/esm/{cli → core}/codegen/orm/input-types-generator.js +0 -0
- /package/esm/{cli → core}/codegen/orm/model-generator.d.ts +0 -0
- /package/esm/{cli → core}/codegen/orm/model-generator.js +0 -0
- /package/esm/{cli → core}/codegen/orm/query-builder.d.ts +0 -0
- /package/esm/{cli → core}/codegen/orm/query-builder.js +0 -0
- /package/esm/{cli → core}/codegen/orm/select-types.d.ts +0 -0
- /package/esm/{cli → core}/codegen/orm/select-types.js +0 -0
- /package/esm/{cli → core}/codegen/queries.d.ts +0 -0
- /package/esm/{cli → core}/codegen/queries.js +0 -0
- /package/esm/{cli → core}/codegen/query-keys.js +0 -0
- /package/esm/{cli → core}/codegen/scalars.d.ts +0 -0
- /package/esm/{cli → core}/codegen/scalars.js +0 -0
- /package/esm/{cli → core}/codegen/schema-gql-ast.d.ts +0 -0
- /package/esm/{cli → core}/codegen/schema-gql-ast.js +0 -0
- /package/esm/{cli → core}/codegen/schema-types-generator.d.ts +0 -0
- /package/esm/{cli → core}/codegen/schema-types-generator.js +0 -0
- /package/esm/{cli → core}/codegen/type-resolver.d.ts +0 -0
- /package/esm/{cli → core}/codegen/type-resolver.js +0 -0
- /package/esm/{cli → core}/codegen/types.d.ts +0 -0
- /package/esm/{cli → core}/codegen/types.js +0 -0
- /package/esm/{cli → core}/codegen/utils.d.ts +0 -0
- /package/esm/{cli → core}/codegen/utils.js +0 -0
- /package/esm/{cli → core}/introspect/fetch-schema.d.ts +0 -0
- /package/esm/{cli → core}/introspect/index.d.ts +0 -0
- /package/esm/{cli → core}/introspect/index.js +0 -0
- /package/esm/{cli → core}/introspect/infer-tables.d.ts +0 -0
- /package/esm/{cli → core}/introspect/infer-tables.js +0 -0
- /package/esm/{cli → core}/introspect/schema-query.d.ts +0 -0
- /package/esm/{cli → core}/introspect/schema-query.js +0 -0
- /package/esm/{cli → core}/introspect/source/endpoint.d.ts +0 -0
- /package/esm/{cli → core}/introspect/source/endpoint.js +0 -0
- /package/esm/{cli → core}/introspect/source/file.d.ts +0 -0
- /package/esm/{cli → core}/introspect/source/file.js +0 -0
- /package/esm/{cli → core}/introspect/source/types.d.ts +0 -0
- /package/esm/{cli → core}/introspect/source/types.js +0 -0
- /package/esm/{cli → core}/introspect/transform-schema.d.ts +0 -0
- /package/esm/{cli → core}/introspect/transform-schema.js +0 -0
- /package/esm/{cli → core}/introspect/transform.d.ts +0 -0
- /package/esm/{cli → core}/introspect/transform.js +0 -0
- /package/esm/{cli → core}/watch/cache.d.ts +0 -0
- /package/esm/{cli → core}/watch/cache.js +0 -0
- /package/esm/{cli → core}/watch/debounce.d.ts +0 -0
- /package/esm/{cli → core}/watch/debounce.js +0 -0
- /package/esm/{cli → core}/watch/hash.d.ts +0 -0
- /package/esm/{cli → core}/watch/hash.js +0 -0
- /package/esm/{cli → core}/watch/index.d.ts +0 -0
- /package/esm/{cli → core}/watch/index.js +0 -0
- /package/esm/{cli → core}/watch/poller.d.ts +0 -0
- /package/esm/{cli → core}/watch/poller.js +0 -0
- /package/esm/{cli → core}/watch/types.js +0 -0
package/cli/index.js
CHANGED
|
@@ -1,588 +1,114 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.options = exports.commands = void 0;
|
|
3
5
|
/**
|
|
4
6
|
* CLI entry point for graphql-codegen
|
|
7
|
+
*
|
|
8
|
+
* This is a thin wrapper around the core generate() function.
|
|
9
|
+
* All business logic is in the core modules.
|
|
5
10
|
*/
|
|
6
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
-
if (k2 === undefined) k2 = k;
|
|
8
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
-
}
|
|
12
|
-
Object.defineProperty(o, k2, desc);
|
|
13
|
-
}) : (function(o, m, k, k2) {
|
|
14
|
-
if (k2 === undefined) k2 = k;
|
|
15
|
-
o[k2] = m[k];
|
|
16
|
-
}));
|
|
17
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
-
}) : function(o, v) {
|
|
20
|
-
o["default"] = v;
|
|
21
|
-
});
|
|
22
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
-
var ownKeys = function(o) {
|
|
24
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
-
var ar = [];
|
|
26
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
-
return ar;
|
|
28
|
-
};
|
|
29
|
-
return ownKeys(o);
|
|
30
|
-
};
|
|
31
|
-
return function (mod) {
|
|
32
|
-
if (mod && mod.__esModule) return mod;
|
|
33
|
-
var result = {};
|
|
34
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
-
__setModuleDefault(result, mod);
|
|
36
|
-
return result;
|
|
37
|
-
};
|
|
38
|
-
})();
|
|
39
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
-
exports.options = exports.commands = void 0;
|
|
41
11
|
const inquirerer_1 = require("inquirerer");
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
const usageText = `
|
|
48
|
-
graphql-codegen - CLI for generating GraphQL SDK from PostGraphile endpoints or schema files
|
|
12
|
+
const generate_1 = require("../core/generate");
|
|
13
|
+
const config_1 = require("../core/config");
|
|
14
|
+
const shared_1 = require("./shared");
|
|
15
|
+
const usage = `
|
|
16
|
+
graphql-codegen - GraphQL SDK generator for Constructive databases
|
|
49
17
|
|
|
50
18
|
Usage:
|
|
51
|
-
graphql-codegen
|
|
19
|
+
graphql-codegen [options]
|
|
52
20
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
introspect Introspect a GraphQL endpoint or schema file and print table info
|
|
21
|
+
Source Options (choose one):
|
|
22
|
+
-c, --config <path> Path to config file
|
|
23
|
+
-e, --endpoint <url> GraphQL endpoint URL
|
|
24
|
+
-s, --schema-file <path> Path to GraphQL schema file
|
|
58
25
|
|
|
59
|
-
Options:
|
|
60
|
-
--
|
|
61
|
-
--
|
|
26
|
+
Database Options:
|
|
27
|
+
--schemas <list> Comma-separated PostgreSQL schemas
|
|
28
|
+
--api-names <list> Comma-separated API names (mutually exclusive with --schemas)
|
|
62
29
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
30
|
+
Generator Options:
|
|
31
|
+
--react-query Generate React Query hooks
|
|
32
|
+
--orm Generate ORM client
|
|
33
|
+
-o, --output <dir> Output directory
|
|
34
|
+
-t, --target <name> Target name (for multi-target configs)
|
|
35
|
+
-a, --authorization <token> Authorization header value
|
|
36
|
+
--dry-run Preview without writing files
|
|
37
|
+
-v, --verbose Show detailed output
|
|
70
38
|
|
|
71
|
-
|
|
72
|
-
--
|
|
73
|
-
--force, -f Force overwrite existing config
|
|
74
|
-
--endpoint, -e <url> GraphQL endpoint URL to pre-populate
|
|
75
|
-
--output, -o <dir> Output directory to pre-populate (default: ./generated)
|
|
76
|
-
--help, -h Show this help message
|
|
39
|
+
-h, --help Show this help message
|
|
40
|
+
--version Show version number
|
|
77
41
|
`;
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
graphql-codegen generate [options]
|
|
83
|
-
|
|
84
|
-
Options:
|
|
85
|
-
--config, -c <path> Path to config file
|
|
86
|
-
--target, -t <name> Target name in config file
|
|
87
|
-
--endpoint, -e <url> GraphQL endpoint URL (overrides config)
|
|
88
|
-
--schema, -s <path> Path to GraphQL schema file (.graphql)
|
|
89
|
-
--output, -o <dir> Output directory (overrides config)
|
|
90
|
-
--authorization, -a <header> Authorization header value
|
|
91
|
-
--verbose, -v Verbose output
|
|
92
|
-
--dry-run Dry run - show what would be generated without writing files
|
|
93
|
-
--watch, -w Watch mode - poll endpoint for schema changes (in-memory)
|
|
94
|
-
--poll-interval <ms> Polling interval in milliseconds (default: 3000)
|
|
95
|
-
--debounce <ms> Debounce delay before regenerating (default: 800)
|
|
96
|
-
--touch <file> File to touch on schema change
|
|
97
|
-
--no-clear Do not clear terminal on regeneration
|
|
98
|
-
--help, -h Show this help message
|
|
99
|
-
`;
|
|
100
|
-
const generateOrmUsageText = `
|
|
101
|
-
graphql-codegen generate-orm - Generate Prisma-like ORM client from GraphQL endpoint or schema file
|
|
102
|
-
|
|
103
|
-
Usage:
|
|
104
|
-
graphql-codegen generate-orm [options]
|
|
105
|
-
|
|
106
|
-
Options:
|
|
107
|
-
--config, -c <path> Path to config file
|
|
108
|
-
--target, -t <name> Target name in config file
|
|
109
|
-
--endpoint, -e <url> GraphQL endpoint URL (overrides config)
|
|
110
|
-
--schema, -s <path> Path to GraphQL schema file (.graphql)
|
|
111
|
-
--output, -o <dir> Output directory (overrides config)
|
|
112
|
-
--authorization, -a <header> Authorization header value
|
|
113
|
-
--verbose, -v Verbose output
|
|
114
|
-
--dry-run Dry run - show what would be generated without writing files
|
|
115
|
-
--skip-custom-operations Skip custom operations (only generate table CRUD)
|
|
116
|
-
--watch, -w Watch mode - poll endpoint for schema changes (in-memory)
|
|
117
|
-
--poll-interval <ms> Polling interval in milliseconds (default: 3000)
|
|
118
|
-
--debounce <ms> Debounce delay before regenerating (default: 800)
|
|
119
|
-
--touch <file> File to touch on schema change
|
|
120
|
-
--no-clear Do not clear terminal on regeneration
|
|
121
|
-
--help, -h Show this help message
|
|
122
|
-
`;
|
|
123
|
-
const introspectUsageText = `
|
|
124
|
-
graphql-codegen introspect - Introspect a GraphQL endpoint or schema file and print table info
|
|
125
|
-
|
|
126
|
-
Usage:
|
|
127
|
-
graphql-codegen introspect [options]
|
|
128
|
-
|
|
129
|
-
Options:
|
|
130
|
-
--endpoint, -e <url> GraphQL endpoint URL
|
|
131
|
-
--schema, -s <path> Path to GraphQL schema file (.graphql)
|
|
132
|
-
--authorization, -a <header> Authorization header value
|
|
133
|
-
--json Output as JSON
|
|
134
|
-
--help, -h Show this help message
|
|
135
|
-
`;
|
|
136
|
-
/**
|
|
137
|
-
* Format duration in a human-readable way
|
|
138
|
-
* - Under 1 second: show milliseconds (e.g., "123ms")
|
|
139
|
-
* - Over 1 second: show seconds with 2 decimal places (e.g., "1.23s")
|
|
140
|
-
*/
|
|
141
|
-
function formatDuration(ms) {
|
|
142
|
-
if (ms < 1000) {
|
|
143
|
-
return `${Math.round(ms)}ms`;
|
|
144
|
-
}
|
|
145
|
-
return `${(ms / 1000).toFixed(2)}s`;
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Load configuration for watch mode, merging CLI options with config file
|
|
149
|
-
*/
|
|
150
|
-
async function loadWatchConfig(options) {
|
|
151
|
-
let configPath = options.config;
|
|
152
|
-
if (!configPath) {
|
|
153
|
-
configPath = (0, init_1.findConfigFile)() ?? undefined;
|
|
154
|
-
}
|
|
155
|
-
let baseConfig = {};
|
|
156
|
-
if (configPath) {
|
|
157
|
-
const loadResult = await (0, init_1.loadConfigFile)(configPath);
|
|
158
|
-
if (!loadResult.success) {
|
|
159
|
-
console.error('x', loadResult.error);
|
|
160
|
-
return null;
|
|
161
|
-
}
|
|
162
|
-
baseConfig = loadResult.config;
|
|
163
|
-
}
|
|
164
|
-
if ((0, config_1.isMultiConfig)(baseConfig)) {
|
|
165
|
-
if (!options.target) {
|
|
166
|
-
console.error('x Watch mode requires --target when using multiple targets.');
|
|
167
|
-
return null;
|
|
168
|
-
}
|
|
169
|
-
if (!baseConfig.targets[options.target]) {
|
|
170
|
-
console.error(`x Target "${options.target}" not found in config file.`);
|
|
171
|
-
return null;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
else if (options.target) {
|
|
175
|
-
console.error('x Config file does not define targets. Remove --target.');
|
|
176
|
-
return null;
|
|
177
|
-
}
|
|
178
|
-
const sourceOverrides = {};
|
|
179
|
-
if (options.endpoint) {
|
|
180
|
-
sourceOverrides.endpoint = options.endpoint;
|
|
181
|
-
sourceOverrides.schema = undefined;
|
|
182
|
-
}
|
|
183
|
-
const watchOverrides = {
|
|
184
|
-
watch: {
|
|
185
|
-
...(options.pollInterval !== undefined && {
|
|
186
|
-
pollInterval: options.pollInterval,
|
|
187
|
-
}),
|
|
188
|
-
...(options.debounce !== undefined && { debounce: options.debounce }),
|
|
189
|
-
...(options.touch !== undefined && { touchFile: options.touch }),
|
|
190
|
-
...(options.clear !== undefined && { clearScreen: options.clear }),
|
|
191
|
-
},
|
|
192
|
-
};
|
|
193
|
-
let mergedTarget;
|
|
194
|
-
if ((0, config_1.isMultiConfig)(baseConfig)) {
|
|
195
|
-
const defaults = baseConfig.defaults ?? {};
|
|
196
|
-
const targetConfig = baseConfig.targets[options.target];
|
|
197
|
-
mergedTarget = (0, config_1.mergeConfig)(defaults, targetConfig);
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
mergedTarget = baseConfig;
|
|
201
|
-
}
|
|
202
|
-
mergedTarget = (0, config_1.mergeConfig)(mergedTarget, sourceOverrides);
|
|
203
|
-
mergedTarget = (0, config_1.mergeConfig)(mergedTarget, watchOverrides);
|
|
204
|
-
if (!mergedTarget.endpoint) {
|
|
205
|
-
console.error('x No endpoint specified. Watch mode only supports live endpoints.');
|
|
206
|
-
return null;
|
|
207
|
-
}
|
|
208
|
-
if (mergedTarget.schema) {
|
|
209
|
-
console.error('x Watch mode is only supported with an endpoint, not schema.');
|
|
210
|
-
return null;
|
|
211
|
-
}
|
|
212
|
-
return (0, config_1.resolveConfig)(mergedTarget);
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Init command handler
|
|
216
|
-
*/
|
|
217
|
-
async function handleInit(argv) {
|
|
218
|
-
if (argv.help || argv.h) {
|
|
219
|
-
console.log(initUsageText);
|
|
42
|
+
const commands = async (argv, prompter, _options) => {
|
|
43
|
+
if (argv.version) {
|
|
44
|
+
const pkg = (0, inquirerer_1.getPackageJson)(__dirname);
|
|
45
|
+
console.log(pkg.version);
|
|
220
46
|
process.exit(0);
|
|
221
47
|
}
|
|
222
|
-
const startTime = performance.now();
|
|
223
|
-
const result = await (0, init_1.initCommand)({
|
|
224
|
-
directory: argv.directory || argv.d || '.',
|
|
225
|
-
force: !!(argv.force || argv.f),
|
|
226
|
-
endpoint: argv.endpoint || argv.e,
|
|
227
|
-
output: argv.output || argv.o || './generated',
|
|
228
|
-
});
|
|
229
|
-
const duration = formatDuration(performance.now() - startTime);
|
|
230
|
-
if (result.success) {
|
|
231
|
-
console.log('[ok]', result.message, `(${duration})`);
|
|
232
|
-
}
|
|
233
|
-
else {
|
|
234
|
-
console.error('x', result.message, `(${duration})`);
|
|
235
|
-
process.exit(1);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Generate command handler
|
|
240
|
-
*/
|
|
241
|
-
async function handleGenerate(argv) {
|
|
242
48
|
if (argv.help || argv.h) {
|
|
243
|
-
console.log(
|
|
49
|
+
console.log(usage);
|
|
244
50
|
process.exit(0);
|
|
245
51
|
}
|
|
246
|
-
const
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
const verbose = !!(argv.verbose || argv.v);
|
|
254
|
-
const dryRun = !!(argv['dry-run'] || argv.dryRun);
|
|
255
|
-
const watch = !!(argv.watch || argv.w);
|
|
256
|
-
const pollInterval = argv['poll-interval'] !== undefined
|
|
257
|
-
? parseInt(argv['poll-interval'], 10)
|
|
258
|
-
: undefined;
|
|
259
|
-
const debounce = argv.debounce !== undefined
|
|
260
|
-
? parseInt(argv.debounce, 10)
|
|
261
|
-
: undefined;
|
|
262
|
-
const touch = argv.touch;
|
|
263
|
-
const clear = argv.clear !== false;
|
|
264
|
-
if (endpoint && schema) {
|
|
265
|
-
console.error('x Cannot use both --endpoint and --schema. Choose one source.');
|
|
266
|
-
process.exit(1);
|
|
267
|
-
}
|
|
268
|
-
if (watch) {
|
|
269
|
-
if (schema) {
|
|
270
|
-
console.error('x Watch mode is only supported with --endpoint, not --schema.');
|
|
271
|
-
process.exit(1);
|
|
272
|
-
}
|
|
273
|
-
const watchConfig = await loadWatchConfig({
|
|
274
|
-
config,
|
|
275
|
-
target,
|
|
276
|
-
endpoint,
|
|
277
|
-
output,
|
|
278
|
-
pollInterval,
|
|
279
|
-
debounce,
|
|
280
|
-
touch,
|
|
281
|
-
clear,
|
|
282
|
-
});
|
|
283
|
-
if (!watchConfig) {
|
|
284
|
-
process.exit(1);
|
|
285
|
-
}
|
|
286
|
-
await (0, watch_1.startWatch)({
|
|
287
|
-
config: watchConfig,
|
|
288
|
-
generatorType: 'generate',
|
|
289
|
-
verbose,
|
|
290
|
-
authorization,
|
|
291
|
-
configPath: config,
|
|
292
|
-
target,
|
|
293
|
-
outputDir: output,
|
|
294
|
-
});
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
|
-
const result = await (0, generate_1.generateCommand)({
|
|
298
|
-
config,
|
|
299
|
-
target,
|
|
300
|
-
endpoint,
|
|
301
|
-
schema,
|
|
302
|
-
output,
|
|
303
|
-
authorization,
|
|
304
|
-
verbose,
|
|
305
|
-
dryRun,
|
|
306
|
-
});
|
|
307
|
-
const duration = formatDuration(performance.now() - startTime);
|
|
308
|
-
const targetResults = result.targets ?? [];
|
|
309
|
-
const hasNamedTargets = targetResults.length > 0 &&
|
|
310
|
-
(targetResults.length > 1 || targetResults[0]?.name !== 'default');
|
|
311
|
-
if (hasNamedTargets) {
|
|
312
|
-
console.log(result.success ? '[ok]' : 'x', result.message);
|
|
313
|
-
targetResults.forEach((t) => {
|
|
314
|
-
const status = t.success ? '[ok]' : 'x';
|
|
315
|
-
console.log(`\n${status} ${t.message}`);
|
|
316
|
-
if (t.tables && t.tables.length > 0) {
|
|
317
|
-
console.log(' Tables:');
|
|
318
|
-
t.tables.forEach((table) => console.log(` - ${table}`));
|
|
319
|
-
}
|
|
320
|
-
if (t.filesWritten && t.filesWritten.length > 0) {
|
|
321
|
-
console.log(' Files written:');
|
|
322
|
-
t.filesWritten.forEach((file) => console.log(` - ${file}`));
|
|
323
|
-
}
|
|
324
|
-
if (!t.success && t.errors) {
|
|
325
|
-
t.errors.forEach((error) => console.error(` - ${error}`));
|
|
326
|
-
}
|
|
327
|
-
});
|
|
328
|
-
if (!result.success) {
|
|
329
|
-
process.exit(1);
|
|
330
|
-
}
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
333
|
-
if (result.success) {
|
|
334
|
-
console.log('[ok]', result.message, `(${duration})`);
|
|
335
|
-
if (result.tables && result.tables.length > 0) {
|
|
336
|
-
console.log('\nTables:');
|
|
337
|
-
result.tables.forEach((t) => console.log(` - ${t}`));
|
|
338
|
-
}
|
|
339
|
-
if (result.filesWritten && result.filesWritten.length > 0) {
|
|
340
|
-
console.log('\nFiles written:');
|
|
341
|
-
result.filesWritten.forEach((f) => console.log(` - ${f}`));
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
else {
|
|
345
|
-
console.error('x', result.message, `(${duration})`);
|
|
346
|
-
if (result.errors) {
|
|
347
|
-
result.errors.forEach((e) => console.error(' -', e));
|
|
348
|
-
}
|
|
349
|
-
process.exit(1);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
/**
|
|
353
|
-
* Generate ORM command handler
|
|
354
|
-
*/
|
|
355
|
-
async function handleGenerateOrm(argv) {
|
|
356
|
-
if (argv.help || argv.h) {
|
|
357
|
-
console.log(generateOrmUsageText);
|
|
358
|
-
process.exit(0);
|
|
359
|
-
}
|
|
360
|
-
const startTime = performance.now();
|
|
361
|
-
const config = argv.config || argv.c;
|
|
362
|
-
const target = argv.target || argv.t;
|
|
363
|
-
const endpoint = argv.endpoint || argv.e;
|
|
364
|
-
const schema = argv.schema || argv.s;
|
|
365
|
-
const output = argv.output || argv.o;
|
|
366
|
-
const authorization = argv.authorization || argv.a;
|
|
367
|
-
const verbose = !!(argv.verbose || argv.v);
|
|
368
|
-
const dryRun = !!(argv['dry-run'] || argv.dryRun);
|
|
369
|
-
const skipCustomOperations = !!(argv['skip-custom-operations'] || argv.skipCustomOperations);
|
|
370
|
-
const watch = !!(argv.watch || argv.w);
|
|
371
|
-
const pollInterval = argv['poll-interval'] !== undefined
|
|
372
|
-
? parseInt(argv['poll-interval'], 10)
|
|
373
|
-
: undefined;
|
|
374
|
-
const debounce = argv.debounce !== undefined
|
|
375
|
-
? parseInt(argv.debounce, 10)
|
|
376
|
-
: undefined;
|
|
377
|
-
const touch = argv.touch;
|
|
378
|
-
const clear = argv.clear !== false;
|
|
379
|
-
if (endpoint && schema) {
|
|
380
|
-
console.error('x Cannot use both --endpoint and --schema. Choose one source.');
|
|
381
|
-
process.exit(1);
|
|
382
|
-
}
|
|
383
|
-
if (watch) {
|
|
384
|
-
if (schema) {
|
|
385
|
-
console.error('x Watch mode is only supported with --endpoint, not --schema.');
|
|
386
|
-
process.exit(1);
|
|
387
|
-
}
|
|
388
|
-
const watchConfig = await loadWatchConfig({
|
|
389
|
-
config,
|
|
390
|
-
target,
|
|
391
|
-
endpoint,
|
|
392
|
-
output,
|
|
393
|
-
pollInterval,
|
|
394
|
-
debounce,
|
|
395
|
-
touch,
|
|
396
|
-
clear,
|
|
397
|
-
});
|
|
398
|
-
if (!watchConfig) {
|
|
52
|
+
const configPath = (argv.config || argv.c || (0, config_1.findConfigFile)());
|
|
53
|
+
const targetName = (argv.target || argv.t);
|
|
54
|
+
// If config file exists, load and run
|
|
55
|
+
if (configPath) {
|
|
56
|
+
const loaded = await (0, config_1.loadConfigFile)(configPath);
|
|
57
|
+
if (!loaded.success) {
|
|
58
|
+
console.error('x', loaded.error);
|
|
399
59
|
process.exit(1);
|
|
400
60
|
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
return;
|
|
412
|
-
}
|
|
413
|
-
const result = await (0, generate_orm_1.generateOrmCommand)({
|
|
414
|
-
config,
|
|
415
|
-
target,
|
|
416
|
-
endpoint,
|
|
417
|
-
schema,
|
|
418
|
-
output,
|
|
419
|
-
authorization,
|
|
420
|
-
verbose,
|
|
421
|
-
dryRun,
|
|
422
|
-
skipCustomOperations,
|
|
423
|
-
});
|
|
424
|
-
const duration = formatDuration(performance.now() - startTime);
|
|
425
|
-
const targetResults = result.targets ?? [];
|
|
426
|
-
const hasNamedTargets = targetResults.length > 0 &&
|
|
427
|
-
(targetResults.length > 1 || targetResults[0]?.name !== 'default');
|
|
428
|
-
if (hasNamedTargets) {
|
|
429
|
-
console.log(result.success ? '[ok]' : 'x', result.message);
|
|
430
|
-
targetResults.forEach((t) => {
|
|
431
|
-
const status = t.success ? '[ok]' : 'x';
|
|
432
|
-
console.log(`\n${status} ${t.message}`);
|
|
433
|
-
if (t.tables && t.tables.length > 0) {
|
|
434
|
-
console.log(' Tables:');
|
|
435
|
-
t.tables.forEach((table) => console.log(` - ${table}`));
|
|
436
|
-
}
|
|
437
|
-
if (t.customQueries && t.customQueries.length > 0) {
|
|
438
|
-
console.log(' Custom Queries:');
|
|
439
|
-
t.customQueries.forEach((query) => console.log(` - ${query}`));
|
|
440
|
-
}
|
|
441
|
-
if (t.customMutations && t.customMutations.length > 0) {
|
|
442
|
-
console.log(' Custom Mutations:');
|
|
443
|
-
t.customMutations.forEach((mutation) => console.log(` - ${mutation}`));
|
|
61
|
+
const config = loaded.config;
|
|
62
|
+
// Check if it's a multi-target config (no source fields at top level)
|
|
63
|
+
const isMulti = !('endpoint' in config || 'schemaFile' in config || 'db' in config);
|
|
64
|
+
if (isMulti) {
|
|
65
|
+
// Multi-target: simple for loop over targets
|
|
66
|
+
const targets = config;
|
|
67
|
+
const names = targetName ? [targetName] : Object.keys(targets);
|
|
68
|
+
if (targetName && !targets[targetName]) {
|
|
69
|
+
console.error('x', `Target "${targetName}" not found. Available: ${Object.keys(targets).join(', ')}`);
|
|
70
|
+
process.exit(1);
|
|
444
71
|
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
72
|
+
let hasError = false;
|
|
73
|
+
for (const name of names) {
|
|
74
|
+
console.log(`\n[${name}]`);
|
|
75
|
+
const result = await (0, generate_1.generate)(targets[name]);
|
|
76
|
+
(0, shared_1.printResult)(result);
|
|
77
|
+
if (!result.success)
|
|
78
|
+
hasError = true;
|
|
448
79
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
80
|
+
prompter.close();
|
|
81
|
+
if (hasError)
|
|
82
|
+
process.exit(1);
|
|
83
|
+
return argv;
|
|
84
|
+
}
|
|
85
|
+
// Single config
|
|
86
|
+
const result = await (0, generate_1.generate)(config);
|
|
87
|
+
(0, shared_1.printResult)(result);
|
|
88
|
+
if (!result.success)
|
|
454
89
|
process.exit(1);
|
|
455
|
-
}
|
|
456
|
-
return;
|
|
457
|
-
}
|
|
458
|
-
if (result.success) {
|
|
459
|
-
console.log('[ok]', result.message, `(${duration})`);
|
|
460
|
-
if (result.tables && result.tables.length > 0) {
|
|
461
|
-
console.log('\nTables:');
|
|
462
|
-
result.tables.forEach((t) => console.log(` - ${t}`));
|
|
463
|
-
}
|
|
464
|
-
if (result.customQueries && result.customQueries.length > 0) {
|
|
465
|
-
console.log('\nCustom Queries:');
|
|
466
|
-
result.customQueries.forEach((q) => console.log(` - ${q}`));
|
|
467
|
-
}
|
|
468
|
-
if (result.customMutations && result.customMutations.length > 0) {
|
|
469
|
-
console.log('\nCustom Mutations:');
|
|
470
|
-
result.customMutations.forEach((m) => console.log(` - ${m}`));
|
|
471
|
-
}
|
|
472
|
-
if (result.filesWritten && result.filesWritten.length > 0) {
|
|
473
|
-
console.log('\nFiles written:');
|
|
474
|
-
result.filesWritten.forEach((f) => console.log(` - ${f}`));
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
else {
|
|
478
|
-
console.error('x', result.message, `(${duration})`);
|
|
479
|
-
if (result.errors) {
|
|
480
|
-
result.errors.forEach((e) => console.error(' -', e));
|
|
481
|
-
}
|
|
482
|
-
process.exit(1);
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
/**
|
|
486
|
-
* Introspect command handler
|
|
487
|
-
*/
|
|
488
|
-
async function handleIntrospect(argv) {
|
|
489
|
-
if (argv.help || argv.h) {
|
|
490
|
-
console.log(introspectUsageText);
|
|
491
|
-
process.exit(0);
|
|
492
|
-
}
|
|
493
|
-
const startTime = performance.now();
|
|
494
|
-
const endpoint = argv.endpoint || argv.e;
|
|
495
|
-
const schema = argv.schema || argv.s;
|
|
496
|
-
const authorization = argv.authorization || argv.a;
|
|
497
|
-
const json = !!argv.json;
|
|
498
|
-
if (!endpoint && !schema) {
|
|
499
|
-
console.error('x Either --endpoint or --schema must be provided.');
|
|
500
|
-
process.exit(1);
|
|
501
|
-
}
|
|
502
|
-
if (endpoint && schema) {
|
|
503
|
-
console.error('x Cannot use both --endpoint and --schema. Choose one source.');
|
|
504
|
-
process.exit(1);
|
|
505
|
-
}
|
|
506
|
-
const { createSchemaSource } = await Promise.resolve().then(() => __importStar(require('./introspect/source')));
|
|
507
|
-
const { inferTablesFromIntrospection } = await Promise.resolve().then(() => __importStar(require('./introspect/infer-tables')));
|
|
508
|
-
try {
|
|
509
|
-
const source = createSchemaSource({
|
|
510
|
-
endpoint,
|
|
511
|
-
schema,
|
|
512
|
-
authorization,
|
|
513
|
-
});
|
|
514
|
-
console.log('Fetching schema from', source.describe(), '...');
|
|
515
|
-
const { introspection } = await source.fetch();
|
|
516
|
-
const tables = inferTablesFromIntrospection(introspection);
|
|
517
|
-
const duration = formatDuration(performance.now() - startTime);
|
|
518
|
-
if (json) {
|
|
519
|
-
console.log(JSON.stringify(tables, null, 2));
|
|
520
|
-
}
|
|
521
|
-
else {
|
|
522
|
-
console.log(`\n[ok] Found ${tables.length} tables (${duration}):\n`);
|
|
523
|
-
tables.forEach((table) => {
|
|
524
|
-
const fieldCount = table.fields.length;
|
|
525
|
-
const relationCount = table.relations.belongsTo.length +
|
|
526
|
-
table.relations.hasOne.length +
|
|
527
|
-
table.relations.hasMany.length +
|
|
528
|
-
table.relations.manyToMany.length;
|
|
529
|
-
console.log(` ${table.name} (${fieldCount} fields, ${relationCount} relations)`);
|
|
530
|
-
});
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
catch (err) {
|
|
534
|
-
const duration = formatDuration(performance.now() - startTime);
|
|
535
|
-
console.error('x Failed to introspect schema:', err instanceof Error ? err.message : err, `(${duration})`);
|
|
536
|
-
process.exit(1);
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
const createCommandMap = () => {
|
|
540
|
-
return {
|
|
541
|
-
init: handleInit,
|
|
542
|
-
generate: handleGenerate,
|
|
543
|
-
'generate-orm': handleGenerateOrm,
|
|
544
|
-
introspect: handleIntrospect,
|
|
545
|
-
};
|
|
546
|
-
};
|
|
547
|
-
const commands = async (argv, prompter, _options) => {
|
|
548
|
-
if (argv.version || argv.v) {
|
|
549
|
-
const pkg = (0, inquirerer_1.getPackageJson)(__dirname);
|
|
550
|
-
console.log(pkg.version);
|
|
551
|
-
process.exit(0);
|
|
552
|
-
}
|
|
553
|
-
const { first: command, newArgv } = (0, inquirerer_1.extractFirst)(argv);
|
|
554
|
-
if ((argv.help || argv.h) && !command) {
|
|
555
|
-
console.log(usageText);
|
|
556
|
-
process.exit(0);
|
|
557
|
-
}
|
|
558
|
-
if (command === 'help') {
|
|
559
|
-
console.log(usageText);
|
|
560
|
-
process.exit(0);
|
|
561
|
-
}
|
|
562
|
-
const commandMap = createCommandMap();
|
|
563
|
-
if (!command) {
|
|
564
|
-
const answer = await prompter.prompt(argv, [
|
|
565
|
-
{
|
|
566
|
-
type: 'autocomplete',
|
|
567
|
-
name: 'command',
|
|
568
|
-
message: 'What do you want to do?',
|
|
569
|
-
options: Object.keys(commandMap),
|
|
570
|
-
},
|
|
571
|
-
]);
|
|
572
|
-
const selectedCommand = answer.command;
|
|
573
|
-
const commandFn = commandMap[selectedCommand];
|
|
574
|
-
if (commandFn) {
|
|
575
|
-
await commandFn(newArgv);
|
|
576
|
-
}
|
|
577
90
|
prompter.close();
|
|
578
91
|
return argv;
|
|
579
92
|
}
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
93
|
+
// No config file - prompt for options using shared questions
|
|
94
|
+
const answers = await prompter.prompt(argv, shared_1.codegenQuestions);
|
|
95
|
+
// Build db config if schemas or apiNames provided
|
|
96
|
+
const db = (answers.schemas || answers.apiNames) ? {
|
|
97
|
+
schemas: answers.schemas,
|
|
98
|
+
apiNames: answers.apiNames,
|
|
99
|
+
} : undefined;
|
|
100
|
+
const result = await (0, generate_1.generate)({
|
|
101
|
+
endpoint: answers.endpoint,
|
|
102
|
+
schemaFile: answers.schemaFile,
|
|
103
|
+
db,
|
|
104
|
+
output: answers.output,
|
|
105
|
+
authorization: answers.authorization,
|
|
106
|
+
reactQuery: answers.reactQuery,
|
|
107
|
+
orm: answers.orm,
|
|
108
|
+
dryRun: answers.dryRun,
|
|
109
|
+
verbose: answers.verbose,
|
|
110
|
+
});
|
|
111
|
+
(0, shared_1.printResult)(result);
|
|
586
112
|
prompter.close();
|
|
587
113
|
return argv;
|
|
588
114
|
};
|
|
@@ -590,35 +116,26 @@ exports.commands = commands;
|
|
|
590
116
|
exports.options = {
|
|
591
117
|
minimistOpts: {
|
|
592
118
|
alias: {
|
|
593
|
-
v: 'version',
|
|
594
119
|
h: 'help',
|
|
595
120
|
c: 'config',
|
|
596
|
-
t: 'target',
|
|
597
121
|
e: 'endpoint',
|
|
598
|
-
s: 'schema',
|
|
122
|
+
s: 'schema-file',
|
|
599
123
|
o: 'output',
|
|
124
|
+
t: 'target',
|
|
600
125
|
a: 'authorization',
|
|
601
|
-
|
|
602
|
-
f: 'force',
|
|
603
|
-
w: 'watch',
|
|
604
|
-
},
|
|
605
|
-
boolean: ['help', 'version', 'force', 'verbose', 'dry-run', 'watch', 'json', 'skip-custom-operations', 'clear'],
|
|
606
|
-
string: ['config', 'target', 'endpoint', 'schema', 'output', 'authorization', 'directory', 'touch', 'poll-interval', 'debounce'],
|
|
607
|
-
default: {
|
|
608
|
-
clear: true,
|
|
126
|
+
v: 'verbose',
|
|
609
127
|
},
|
|
128
|
+
boolean: [
|
|
129
|
+
'help', 'version', 'verbose', 'dry-run', 'react-query', 'orm', 'keep-db',
|
|
130
|
+
],
|
|
131
|
+
string: [
|
|
132
|
+
'config', 'endpoint', 'schema-file', 'output', 'target', 'authorization',
|
|
133
|
+
'pgpm-module-path', 'pgpm-workspace-path', 'pgpm-module-name',
|
|
134
|
+
'schemas', 'api-names',
|
|
135
|
+
],
|
|
610
136
|
},
|
|
611
137
|
};
|
|
612
138
|
if (require.main === module) {
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
console.log(pkg.version);
|
|
616
|
-
process.exit(0);
|
|
617
|
-
}
|
|
618
|
-
const app = new inquirerer_1.CLI(exports.commands, exports.options);
|
|
619
|
-
app.run().then(() => {
|
|
620
|
-
}).catch((error) => {
|
|
621
|
-
console.error('Unexpected error:', error);
|
|
622
|
-
process.exit(1);
|
|
623
|
-
});
|
|
139
|
+
const cli = new inquirerer_1.CLI(exports.commands, exports.options);
|
|
140
|
+
cli.run();
|
|
624
141
|
}
|