@constructive-io/cli 5.11.1 → 6.0.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/commands/codegen.d.ts +2 -2
- package/commands/codegen.js +40 -147
- package/commands/get-graphql-schema.d.ts +2 -2
- package/commands/get-graphql-schema.js +41 -25
- package/esm/commands/codegen.js +41 -115
- package/esm/commands/get-graphql-schema.js +41 -25
- package/package.json +11 -11
package/commands/codegen.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { CLIOptions, Inquirerer
|
|
2
|
-
declare const _default: (argv: Partial<
|
|
1
|
+
import { CLIOptions, Inquirerer } from 'inquirerer';
|
|
2
|
+
declare const _default: (argv: Partial<Record<string, unknown>>, prompter: Inquirerer, _options: CLIOptions) => Promise<void>;
|
|
3
3
|
export default _default;
|
package/commands/codegen.js
CHANGED
|
@@ -1,167 +1,60 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
const fs = __importStar(require("node:fs"));
|
|
37
|
-
const path = __importStar(require("node:path"));
|
|
38
|
-
const graphql_server_1 = require("@constructive-io/graphql-server");
|
|
39
3
|
const graphql_codegen_1 = require("@constructive-io/graphql-codegen");
|
|
40
|
-
const graphql_env_1 = require("@constructive-io/graphql-env");
|
|
41
4
|
const usage = `
|
|
42
5
|
Constructive GraphQL Codegen:
|
|
43
6
|
|
|
44
7
|
cnc codegen [OPTIONS]
|
|
45
8
|
|
|
46
|
-
Options:
|
|
47
|
-
--help, -h Show this help message
|
|
9
|
+
Source Options (choose one):
|
|
48
10
|
--config <path> Path to graphql-codegen config file
|
|
49
|
-
--target <name> Target name in config file
|
|
50
11
|
--endpoint <url> GraphQL endpoint URL
|
|
51
|
-
--
|
|
52
|
-
--out <dir> Output directory (default: codegen)
|
|
53
|
-
--dry-run Preview without writing files
|
|
54
|
-
-v, --verbose Verbose output
|
|
12
|
+
--schemaFile <path> Path to GraphQL schema file
|
|
55
13
|
|
|
56
|
-
|
|
14
|
+
Database Options:
|
|
15
|
+
--schemas <list> Comma-separated PostgreSQL schemas
|
|
16
|
+
--apiNames <list> Comma-separated API names
|
|
57
17
|
|
|
58
|
-
|
|
59
|
-
--
|
|
18
|
+
Generator Options:
|
|
19
|
+
--reactQuery Generate React Query hooks (default)
|
|
20
|
+
--orm Generate ORM client
|
|
21
|
+
--output <dir> Output directory (default: codegen)
|
|
22
|
+
--authorization <token> Authorization header value
|
|
23
|
+
--dryRun Preview without writing files
|
|
24
|
+
--verbose Verbose output
|
|
25
|
+
|
|
26
|
+
--help, -h Show this help message
|
|
60
27
|
`;
|
|
61
|
-
exports.default = async (argv,
|
|
28
|
+
exports.default = async (argv, prompter, _options) => {
|
|
62
29
|
if (argv.help || argv.h) {
|
|
63
30
|
console.log(usage);
|
|
64
31
|
process.exit(0);
|
|
65
32
|
}
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
if (
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
// Build schema from database if needed
|
|
73
|
-
const outDir = opts.output || 'codegen';
|
|
74
|
-
const schemaPath = mode.type === 'database'
|
|
75
|
-
? await buildSchemaFromDatabase(mode.database, mode.schemas, outDir)
|
|
76
|
-
: undefined;
|
|
77
|
-
const commandOptions = {
|
|
78
|
-
config: opts.config,
|
|
79
|
-
target: opts.target,
|
|
80
|
-
endpoint: mode.type === 'endpoint' ? mode.endpoint : undefined,
|
|
81
|
-
schema: schemaPath,
|
|
82
|
-
output: opts.config ? opts.output : outDir,
|
|
83
|
-
authorization: opts.auth,
|
|
84
|
-
verbose: opts.verbose,
|
|
85
|
-
dryRun: opts.dryRun,
|
|
86
|
-
};
|
|
87
|
-
const result = opts.orm
|
|
88
|
-
? await (0, graphql_codegen_1.generateOrm)(commandOptions)
|
|
89
|
-
: await (0, graphql_codegen_1.generateReactQuery)(commandOptions);
|
|
90
|
-
printResult(result);
|
|
91
|
-
if (!result.success) {
|
|
92
|
-
process.exit(1);
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
function parseArgs(argv) {
|
|
96
|
-
const schemasArg = argv.schemas || '';
|
|
97
|
-
return {
|
|
98
|
-
endpoint: argv.endpoint || undefined,
|
|
99
|
-
config: argv.config || (0, graphql_codegen_1.findConfigFile)() || undefined,
|
|
100
|
-
target: argv.target || undefined,
|
|
101
|
-
output: argv.out || undefined,
|
|
102
|
-
auth: argv.auth || undefined,
|
|
103
|
-
database: argv.database || undefined,
|
|
104
|
-
schemas: schemasArg
|
|
105
|
-
? schemasArg.split(',').map((s) => s.trim()).filter(Boolean)
|
|
106
|
-
: undefined,
|
|
107
|
-
dryRun: !!(argv['dry-run'] || argv.dryRun),
|
|
108
|
-
verbose: !!(argv.verbose || argv.v),
|
|
109
|
-
orm: !!argv.orm,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
function determineMode(opts) {
|
|
113
|
-
if (opts.endpoint) {
|
|
114
|
-
return { type: 'endpoint', endpoint: opts.endpoint };
|
|
115
|
-
}
|
|
116
|
-
if (opts.schemas?.length) {
|
|
117
|
-
const database = opts.database || (0, graphql_env_1.getEnvOptions)().pg.database;
|
|
118
|
-
return { type: 'database', database, schemas: opts.schemas };
|
|
119
|
-
}
|
|
120
|
-
if (opts.config) {
|
|
121
|
-
return { type: 'config', configPath: opts.config };
|
|
122
|
-
}
|
|
123
|
-
return { type: 'none' };
|
|
124
|
-
}
|
|
125
|
-
function printTargetResult(target) {
|
|
126
|
-
const status = target.success ? '[ok]' : 'x';
|
|
127
|
-
console.log(`\n${status} ${target.message}`);
|
|
128
|
-
if (target.tables?.length) {
|
|
129
|
-
console.log(' Tables:');
|
|
130
|
-
target.tables.forEach((t) => console.log(` - ${t}`));
|
|
131
|
-
}
|
|
132
|
-
if (target.filesWritten?.length) {
|
|
133
|
-
console.log(' Files written:');
|
|
134
|
-
target.filesWritten.forEach((f) => console.log(` - ${f}`));
|
|
135
|
-
}
|
|
136
|
-
if (!target.success && target.errors?.length) {
|
|
137
|
-
target.errors.forEach((e) => console.error(` - ${e}`));
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
function printResult(result) {
|
|
141
|
-
const targets = result.targets ?? [];
|
|
142
|
-
const isMultiTarget = targets.length > 1 || (targets.length === 1 && targets[0]?.name !== 'default');
|
|
143
|
-
if (isMultiTarget) {
|
|
144
|
-
console.log(result.message);
|
|
145
|
-
targets.forEach(printTargetResult);
|
|
33
|
+
// Auto-detect config file if not provided
|
|
34
|
+
const config = argv.config || (0, graphql_codegen_1.findConfigFile)();
|
|
35
|
+
if (config) {
|
|
36
|
+
// If config file exists, just run generate with it (config file handles everything)
|
|
37
|
+
const result = await (0, graphql_codegen_1.generate)({});
|
|
38
|
+
(0, graphql_codegen_1.printResult)(result);
|
|
146
39
|
return;
|
|
147
40
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
41
|
+
// No config file - prompt for options using shared questions
|
|
42
|
+
const answers = await prompter.prompt(argv, graphql_codegen_1.codegenQuestions);
|
|
43
|
+
// Build db config if schemas or apiNames provided
|
|
44
|
+
const db = (answers.schemas || answers.apiNames) ? {
|
|
45
|
+
schemas: answers.schemas,
|
|
46
|
+
apiNames: answers.apiNames,
|
|
47
|
+
} : undefined;
|
|
48
|
+
const result = await (0, graphql_codegen_1.generate)({
|
|
49
|
+
endpoint: answers.endpoint,
|
|
50
|
+
schemaFile: answers.schemaFile,
|
|
51
|
+
db,
|
|
52
|
+
output: answers.output,
|
|
53
|
+
authorization: answers.authorization,
|
|
54
|
+
reactQuery: answers.reactQuery,
|
|
55
|
+
orm: answers.orm,
|
|
56
|
+
dryRun: answers.dryRun,
|
|
57
|
+
verbose: answers.verbose,
|
|
163
58
|
});
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
return schemaPath;
|
|
167
|
-
}
|
|
59
|
+
(0, graphql_codegen_1.printResult)(result);
|
|
60
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { CLIOptions, Inquirerer
|
|
2
|
-
declare const _default: (argv: Partial<
|
|
1
|
+
import { CLIOptions, Inquirerer } from 'inquirerer';
|
|
2
|
+
declare const _default: (argv: Partial<Record<string, unknown>>, prompter: Inquirerer, _options: CLIOptions) => Promise<void>;
|
|
3
3
|
export default _default;
|
|
@@ -7,32 +7,52 @@ Constructive Get GraphQL Schema:
|
|
|
7
7
|
|
|
8
8
|
cnc get-graphql-schema [OPTIONS]
|
|
9
9
|
|
|
10
|
-
Options:
|
|
11
|
-
--
|
|
10
|
+
Source Options (choose one):
|
|
11
|
+
--endpoint <url> GraphQL endpoint to fetch schema via introspection
|
|
12
12
|
--database <name> Database name (default: constructive)
|
|
13
|
+
|
|
14
|
+
Options:
|
|
13
15
|
--schemas <list> Comma-separated schemas to include
|
|
14
|
-
--
|
|
15
|
-
--
|
|
16
|
-
--auth <token> Optional Authorization header value (e.g., "Bearer 123")
|
|
17
|
-
--header "Name: Value" Optional HTTP header; repeat to add multiple headers
|
|
16
|
+
--headerHost <host> Host header to send with endpoint requests
|
|
17
|
+
--auth <token> Authorization header value
|
|
18
18
|
--out <path> Output file path (default: print to stdout)
|
|
19
|
+
|
|
20
|
+
--help, -h Show this help message
|
|
19
21
|
`;
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
const questions = [
|
|
23
|
+
{
|
|
24
|
+
name: 'endpoint',
|
|
25
|
+
message: 'GraphQL endpoint URL',
|
|
26
|
+
type: 'text',
|
|
27
|
+
required: false,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'database',
|
|
31
|
+
message: 'Database name',
|
|
32
|
+
type: 'text',
|
|
33
|
+
required: false,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: 'schemas',
|
|
37
|
+
message: 'Comma-separated schemas',
|
|
38
|
+
type: 'text',
|
|
39
|
+
required: false,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: 'out',
|
|
43
|
+
message: 'Output file path',
|
|
44
|
+
type: 'text',
|
|
45
|
+
required: false,
|
|
46
|
+
},
|
|
24
47
|
];
|
|
25
48
|
exports.default = async (argv, prompter, _options) => {
|
|
26
49
|
if (argv.help || argv.h) {
|
|
27
50
|
console.log(usage);
|
|
28
51
|
process.exit(0);
|
|
29
52
|
}
|
|
30
|
-
const endpoint = argv
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
const database = argv.database ?? 'constructive';
|
|
34
|
-
const schemasArg = argv.schemas ?? defaultSchemas.join(',');
|
|
35
|
-
const out = argv.out ?? '';
|
|
53
|
+
const { endpoint, database, schemas: schemasArg, out, } = await prompter.prompt(argv, questions);
|
|
54
|
+
const schemas = String(schemasArg).split(',').map((s) => s.trim()).filter(Boolean);
|
|
55
|
+
// Parse repeated --header values into headers object
|
|
36
56
|
const headerArg = argv.header;
|
|
37
57
|
const headerList = Array.isArray(headerArg) ? headerArg : headerArg ? [headerArg] : [];
|
|
38
58
|
const headers = {};
|
|
@@ -46,23 +66,19 @@ exports.default = async (argv, prompter, _options) => {
|
|
|
46
66
|
continue;
|
|
47
67
|
headers[name] = value;
|
|
48
68
|
}
|
|
49
|
-
const schemas = schemasArg.split(',').map(s => s.trim()).filter(Boolean);
|
|
50
69
|
let sdl;
|
|
51
70
|
if (endpoint) {
|
|
52
71
|
const opts = {};
|
|
53
|
-
if (headerHost)
|
|
54
|
-
opts.headerHost = headerHost;
|
|
55
|
-
if (auth)
|
|
56
|
-
opts.auth = auth;
|
|
72
|
+
if (argv.headerHost)
|
|
73
|
+
opts.headerHost = argv.headerHost;
|
|
74
|
+
if (argv.auth)
|
|
75
|
+
opts.auth = argv.auth;
|
|
57
76
|
if (Object.keys(headers).length)
|
|
58
77
|
opts.headers = headers;
|
|
59
78
|
sdl = await graphql_server_1.fetchEndpointSchemaSDL(endpoint, opts);
|
|
60
79
|
}
|
|
61
80
|
else {
|
|
62
|
-
|
|
63
|
-
// and exporting a reusable programmatic builder from there
|
|
64
|
-
// avoids adding new dependencies to cli and prevents duplication.
|
|
65
|
-
sdl = await (0, graphql_server_1.buildSchemaSDL)({ database, schemas });
|
|
81
|
+
sdl = await (0, graphql_server_1.buildSchemaSDL)({ database: database, schemas });
|
|
66
82
|
}
|
|
67
83
|
if (out) {
|
|
68
84
|
await fs_1.promises.writeFile(out, sdl, 'utf8');
|
package/esm/commands/codegen.js
CHANGED
|
@@ -1,132 +1,58 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as path from 'node:path';
|
|
3
|
-
import { buildSchemaSDL } from '@constructive-io/graphql-server';
|
|
4
|
-
import { generateReactQuery, generateOrm, findConfigFile, } from '@constructive-io/graphql-codegen';
|
|
5
|
-
import { getEnvOptions } from '@constructive-io/graphql-env';
|
|
1
|
+
import { generate, findConfigFile, codegenQuestions, printResult, } from '@constructive-io/graphql-codegen';
|
|
6
2
|
const usage = `
|
|
7
3
|
Constructive GraphQL Codegen:
|
|
8
4
|
|
|
9
5
|
cnc codegen [OPTIONS]
|
|
10
6
|
|
|
11
|
-
Options:
|
|
12
|
-
--help, -h Show this help message
|
|
7
|
+
Source Options (choose one):
|
|
13
8
|
--config <path> Path to graphql-codegen config file
|
|
14
|
-
--target <name> Target name in config file
|
|
15
9
|
--endpoint <url> GraphQL endpoint URL
|
|
16
|
-
--
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
-
|
|
10
|
+
--schemaFile <path> Path to GraphQL schema file
|
|
11
|
+
|
|
12
|
+
Database Options:
|
|
13
|
+
--schemas <list> Comma-separated PostgreSQL schemas
|
|
14
|
+
--apiNames <list> Comma-separated API names
|
|
20
15
|
|
|
21
|
-
|
|
16
|
+
Generator Options:
|
|
17
|
+
--reactQuery Generate React Query hooks (default)
|
|
18
|
+
--orm Generate ORM client
|
|
19
|
+
--output <dir> Output directory (default: codegen)
|
|
20
|
+
--authorization <token> Authorization header value
|
|
21
|
+
--dryRun Preview without writing files
|
|
22
|
+
--verbose Verbose output
|
|
22
23
|
|
|
23
|
-
--
|
|
24
|
-
--schemas <list> Comma-separated schemas (required for DB mode)
|
|
24
|
+
--help, -h Show this help message
|
|
25
25
|
`;
|
|
26
|
-
export default async (argv,
|
|
26
|
+
export default async (argv, prompter, _options) => {
|
|
27
27
|
if (argv.help || argv.h) {
|
|
28
28
|
console.log(usage);
|
|
29
29
|
process.exit(0);
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// Build schema from database if needed
|
|
38
|
-
const outDir = opts.output || 'codegen';
|
|
39
|
-
const schemaPath = mode.type === 'database'
|
|
40
|
-
? await buildSchemaFromDatabase(mode.database, mode.schemas, outDir)
|
|
41
|
-
: undefined;
|
|
42
|
-
const commandOptions = {
|
|
43
|
-
config: opts.config,
|
|
44
|
-
target: opts.target,
|
|
45
|
-
endpoint: mode.type === 'endpoint' ? mode.endpoint : undefined,
|
|
46
|
-
schema: schemaPath,
|
|
47
|
-
output: opts.config ? opts.output : outDir,
|
|
48
|
-
authorization: opts.auth,
|
|
49
|
-
verbose: opts.verbose,
|
|
50
|
-
dryRun: opts.dryRun,
|
|
51
|
-
};
|
|
52
|
-
const result = opts.orm
|
|
53
|
-
? await generateOrm(commandOptions)
|
|
54
|
-
: await generateReactQuery(commandOptions);
|
|
55
|
-
printResult(result);
|
|
56
|
-
if (!result.success) {
|
|
57
|
-
process.exit(1);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
function parseArgs(argv) {
|
|
61
|
-
const schemasArg = argv.schemas || '';
|
|
62
|
-
return {
|
|
63
|
-
endpoint: argv.endpoint || undefined,
|
|
64
|
-
config: argv.config || findConfigFile() || undefined,
|
|
65
|
-
target: argv.target || undefined,
|
|
66
|
-
output: argv.out || undefined,
|
|
67
|
-
auth: argv.auth || undefined,
|
|
68
|
-
database: argv.database || undefined,
|
|
69
|
-
schemas: schemasArg
|
|
70
|
-
? schemasArg.split(',').map((s) => s.trim()).filter(Boolean)
|
|
71
|
-
: undefined,
|
|
72
|
-
dryRun: !!(argv['dry-run'] || argv.dryRun),
|
|
73
|
-
verbose: !!(argv.verbose || argv.v),
|
|
74
|
-
orm: !!argv.orm,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
function determineMode(opts) {
|
|
78
|
-
if (opts.endpoint) {
|
|
79
|
-
return { type: 'endpoint', endpoint: opts.endpoint };
|
|
80
|
-
}
|
|
81
|
-
if (opts.schemas?.length) {
|
|
82
|
-
const database = opts.database || getEnvOptions().pg.database;
|
|
83
|
-
return { type: 'database', database, schemas: opts.schemas };
|
|
84
|
-
}
|
|
85
|
-
if (opts.config) {
|
|
86
|
-
return { type: 'config', configPath: opts.config };
|
|
87
|
-
}
|
|
88
|
-
return { type: 'none' };
|
|
89
|
-
}
|
|
90
|
-
function printTargetResult(target) {
|
|
91
|
-
const status = target.success ? '[ok]' : 'x';
|
|
92
|
-
console.log(`\n${status} ${target.message}`);
|
|
93
|
-
if (target.tables?.length) {
|
|
94
|
-
console.log(' Tables:');
|
|
95
|
-
target.tables.forEach((t) => console.log(` - ${t}`));
|
|
96
|
-
}
|
|
97
|
-
if (target.filesWritten?.length) {
|
|
98
|
-
console.log(' Files written:');
|
|
99
|
-
target.filesWritten.forEach((f) => console.log(` - ${f}`));
|
|
100
|
-
}
|
|
101
|
-
if (!target.success && target.errors?.length) {
|
|
102
|
-
target.errors.forEach((e) => console.error(` - ${e}`));
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
function printResult(result) {
|
|
106
|
-
const targets = result.targets ?? [];
|
|
107
|
-
const isMultiTarget = targets.length > 1 || (targets.length === 1 && targets[0]?.name !== 'default');
|
|
108
|
-
if (isMultiTarget) {
|
|
109
|
-
console.log(result.message);
|
|
110
|
-
targets.forEach(printTargetResult);
|
|
31
|
+
// Auto-detect config file if not provided
|
|
32
|
+
const config = argv.config || findConfigFile();
|
|
33
|
+
if (config) {
|
|
34
|
+
// If config file exists, just run generate with it (config file handles everything)
|
|
35
|
+
const result = await generate({});
|
|
36
|
+
printResult(result);
|
|
111
37
|
return;
|
|
112
38
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
39
|
+
// No config file - prompt for options using shared questions
|
|
40
|
+
const answers = await prompter.prompt(argv, codegenQuestions);
|
|
41
|
+
// Build db config if schemas or apiNames provided
|
|
42
|
+
const db = (answers.schemas || answers.apiNames) ? {
|
|
43
|
+
schemas: answers.schemas,
|
|
44
|
+
apiNames: answers.apiNames,
|
|
45
|
+
} : undefined;
|
|
46
|
+
const result = await generate({
|
|
47
|
+
endpoint: answers.endpoint,
|
|
48
|
+
schemaFile: answers.schemaFile,
|
|
49
|
+
db,
|
|
50
|
+
output: answers.output,
|
|
51
|
+
authorization: answers.authorization,
|
|
52
|
+
reactQuery: answers.reactQuery,
|
|
53
|
+
orm: answers.orm,
|
|
54
|
+
dryRun: answers.dryRun,
|
|
55
|
+
verbose: answers.verbose,
|
|
128
56
|
});
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
return schemaPath;
|
|
132
|
-
}
|
|
57
|
+
printResult(result);
|
|
58
|
+
};
|
|
@@ -5,32 +5,52 @@ Constructive Get GraphQL Schema:
|
|
|
5
5
|
|
|
6
6
|
cnc get-graphql-schema [OPTIONS]
|
|
7
7
|
|
|
8
|
-
Options:
|
|
9
|
-
--
|
|
8
|
+
Source Options (choose one):
|
|
9
|
+
--endpoint <url> GraphQL endpoint to fetch schema via introspection
|
|
10
10
|
--database <name> Database name (default: constructive)
|
|
11
|
+
|
|
12
|
+
Options:
|
|
11
13
|
--schemas <list> Comma-separated schemas to include
|
|
12
|
-
--
|
|
13
|
-
--
|
|
14
|
-
--auth <token> Optional Authorization header value (e.g., "Bearer 123")
|
|
15
|
-
--header "Name: Value" Optional HTTP header; repeat to add multiple headers
|
|
14
|
+
--headerHost <host> Host header to send with endpoint requests
|
|
15
|
+
--auth <token> Authorization header value
|
|
16
16
|
--out <path> Output file path (default: print to stdout)
|
|
17
|
+
|
|
18
|
+
--help, -h Show this help message
|
|
17
19
|
`;
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const questions = [
|
|
21
|
+
{
|
|
22
|
+
name: 'endpoint',
|
|
23
|
+
message: 'GraphQL endpoint URL',
|
|
24
|
+
type: 'text',
|
|
25
|
+
required: false,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: 'database',
|
|
29
|
+
message: 'Database name',
|
|
30
|
+
type: 'text',
|
|
31
|
+
required: false,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: 'schemas',
|
|
35
|
+
message: 'Comma-separated schemas',
|
|
36
|
+
type: 'text',
|
|
37
|
+
required: false,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: 'out',
|
|
41
|
+
message: 'Output file path',
|
|
42
|
+
type: 'text',
|
|
43
|
+
required: false,
|
|
44
|
+
},
|
|
22
45
|
];
|
|
23
46
|
export default async (argv, prompter, _options) => {
|
|
24
47
|
if (argv.help || argv.h) {
|
|
25
48
|
console.log(usage);
|
|
26
49
|
process.exit(0);
|
|
27
50
|
}
|
|
28
|
-
const endpoint = argv
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
const database = argv.database ?? 'constructive';
|
|
32
|
-
const schemasArg = argv.schemas ?? defaultSchemas.join(',');
|
|
33
|
-
const out = argv.out ?? '';
|
|
51
|
+
const { endpoint, database, schemas: schemasArg, out, } = await prompter.prompt(argv, questions);
|
|
52
|
+
const schemas = String(schemasArg).split(',').map((s) => s.trim()).filter(Boolean);
|
|
53
|
+
// Parse repeated --header values into headers object
|
|
34
54
|
const headerArg = argv.header;
|
|
35
55
|
const headerList = Array.isArray(headerArg) ? headerArg : headerArg ? [headerArg] : [];
|
|
36
56
|
const headers = {};
|
|
@@ -44,23 +64,19 @@ export default async (argv, prompter, _options) => {
|
|
|
44
64
|
continue;
|
|
45
65
|
headers[name] = value;
|
|
46
66
|
}
|
|
47
|
-
const schemas = schemasArg.split(',').map(s => s.trim()).filter(Boolean);
|
|
48
67
|
let sdl;
|
|
49
68
|
if (endpoint) {
|
|
50
69
|
const opts = {};
|
|
51
|
-
if (headerHost)
|
|
52
|
-
opts.headerHost = headerHost;
|
|
53
|
-
if (auth)
|
|
54
|
-
opts.auth = auth;
|
|
70
|
+
if (argv.headerHost)
|
|
71
|
+
opts.headerHost = argv.headerHost;
|
|
72
|
+
if (argv.auth)
|
|
73
|
+
opts.auth = argv.auth;
|
|
55
74
|
if (Object.keys(headers).length)
|
|
56
75
|
opts.headers = headers;
|
|
57
76
|
sdl = await fetchEndpointSchemaSDL(endpoint, opts);
|
|
58
77
|
}
|
|
59
78
|
else {
|
|
60
|
-
|
|
61
|
-
// and exporting a reusable programmatic builder from there
|
|
62
|
-
// avoids adding new dependencies to cli and prevents duplication.
|
|
63
|
-
sdl = await buildSchemaSDL({ database, schemas });
|
|
79
|
+
sdl = await buildSchemaSDL({ database: database, schemas });
|
|
64
80
|
}
|
|
65
81
|
if (out) {
|
|
66
82
|
await fs.writeFile(out, sdl, 'utf8');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constructive-io/cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.1",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "Constructive CLI",
|
|
6
6
|
"main": "index.js",
|
|
@@ -45,22 +45,22 @@
|
|
|
45
45
|
"ts-node": "^10.9.2"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@constructive-io/graphql-codegen": "^
|
|
48
|
+
"@constructive-io/graphql-codegen": "^3.0.1",
|
|
49
49
|
"@constructive-io/graphql-env": "^2.9.4",
|
|
50
|
-
"@constructive-io/graphql-explorer": "^
|
|
51
|
-
"@constructive-io/graphql-server": "^
|
|
52
|
-
"@constructive-io/knative-job-service": "^0.
|
|
50
|
+
"@constructive-io/graphql-explorer": "^3.0.1",
|
|
51
|
+
"@constructive-io/graphql-server": "^3.0.1",
|
|
52
|
+
"@constructive-io/knative-job-service": "^1.0.1",
|
|
53
53
|
"@inquirerer/utils": "^3.2.0",
|
|
54
|
-
"@pgpmjs/core": "^
|
|
55
|
-
"@pgpmjs/logger": "^
|
|
56
|
-
"@pgpmjs/server-utils": "^
|
|
54
|
+
"@pgpmjs/core": "^5.0.0",
|
|
55
|
+
"@pgpmjs/logger": "^2.0.0",
|
|
56
|
+
"@pgpmjs/server-utils": "^3.0.0",
|
|
57
57
|
"@pgpmjs/types": "^2.15.0",
|
|
58
58
|
"find-and-require-package-json": "^0.9.0",
|
|
59
59
|
"inquirerer": "^4.4.0",
|
|
60
60
|
"js-yaml": "^4.1.0",
|
|
61
|
-
"pg-cache": "^
|
|
61
|
+
"pg-cache": "^2.0.0",
|
|
62
62
|
"pg-env": "^1.3.0",
|
|
63
|
-
"pgpm": "^
|
|
63
|
+
"pgpm": "^3.0.0",
|
|
64
64
|
"shelljs": "^0.10.0",
|
|
65
65
|
"yanse": "^0.2.0"
|
|
66
66
|
},
|
|
@@ -75,5 +75,5 @@
|
|
|
75
75
|
"postgres",
|
|
76
76
|
"graphile"
|
|
77
77
|
],
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "f6b4b738f0d069833af001a80b97d86fea6499ae"
|
|
79
79
|
}
|