@constructive-io/cli 5.6.22 → 5.6.24

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
@@ -58,55 +58,26 @@ cnc explorer --origin http://localhost:3000
58
58
 
59
59
  ### `cnc codegen`
60
60
 
61
- Generate TypeScript types, operations, and SDK from a GraphQL schema.
61
+ Generate TypeScript types, operations, and SDK from a GraphQL schema or endpoint.
62
62
 
63
63
  ```bash
64
- # From SDL file
65
- cnc codegen --schema ./schema.graphql --out ./codegen
64
+ # From endpoint
65
+ cnc codegen --endpoint http://localhost:5555/graphql --out ./codegen
66
66
 
67
- # From endpoint with Host override
68
- cnc codegen --endpoint http://localhost:3000/graphql --headerHost meta8.localhost --out ./codegen
67
+ # From database
68
+ cnc codegen --database constructive_db --out ./codegen --verbose
69
69
  ```
70
70
 
71
71
  **Options:**
72
72
 
73
- - `--schema <path>` - Schema SDL file path
74
- - `--endpoint <url>` - GraphQL endpoint to fetch schema via introspection
75
- - `--headerHost <host>` - Optional Host header for endpoint requests
76
- - `--auth <token>` - Optional Authorization header value
77
- - `--header "Name: Value"` - Optional HTTP header (repeatable)
78
- - `--out <dir>` - Output root directory (default: graphql/codegen/dist)
79
- - `--format <gql|ts>` - Document format (default: gql)
80
- - `--convention <style>` - Filename convention (dashed|underscore|camelcase|camelUpper)
81
- - `--emitTypes <bool>` - Emit types (default: true)
82
- - `--emitOperations <bool>` - Emit operations (default: true)
83
- - `--emitSdk <bool>` - Emit SDK (default: true)
84
- - `--config <path>` - Config file (JSON/YAML)
85
-
86
- **Config file example (`codegen.json`):**
87
-
88
- ```json
89
- {
90
- "input": {
91
- "schema": "./schema.graphql",
92
- "headers": { "Host": "meta8.localhost" }
93
- },
94
- "output": {
95
- "root": "graphql/codegen/dist"
96
- },
97
- "documents": {
98
- "format": "gql",
99
- "convention": "dashed",
100
- "excludePatterns": [".*Module$"]
101
- },
102
- "features": {
103
- "emitTypes": true,
104
- "emitOperations": true,
105
- "emitSdk": true,
106
- "emitReactQuery": true
107
- }
108
- }
109
- ```
73
+ - `--endpoint <url>` - GraphQL endpoint URL
74
+ - `--auth <token>` - Authorization header value (e.g., "Bearer 123")
75
+ - `--out <dir>` - Output directory (default: graphql/codegen/dist)
76
+ - `--dry-run` - Preview without writing files
77
+ - `--verbose` - Verbose output
78
+
79
+ - `--database <name>` - Database override for DB mode (defaults to PGDATABASE)
80
+ - `--schemas <list>` - Comma-separated schemas (required unless using --endpoint)
110
81
 
111
82
  ### `cnc get-graphql-schema`
112
83
 
@@ -123,7 +94,7 @@ cnc get-graphql-schema --endpoint http://localhost:3000/graphql --out ./schema.g
123
94
  **Options:**
124
95
 
125
96
  - `--database <name>` - Database name (for programmatic builder)
126
- - `--schemas <list>` - Comma-separated schemas to include
97
+ - `--schemas <list>` - Comma-separated schemas to include (required unless using --endpoint)
127
98
  - `--endpoint <url>` - GraphQL endpoint to fetch schema via introspection
128
99
  - `--headerHost <host>` - Optional Host header for endpoint requests
129
100
  - `--auth <token>` - Optional Authorization header value
@@ -1,6 +1,43 @@
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
+ })();
2
35
  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");
3
39
  const generate_1 = require("@constructive-io/graphql-codegen/cli/commands/generate");
40
+ const graphql_env_1 = require("@constructive-io/graphql-env");
4
41
  const usage = `
5
42
  Constructive GraphQL Codegen:
6
43
 
@@ -14,29 +51,63 @@ Options:
14
51
  --out <dir> Output directory (default: graphql/codegen/dist)
15
52
  --dry-run Preview without writing files
16
53
  -v, --verbose Verbose output
54
+
55
+ --database <name> Database override for DB mode (defaults to PGDATABASE)
56
+ --schemas <list> Comma-separated schemas (required for DB mode)
17
57
  `;
18
58
  exports.default = async (argv, _prompter, _options) => {
19
59
  if (argv.help || argv.h) {
20
60
  console.log(usage);
21
61
  process.exit(0);
22
62
  }
23
- const endpoint = argv.endpoint || '';
63
+ const endpointArg = argv.endpoint || '';
24
64
  const outDir = argv.out || 'codegen';
25
65
  const auth = argv.auth || '';
26
66
  const configPath = argv.config || '';
27
67
  const dryRun = !!(argv['dry-run'] || argv.dryRun);
28
68
  const verbose = !!(argv.verbose || argv.v);
29
- const result = await (0, generate_1.generateCommand)({
30
- config: configPath,
31
- endpoint,
32
- output: outDir,
33
- authorization: auth,
34
- verbose,
35
- dryRun,
36
- });
37
- if (!result.success) {
38
- console.error('x', result.message);
69
+ const selectedDb = argv.database || undefined;
70
+ const options = selectedDb ? (0, graphql_env_1.getEnvOptions)({ pg: { database: selectedDb } }) : (0, graphql_env_1.getEnvOptions)();
71
+ const schemasArg = argv.schemas || '';
72
+ const runGenerate = async ({ endpoint, schema }) => {
73
+ const result = await (0, generate_1.generateCommand)({
74
+ config: configPath || undefined,
75
+ endpoint,
76
+ schema,
77
+ output: outDir,
78
+ authorization: auth || undefined,
79
+ verbose,
80
+ dryRun,
81
+ });
82
+ if (!result.success) {
83
+ console.error(result.message);
84
+ if (result.errors?.length)
85
+ result.errors.forEach(e => console.error(' -', e));
86
+ process.exit(1);
87
+ }
88
+ console.log(result.message);
89
+ if (result.filesWritten?.length) {
90
+ result.filesWritten.forEach(f => console.log(f));
91
+ }
92
+ };
93
+ if (endpointArg) {
94
+ await runGenerate({ endpoint: endpointArg });
95
+ return;
96
+ }
97
+ if (!schemasArg.trim()) {
98
+ console.error('Error: --schemas is required when building from database. Provide a comma-separated list of schemas.');
39
99
  process.exit(1);
40
100
  }
41
- console.log('[ok]', result.message);
101
+ const schemas = schemasArg.split(',').map((s) => s.trim()).filter(Boolean);
102
+ await fs.promises.mkdir(outDir, { recursive: true });
103
+ const sdl = await (0, graphql_server_1.buildSchemaSDL)({
104
+ database: options.pg.database,
105
+ schemas,
106
+ graphile: {
107
+ pgSettings: async () => ({ role: 'administrator' }),
108
+ },
109
+ });
110
+ const schemaPath = path.join(outDir, 'schema.graphql');
111
+ await fs.promises.writeFile(schemaPath, sdl, 'utf-8');
112
+ await runGenerate({ schema: schemaPath });
42
113
  };
package/commands.js CHANGED
@@ -16,7 +16,7 @@ const createCommandMap = () => {
16
16
  server: server_1.default,
17
17
  explorer: explorer_1.default,
18
18
  'get-graphql-schema': get_graphql_schema_1.default,
19
- codegen: codegen_1.default
19
+ codegen: codegen_1.default,
20
20
  };
21
21
  };
22
22
  const commands = async (argv, prompter, options) => {
@@ -1,4 +1,8 @@
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
+ import { buildSchemaSDL } from '@constructive-io/graphql-server';
1
4
  import { generateCommand } from '@constructive-io/graphql-codegen/cli/commands/generate';
5
+ import { getEnvOptions } from '@constructive-io/graphql-env';
2
6
  const usage = `
3
7
  Constructive GraphQL Codegen:
4
8
 
@@ -12,29 +16,63 @@ Options:
12
16
  --out <dir> Output directory (default: graphql/codegen/dist)
13
17
  --dry-run Preview without writing files
14
18
  -v, --verbose Verbose output
19
+
20
+ --database <name> Database override for DB mode (defaults to PGDATABASE)
21
+ --schemas <list> Comma-separated schemas (required for DB mode)
15
22
  `;
16
23
  export default async (argv, _prompter, _options) => {
17
24
  if (argv.help || argv.h) {
18
25
  console.log(usage);
19
26
  process.exit(0);
20
27
  }
21
- const endpoint = argv.endpoint || '';
28
+ const endpointArg = argv.endpoint || '';
22
29
  const outDir = argv.out || 'codegen';
23
30
  const auth = argv.auth || '';
24
31
  const configPath = argv.config || '';
25
32
  const dryRun = !!(argv['dry-run'] || argv.dryRun);
26
33
  const verbose = !!(argv.verbose || argv.v);
27
- const result = await generateCommand({
28
- config: configPath,
29
- endpoint,
30
- output: outDir,
31
- authorization: auth,
32
- verbose,
33
- dryRun,
34
- });
35
- if (!result.success) {
36
- console.error('x', result.message);
34
+ const selectedDb = argv.database || undefined;
35
+ const options = selectedDb ? getEnvOptions({ pg: { database: selectedDb } }) : getEnvOptions();
36
+ const schemasArg = argv.schemas || '';
37
+ const runGenerate = async ({ endpoint, schema }) => {
38
+ const result = await generateCommand({
39
+ config: configPath || undefined,
40
+ endpoint,
41
+ schema,
42
+ output: outDir,
43
+ authorization: auth || undefined,
44
+ verbose,
45
+ dryRun,
46
+ });
47
+ if (!result.success) {
48
+ console.error(result.message);
49
+ if (result.errors?.length)
50
+ result.errors.forEach(e => console.error(' -', e));
51
+ process.exit(1);
52
+ }
53
+ console.log(result.message);
54
+ if (result.filesWritten?.length) {
55
+ result.filesWritten.forEach(f => console.log(f));
56
+ }
57
+ };
58
+ if (endpointArg) {
59
+ await runGenerate({ endpoint: endpointArg });
60
+ return;
61
+ }
62
+ if (!schemasArg.trim()) {
63
+ console.error('Error: --schemas is required when building from database. Provide a comma-separated list of schemas.');
37
64
  process.exit(1);
38
65
  }
39
- console.log('[ok]', result.message);
66
+ const schemas = schemasArg.split(',').map((s) => s.trim()).filter(Boolean);
67
+ await fs.promises.mkdir(outDir, { recursive: true });
68
+ const sdl = await buildSchemaSDL({
69
+ database: options.pg.database,
70
+ schemas,
71
+ graphile: {
72
+ pgSettings: async () => ({ role: 'administrator' }),
73
+ },
74
+ });
75
+ const schemaPath = path.join(outDir, 'schema.graphql');
76
+ await fs.promises.writeFile(schemaPath, sdl, 'utf-8');
77
+ await runGenerate({ schema: schemaPath });
40
78
  };
package/esm/commands.js CHANGED
@@ -10,7 +10,7 @@ const createCommandMap = () => {
10
10
  server,
11
11
  explorer,
12
12
  'get-graphql-schema': getGraphqlSchema,
13
- codegen
13
+ codegen,
14
14
  };
15
15
  };
16
16
  export const commands = async (argv, prompter, options) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructive-io/cli",
3
- "version": "5.6.22",
3
+ "version": "5.6.24",
4
4
  "author": "Constructive <developers@constructive.io>",
5
5
  "description": "Constructive CLI",
6
6
  "main": "index.js",
@@ -48,10 +48,10 @@
48
48
  "dependencies": {
49
49
  "@constructive-io/graphql-codegen": "^2.23.3",
50
50
  "@constructive-io/graphql-env": "^2.8.19",
51
- "@constructive-io/graphql-explorer": "^2.13.16",
52
- "@constructive-io/graphql-server": "^2.16.1",
51
+ "@constructive-io/graphql-explorer": "^2.13.17",
52
+ "@constructive-io/graphql-server": "^2.16.2",
53
53
  "@inquirerer/utils": "^3.1.3",
54
- "@pgpmjs/core": "^4.15.0",
54
+ "@pgpmjs/core": "^4.15.1",
55
55
  "@pgpmjs/logger": "^1.3.7",
56
56
  "@pgpmjs/server-utils": "^2.8.15",
57
57
  "@pgpmjs/types": "^2.14.1",
@@ -61,7 +61,7 @@
61
61
  "minimist": "^1.2.8",
62
62
  "pg-cache": "^1.6.15",
63
63
  "pg-env": "^1.2.5",
64
- "pgpm": "^2.10.14",
64
+ "pgpm": "^2.10.15",
65
65
  "shelljs": "^0.10.0",
66
66
  "yanse": "^0.1.11"
67
67
  },
@@ -76,5 +76,5 @@
76
76
  "postgres",
77
77
  "graphile"
78
78
  ],
79
- "gitHead": "15e8f92ee6ec7bfebd6647dec743e4235b0362ac"
79
+ "gitHead": "b9719cd48487af70e6e065510197c9d2d6b331b6"
80
80
  }