@constructive-io/graphql-codegen 2.32.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} +4 -0
- 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} +1 -0
- 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 +101 -138
- package/esm/types/config.js +8 -35
- 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 +18 -11
- package/types/config.d.ts +101 -138
- package/types/config.js +9 -38
- 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
|
@@ -33,95 +33,26 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.
|
|
36
|
+
exports.CONFIG_FILENAME = void 0;
|
|
37
37
|
exports.findConfigFile = findConfigFile;
|
|
38
38
|
exports.loadConfigFile = loadConfigFile;
|
|
39
39
|
/**
|
|
40
|
-
*
|
|
40
|
+
* Configuration file loading utilities
|
|
41
|
+
*
|
|
42
|
+
* Pure functions for finding and loading graphql-codegen configuration files.
|
|
43
|
+
* These are core utilities that can be used programmatically or by the CLI.
|
|
41
44
|
*/
|
|
42
45
|
const fs = __importStar(require("node:fs"));
|
|
43
46
|
const path = __importStar(require("node:path"));
|
|
44
47
|
const jiti_1 = require("jiti");
|
|
45
|
-
|
|
46
|
-
const CONFIG_TEMPLATE = `import { defineConfig } from '@constructive-io/graphql-codegen';
|
|
47
|
-
|
|
48
|
-
export default defineConfig({
|
|
49
|
-
// GraphQL endpoint URL (PostGraphile with _meta plugin)
|
|
50
|
-
endpoint: '{{ENDPOINT}}',
|
|
51
|
-
|
|
52
|
-
// Output directory for generated files
|
|
53
|
-
output: '{{OUTPUT}}',
|
|
54
|
-
|
|
55
|
-
// Optional: Multi-target config (use instead of endpoint/output)
|
|
56
|
-
// defaults: {
|
|
57
|
-
// headers: { Authorization: 'Bearer YOUR_TOKEN' },
|
|
58
|
-
// },
|
|
59
|
-
// targets: {
|
|
60
|
-
// public: { endpoint: 'https://api.example.com/graphql', output: './generated/public' },
|
|
61
|
-
// admin: { schema: './admin.schema.graphql', output: './generated/admin' },
|
|
62
|
-
// },
|
|
63
|
-
|
|
64
|
-
// Optional: Tables to include/exclude (supports glob patterns)
|
|
65
|
-
// tables: {
|
|
66
|
-
// include: ['*'],
|
|
67
|
-
// exclude: ['_*', 'pg_*'],
|
|
68
|
-
// },
|
|
69
|
-
|
|
70
|
-
// Optional: Authorization header for authenticated endpoints
|
|
71
|
-
// headers: {
|
|
72
|
-
// Authorization: 'Bearer YOUR_TOKEN',
|
|
73
|
-
// },
|
|
74
|
-
|
|
75
|
-
// Optional: Watch mode settings (in-memory caching, no file I/O)
|
|
76
|
-
// watch: {
|
|
77
|
-
// pollInterval: 3000, // ms
|
|
78
|
-
// debounce: 800, // ms
|
|
79
|
-
// clearScreen: true,
|
|
80
|
-
// touchFile: '.trigger', // Optional: file to touch on change
|
|
81
|
-
// },
|
|
82
|
-
});
|
|
83
|
-
`;
|
|
84
|
-
/**
|
|
85
|
-
* Execute the init command
|
|
86
|
-
*/
|
|
87
|
-
async function initCommand(options = {}) {
|
|
88
|
-
const { directory = process.cwd(), force = false, endpoint = '', output = './generated', } = options;
|
|
89
|
-
const configPath = path.join(directory, CONFIG_FILENAME);
|
|
90
|
-
// Check if config already exists
|
|
91
|
-
if (fs.existsSync(configPath) && !force) {
|
|
92
|
-
return {
|
|
93
|
-
success: false,
|
|
94
|
-
message: `Configuration file already exists: ${configPath}\nUse --force to overwrite.`,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
// Generate config content
|
|
98
|
-
const content = CONFIG_TEMPLATE.replace('{{ENDPOINT}}', endpoint || 'http://localhost:5000/graphql').replace('{{OUTPUT}}', output);
|
|
99
|
-
try {
|
|
100
|
-
// Ensure directory exists
|
|
101
|
-
fs.mkdirSync(directory, { recursive: true });
|
|
102
|
-
// Write config file
|
|
103
|
-
fs.writeFileSync(configPath, content, 'utf-8');
|
|
104
|
-
return {
|
|
105
|
-
success: true,
|
|
106
|
-
message: `Created configuration file: ${configPath}`,
|
|
107
|
-
configPath,
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
catch (err) {
|
|
111
|
-
const message = err instanceof Error ? err.message : 'Unknown error';
|
|
112
|
-
return {
|
|
113
|
-
success: false,
|
|
114
|
-
message: `Failed to create configuration file: ${message}`,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
}
|
|
48
|
+
exports.CONFIG_FILENAME = 'graphql-codegen.config.ts';
|
|
118
49
|
/**
|
|
119
50
|
* Find the nearest config file by walking up directories
|
|
120
51
|
*/
|
|
121
52
|
function findConfigFile(startDir = process.cwd()) {
|
|
122
53
|
let currentDir = startDir;
|
|
123
54
|
while (true) {
|
|
124
|
-
const configPath = path.join(currentDir, CONFIG_FILENAME);
|
|
55
|
+
const configPath = path.join(currentDir, exports.CONFIG_FILENAME);
|
|
125
56
|
if (fs.existsSync(configPath)) {
|
|
126
57
|
return configPath;
|
|
127
58
|
}
|
|
@@ -163,24 +94,6 @@ async function loadConfigFile(configPath) {
|
|
|
163
94
|
error: 'Config file must export a configuration object',
|
|
164
95
|
};
|
|
165
96
|
}
|
|
166
|
-
const hasEndpoint = 'endpoint' in config;
|
|
167
|
-
const hasSchema = 'schema' in config;
|
|
168
|
-
const hasTargets = 'targets' in config;
|
|
169
|
-
if (!hasEndpoint && !hasSchema && !hasTargets) {
|
|
170
|
-
return {
|
|
171
|
-
success: false,
|
|
172
|
-
error: 'Config file must define "endpoint", "schema", or "targets".',
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
if (hasTargets) {
|
|
176
|
-
const targets = config.targets;
|
|
177
|
-
if (!targets || typeof targets !== 'object' || Array.isArray(targets)) {
|
|
178
|
-
return {
|
|
179
|
-
success: false,
|
|
180
|
-
error: 'Config file "targets" must be an object of named configs.',
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
97
|
return {
|
|
185
98
|
success: true,
|
|
186
99
|
config,
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration resolution utilities
|
|
3
|
+
*
|
|
4
|
+
* Functions for resolving and merging configuration from various sources
|
|
5
|
+
* (config file, CLI options, defaults) into a final resolved configuration.
|
|
6
|
+
*/
|
|
7
|
+
import type { GraphQLSDKConfigTarget } from '../../types/config';
|
|
8
|
+
/**
|
|
9
|
+
* Options that can override config file settings.
|
|
10
|
+
* Extends GraphQLSDKConfigTarget with CLI-specific fields.
|
|
11
|
+
*/
|
|
12
|
+
export interface ConfigOverrideOptions extends GraphQLSDKConfigTarget {
|
|
13
|
+
/** Path to config file (CLI-only) */
|
|
14
|
+
config?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Result of loading and resolving configuration
|
|
18
|
+
*/
|
|
19
|
+
export interface LoadConfigResult {
|
|
20
|
+
success: boolean;
|
|
21
|
+
config?: GraphQLSDKConfigTarget;
|
|
22
|
+
error?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Load and resolve configuration from file and/or options
|
|
26
|
+
*
|
|
27
|
+
* This is the main entry point for configuration loading. It:
|
|
28
|
+
* 1. Finds and loads the config file (if any)
|
|
29
|
+
* 2. Applies CLI option overrides
|
|
30
|
+
* 3. Returns fully resolved configuration ready for use
|
|
31
|
+
*/
|
|
32
|
+
export declare function loadAndResolveConfig(options: ConfigOverrideOptions): Promise<LoadConfigResult>;
|
|
33
|
+
/**
|
|
34
|
+
* Build watch configuration from options
|
|
35
|
+
*
|
|
36
|
+
* Used by watch mode to resolve configuration with watch-specific overrides.
|
|
37
|
+
*/
|
|
38
|
+
export declare function loadWatchConfig(options: {
|
|
39
|
+
config?: string;
|
|
40
|
+
endpoint?: string;
|
|
41
|
+
output?: string;
|
|
42
|
+
pollInterval?: number;
|
|
43
|
+
debounce?: number;
|
|
44
|
+
touch?: string;
|
|
45
|
+
clear?: boolean;
|
|
46
|
+
}): Promise<GraphQLSDKConfigTarget | null>;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadAndResolveConfig = loadAndResolveConfig;
|
|
4
|
+
exports.loadWatchConfig = loadWatchConfig;
|
|
5
|
+
const config_1 = require("../../types/config");
|
|
6
|
+
const loader_1 = require("./loader");
|
|
7
|
+
/**
|
|
8
|
+
* Load and resolve configuration from file and/or options
|
|
9
|
+
*
|
|
10
|
+
* This is the main entry point for configuration loading. It:
|
|
11
|
+
* 1. Finds and loads the config file (if any)
|
|
12
|
+
* 2. Applies CLI option overrides
|
|
13
|
+
* 3. Returns fully resolved configuration ready for use
|
|
14
|
+
*/
|
|
15
|
+
async function loadAndResolveConfig(options) {
|
|
16
|
+
// Destructure CLI-only fields, rest is config overrides
|
|
17
|
+
const { config: configPath, ...overrides } = options;
|
|
18
|
+
// Validate that at most one source is specified
|
|
19
|
+
const sources = [
|
|
20
|
+
overrides.endpoint,
|
|
21
|
+
overrides.schemaFile,
|
|
22
|
+
overrides.db,
|
|
23
|
+
].filter(Boolean);
|
|
24
|
+
if (sources.length > 1) {
|
|
25
|
+
return {
|
|
26
|
+
success: false,
|
|
27
|
+
error: 'Multiple sources specified. Use only one of: endpoint, schemaFile, or db.',
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
// Find config file
|
|
31
|
+
let resolvedConfigPath = configPath;
|
|
32
|
+
if (!resolvedConfigPath) {
|
|
33
|
+
resolvedConfigPath = (0, loader_1.findConfigFile)() ?? undefined;
|
|
34
|
+
}
|
|
35
|
+
let baseConfig = {};
|
|
36
|
+
if (resolvedConfigPath) {
|
|
37
|
+
const loadResult = await (0, loader_1.loadConfigFile)(resolvedConfigPath);
|
|
38
|
+
if (!loadResult.success) {
|
|
39
|
+
return { success: false, error: loadResult.error };
|
|
40
|
+
}
|
|
41
|
+
baseConfig = loadResult.config;
|
|
42
|
+
}
|
|
43
|
+
const mergedConfig = (0, config_1.mergeConfig)(baseConfig, overrides);
|
|
44
|
+
// Check if we have a source (endpoint, schemaFile, or db)
|
|
45
|
+
const hasSource = mergedConfig.endpoint ||
|
|
46
|
+
mergedConfig.schemaFile ||
|
|
47
|
+
mergedConfig.db;
|
|
48
|
+
if (!hasSource) {
|
|
49
|
+
return {
|
|
50
|
+
success: false,
|
|
51
|
+
error: 'No source specified. Use --endpoint, --schema-file, or --db, or create a config file with "graphql-codegen init".',
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
success: true,
|
|
56
|
+
config: (0, config_1.getConfigOptions)(mergedConfig),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Build watch configuration from options
|
|
61
|
+
*
|
|
62
|
+
* Used by watch mode to resolve configuration with watch-specific overrides.
|
|
63
|
+
*/
|
|
64
|
+
async function loadWatchConfig(options) {
|
|
65
|
+
let configPath = options.config;
|
|
66
|
+
if (!configPath) {
|
|
67
|
+
configPath = (0, loader_1.findConfigFile)() ?? undefined;
|
|
68
|
+
}
|
|
69
|
+
let baseConfig = {};
|
|
70
|
+
if (configPath) {
|
|
71
|
+
const loadResult = await (0, loader_1.loadConfigFile)(configPath);
|
|
72
|
+
if (!loadResult.success) {
|
|
73
|
+
console.error('x', loadResult.error);
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
baseConfig = loadResult.config;
|
|
77
|
+
}
|
|
78
|
+
const sourceOverrides = {};
|
|
79
|
+
if (options.endpoint) {
|
|
80
|
+
sourceOverrides.endpoint = options.endpoint;
|
|
81
|
+
sourceOverrides.schemaFile = undefined;
|
|
82
|
+
}
|
|
83
|
+
const watchOverrides = {
|
|
84
|
+
watch: {
|
|
85
|
+
...(options.pollInterval !== undefined && {
|
|
86
|
+
pollInterval: options.pollInterval,
|
|
87
|
+
}),
|
|
88
|
+
...(options.debounce !== undefined && { debounce: options.debounce }),
|
|
89
|
+
...(options.touch !== undefined && { touchFile: options.touch }),
|
|
90
|
+
...(options.clear !== undefined && { clearScreen: options.clear }),
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
let mergedConfig = (0, config_1.mergeConfig)(baseConfig, sourceOverrides);
|
|
94
|
+
mergedConfig = (0, config_1.mergeConfig)(mergedConfig, watchOverrides);
|
|
95
|
+
if (!mergedConfig.endpoint) {
|
|
96
|
+
console.error('x No endpoint specified. Watch mode only supports live endpoints.');
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
if (mergedConfig.schemaFile) {
|
|
100
|
+
console.error('x Watch mode is only supported with an endpoint, not schemaFile.');
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
return (0, config_1.getConfigOptions)(mergedConfig);
|
|
104
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database schema utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides functions for building GraphQL schemas directly from PostgreSQL databases.
|
|
5
|
+
*/
|
|
6
|
+
export interface BuildSchemaFromDatabaseOptions {
|
|
7
|
+
/** Database name */
|
|
8
|
+
database: string;
|
|
9
|
+
/** PostgreSQL schemas to include */
|
|
10
|
+
schemas: string[];
|
|
11
|
+
/** Output directory for the schema file */
|
|
12
|
+
outDir: string;
|
|
13
|
+
/** Optional filename (default: schema.graphql) */
|
|
14
|
+
filename?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface BuildSchemaFromDatabaseResult {
|
|
17
|
+
/** Path to the generated schema file */
|
|
18
|
+
schemaPath: string;
|
|
19
|
+
/** The SDL content */
|
|
20
|
+
sdl: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Build a GraphQL schema from a PostgreSQL database and write it to a file.
|
|
24
|
+
*
|
|
25
|
+
* This function introspects the database using PostGraphile and generates
|
|
26
|
+
* a GraphQL SDL file that can be used for code generation.
|
|
27
|
+
*
|
|
28
|
+
* @param options - Configuration options
|
|
29
|
+
* @returns The path to the generated schema file and the SDL content
|
|
30
|
+
*/
|
|
31
|
+
export declare function buildSchemaFromDatabase(options: BuildSchemaFromDatabaseOptions): Promise<BuildSchemaFromDatabaseResult>;
|
|
32
|
+
/**
|
|
33
|
+
* Build a GraphQL schema SDL string from a PostgreSQL database without writing to file.
|
|
34
|
+
*
|
|
35
|
+
* This is a convenience wrapper around buildSchemaSDL from graphql-server.
|
|
36
|
+
*
|
|
37
|
+
* @param options - Configuration options
|
|
38
|
+
* @returns The SDL content as a string
|
|
39
|
+
*/
|
|
40
|
+
export declare function buildSchemaSDLFromDatabase(options: {
|
|
41
|
+
database: string;
|
|
42
|
+
schemas: string[];
|
|
43
|
+
}): Promise<string>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Database schema utilities
|
|
4
|
+
*
|
|
5
|
+
* Provides functions for building GraphQL schemas directly from PostgreSQL databases.
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
+
}) : function(o, v) {
|
|
21
|
+
o["default"] = v;
|
|
22
|
+
});
|
|
23
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
+
var ownKeys = function(o) {
|
|
25
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
+
var ar = [];
|
|
27
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
+
return ar;
|
|
29
|
+
};
|
|
30
|
+
return ownKeys(o);
|
|
31
|
+
};
|
|
32
|
+
return function (mod) {
|
|
33
|
+
if (mod && mod.__esModule) return mod;
|
|
34
|
+
var result = {};
|
|
35
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
+
__setModuleDefault(result, mod);
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.buildSchemaFromDatabase = buildSchemaFromDatabase;
|
|
42
|
+
exports.buildSchemaSDLFromDatabase = buildSchemaSDLFromDatabase;
|
|
43
|
+
const fs = __importStar(require("node:fs"));
|
|
44
|
+
const path = __importStar(require("node:path"));
|
|
45
|
+
const graphql_server_1 = require("@constructive-io/graphql-server");
|
|
46
|
+
/**
|
|
47
|
+
* Build a GraphQL schema from a PostgreSQL database and write it to a file.
|
|
48
|
+
*
|
|
49
|
+
* This function introspects the database using PostGraphile and generates
|
|
50
|
+
* a GraphQL SDL file that can be used for code generation.
|
|
51
|
+
*
|
|
52
|
+
* @param options - Configuration options
|
|
53
|
+
* @returns The path to the generated schema file and the SDL content
|
|
54
|
+
*/
|
|
55
|
+
async function buildSchemaFromDatabase(options) {
|
|
56
|
+
const { database, schemas, outDir, filename = 'schema.graphql' } = options;
|
|
57
|
+
// Ensure output directory exists
|
|
58
|
+
await fs.promises.mkdir(outDir, { recursive: true });
|
|
59
|
+
// Build schema SDL from database
|
|
60
|
+
const sdl = await (0, graphql_server_1.buildSchemaSDL)({
|
|
61
|
+
database,
|
|
62
|
+
schemas,
|
|
63
|
+
graphile: { pgSettings: async () => ({ role: 'administrator' }) },
|
|
64
|
+
});
|
|
65
|
+
// Write schema to file
|
|
66
|
+
const schemaPath = path.join(outDir, filename);
|
|
67
|
+
await fs.promises.writeFile(schemaPath, sdl, 'utf-8');
|
|
68
|
+
return { schemaPath, sdl };
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Build a GraphQL schema SDL string from a PostgreSQL database without writing to file.
|
|
72
|
+
*
|
|
73
|
+
* This is a convenience wrapper around buildSchemaSDL from graphql-server.
|
|
74
|
+
*
|
|
75
|
+
* @param options - Configuration options
|
|
76
|
+
* @returns The SDL content as a string
|
|
77
|
+
*/
|
|
78
|
+
async function buildSchemaSDLFromDatabase(options) {
|
|
79
|
+
const { database, schemas } = options;
|
|
80
|
+
return (0, graphql_server_1.buildSchemaSDL)({
|
|
81
|
+
database,
|
|
82
|
+
schemas,
|
|
83
|
+
graphile: { pgSettings: async () => ({ role: 'administrator' }) },
|
|
84
|
+
});
|
|
85
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { GraphQLSDKConfigTarget } from '../types/config';
|
|
2
|
+
export interface GenerateOptions extends GraphQLSDKConfigTarget {
|
|
3
|
+
authorization?: string;
|
|
4
|
+
verbose?: boolean;
|
|
5
|
+
dryRun?: boolean;
|
|
6
|
+
skipCustomOperations?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface GenerateResult {
|
|
9
|
+
success: boolean;
|
|
10
|
+
message: string;
|
|
11
|
+
output?: string;
|
|
12
|
+
tables?: string[];
|
|
13
|
+
filesWritten?: string[];
|
|
14
|
+
errors?: string[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Main generate function - takes a single config and generates code
|
|
18
|
+
*
|
|
19
|
+
* This is the primary entry point for programmatic usage.
|
|
20
|
+
* For multiple configs, call this function in a loop.
|
|
21
|
+
*/
|
|
22
|
+
export declare function generate(options?: GenerateOptions): Promise<GenerateResult>;
|
package/core/generate.js
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generate = generate;
|
|
7
|
+
/**
|
|
8
|
+
* Main generate function - orchestrates the entire codegen pipeline
|
|
9
|
+
*
|
|
10
|
+
* This is the primary entry point for programmatic usage.
|
|
11
|
+
* The CLI is a thin wrapper around this function.
|
|
12
|
+
*/
|
|
13
|
+
const path_1 = __importDefault(require("path"));
|
|
14
|
+
const introspect_1 = require("./introspect");
|
|
15
|
+
const pipeline_1 = require("./pipeline");
|
|
16
|
+
const codegen_1 = require("./codegen");
|
|
17
|
+
const orm_1 = require("./codegen/orm");
|
|
18
|
+
const shared_1 = require("./codegen/shared");
|
|
19
|
+
const output_1 = require("./output");
|
|
20
|
+
const config_1 = require("../types/config");
|
|
21
|
+
/**
|
|
22
|
+
* Main generate function - takes a single config and generates code
|
|
23
|
+
*
|
|
24
|
+
* This is the primary entry point for programmatic usage.
|
|
25
|
+
* For multiple configs, call this function in a loop.
|
|
26
|
+
*/
|
|
27
|
+
async function generate(options = {}) {
|
|
28
|
+
// Apply defaults to get resolved config
|
|
29
|
+
const config = (0, config_1.getConfigOptions)(options);
|
|
30
|
+
const outputRoot = config.output;
|
|
31
|
+
// Determine which generators to run
|
|
32
|
+
const runReactQuery = config.reactQuery ?? false;
|
|
33
|
+
const runOrm = config.orm ?? false;
|
|
34
|
+
if (!runReactQuery && !runOrm) {
|
|
35
|
+
return {
|
|
36
|
+
success: false,
|
|
37
|
+
message: 'No generators enabled. Use reactQuery: true or orm: true in your config.',
|
|
38
|
+
output: outputRoot,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
// Validate source
|
|
42
|
+
const sourceValidation = (0, introspect_1.validateSourceOptions)({
|
|
43
|
+
endpoint: config.endpoint || undefined,
|
|
44
|
+
schemaFile: config.schemaFile || undefined,
|
|
45
|
+
db: config.db,
|
|
46
|
+
});
|
|
47
|
+
if (!sourceValidation.valid) {
|
|
48
|
+
return {
|
|
49
|
+
success: false,
|
|
50
|
+
message: sourceValidation.error,
|
|
51
|
+
output: outputRoot,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const source = (0, introspect_1.createSchemaSource)({
|
|
55
|
+
endpoint: config.endpoint || undefined,
|
|
56
|
+
schemaFile: config.schemaFile || undefined,
|
|
57
|
+
db: config.db,
|
|
58
|
+
authorization: options.authorization || config.headers?.['Authorization'],
|
|
59
|
+
headers: config.headers,
|
|
60
|
+
});
|
|
61
|
+
// Run pipeline
|
|
62
|
+
let pipelineResult;
|
|
63
|
+
try {
|
|
64
|
+
console.log(`Fetching schema from ${source.describe()}...`);
|
|
65
|
+
pipelineResult = await (0, pipeline_1.runCodegenPipeline)({
|
|
66
|
+
source,
|
|
67
|
+
config,
|
|
68
|
+
verbose: options.verbose,
|
|
69
|
+
skipCustomOperations: options.skipCustomOperations,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
return {
|
|
74
|
+
success: false,
|
|
75
|
+
message: `Failed to fetch schema: ${err instanceof Error ? err.message : 'Unknown error'}`,
|
|
76
|
+
output: outputRoot,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const { tables, customOperations } = pipelineResult;
|
|
80
|
+
// Validate tables
|
|
81
|
+
const tablesValidation = (0, pipeline_1.validateTablesFound)(tables);
|
|
82
|
+
if (!tablesValidation.valid) {
|
|
83
|
+
return {
|
|
84
|
+
success: false,
|
|
85
|
+
message: tablesValidation.error,
|
|
86
|
+
output: outputRoot,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
const allFilesWritten = [];
|
|
90
|
+
const bothEnabled = runReactQuery && runOrm;
|
|
91
|
+
// Generate shared types when both are enabled
|
|
92
|
+
if (bothEnabled) {
|
|
93
|
+
console.log('Generating shared types...');
|
|
94
|
+
const sharedResult = (0, shared_1.generateSharedTypes)({
|
|
95
|
+
tables,
|
|
96
|
+
customOperations: {
|
|
97
|
+
queries: customOperations.queries,
|
|
98
|
+
mutations: customOperations.mutations,
|
|
99
|
+
typeRegistry: customOperations.typeRegistry,
|
|
100
|
+
},
|
|
101
|
+
config,
|
|
102
|
+
});
|
|
103
|
+
if (!options.dryRun) {
|
|
104
|
+
const writeResult = await (0, output_1.writeGeneratedFiles)(sharedResult.files, outputRoot, []);
|
|
105
|
+
if (!writeResult.success) {
|
|
106
|
+
return {
|
|
107
|
+
success: false,
|
|
108
|
+
message: `Failed to write shared types: ${writeResult.errors?.join(', ')}`,
|
|
109
|
+
output: outputRoot,
|
|
110
|
+
errors: writeResult.errors,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
allFilesWritten.push(...(writeResult.filesWritten ?? []));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// Generate React Query hooks
|
|
117
|
+
if (runReactQuery) {
|
|
118
|
+
const hooksDir = path_1.default.join(outputRoot, 'hooks');
|
|
119
|
+
console.log('Generating React Query hooks...');
|
|
120
|
+
const { files } = (0, codegen_1.generate)({
|
|
121
|
+
tables,
|
|
122
|
+
customOperations: {
|
|
123
|
+
queries: customOperations.queries,
|
|
124
|
+
mutations: customOperations.mutations,
|
|
125
|
+
typeRegistry: customOperations.typeRegistry,
|
|
126
|
+
},
|
|
127
|
+
config,
|
|
128
|
+
sharedTypesPath: bothEnabled ? '..' : undefined,
|
|
129
|
+
});
|
|
130
|
+
if (!options.dryRun) {
|
|
131
|
+
const writeResult = await (0, output_1.writeGeneratedFiles)(files, hooksDir, ['queries', 'mutations']);
|
|
132
|
+
if (!writeResult.success) {
|
|
133
|
+
return {
|
|
134
|
+
success: false,
|
|
135
|
+
message: `Failed to write React Query hooks: ${writeResult.errors?.join(', ')}`,
|
|
136
|
+
output: outputRoot,
|
|
137
|
+
errors: writeResult.errors,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
allFilesWritten.push(...(writeResult.filesWritten ?? []));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// Generate ORM client
|
|
144
|
+
if (runOrm) {
|
|
145
|
+
const ormDir = path_1.default.join(outputRoot, 'orm');
|
|
146
|
+
console.log('Generating ORM client...');
|
|
147
|
+
const { files } = (0, orm_1.generateOrm)({
|
|
148
|
+
tables,
|
|
149
|
+
customOperations: {
|
|
150
|
+
queries: customOperations.queries,
|
|
151
|
+
mutations: customOperations.mutations,
|
|
152
|
+
typeRegistry: customOperations.typeRegistry,
|
|
153
|
+
},
|
|
154
|
+
config,
|
|
155
|
+
sharedTypesPath: bothEnabled ? '..' : undefined,
|
|
156
|
+
});
|
|
157
|
+
if (!options.dryRun) {
|
|
158
|
+
const writeResult = await (0, output_1.writeGeneratedFiles)(files, ormDir, ['models', 'query', 'mutation']);
|
|
159
|
+
if (!writeResult.success) {
|
|
160
|
+
return {
|
|
161
|
+
success: false,
|
|
162
|
+
message: `Failed to write ORM client: ${writeResult.errors?.join(', ')}`,
|
|
163
|
+
output: outputRoot,
|
|
164
|
+
errors: writeResult.errors,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
allFilesWritten.push(...(writeResult.filesWritten ?? []));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// Generate unified barrel when both are enabled
|
|
171
|
+
if (bothEnabled && !options.dryRun) {
|
|
172
|
+
const barrelContent = `/**
|
|
173
|
+
* Generated SDK - auto-generated, do not edit
|
|
174
|
+
* @generated by @constructive-io/graphql-codegen
|
|
175
|
+
*/
|
|
176
|
+
export * from './types';
|
|
177
|
+
export * from './hooks';
|
|
178
|
+
export * from './orm';
|
|
179
|
+
`;
|
|
180
|
+
await (0, output_1.writeGeneratedFiles)([{ path: 'index.ts', content: barrelContent }], outputRoot, []);
|
|
181
|
+
}
|
|
182
|
+
const generators = [runReactQuery && 'React Query', runOrm && 'ORM'].filter(Boolean).join(' and ');
|
|
183
|
+
return {
|
|
184
|
+
success: true,
|
|
185
|
+
message: options.dryRun
|
|
186
|
+
? `Dry run complete. Would generate ${generators} for ${tables.length} tables.`
|
|
187
|
+
: `Generated ${generators} for ${tables.length} tables. Files written to ${outputRoot}`,
|
|
188
|
+
output: outputRoot,
|
|
189
|
+
tables: tables.map((t) => t.name),
|
|
190
|
+
filesWritten: allFilesWritten,
|
|
191
|
+
};
|
|
192
|
+
}
|
package/core/index.d.ts
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Core
|
|
2
|
+
* Core module exports
|
|
3
|
+
*
|
|
4
|
+
* This module contains all the core business logic for graphql-codegen.
|
|
5
|
+
* The CLI is a thin wrapper around these core functions.
|
|
3
6
|
*/
|
|
7
|
+
export { generate } from './generate';
|
|
8
|
+
export type { GenerateOptions, GenerateResult } from './generate';
|
|
4
9
|
export * from './types';
|
|
5
10
|
export * from './ast';
|
|
6
11
|
export * from './custom-ast';
|
|
7
12
|
export { QueryBuilder, MetaObject } from './query-builder';
|
|
8
13
|
export { validateMetaObject, convertFromMetaSchema } from './meta-object';
|
|
14
|
+
export * from './config';
|
|
15
|
+
export * from './codegen';
|
|
16
|
+
export * from './introspect';
|
|
17
|
+
export * from './pipeline';
|
|
18
|
+
export * from './output';
|
|
19
|
+
export * from './watch';
|
|
20
|
+
export * from './database';
|
package/core/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Core
|
|
3
|
+
* Core module exports
|
|
4
|
+
*
|
|
5
|
+
* This module contains all the core business logic for graphql-codegen.
|
|
6
|
+
* The CLI is a thin wrapper around these core functions.
|
|
4
7
|
*/
|
|
5
8
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
9
|
if (k2 === undefined) k2 = k;
|
|
@@ -17,7 +20,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
17
20
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
21
|
};
|
|
19
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.convertFromMetaSchema = exports.validateMetaObject = exports.MetaObject = exports.QueryBuilder = void 0;
|
|
23
|
+
exports.convertFromMetaSchema = exports.validateMetaObject = exports.MetaObject = exports.QueryBuilder = exports.generate = void 0;
|
|
24
|
+
// Main generate function (orchestrates the entire pipeline)
|
|
25
|
+
var generate_1 = require("./generate");
|
|
26
|
+
Object.defineProperty(exports, "generate", { enumerable: true, get: function () { return generate_1.generate; } });
|
|
21
27
|
// Types
|
|
22
28
|
__exportStar(require("./types"), exports);
|
|
23
29
|
// AST generation
|
|
@@ -31,3 +37,17 @@ Object.defineProperty(exports, "MetaObject", { enumerable: true, get: function (
|
|
|
31
37
|
var meta_object_1 = require("./meta-object");
|
|
32
38
|
Object.defineProperty(exports, "validateMetaObject", { enumerable: true, get: function () { return meta_object_1.validateMetaObject; } });
|
|
33
39
|
Object.defineProperty(exports, "convertFromMetaSchema", { enumerable: true, get: function () { return meta_object_1.convertFromMetaSchema; } });
|
|
40
|
+
// Configuration loading and resolution
|
|
41
|
+
__exportStar(require("./config"), exports);
|
|
42
|
+
// Code generation
|
|
43
|
+
__exportStar(require("./codegen"), exports);
|
|
44
|
+
// Schema introspection
|
|
45
|
+
__exportStar(require("./introspect"), exports);
|
|
46
|
+
// Codegen pipeline
|
|
47
|
+
__exportStar(require("./pipeline"), exports);
|
|
48
|
+
// File output
|
|
49
|
+
__exportStar(require("./output"), exports);
|
|
50
|
+
// Watch mode
|
|
51
|
+
__exportStar(require("./watch"), exports);
|
|
52
|
+
// Database schema utilities
|
|
53
|
+
__exportStar(require("./database"), exports);
|