@constructive-io/cli 7.0.3 → 7.1.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/README.md CHANGED
@@ -95,27 +95,33 @@ cnc codegen --api-names my_api --output ./codegen --orm
95
95
  - `--dry-run` - Preview without writing files
96
96
  - `--verbose` - Verbose output
97
97
 
98
- ### `cnc get-graphql-schema`
98
+ ### `cnc codegen --schema-only`
99
99
 
100
- Fetch or build GraphQL schema SDL.
100
+ Export GraphQL schema SDL without running full code generation. Works with any source (endpoint, file, database, PGPM).
101
101
 
102
102
  ```bash
103
103
  # From database schemas
104
- cnc get-graphql-schema --database mydb --schemas myapp,public --out ./schema.graphql
104
+ cnc codegen --schema-only --schemas myapp,public --output ./schemas
105
105
 
106
106
  # From running server
107
- cnc get-graphql-schema --endpoint http://localhost:3000/graphql --out ./schema.graphql
107
+ cnc codegen --schema-only --endpoint http://localhost:3000/graphql --output ./schemas
108
+
109
+ # From schema file (useful for converting/validating)
110
+ cnc codegen --schema-only --schema-file ./input.graphql --output ./schemas
111
+
112
+ # From a directory of .graphql files (multi-target)
113
+ cnc codegen --schema-only --schema-dir ./schemas --output ./exported
108
114
  ```
109
115
 
110
116
  **Options:**
111
117
 
112
- - `--database <name>` - Database name (for programmatic builder)
113
- - `--schemas <list>` - Comma-separated schemas to include (required unless using --endpoint)
114
- - `--endpoint <url>` - GraphQL endpoint to fetch schema via introspection
115
- - `--headerHost <host>` - Optional Host header for endpoint requests
116
- - `--auth <token>` - Optional Authorization header value
117
- - `--header "Name: Value"` - Optional HTTP header (repeatable)
118
- - `--out <path>` - Output file path (prints to stdout if omitted)
118
+ - `--endpoint <url>` - GraphQL endpoint URL
119
+ - `--schema-file <path>` - Path to GraphQL schema file
120
+ - `--schemas <list>` - Comma-separated PostgreSQL schemas
121
+ - `--api-names <list>` - Comma-separated API names (multi-target when >1)
122
+ - `--schema-dir <path>` - Directory of .graphql files (auto-creates one target per file)
123
+ - `--output <dir>` - Output directory (default: ./generated/graphql)
124
+ - `--authorization <token>` - Authorization header value
119
125
 
120
126
  ## Configuration
121
127
 
@@ -1,3 +1,3 @@
1
- import { CLIOptions, Inquirerer } from 'inquirerer';
1
+ import type { CLIOptions, Inquirerer } from 'inquirerer';
2
2
  declare const _default: (argv: Partial<Record<string, unknown>>, prompter: Inquirerer, _options: CLIOptions) => Promise<void>;
3
3
  export default _default;
@@ -10,6 +10,7 @@ Source Options (choose one):
10
10
  --config <path> Path to graphql-codegen config file
11
11
  --endpoint <url> GraphQL endpoint URL
12
12
  --schema-file <path> Path to GraphQL schema file
13
+ --schema-dir <dir> Directory of .graphql files (auto-expands to multi-target)
13
14
 
14
15
  Database Options:
15
16
  --schemas <list> Comma-separated PostgreSQL schemas
@@ -19,10 +20,16 @@ Generator Options:
19
20
  --react-query Generate React Query hooks (default)
20
21
  --orm Generate ORM client
21
22
  --output <dir> Output directory (default: codegen)
23
+ --target <name> Target name (for multi-target configs)
22
24
  --authorization <token> Authorization header value
23
25
  --dry-run Preview without writing files
24
26
  --verbose Verbose output
25
27
 
28
+ Schema Export:
29
+ --schema-only Export GraphQL SDL instead of running full codegen.
30
+ Works with any source (endpoint, file, database, PGPM).
31
+ With multiple apiNames, writes one .graphql per API.
32
+
26
33
  --help, -h Show this help message
27
34
  `;
28
35
  exports.default = async (argv, prompter, _options) => {
@@ -30,23 +37,5 @@ exports.default = async (argv, prompter, _options) => {
30
37
  console.log(usage);
31
38
  process.exit(0);
32
39
  }
33
- const hasSourceFlags = Boolean(argv.endpoint || argv['schema-file'] || argv.schemas || argv['api-names']);
34
- const configPath = argv.config ||
35
- (!hasSourceFlags ? (0, graphql_codegen_1.findConfigFile)() : undefined);
36
- let fileConfig = {};
37
- if (configPath) {
38
- const loaded = await (0, graphql_codegen_1.loadConfigFile)(configPath);
39
- if (!loaded.success) {
40
- console.error('x', loaded.error);
41
- process.exit(1);
42
- }
43
- fileConfig = loaded.config;
44
- }
45
- const seeded = (0, graphql_codegen_1.seedArgvFromConfig)(argv, fileConfig);
46
- const answers = (0, graphql_codegen_1.hasResolvedCodegenSource)(seeded)
47
- ? seeded
48
- : await prompter.prompt(seeded, graphql_codegen_1.codegenQuestions);
49
- const options = (0, graphql_codegen_1.buildGenerateOptions)(answers, fileConfig);
50
- const result = await (0, graphql_codegen_1.generate)(options);
51
- (0, graphql_codegen_1.printResult)(result);
40
+ await (0, graphql_codegen_1.runCodegenHandler)(argv, prompter);
52
41
  };
package/commands.js CHANGED
@@ -11,7 +11,6 @@ const codegen_1 = __importDefault(require("./commands/codegen"));
11
11
  const context_1 = __importDefault(require("./commands/context"));
12
12
  const execute_1 = __importDefault(require("./commands/execute"));
13
13
  const explorer_1 = __importDefault(require("./commands/explorer"));
14
- const get_graphql_schema_1 = __importDefault(require("./commands/get-graphql-schema"));
15
14
  const jobs_1 = __importDefault(require("./commands/jobs"));
16
15
  const server_1 = __importDefault(require("./commands/server"));
17
16
  const utils_2 = require("./utils");
@@ -19,7 +18,6 @@ const createCommandMap = () => {
19
18
  return {
20
19
  server: server_1.default,
21
20
  explorer: explorer_1.default,
22
- 'get-graphql-schema': get_graphql_schema_1.default,
23
21
  codegen: codegen_1.default,
24
22
  jobs: jobs_1.default,
25
23
  context: context_1.default,
@@ -1,4 +1,4 @@
1
- import { generate, findConfigFile, loadConfigFile, codegenQuestions, printResult, buildGenerateOptions, seedArgvFromConfig, hasResolvedCodegenSource, } from '@constructive-io/graphql-codegen';
1
+ import { runCodegenHandler } from '@constructive-io/graphql-codegen';
2
2
  const usage = `
3
3
  Constructive GraphQL Codegen:
4
4
 
@@ -8,6 +8,7 @@ Source Options (choose one):
8
8
  --config <path> Path to graphql-codegen config file
9
9
  --endpoint <url> GraphQL endpoint URL
10
10
  --schema-file <path> Path to GraphQL schema file
11
+ --schema-dir <dir> Directory of .graphql files (auto-expands to multi-target)
11
12
 
12
13
  Database Options:
13
14
  --schemas <list> Comma-separated PostgreSQL schemas
@@ -17,10 +18,16 @@ Generator Options:
17
18
  --react-query Generate React Query hooks (default)
18
19
  --orm Generate ORM client
19
20
  --output <dir> Output directory (default: codegen)
21
+ --target <name> Target name (for multi-target configs)
20
22
  --authorization <token> Authorization header value
21
23
  --dry-run Preview without writing files
22
24
  --verbose Verbose output
23
25
 
26
+ Schema Export:
27
+ --schema-only Export GraphQL SDL instead of running full codegen.
28
+ Works with any source (endpoint, file, database, PGPM).
29
+ With multiple apiNames, writes one .graphql per API.
30
+
24
31
  --help, -h Show this help message
25
32
  `;
26
33
  export default async (argv, prompter, _options) => {
@@ -28,23 +35,5 @@ export default async (argv, prompter, _options) => {
28
35
  console.log(usage);
29
36
  process.exit(0);
30
37
  }
31
- const hasSourceFlags = Boolean(argv.endpoint || argv['schema-file'] || argv.schemas || argv['api-names']);
32
- const configPath = argv.config ||
33
- (!hasSourceFlags ? findConfigFile() : undefined);
34
- let fileConfig = {};
35
- if (configPath) {
36
- const loaded = await loadConfigFile(configPath);
37
- if (!loaded.success) {
38
- console.error('x', loaded.error);
39
- process.exit(1);
40
- }
41
- fileConfig = loaded.config;
42
- }
43
- const seeded = seedArgvFromConfig(argv, fileConfig);
44
- const answers = hasResolvedCodegenSource(seeded)
45
- ? seeded
46
- : await prompter.prompt(seeded, codegenQuestions);
47
- const options = buildGenerateOptions(answers, fileConfig);
48
- const result = await generate(options);
49
- printResult(result);
38
+ await runCodegenHandler(argv, prompter);
50
39
  };
package/esm/commands.js CHANGED
@@ -5,7 +5,6 @@ import codegen from './commands/codegen';
5
5
  import context from './commands/context';
6
6
  import execute from './commands/execute';
7
7
  import explorer from './commands/explorer';
8
- import getGraphqlSchema from './commands/get-graphql-schema';
9
8
  import jobs from './commands/jobs';
10
9
  import server from './commands/server';
11
10
  import { usageText } from './utils';
@@ -13,7 +12,6 @@ const createCommandMap = () => {
13
12
  return {
14
13
  server,
15
14
  explorer,
16
- 'get-graphql-schema': getGraphqlSchema,
17
15
  codegen,
18
16
  jobs,
19
17
  context,
@@ -10,7 +10,6 @@ export const usageText = `
10
10
 
11
11
  Code Generation:
12
12
  codegen Generate TypeScript types and SDK from GraphQL schema
13
- get-graphql-schema Fetch or build GraphQL schema SDL
14
13
 
15
14
  Jobs:
16
15
  jobs up Start combined server (jobs runtime)
@@ -34,7 +33,7 @@ export const usageText = `
34
33
  cnc server --port 8080 Start server on custom port
35
34
  cnc explorer Launch GraphiQL explorer
36
35
  cnc codegen --schema schema.graphql Generate types from schema
37
- cnc get-graphql-schema --out schema.graphql Export schema SDL
36
+ cnc codegen --schema-only --out schema.graphql Export schema SDL
38
37
  cnc jobs up Start combined server (jobs runtime)
39
38
 
40
39
  # Execution Engine
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructive-io/cli",
3
- "version": "7.0.3",
3
+ "version": "7.1.1",
4
4
  "author": "Constructive <developers@constructive.io>",
5
5
  "description": "Constructive CLI",
6
6
  "main": "index.js",
@@ -30,7 +30,7 @@
30
30
  "build:dev": "makage build --dev",
31
31
  "dev": "ts-node ./src/index.ts",
32
32
  "lint": "eslint . --fix",
33
- "test": "jest --passWithNoTests",
33
+ "test": "jest",
34
34
  "test:watch": "jest --watch"
35
35
  },
36
36
  "devDependencies": {
@@ -45,14 +45,14 @@
45
45
  "ts-node": "^10.9.2"
46
46
  },
47
47
  "dependencies": {
48
- "@constructive-io/graphql-codegen": "^4.0.2",
49
- "@constructive-io/graphql-env": "^3.0.0",
50
- "@constructive-io/graphql-explorer": "^4.0.1",
51
- "@constructive-io/graphql-server": "^4.0.1",
48
+ "@constructive-io/graphql-codegen": "^4.1.1",
49
+ "@constructive-io/graphql-env": "^3.1.0",
50
+ "@constructive-io/graphql-explorer": "^4.1.1",
51
+ "@constructive-io/graphql-server": "^4.1.1",
52
52
  "@constructive-io/graphql-types": "^3.0.0",
53
- "@constructive-io/knative-job-service": "^2.0.1",
53
+ "@constructive-io/knative-job-service": "^2.1.1",
54
54
  "@inquirerer/utils": "^3.2.3",
55
- "@pgpmjs/core": "^6.0.0",
55
+ "@pgpmjs/core": "^6.1.0",
56
56
  "@pgpmjs/logger": "^2.1.0",
57
57
  "@pgpmjs/server-utils": "^3.1.0",
58
58
  "@pgpmjs/types": "^2.16.0",
@@ -62,7 +62,7 @@
62
62
  "js-yaml": "^4.1.0",
63
63
  "pg-cache": "^3.0.0",
64
64
  "pg-env": "^1.4.0",
65
- "pgpm": "^4.0.1",
65
+ "pgpm": "^4.1.0",
66
66
  "shelljs": "^0.10.0",
67
67
  "yanse": "^0.2.0"
68
68
  },
@@ -77,5 +77,5 @@
77
77
  "postgres",
78
78
  "graphile"
79
79
  ],
80
- "gitHead": "44410afc7857f14414b69c7e3cfa893a270bf08f"
80
+ "gitHead": "921594a77964d3467261c70fed1d529eddabb549"
81
81
  }
@@ -1 +1 @@
1
- export declare const usageText = "\n Usage: cnc <command> [options]\n constructive <command> [options]\n\n Constructive CLI - API Server and Development Tools\n\n GraphQL Server:\n server Start a GraphQL server\n explorer Launch GraphiQL explorer interface\n\n Code Generation:\n codegen Generate TypeScript types and SDK from GraphQL schema\n get-graphql-schema Fetch or build GraphQL schema SDL\n\n Jobs:\n jobs up Start combined server (jobs runtime)\n\n Execution Engine:\n context Manage contexts (create, list, use, current, delete)\n auth Manage authentication (set-token, status, logout)\n execute Execute GraphQL queries against configured endpoints\n\n Global Options:\n -h, --help Display this help information\n -v, --version Display version information\n --cwd <directory> Working directory (default: current directory)\n\n Individual Command Help:\n cnc <command> --help Display detailed help for specific command\n cnc <command> -h Display detailed help for specific command\n\n Examples:\n cnc server Start GraphQL server\n cnc server --port 8080 Start server on custom port\n cnc explorer Launch GraphiQL explorer\n cnc codegen --schema schema.graphql Generate types from schema\n cnc get-graphql-schema --out schema.graphql Export schema SDL\n cnc jobs up Start combined server (jobs runtime)\n\n # Execution Engine\n cnc context create my-api --endpoint https://api.example.com/graphql\n cnc auth set-token\n cnc execute --query 'query { __typename }'\n\n Database Operations:\n For database migrations, packages, and deployment, use pgpm:\n https://pgpm.io\n ";
1
+ export declare const usageText = "\n Usage: cnc <command> [options]\n constructive <command> [options]\n\n Constructive CLI - API Server and Development Tools\n\n GraphQL Server:\n server Start a GraphQL server\n explorer Launch GraphiQL explorer interface\n\n Code Generation:\n codegen Generate TypeScript types and SDK from GraphQL schema\n\n Jobs:\n jobs up Start combined server (jobs runtime)\n\n Execution Engine:\n context Manage contexts (create, list, use, current, delete)\n auth Manage authentication (set-token, status, logout)\n execute Execute GraphQL queries against configured endpoints\n\n Global Options:\n -h, --help Display this help information\n -v, --version Display version information\n --cwd <directory> Working directory (default: current directory)\n\n Individual Command Help:\n cnc <command> --help Display detailed help for specific command\n cnc <command> -h Display detailed help for specific command\n\n Examples:\n cnc server Start GraphQL server\n cnc server --port 8080 Start server on custom port\n cnc explorer Launch GraphiQL explorer\n cnc codegen --schema schema.graphql Generate types from schema\n cnc codegen --schema-only --out schema.graphql Export schema SDL\n cnc jobs up Start combined server (jobs runtime)\n\n # Execution Engine\n cnc context create my-api --endpoint https://api.example.com/graphql\n cnc auth set-token\n cnc execute --query 'query { __typename }'\n\n Database Operations:\n For database migrations, packages, and deployment, use pgpm:\n https://pgpm.io\n ";
package/utils/display.js CHANGED
@@ -13,7 +13,6 @@ exports.usageText = `
13
13
 
14
14
  Code Generation:
15
15
  codegen Generate TypeScript types and SDK from GraphQL schema
16
- get-graphql-schema Fetch or build GraphQL schema SDL
17
16
 
18
17
  Jobs:
19
18
  jobs up Start combined server (jobs runtime)
@@ -37,7 +36,7 @@ exports.usageText = `
37
36
  cnc server --port 8080 Start server on custom port
38
37
  cnc explorer Launch GraphiQL explorer
39
38
  cnc codegen --schema schema.graphql Generate types from schema
40
- cnc get-graphql-schema --out schema.graphql Export schema SDL
39
+ cnc codegen --schema-only --out schema.graphql Export schema SDL
41
40
  cnc jobs up Start combined server (jobs runtime)
42
41
 
43
42
  # Execution Engine
@@ -1,3 +0,0 @@
1
- import { CLIOptions, Inquirerer } from 'inquirerer';
2
- declare const _default: (argv: Partial<Record<string, unknown>>, prompter: Inquirerer, _options: CLIOptions) => Promise<void>;
3
- export default _default;
@@ -1,90 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const fs_1 = require("fs");
4
- const graphql_server_1 = require("@constructive-io/graphql-server");
5
- const usage = `
6
- Constructive Get GraphQL Schema:
7
-
8
- cnc get-graphql-schema [OPTIONS]
9
-
10
- Source Options (choose one):
11
- --endpoint <url> GraphQL endpoint to fetch schema via introspection
12
- --database <name> Database name (default: constructive)
13
-
14
- Options:
15
- --schemas <list> Comma-separated schemas to include
16
- --headerHost <host> Host header to send with endpoint requests
17
- --auth <token> Authorization header value
18
- --out <path> Output file path (default: print to stdout)
19
-
20
- --help, -h Show this help message
21
- `;
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
- },
47
- ];
48
- exports.default = async (argv, prompter, _options) => {
49
- if (argv.help || argv.h) {
50
- console.log(usage);
51
- process.exit(0);
52
- }
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
56
- const headerArg = argv.header;
57
- const headerList = Array.isArray(headerArg) ? headerArg : headerArg ? [headerArg] : [];
58
- const headers = {};
59
- for (const h of headerList) {
60
- const idx = typeof h === 'string' ? h.indexOf(':') : -1;
61
- if (idx <= 0)
62
- continue;
63
- const name = h.slice(0, idx).trim();
64
- const value = h.slice(idx + 1).trim();
65
- if (!name)
66
- continue;
67
- headers[name] = value;
68
- }
69
- let sdl;
70
- if (endpoint) {
71
- const opts = {};
72
- if (argv.headerHost)
73
- opts.headerHost = argv.headerHost;
74
- if (argv.auth)
75
- opts.auth = argv.auth;
76
- if (Object.keys(headers).length)
77
- opts.headers = headers;
78
- sdl = await graphql_server_1.fetchEndpointSchemaSDL(endpoint, opts);
79
- }
80
- else {
81
- sdl = await (0, graphql_server_1.buildSchemaSDL)({ database: database, schemas });
82
- }
83
- if (out) {
84
- await fs_1.promises.writeFile(out, sdl, 'utf8');
85
- console.log(`Wrote schema SDL to ${out}`);
86
- }
87
- else {
88
- process.stdout.write(sdl + '\n');
89
- }
90
- };
@@ -1,88 +0,0 @@
1
- import { promises as fs } from 'fs';
2
- import { buildSchemaSDL, fetchEndpointSchemaSDL } from '@constructive-io/graphql-server';
3
- const usage = `
4
- Constructive Get GraphQL Schema:
5
-
6
- cnc get-graphql-schema [OPTIONS]
7
-
8
- Source Options (choose one):
9
- --endpoint <url> GraphQL endpoint to fetch schema via introspection
10
- --database <name> Database name (default: constructive)
11
-
12
- Options:
13
- --schemas <list> Comma-separated schemas to include
14
- --headerHost <host> Host header to send with endpoint requests
15
- --auth <token> Authorization header value
16
- --out <path> Output file path (default: print to stdout)
17
-
18
- --help, -h Show this help message
19
- `;
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
- },
45
- ];
46
- export default async (argv, prompter, _options) => {
47
- if (argv.help || argv.h) {
48
- console.log(usage);
49
- process.exit(0);
50
- }
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
54
- const headerArg = argv.header;
55
- const headerList = Array.isArray(headerArg) ? headerArg : headerArg ? [headerArg] : [];
56
- const headers = {};
57
- for (const h of headerList) {
58
- const idx = typeof h === 'string' ? h.indexOf(':') : -1;
59
- if (idx <= 0)
60
- continue;
61
- const name = h.slice(0, idx).trim();
62
- const value = h.slice(idx + 1).trim();
63
- if (!name)
64
- continue;
65
- headers[name] = value;
66
- }
67
- let sdl;
68
- if (endpoint) {
69
- const opts = {};
70
- if (argv.headerHost)
71
- opts.headerHost = argv.headerHost;
72
- if (argv.auth)
73
- opts.auth = argv.auth;
74
- if (Object.keys(headers).length)
75
- opts.headers = headers;
76
- sdl = await fetchEndpointSchemaSDL(endpoint, opts);
77
- }
78
- else {
79
- sdl = await buildSchemaSDL({ database: database, schemas });
80
- }
81
- if (out) {
82
- await fs.writeFile(out, sdl, 'utf8');
83
- console.log(`Wrote schema SDL to ${out}`);
84
- }
85
- else {
86
- process.stdout.write(sdl + '\n');
87
- }
88
- };