@depup/graphql-codegen__cli 6.2.1-depup.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.
Files changed (112) hide show
  1. package/README.md +51 -0
  2. package/changes.json +90 -0
  3. package/cjs/bin.js +13 -0
  4. package/cjs/cli.js +64 -0
  5. package/cjs/codegen.js +388 -0
  6. package/cjs/config.js +370 -0
  7. package/cjs/documentTransforms.js +63 -0
  8. package/cjs/generate-and-save.js +153 -0
  9. package/cjs/graphql-config.js +67 -0
  10. package/cjs/hooks.js +93 -0
  11. package/cjs/index.js +13 -0
  12. package/cjs/init/helpers.js +90 -0
  13. package/cjs/init/index.js +62 -0
  14. package/cjs/init/plugins.js +136 -0
  15. package/cjs/init/questions.js +177 -0
  16. package/cjs/init/targets.js +45 -0
  17. package/cjs/init/types.js +15 -0
  18. package/cjs/load.js +102 -0
  19. package/cjs/package.json +1 -0
  20. package/cjs/plugins.js +43 -0
  21. package/cjs/presets.js +50 -0
  22. package/cjs/utils/abort-controller-polyfill.js +99 -0
  23. package/cjs/utils/cli-error.js +24 -0
  24. package/cjs/utils/debugging.js +22 -0
  25. package/cjs/utils/file-system.js +24 -0
  26. package/cjs/utils/get-latest-version.js +14 -0
  27. package/cjs/utils/helpers.js +12 -0
  28. package/cjs/utils/logger.js +24 -0
  29. package/cjs/utils/patterns.js +235 -0
  30. package/cjs/utils/watcher.js +244 -0
  31. package/esm/bin.js +11 -0
  32. package/esm/cli.js +37 -0
  33. package/esm/codegen.js +384 -0
  34. package/esm/config.js +357 -0
  35. package/esm/documentTransforms.js +59 -0
  36. package/esm/generate-and-save.js +149 -0
  37. package/esm/graphql-config.js +62 -0
  38. package/esm/hooks.js +89 -0
  39. package/esm/index.js +7 -0
  40. package/esm/init/helpers.js +82 -0
  41. package/esm/init/index.js +59 -0
  42. package/esm/init/plugins.js +133 -0
  43. package/esm/init/questions.js +172 -0
  44. package/esm/init/targets.js +42 -0
  45. package/esm/init/types.js +12 -0
  46. package/esm/load.js +97 -0
  47. package/esm/plugins.js +40 -0
  48. package/esm/presets.js +47 -0
  49. package/esm/utils/abort-controller-polyfill.js +96 -0
  50. package/esm/utils/cli-error.js +20 -0
  51. package/esm/utils/debugging.js +17 -0
  52. package/esm/utils/file-system.js +17 -0
  53. package/esm/utils/get-latest-version.js +11 -0
  54. package/esm/utils/helpers.js +9 -0
  55. package/esm/utils/logger.js +18 -0
  56. package/esm/utils/patterns.js +226 -0
  57. package/esm/utils/watcher.js +239 -0
  58. package/package.json +205 -0
  59. package/typings/bin.d.cts +2 -0
  60. package/typings/bin.d.ts +2 -0
  61. package/typings/cli.d.cts +2 -0
  62. package/typings/cli.d.ts +2 -0
  63. package/typings/codegen.d.cts +6 -0
  64. package/typings/codegen.d.ts +6 -0
  65. package/typings/config.d.cts +152 -0
  66. package/typings/config.d.ts +152 -0
  67. package/typings/documentTransforms.d.cts +3 -0
  68. package/typings/documentTransforms.d.ts +3 -0
  69. package/typings/generate-and-save.d.cts +10 -0
  70. package/typings/generate-and-save.d.ts +10 -0
  71. package/typings/graphql-config.d.cts +3 -0
  72. package/typings/graphql-config.d.ts +3 -0
  73. package/typings/hooks.d.cts +11 -0
  74. package/typings/hooks.d.ts +11 -0
  75. package/typings/index.d.cts +8 -0
  76. package/typings/index.d.ts +8 -0
  77. package/typings/init/helpers.d.cts +10 -0
  78. package/typings/init/helpers.d.ts +10 -0
  79. package/typings/init/index.d.cts +1 -0
  80. package/typings/init/index.d.ts +1 -0
  81. package/typings/init/plugins.d.cts +2 -0
  82. package/typings/init/plugins.d.ts +2 -0
  83. package/typings/init/questions.d.cts +13 -0
  84. package/typings/init/questions.d.ts +13 -0
  85. package/typings/init/targets.d.cts +2 -0
  86. package/typings/init/targets.d.ts +2 -0
  87. package/typings/init/types.d.cts +30 -0
  88. package/typings/init/types.d.ts +30 -0
  89. package/typings/load.d.cts +15 -0
  90. package/typings/load.d.ts +15 -0
  91. package/typings/plugins.d.cts +2 -0
  92. package/typings/plugins.d.ts +2 -0
  93. package/typings/presets.d.cts +5 -0
  94. package/typings/presets.d.ts +5 -0
  95. package/typings/utils/abort-controller-polyfill.d.cts +5 -0
  96. package/typings/utils/abort-controller-polyfill.d.ts +5 -0
  97. package/typings/utils/cli-error.d.cts +10 -0
  98. package/typings/utils/cli-error.d.ts +10 -0
  99. package/typings/utils/debugging.d.cts +3 -0
  100. package/typings/utils/debugging.d.ts +3 -0
  101. package/typings/utils/file-system.d.cts +8 -0
  102. package/typings/utils/file-system.d.ts +8 -0
  103. package/typings/utils/get-latest-version.d.cts +6 -0
  104. package/typings/utils/get-latest-version.d.ts +6 -0
  105. package/typings/utils/helpers.d.cts +1 -0
  106. package/typings/utils/helpers.d.ts +1 -0
  107. package/typings/utils/logger.d.cts +5 -0
  108. package/typings/utils/logger.d.ts +5 -0
  109. package/typings/utils/patterns.d.cts +91 -0
  110. package/typings/utils/patterns.d.ts +91 -0
  111. package/typings/utils/watcher.d.cts +16 -0
  112. package/typings/utils/watcher.d.ts +16 -0
package/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # @depup/graphql-codegen__cli
2
+
3
+ > Dependency-bumped version of [@graphql-codegen/cli](https://www.npmjs.com/package/@graphql-codegen/cli)
4
+
5
+ Generated by [DepUp](https://github.com/depup/npm) -- all production
6
+ dependencies bumped to latest versions.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install @depup/graphql-codegen__cli
12
+ ```
13
+
14
+ | Field | Value |
15
+ |-------|-------|
16
+ | Original | [@graphql-codegen/cli](https://www.npmjs.com/package/@graphql-codegen/cli) @ 6.2.1 |
17
+ | Processed | 2026-03-17 |
18
+ | Smoke test | passed |
19
+ | Deps updated | 21 |
20
+
21
+ ## Dependency Changes
22
+
23
+ | Dependency | From | To |
24
+ |------------|------|-----|
25
+ | @babel/generator | ^7.18.13 | ^7.29.1 |
26
+ | @babel/template | ^7.18.10 | ^7.28.6 |
27
+ | @babel/types | ^7.18.13 | ^7.29.0 |
28
+ | @graphql-tools/graphql-file-loader | ^8.1.11 | ^8.1.12 |
29
+ | @graphql-tools/merge | ^9.0.6 | ^9.1.7 |
30
+ | @inquirer/prompts | ^7.8.2 | ^8.3.2 |
31
+ | @whatwg-node/fetch | ^0.10.0 | ^0.10.13 |
32
+ | chalk | ^4.1.0 | ^5.6.2 |
33
+ | cosmiconfig | ^9.0.0 | ^9.0.1 |
34
+ | debounce | ^2.0.0 | ^3.0.0 |
35
+ | detect-indent | ^6.0.0 | ^7.0.2 |
36
+ | is-glob | ^4.0.1 | ^4.0.3 |
37
+ | jiti | ^2.3.0 | ^2.6.1 |
38
+ | listr2 | ^9.0.0 | ^10.2.1 |
39
+ | log-symbols | ^4.0.0 | ^7.0.1 |
40
+ | micromatch | ^4.0.5 | ^4.0.8 |
41
+ | shell-quote | ^1.7.3 | ^1.8.3 |
42
+ | ts-log | ^2.2.3 | ^2.2.7 |
43
+ | tslib | ^2.4.0 | ^2.8.1 |
44
+ | yaml | ^2.3.1 | ^2.8.2 |
45
+ | yargs | ^17.0.0 | ^18.0.0 |
46
+
47
+ ---
48
+
49
+ Source: https://github.com/depup/npm | Original: https://www.npmjs.com/package/@graphql-codegen/cli
50
+
51
+ License inherited from the original package.
package/changes.json ADDED
@@ -0,0 +1,90 @@
1
+ {
2
+ "bumped": {
3
+ "@babel/generator": {
4
+ "from": "^7.18.13",
5
+ "to": "^7.29.1"
6
+ },
7
+ "@babel/template": {
8
+ "from": "^7.18.10",
9
+ "to": "^7.28.6"
10
+ },
11
+ "@babel/types": {
12
+ "from": "^7.18.13",
13
+ "to": "^7.29.0"
14
+ },
15
+ "@graphql-tools/graphql-file-loader": {
16
+ "from": "^8.1.11",
17
+ "to": "^8.1.12"
18
+ },
19
+ "@graphql-tools/merge": {
20
+ "from": "^9.0.6",
21
+ "to": "^9.1.7"
22
+ },
23
+ "@inquirer/prompts": {
24
+ "from": "^7.8.2",
25
+ "to": "^8.3.2"
26
+ },
27
+ "@whatwg-node/fetch": {
28
+ "from": "^0.10.0",
29
+ "to": "^0.10.13"
30
+ },
31
+ "chalk": {
32
+ "from": "^4.1.0",
33
+ "to": "^5.6.2"
34
+ },
35
+ "cosmiconfig": {
36
+ "from": "^9.0.0",
37
+ "to": "^9.0.1"
38
+ },
39
+ "debounce": {
40
+ "from": "^2.0.0",
41
+ "to": "^3.0.0"
42
+ },
43
+ "detect-indent": {
44
+ "from": "^6.0.0",
45
+ "to": "^7.0.2"
46
+ },
47
+ "is-glob": {
48
+ "from": "^4.0.1",
49
+ "to": "^4.0.3"
50
+ },
51
+ "jiti": {
52
+ "from": "^2.3.0",
53
+ "to": "^2.6.1"
54
+ },
55
+ "listr2": {
56
+ "from": "^9.0.0",
57
+ "to": "^10.2.1"
58
+ },
59
+ "log-symbols": {
60
+ "from": "^4.0.0",
61
+ "to": "^7.0.1"
62
+ },
63
+ "micromatch": {
64
+ "from": "^4.0.5",
65
+ "to": "^4.0.8"
66
+ },
67
+ "shell-quote": {
68
+ "from": "^1.7.3",
69
+ "to": "^1.8.3"
70
+ },
71
+ "ts-log": {
72
+ "from": "^2.2.3",
73
+ "to": "^2.2.7"
74
+ },
75
+ "tslib": {
76
+ "from": "^2.4.0",
77
+ "to": "^2.8.1"
78
+ },
79
+ "yaml": {
80
+ "from": "^2.3.1",
81
+ "to": "^2.8.2"
82
+ },
83
+ "yargs": {
84
+ "from": "^17.0.0",
85
+ "to": "^18.0.0"
86
+ }
87
+ },
88
+ "timestamp": "2026-03-17T16:31:22.793Z",
89
+ "totalUpdated": 21
90
+ }
package/cjs/bin.js ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const cli_js_1 = require("./cli.js");
5
+ const cli_error_js_1 = require("./utils/cli-error.js");
6
+ const [, , cmd] = process.argv;
7
+ (0, cli_js_1.runCli)(cmd)
8
+ .then(returnCode => {
9
+ process.exit(returnCode);
10
+ })
11
+ .catch(error => {
12
+ (0, cli_error_js_1.cliError)(error);
13
+ });
package/cjs/cli.js ADDED
@@ -0,0 +1,64 @@
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 (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.runCli = runCli;
27
+ exports.ensureGraphQlPackage = ensureGraphQlPackage;
28
+ const config_js_1 = require("./config.js");
29
+ const generate_and_save_js_1 = require("./generate-and-save.js");
30
+ const hooks_js_1 = require("./hooks.js");
31
+ const index_js_1 = require("./init/index.js");
32
+ async function runCli(cmd) {
33
+ await ensureGraphQlPackage();
34
+ if (cmd === 'init') {
35
+ await (0, index_js_1.init)();
36
+ return 0;
37
+ }
38
+ const context = await (0, config_js_1.createContext)();
39
+ try {
40
+ await (0, generate_and_save_js_1.generate)(context);
41
+ if (context.checkMode && context.checkModeStaleFiles.length > 0) {
42
+ // eslint-disable-next-line no-console
43
+ console.log(`The following stale files were detected:\n${context.checkModeStaleFiles.map(file => ` - ${file}\n`)}`);
44
+ return 1;
45
+ }
46
+ return 0;
47
+ }
48
+ catch (error) {
49
+ await (0, hooks_js_1.lifecycleHooks)(context.getConfig().hooks).onError(error.toString());
50
+ return 1;
51
+ }
52
+ }
53
+ async function ensureGraphQlPackage() {
54
+ try {
55
+ await Promise.resolve().then(() => __importStar(require('graphql')));
56
+ }
57
+ catch {
58
+ throw new Error(`Unable to load "graphql" package. Please make sure to install "graphql" as a dependency! \n
59
+ To install "graphql", run:
60
+ yarn add graphql
61
+ Or, with NPM:
62
+ npm install --save graphql`);
63
+ }
64
+ }
package/cjs/codegen.js ADDED
@@ -0,0 +1,388 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.executeCodegen = executeCodegen;
4
+ const tslib_1 = require("tslib");
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
6
+ const module_1 = require("module");
7
+ const os_1 = require("os");
8
+ const path_1 = tslib_1.__importDefault(require("path"));
9
+ const core_1 = require("@graphql-codegen/core");
10
+ const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
11
+ const load_1 = require("@graphql-tools/load");
12
+ const graphql_1 = require("graphql");
13
+ const merge_1 = require("@graphql-tools/merge");
14
+ const listr2_1 = require("listr2");
15
+ const config_js_1 = require("./config.js");
16
+ const plugins_js_1 = require("./plugins.js");
17
+ const presets_js_1 = require("./presets.js");
18
+ const debugging_js_1 = require("./utils/debugging.js");
19
+ const documentTransforms_js_1 = require("./documentTransforms.js");
20
+ /**
21
+ * Poor mans ESM detection.
22
+ * Looking at this and you have a better method?
23
+ * Send a PR.
24
+ */
25
+ const isESMModule = (typeof __dirname === 'string') === false;
26
+ const makeDefaultLoader = (from) => {
27
+ if (fs_1.default.statSync(from).isDirectory()) {
28
+ from = path_1.default.join(from, '__fake.js');
29
+ }
30
+ const relativeRequire = (0, module_1.createRequire)(from);
31
+ return async (mod) => {
32
+ return Promise.resolve(`${isESMModule
33
+ ? /**
34
+ * For ESM we currently have no "resolve path" solution
35
+ * as import.meta is unavailable in a CommonJS context
36
+ * and furthermore unavailable in stable Node.js.
37
+ **/
38
+ mod
39
+ : relativeRequire.resolve(mod)}`).then(s => tslib_1.__importStar(require(s)));
40
+ };
41
+ };
42
+ function createCache() {
43
+ const cache = new Map();
44
+ return function ensure(namespace, key, factory) {
45
+ const cacheKey = `${namespace}:${key}`;
46
+ const cachedValue = cache.get(cacheKey);
47
+ if (cachedValue) {
48
+ return cachedValue;
49
+ }
50
+ const value = factory();
51
+ cache.set(cacheKey, value);
52
+ return value;
53
+ };
54
+ }
55
+ async function executeCodegen(input) {
56
+ const context = (0, config_js_1.ensureContext)(input);
57
+ const config = context.getConfig();
58
+ const pluginContext = context.getPluginContext();
59
+ const result = [];
60
+ let rootConfig = {};
61
+ let rootSchemas;
62
+ let rootDocuments;
63
+ const generates = {};
64
+ const cache = createCache();
65
+ // We need a simple string to uniqually identify the provided GraphQLSchema objects for the above cache.
66
+ // Because JavaScript does not provide access to its internal object ids, we need a workaround.
67
+ // Below is a common way to get unique ids for objects in JavaScript,
68
+ // by using a WeakMap and autoincrementing the id.
69
+ const jsObjectIds = new WeakMap();
70
+ let jsObjectIdCounter = 0;
71
+ function getJsObjectId(schema) {
72
+ if (!jsObjectIds.has(schema)) {
73
+ jsObjectIds.set(schema, jsObjectIdCounter++);
74
+ }
75
+ return jsObjectIds.get(schema);
76
+ }
77
+ function wrapTask(task, source, taskName, ctx) {
78
+ return () => context.profiler.run(async () => {
79
+ try {
80
+ await Promise.resolve().then(() => task());
81
+ }
82
+ catch (error) {
83
+ if (source && !(error instanceof graphql_1.GraphQLError)) {
84
+ error.source = source;
85
+ }
86
+ ctx.errors.push(error);
87
+ throw error;
88
+ }
89
+ }, taskName);
90
+ }
91
+ async function normalize() {
92
+ /* Load Require extensions */
93
+ const requireExtensions = (0, plugin_helpers_1.normalizeInstanceOrArray)(config.require);
94
+ const loader = makeDefaultLoader(context.cwd);
95
+ for (const mod of requireExtensions) {
96
+ await loader(mod);
97
+ }
98
+ /* Root plugin config */
99
+ rootConfig = config.config || {};
100
+ /* Normalize root "schema" field */
101
+ rootSchemas = (0, plugin_helpers_1.normalizeInstanceOrArray)(config.schema);
102
+ /* Normalize root "documents" field */
103
+ rootDocuments = (0, plugin_helpers_1.normalizeInstanceOrArray)(config.documents);
104
+ /* Normalize "generators" field */
105
+ const generateKeys = Object.keys(config.generates || {});
106
+ if (generateKeys.length === 0) {
107
+ throw new Error(`Invalid Codegen Configuration! \n
108
+ Please make sure that your codegen config file contains the "generates" field, with a specification for the plugins you need.
109
+
110
+ It should looks like that:
111
+
112
+ schema:
113
+ - my-schema.graphql
114
+ generates:
115
+ my-file.ts:
116
+ - plugin1
117
+ - plugin2
118
+ - plugin3`);
119
+ }
120
+ for (const filename of generateKeys) {
121
+ const output = (generates[filename] = (0, plugin_helpers_1.normalizeOutputParam)(config.generates[filename]));
122
+ if (!output.preset && (!output.plugins || output.plugins.length === 0)) {
123
+ throw new Error(`Invalid Codegen Configuration! \n
124
+ Please make sure that your codegen config file has defined plugins list for output "${filename}".
125
+
126
+ It should looks like that:
127
+
128
+ schema:
129
+ - my-schema.graphql
130
+ generates:
131
+ my-file.ts:
132
+ - plugin1
133
+ - plugin2
134
+ - plugin3
135
+ `);
136
+ }
137
+ }
138
+ if (rootSchemas.length === 0 &&
139
+ Object.keys(generates).some(filename => !generates[filename].schema ||
140
+ (Array.isArray(generates[filename].schema === 'object') &&
141
+ generates[filename].schema.length === 0))) {
142
+ throw new Error(`Invalid Codegen Configuration! \n
143
+ Please make sure that your codegen config file contains either the "schema" field
144
+ or every generated file has its own "schema" field.
145
+
146
+ It should looks like that:
147
+ schema:
148
+ - my-schema.graphql
149
+
150
+ or:
151
+ generates:
152
+ path/to/output:
153
+ schema: my-schema.graphql
154
+ `);
155
+ }
156
+ }
157
+ const isTest = process.env.NODE_ENV === 'test';
158
+ const tasks = new listr2_1.Listr([
159
+ {
160
+ title: 'Parse Configuration',
161
+ task: () => normalize(),
162
+ },
163
+ {
164
+ title: 'Generate outputs',
165
+ task: (ctx, task) => {
166
+ const generateTasks = Object.keys(generates).map(filename => {
167
+ const outputConfig = generates[filename];
168
+ const hasPreset = !!outputConfig.preset;
169
+ const title = `Generate to ${filename}`;
170
+ return {
171
+ title,
172
+ async task(_, subTask) {
173
+ let outputSchemaAst;
174
+ let outputSchema;
175
+ const outputFileTemplateConfig = outputConfig.config || {};
176
+ let outputDocuments = [];
177
+ const outputSpecificSchemas = (0, plugin_helpers_1.normalizeInstanceOrArray)(outputConfig.schema);
178
+ let outputSpecificDocuments = (0, plugin_helpers_1.normalizeInstanceOrArray)(outputConfig.documents);
179
+ const preset = hasPreset
180
+ ? typeof outputConfig.preset === 'string'
181
+ ? await (0, presets_js_1.getPresetByName)(outputConfig.preset, makeDefaultLoader(context.cwd))
182
+ : outputConfig.preset
183
+ : null;
184
+ if (preset?.prepareDocuments) {
185
+ outputSpecificDocuments = await preset.prepareDocuments(filename, outputSpecificDocuments);
186
+ }
187
+ return subTask.newListr([
188
+ {
189
+ title: 'Load GraphQL schemas',
190
+ task: wrapTask(async () => {
191
+ (0, debugging_js_1.debugLog)(`[CLI] Loading Schemas`);
192
+ const schemaPointerMap = {};
193
+ const parsedSchemas = [];
194
+ const allSchemaDenormalizedPointers = [...rootSchemas, ...outputSpecificSchemas];
195
+ for (const denormalizedPtr of allSchemaDenormalizedPointers) {
196
+ if ((0, graphql_1.isSchema)(denormalizedPtr)) {
197
+ parsedSchemas.push(denormalizedPtr);
198
+ }
199
+ else if (typeof denormalizedPtr === 'string') {
200
+ schemaPointerMap[denormalizedPtr] = {};
201
+ }
202
+ else if (typeof denormalizedPtr === 'object') {
203
+ Object.assign(schemaPointerMap, denormalizedPtr);
204
+ }
205
+ }
206
+ const hash = JSON.stringify(schemaPointerMap) + parsedSchemas.map(getJsObjectId).join(',');
207
+ const result = await cache('schema', hash, async () => {
208
+ // collect parsed schemas
209
+ const schemasToMerge = [...parsedSchemas];
210
+ // collect schemas, provided by pointers
211
+ if (Object.keys(schemaPointerMap).length) {
212
+ schemasToMerge.push(await context.loadSchema(schemaPointerMap));
213
+ }
214
+ // merge all collected schemas into one
215
+ const outputSchemaAst = schemasToMerge.length === 1
216
+ ? schemasToMerge[0]
217
+ : (0, graphql_1.buildASTSchema)((0, merge_1.mergeTypeDefs)(schemasToMerge));
218
+ const outputSchema = (0, plugin_helpers_1.getCachedDocumentNodeFromSchema)(outputSchemaAst);
219
+ return {
220
+ outputSchemaAst,
221
+ outputSchema,
222
+ };
223
+ });
224
+ outputSchemaAst = result.outputSchemaAst;
225
+ outputSchema = result.outputSchema;
226
+ }, filename, `Load GraphQL schemas: ${filename}`, ctx),
227
+ },
228
+ {
229
+ title: 'Load GraphQL documents',
230
+ task: wrapTask(async () => {
231
+ (0, debugging_js_1.debugLog)(`[CLI] Loading Documents`);
232
+ const documentPointerMap = {};
233
+ const allDocumentsDenormalizedPointers = [...rootDocuments, ...outputSpecificDocuments];
234
+ for (const denormalizedPtr of allDocumentsDenormalizedPointers) {
235
+ if (typeof denormalizedPtr === 'string') {
236
+ documentPointerMap[denormalizedPtr] = {};
237
+ }
238
+ else if (typeof denormalizedPtr === 'object') {
239
+ Object.assign(documentPointerMap, denormalizedPtr);
240
+ }
241
+ }
242
+ const hash = JSON.stringify(documentPointerMap);
243
+ const result = await cache('documents', hash, async () => {
244
+ try {
245
+ const documents = await context.loadDocuments(documentPointerMap);
246
+ return {
247
+ documents,
248
+ };
249
+ }
250
+ catch (error) {
251
+ if (error instanceof load_1.NoTypeDefinitionsFound && config.ignoreNoDocuments) {
252
+ return {
253
+ documents: [],
254
+ };
255
+ }
256
+ throw error;
257
+ }
258
+ });
259
+ outputDocuments = result.documents;
260
+ }, filename, `Load GraphQL documents: ${filename}`, ctx),
261
+ },
262
+ {
263
+ title: 'Generate',
264
+ task: wrapTask(async () => {
265
+ (0, debugging_js_1.debugLog)(`[CLI] Generating output`);
266
+ const normalizedPluginsArray = (0, plugin_helpers_1.normalizeConfig)(outputConfig.plugins);
267
+ const pluginLoader = config.pluginLoader || makeDefaultLoader(context.cwd);
268
+ const pluginPackages = await Promise.all(normalizedPluginsArray.map(plugin => (0, plugins_js_1.getPluginByName)(Object.keys(plugin)[0], pluginLoader)));
269
+ const pluginMap = Object.fromEntries(pluginPackages.map((pkg, i) => {
270
+ const plugin = normalizedPluginsArray[i];
271
+ const name = Object.keys(plugin)[0];
272
+ return [name, pkg];
273
+ }));
274
+ const rawMergedConfig = {
275
+ ...rootConfig,
276
+ emitLegacyCommonJSImports: config.emitLegacyCommonJSImports,
277
+ importExtension: config.importExtension,
278
+ ...(typeof outputFileTemplateConfig === 'string'
279
+ ? { value: outputFileTemplateConfig }
280
+ : outputFileTemplateConfig),
281
+ };
282
+ const importExtension = (0, plugin_helpers_1.normalizeImportExtension)({
283
+ emitLegacyCommonJSImports: rawMergedConfig.emitLegacyCommonJSImports,
284
+ importExtension: rawMergedConfig.importExtension,
285
+ });
286
+ const mergedConfig = {
287
+ ...rawMergedConfig,
288
+ importExtension,
289
+ emitLegacyCommonJSImports: rawMergedConfig.emitLegacyCommonJSImports ?? true,
290
+ };
291
+ const documentTransforms = Array.isArray(outputConfig.documentTransforms)
292
+ ? await Promise.all(outputConfig.documentTransforms.map(async (config, index) => {
293
+ return await (0, documentTransforms_js_1.getDocumentTransform)(config, makeDefaultLoader(context.cwd), `the element at index ${index} of the documentTransforms`);
294
+ }))
295
+ : [];
296
+ const outputs = preset
297
+ ? await context.profiler.run(async () => preset.buildGeneratesSection({
298
+ baseOutputDir: filename,
299
+ presetConfig: outputConfig.presetConfig || {},
300
+ plugins: normalizedPluginsArray,
301
+ schema: outputSchema,
302
+ schemaAst: outputSchemaAst,
303
+ documents: outputDocuments,
304
+ config: mergedConfig,
305
+ pluginMap,
306
+ pluginContext,
307
+ profiler: context.profiler,
308
+ documentTransforms,
309
+ }), `Build Generates Section: ${filename}`)
310
+ : [
311
+ {
312
+ filename,
313
+ plugins: normalizedPluginsArray,
314
+ schema: outputSchema,
315
+ schemaAst: outputSchemaAst,
316
+ documents: outputDocuments,
317
+ config: mergedConfig,
318
+ pluginMap,
319
+ pluginContext,
320
+ profiler: context.profiler,
321
+ documentTransforms,
322
+ },
323
+ ];
324
+ const process = async (outputArgs) => {
325
+ const output = await (0, core_1.codegen)({
326
+ ...outputArgs,
327
+ importExtension,
328
+ emitLegacyCommonJSImports: rawMergedConfig.emitLegacyCommonJSImports ?? true,
329
+ cache,
330
+ });
331
+ result.push({
332
+ filename: outputArgs.filename,
333
+ content: output,
334
+ hooks: outputConfig.hooks || {},
335
+ });
336
+ };
337
+ await context.profiler.run(() => Promise.all(outputs.map(process)), `Codegen: ${filename}`);
338
+ }, filename, `Generate: ${filename}`, ctx),
339
+ },
340
+ ], {
341
+ /**
342
+ * For each `generates` task, we must do the following in order:
343
+ *
344
+ * 1. Load schema
345
+ * 2. Load documents
346
+ * 3. Generate based on the schema + documents
347
+ *
348
+ * This way, the 3rd step has all the schema and documents loaded in previous steps to work correctly
349
+ */
350
+ exitOnError: true,
351
+ concurrent: false,
352
+ });
353
+ },
354
+ // It doesn't stop when one of tasks failed, to finish at least some of outputs
355
+ exitOnError: false,
356
+ };
357
+ });
358
+ return task.newListr(generateTasks, { concurrent: (0, os_1.cpus)().length || 1 });
359
+ },
360
+ },
361
+ ], {
362
+ rendererOptions: {
363
+ clearOutput: false,
364
+ collapseSubtasks: true,
365
+ formatOutput: 'wrap',
366
+ removeEmptyLines: false,
367
+ },
368
+ renderer: config.verbose ? 'verbose' : 'default',
369
+ ctx: { errors: [] },
370
+ silentRendererCondition: isTest || config.silent,
371
+ exitOnError: true,
372
+ });
373
+ // All the errors throw in `listr2` are collected in context
374
+ // Running tasks doesn't throw anything
375
+ const executedContext = await tasks.run();
376
+ if (config.debug) {
377
+ // if we have debug logs, make sure to print them before throwing the errors
378
+ (0, debugging_js_1.printLogs)();
379
+ }
380
+ let error = null;
381
+ if (executedContext.errors.length > 0) {
382
+ const errors = executedContext.errors.map(subErr => subErr.message || subErr.toString());
383
+ error = new AggregateError(executedContext.errors, String(errors.join('\n\n')));
384
+ // Best-effort to all stack traces for debugging
385
+ error.stack = `${error.stack}\n\n${executedContext.errors.map(subErr => subErr.stack).join('\n\n')}`;
386
+ }
387
+ return { result, error };
388
+ }