@graphql-codegen/cli 5.1.0-alpha-20240109162959-02627c189 → 6.0.0-alpha-20250627120029-c0ce0575208040dec5264c93cb830e7038549d66
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/cjs/cli.js +3 -4
- package/cjs/codegen.js +9 -7
- package/cjs/config.js +10 -10
- package/cjs/documentTransforms.js +2 -3
- package/cjs/generate-and-save.js +14 -3
- package/cjs/graphql-config.js +4 -4
- package/cjs/init/helpers.js +5 -6
- package/cjs/init/index.js +1 -2
- package/cjs/init/questions.js +6 -7
- package/cjs/init/targets.js +1 -2
- package/cjs/load.js +27 -22
- package/cjs/plugins.js +1 -2
- package/cjs/presets.js +1 -2
- package/cjs/utils/cli-error.js +2 -3
- package/cjs/utils/debugging.js +3 -4
- package/cjs/utils/file-system.js +5 -6
- package/cjs/utils/get-latest-version.js +1 -2
- package/cjs/utils/helpers.js +12 -0
- package/cjs/utils/logger.js +4 -5
- package/cjs/utils/patterns.js +2 -1
- package/cjs/utils/watcher.js +5 -5
- package/esm/cli.js +1 -1
- package/esm/codegen.js +8 -5
- package/esm/generate-and-save.js +12 -1
- package/esm/graphql-config.js +2 -2
- package/esm/init/questions.js +1 -1
- package/esm/load.js +25 -20
- package/esm/utils/helpers.js +9 -0
- package/esm/utils/patterns.js +2 -1
- package/esm/utils/watcher.js +5 -5
- package/package.json +10 -7
- package/typings/codegen.d.cts +4 -1
- package/typings/codegen.d.ts +4 -1
- package/typings/config.d.cts +1 -1
- package/typings/config.d.ts +1 -1
- package/typings/load.d.cts +1 -1
- package/typings/load.d.ts +1 -1
- package/typings/utils/file-system.d.cts +0 -1
- package/typings/utils/file-system.d.ts +0 -1
- package/typings/utils/helpers.d.cts +1 -0
- package/typings/utils/helpers.d.ts +1 -0
- package/typings/utils/patterns.d.cts +1 -1
- package/typings/utils/patterns.d.ts +1 -1
package/cjs/cli.js
CHANGED
|
@@ -23,7 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
26
|
+
exports.runCli = runCli;
|
|
27
|
+
exports.ensureGraphQlPackage = ensureGraphQlPackage;
|
|
27
28
|
const config_js_1 = require("./config.js");
|
|
28
29
|
const generate_and_save_js_1 = require("./generate-and-save.js");
|
|
29
30
|
const hooks_js_1 = require("./hooks.js");
|
|
@@ -49,12 +50,11 @@ async function runCli(cmd) {
|
|
|
49
50
|
return 1;
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
|
-
exports.runCli = runCli;
|
|
53
53
|
async function ensureGraphQlPackage() {
|
|
54
54
|
try {
|
|
55
55
|
await Promise.resolve().then(() => __importStar(require('graphql')));
|
|
56
56
|
}
|
|
57
|
-
catch
|
|
57
|
+
catch {
|
|
58
58
|
throw new Error(`Unable to load "graphql" package. Please make sure to install "graphql" as a dependency! \n
|
|
59
59
|
To install "graphql", run:
|
|
60
60
|
yarn add graphql
|
|
@@ -62,4 +62,3 @@ async function ensureGraphQlPackage() {
|
|
|
62
62
|
npm install --save graphql`);
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
-
exports.ensureGraphQlPackage = ensureGraphQlPackage;
|
package/cjs/codegen.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.executeCodegen =
|
|
3
|
+
exports.executeCodegen = executeCodegen;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
6
6
|
const module_1 = require("module");
|
|
@@ -8,6 +8,7 @@ const os_1 = require("os");
|
|
|
8
8
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
9
9
|
const core_1 = require("@graphql-codegen/core");
|
|
10
10
|
const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
|
|
11
|
+
const load_1 = require("@graphql-tools/load");
|
|
11
12
|
const graphql_1 = require("graphql");
|
|
12
13
|
const listr2_1 = require("listr2");
|
|
13
14
|
const config_js_1 = require("./config.js");
|
|
@@ -221,7 +222,7 @@ async function executeCodegen(input) {
|
|
|
221
222
|
};
|
|
222
223
|
}
|
|
223
224
|
catch (error) {
|
|
224
|
-
if (config.ignoreNoDocuments) {
|
|
225
|
+
if (error instanceof load_1.NoTypeDefinitionsFound && config.ignoreNoDocuments) {
|
|
225
226
|
return {
|
|
226
227
|
documents: [],
|
|
227
228
|
};
|
|
@@ -316,6 +317,8 @@ async function executeCodegen(input) {
|
|
|
316
317
|
rendererOptions: {
|
|
317
318
|
clearOutput: false,
|
|
318
319
|
collapse: true,
|
|
320
|
+
formatOutput: 'wrap',
|
|
321
|
+
removeEmptyLines: false,
|
|
319
322
|
},
|
|
320
323
|
renderer: config.verbose ? 'verbose' : 'default',
|
|
321
324
|
ctx: { errors: [] },
|
|
@@ -329,13 +332,12 @@ async function executeCodegen(input) {
|
|
|
329
332
|
// if we have debug logs, make sure to print them before throwing the errors
|
|
330
333
|
(0, debugging_js_1.printLogs)();
|
|
331
334
|
}
|
|
335
|
+
let error = null;
|
|
332
336
|
if (executedContext.errors.length > 0) {
|
|
333
337
|
const errors = executedContext.errors.map(subErr => subErr.message || subErr.toString());
|
|
334
|
-
|
|
338
|
+
error = new AggregateError(executedContext.errors, String(errors.join('\n\n')));
|
|
335
339
|
// Best-effort to all stack traces for debugging
|
|
336
|
-
|
|
337
|
-
throw newErr;
|
|
340
|
+
error.stack = `${error.stack}\n\n${executedContext.errors.map(subErr => subErr.stack).join('\n\n')}`;
|
|
338
341
|
}
|
|
339
|
-
return result;
|
|
342
|
+
return { result, error };
|
|
340
343
|
}
|
|
341
|
-
exports.executeCodegen = executeCodegen;
|
package/cjs/config.js
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.CodegenContext = void 0;
|
|
4
|
+
exports.generateSearchPlaces = generateSearchPlaces;
|
|
5
|
+
exports.loadCodegenConfig = loadCodegenConfig;
|
|
6
|
+
exports.loadContext = loadContext;
|
|
7
|
+
exports.buildOptions = buildOptions;
|
|
8
|
+
exports.parseArgv = parseArgv;
|
|
9
|
+
exports.createContext = createContext;
|
|
10
|
+
exports.updateContextWithCliFlags = updateContextWithCliFlags;
|
|
11
|
+
exports.ensureContext = ensureContext;
|
|
12
|
+
exports.shouldEmitLegacyCommonJSImports = shouldEmitLegacyCommonJSImports;
|
|
4
13
|
const tslib_1 = require("tslib");
|
|
5
14
|
const crypto_1 = require("crypto");
|
|
6
15
|
const fs_1 = require("fs");
|
|
@@ -24,7 +33,6 @@ function generateSearchPlaces(moduleName) {
|
|
|
24
33
|
const dot = extensions.filter(ext => ext !== 'config.js').map(ext => `.${moduleName}rc.${ext}`);
|
|
25
34
|
return [...regular.concat(dot), 'package.json'];
|
|
26
35
|
}
|
|
27
|
-
exports.generateSearchPlaces = generateSearchPlaces;
|
|
28
36
|
function customLoader(ext) {
|
|
29
37
|
return async function loader(filepath, content) {
|
|
30
38
|
if (typeof process !== 'undefined' && 'env' in process) {
|
|
@@ -74,7 +82,6 @@ async function loadCodegenConfig({ configFilePath, moduleName, searchPlaces: add
|
|
|
74
82
|
const pathStats = await lstat(configFilePath);
|
|
75
83
|
return pathStats.isDirectory() ? cosmi.search(configFilePath) : cosmi.load(configFilePath);
|
|
76
84
|
}
|
|
77
|
-
exports.loadCodegenConfig = loadCodegenConfig;
|
|
78
85
|
async function loadContext(configFilePath) {
|
|
79
86
|
const graphqlConfig = await (0, graphql_config_js_1.findAndLoadGraphQLConfig)(configFilePath);
|
|
80
87
|
if (graphqlConfig) {
|
|
@@ -105,7 +112,6 @@ async function loadContext(configFilePath) {
|
|
|
105
112
|
config: result.config,
|
|
106
113
|
});
|
|
107
114
|
}
|
|
108
|
-
exports.loadContext = loadContext;
|
|
109
115
|
function getCustomConfigPath(cliFlags) {
|
|
110
116
|
const configFile = cliFlags.config;
|
|
111
117
|
return configFile ? (0, path_1.resolve)(process.cwd(), configFile) : null;
|
|
@@ -174,11 +180,9 @@ function buildOptions() {
|
|
|
174
180
|
},
|
|
175
181
|
};
|
|
176
182
|
}
|
|
177
|
-
exports.buildOptions = buildOptions;
|
|
178
183
|
function parseArgv(argv = process.argv) {
|
|
179
184
|
return (0, yargs_1.default)(argv).options(buildOptions()).parse(argv);
|
|
180
185
|
}
|
|
181
|
-
exports.parseArgv = parseArgv;
|
|
182
186
|
async function createContext(cliFlags = parseArgv(process.argv)) {
|
|
183
187
|
if (cliFlags.require && cliFlags.require.length > 0) {
|
|
184
188
|
const relativeRequire = (0, module_1.createRequire)(process.cwd());
|
|
@@ -191,7 +195,6 @@ async function createContext(cliFlags = parseArgv(process.argv)) {
|
|
|
191
195
|
updateContextWithCliFlags(context, cliFlags);
|
|
192
196
|
return context;
|
|
193
197
|
}
|
|
194
|
-
exports.createContext = createContext;
|
|
195
198
|
function updateContextWithCliFlags(context, cliFlags) {
|
|
196
199
|
const config = {
|
|
197
200
|
configFilePath: context.filepath,
|
|
@@ -233,7 +236,6 @@ function updateContextWithCliFlags(context, cliFlags) {
|
|
|
233
236
|
}
|
|
234
237
|
context.updateConfig(config);
|
|
235
238
|
}
|
|
236
|
-
exports.updateContextWithCliFlags = updateContextWithCliFlags;
|
|
237
239
|
class CodegenContext {
|
|
238
240
|
constructor({ config, graphqlConfig, filepath, }) {
|
|
239
241
|
this._checkMode = false;
|
|
@@ -311,7 +313,6 @@ exports.CodegenContext = CodegenContext;
|
|
|
311
313
|
function ensureContext(input) {
|
|
312
314
|
return input instanceof CodegenContext ? input : new CodegenContext({ config: input });
|
|
313
315
|
}
|
|
314
|
-
exports.ensureContext = ensureContext;
|
|
315
316
|
function hashContent(content, encoding = 'hex') {
|
|
316
317
|
return (0, crypto_1.createHash)('sha256').update(content).digest(encoding);
|
|
317
318
|
}
|
|
@@ -355,4 +356,3 @@ function shouldEmitLegacyCommonJSImports(config) {
|
|
|
355
356
|
// }
|
|
356
357
|
return globalValue;
|
|
357
358
|
}
|
|
358
|
-
exports.shouldEmitLegacyCommonJSImports = shouldEmitLegacyCommonJSImports;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getDocumentTransform = getDocumentTransform;
|
|
4
|
+
exports.getDocumentTransformByName = getDocumentTransformByName;
|
|
4
5
|
const path_1 = require("path");
|
|
5
6
|
async function getDocumentTransform(documentTransform, loader, defaultName) {
|
|
6
7
|
if (typeof documentTransform === 'string') {
|
|
@@ -19,7 +20,6 @@ async function getDocumentTransform(documentTransform, loader, defaultName) {
|
|
|
19
20
|
An unknown format document transform: '${defaultName}'.
|
|
20
21
|
`);
|
|
21
22
|
}
|
|
22
|
-
exports.getDocumentTransform = getDocumentTransform;
|
|
23
23
|
function isTransformObject(config) {
|
|
24
24
|
return typeof config === 'object' && config.transform && typeof config.transform === 'function';
|
|
25
25
|
}
|
|
@@ -61,4 +61,3 @@ async function getDocumentTransformByName(name, loader) {
|
|
|
61
61
|
${possibleNamesMsg}
|
|
62
62
|
`);
|
|
63
63
|
}
|
|
64
|
-
exports.getDocumentTransformByName = getDocumentTransformByName;
|
package/cjs/generate-and-save.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generate =
|
|
3
|
+
exports.generate = generate;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
const crypto_1 = require("crypto");
|
|
5
6
|
const path_1 = require("path");
|
|
7
|
+
const log_symbols_1 = tslib_1.__importDefault(require("log-symbols"));
|
|
6
8
|
const codegen_js_1 = require("./codegen.js");
|
|
7
9
|
const config_js_1 = require("./config.js");
|
|
8
10
|
const hooks_js_1 = require("./hooks.js");
|
|
9
11
|
const debugging_js_1 = require("./utils/debugging.js");
|
|
10
12
|
const file_system_js_1 = require("./utils/file-system.js");
|
|
11
13
|
const watcher_js_1 = require("./utils/watcher.js");
|
|
14
|
+
const logger_js_1 = require("./utils/logger.js");
|
|
12
15
|
const hash = (content) => (0, crypto_1.createHash)('sha1').update(content).digest('base64');
|
|
13
16
|
async function generate(input, saveToFile = true) {
|
|
14
17
|
const context = (0, config_js_1.ensureContext)(input);
|
|
@@ -99,7 +102,16 @@ async function generate(input, saveToFile = true) {
|
|
|
99
102
|
if (config.watch) {
|
|
100
103
|
return (0, watcher_js_1.createWatcher)(context, writeOutput).runningWatcher;
|
|
101
104
|
}
|
|
102
|
-
const outputFiles = await context.profiler.run(() => (0, codegen_js_1.executeCodegen)(context), 'executeCodegen');
|
|
105
|
+
const { result: outputFiles, error } = await context.profiler.run(() => (0, codegen_js_1.executeCodegen)(context), 'executeCodegen');
|
|
106
|
+
if (error) {
|
|
107
|
+
if (config.writeOnPartialSuccess) {
|
|
108
|
+
(0, logger_js_1.getLogger)().warn(` ${log_symbols_1.default.warning} One or more errors occurred. Successful generation wrote to files.`);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
(0, logger_js_1.getLogger)().error(` ${log_symbols_1.default.error} One or more errors occurred. No output was written to files.`);
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
103
115
|
await context.profiler.run(() => writeOutput(outputFiles), 'writeOutput');
|
|
104
116
|
await context.profiler.run(() => (0, hooks_js_1.lifecycleHooks)(config.hooks).beforeDone(), 'Lifecycle: beforeDone');
|
|
105
117
|
if (context.profilerOutput) {
|
|
@@ -107,7 +119,6 @@ async function generate(input, saveToFile = true) {
|
|
|
107
119
|
}
|
|
108
120
|
return outputFiles;
|
|
109
121
|
}
|
|
110
|
-
exports.generate = generate;
|
|
111
122
|
function shouldOverwrite(config, outputPath) {
|
|
112
123
|
const globalValue = config.overwrite === undefined ? true : !!config.overwrite;
|
|
113
124
|
const outputConfig = config.generates[outputPath];
|
package/cjs/graphql-config.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.CodegenExtension = void 0;
|
|
4
|
+
exports.findAndLoadGraphQLConfig = findAndLoadGraphQLConfig;
|
|
4
5
|
const apollo_engine_loader_1 = require("@graphql-tools/apollo-engine-loader");
|
|
5
6
|
const code_file_loader_1 = require("@graphql-tools/code-file-loader");
|
|
6
7
|
const git_loader_1 = require("@graphql-tools/git-loader");
|
|
@@ -43,7 +44,6 @@ async function findAndLoadGraphQLConfig(filepath) {
|
|
|
43
44
|
return config;
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
|
-
exports.findAndLoadGraphQLConfig = findAndLoadGraphQLConfig;
|
|
47
47
|
// Kamil: user might load a config that is not GraphQL Config
|
|
48
48
|
// so we need to check if it's a regular config or not
|
|
49
49
|
function isGraphQLConfig(config) {
|
|
@@ -53,7 +53,7 @@ function isGraphQLConfig(config) {
|
|
|
53
53
|
try {
|
|
54
54
|
return config.getDefault().hasExtension('codegen');
|
|
55
55
|
}
|
|
56
|
-
catch
|
|
56
|
+
catch { }
|
|
57
57
|
try {
|
|
58
58
|
for (const projectName in config.projects) {
|
|
59
59
|
if (Object.prototype.hasOwnProperty.call(config.projects, projectName)) {
|
|
@@ -64,6 +64,6 @@ function isGraphQLConfig(config) {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
-
catch
|
|
67
|
+
catch { }
|
|
68
68
|
return false;
|
|
69
69
|
}
|
package/cjs/init/helpers.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.writeConfig = writeConfig;
|
|
4
|
+
exports.writePackage = writePackage;
|
|
5
|
+
exports.bold = bold;
|
|
6
|
+
exports.grey = grey;
|
|
7
|
+
exports.italic = italic;
|
|
4
8
|
const tslib_1 = require("tslib");
|
|
5
9
|
const fs_1 = require("fs");
|
|
6
10
|
const path_1 = require("path");
|
|
@@ -52,7 +56,6 @@ export default config;
|
|
|
52
56
|
fullPath,
|
|
53
57
|
};
|
|
54
58
|
}
|
|
55
|
-
exports.writeConfig = writeConfig;
|
|
56
59
|
// Updates package.json (script and plugins as dependencies)
|
|
57
60
|
async function writePackage(answers, configLocation) {
|
|
58
61
|
// script
|
|
@@ -76,16 +79,12 @@ async function writePackage(answers, configLocation) {
|
|
|
76
79
|
}
|
|
77
80
|
(0, fs_1.writeFileSync)(pkgPath, JSON.stringify(pkg, null, indent));
|
|
78
81
|
}
|
|
79
|
-
exports.writePackage = writePackage;
|
|
80
82
|
function bold(str) {
|
|
81
83
|
return chalk_1.default.bold(str);
|
|
82
84
|
}
|
|
83
|
-
exports.bold = bold;
|
|
84
85
|
function grey(str) {
|
|
85
86
|
return chalk_1.default.grey(str);
|
|
86
87
|
}
|
|
87
|
-
exports.grey = grey;
|
|
88
88
|
function italic(str) {
|
|
89
89
|
return chalk_1.default.italic(str);
|
|
90
90
|
}
|
|
91
|
-
exports.italic = italic;
|
package/cjs/init/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.init =
|
|
3
|
+
exports.init = init;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
|
|
6
6
|
const helpers_js_1 = require("./helpers.js");
|
|
@@ -56,7 +56,6 @@ async function init() {
|
|
|
56
56
|
To run GraphQL Code Generator.
|
|
57
57
|
`);
|
|
58
58
|
}
|
|
59
|
-
exports.init = init;
|
|
60
59
|
// adds an introspection to `generates`
|
|
61
60
|
function addIntrospection(config) {
|
|
62
61
|
config.generates['./graphql.schema.json'] = {
|
package/cjs/init/questions.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getQuestions = getQuestions;
|
|
4
|
+
exports.getApplicationTypeChoices = getApplicationTypeChoices;
|
|
5
|
+
exports.getPluginChoices = getPluginChoices;
|
|
6
|
+
exports.getOutputDefaultValue = getOutputDefaultValue;
|
|
7
|
+
exports.getDocumentsDefaultValue = getDocumentsDefaultValue;
|
|
4
8
|
const helpers_js_1 = require("./helpers.js");
|
|
5
9
|
const plugins_js_1 = require("./plugins.js");
|
|
6
10
|
const types_js_1 = require("./types.js");
|
|
@@ -19,7 +23,7 @@ function getQuestions(possibleTargets) {
|
|
|
19
23
|
name: 'schema',
|
|
20
24
|
message: 'Where is your schema?:',
|
|
21
25
|
suffix: (0, helpers_js_1.grey)(' (path or url)'),
|
|
22
|
-
default: 'http://localhost:4000',
|
|
26
|
+
default: 'http://localhost:4000', // matches Apollo Server's default
|
|
23
27
|
validate: (str) => str.length > 0,
|
|
24
28
|
},
|
|
25
29
|
{
|
|
@@ -87,7 +91,6 @@ function getQuestions(possibleTargets) {
|
|
|
87
91
|
},
|
|
88
92
|
];
|
|
89
93
|
}
|
|
90
|
-
exports.getQuestions = getQuestions;
|
|
91
94
|
function getApplicationTypeChoices(possibleTargets) {
|
|
92
95
|
function withFlowOrTypescript(tags) {
|
|
93
96
|
if (possibleTargets.TypeScript) {
|
|
@@ -146,7 +149,6 @@ function getApplicationTypeChoices(possibleTargets) {
|
|
|
146
149
|
},
|
|
147
150
|
];
|
|
148
151
|
}
|
|
149
|
-
exports.getApplicationTypeChoices = getApplicationTypeChoices;
|
|
150
152
|
function getPluginChoices(answers) {
|
|
151
153
|
return plugins_js_1.plugins
|
|
152
154
|
.filter(p => p.available(answers.targets))
|
|
@@ -158,7 +160,6 @@ function getPluginChoices(answers) {
|
|
|
158
160
|
};
|
|
159
161
|
});
|
|
160
162
|
}
|
|
161
|
-
exports.getPluginChoices = getPluginChoices;
|
|
162
163
|
function normalizeTargets(targets) {
|
|
163
164
|
return [].concat(...targets);
|
|
164
165
|
}
|
|
@@ -174,7 +175,6 @@ function getOutputDefaultValue(answers) {
|
|
|
174
175
|
}
|
|
175
176
|
return 'src/generated/graphql.js';
|
|
176
177
|
}
|
|
177
|
-
exports.getOutputDefaultValue = getOutputDefaultValue;
|
|
178
178
|
function getDocumentsDefaultValue(answers) {
|
|
179
179
|
if (answers.targets.includes(types_js_1.Tags.vue)) {
|
|
180
180
|
return 'src/**/*.vue';
|
|
@@ -187,4 +187,3 @@ function getDocumentsDefaultValue(answers) {
|
|
|
187
187
|
}
|
|
188
188
|
return 'src/**/*.graphql';
|
|
189
189
|
}
|
|
190
|
-
exports.getDocumentsDefaultValue = getDocumentsDefaultValue;
|
package/cjs/init/targets.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.guessTargets =
|
|
3
|
+
exports.guessTargets = guessTargets;
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const types_js_1 = require("./types.js");
|
|
@@ -22,7 +22,6 @@ async function guessTargets() {
|
|
|
22
22
|
[types_js_1.Tags.graphqlRequest]: isGraphqlRequest(dependencies),
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
|
-
exports.guessTargets = guessTargets;
|
|
26
25
|
function isAngular(dependencies) {
|
|
27
26
|
return dependencies.includes('@angular/core');
|
|
28
27
|
}
|
package/cjs/load.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.defaultDocumentsLoadOptions = exports.defaultSchemaLoadOptions = void 0;
|
|
4
|
+
exports.loadSchema = loadSchema;
|
|
5
|
+
exports.loadDocuments = loadDocuments;
|
|
4
6
|
const path_1 = require("path");
|
|
5
7
|
const apollo_engine_loader_1 = require("@graphql-tools/apollo-engine-loader");
|
|
6
8
|
const code_file_loader_1 = require("@graphql-tools/code-file-loader");
|
|
@@ -11,6 +13,7 @@ const json_file_loader_1 = require("@graphql-tools/json-file-loader");
|
|
|
11
13
|
const load_1 = require("@graphql-tools/load");
|
|
12
14
|
const prisma_loader_1 = require("@graphql-tools/prisma-loader");
|
|
13
15
|
const url_loader_1 = require("@graphql-tools/url-loader");
|
|
16
|
+
const graphql_1 = require("graphql");
|
|
14
17
|
exports.defaultSchemaLoadOptions = {
|
|
15
18
|
assumeValidSDL: true,
|
|
16
19
|
sort: true,
|
|
@@ -42,25 +45,19 @@ async function loadSchema(schemaPointers, config) {
|
|
|
42
45
|
return schema;
|
|
43
46
|
}
|
|
44
47
|
catch (e) {
|
|
45
|
-
throw new Error(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
- String in config file
|
|
57
|
-
|
|
58
|
-
Try to use one of above options and run codegen again.
|
|
59
|
-
|
|
60
|
-
`);
|
|
48
|
+
throw new Error([
|
|
49
|
+
`Failed to load schema from ${Object.keys(schemaPointers).join(',')}:`,
|
|
50
|
+
printError(e),
|
|
51
|
+
'\nGraphQL Code Generator supports:',
|
|
52
|
+
'\n- ES Modules and CommonJS exports (export as default or named export "schema")',
|
|
53
|
+
'- Introspection JSON File',
|
|
54
|
+
'- URL of GraphQL endpoint',
|
|
55
|
+
'- Multiple files with type definitions (glob expression)',
|
|
56
|
+
'- String in config file',
|
|
57
|
+
'\nTry to use one of above options and run codegen again.\n',
|
|
58
|
+
].join('\n'));
|
|
61
59
|
}
|
|
62
60
|
}
|
|
63
|
-
exports.loadSchema = loadSchema;
|
|
64
61
|
async function loadDocuments(documentPointers, config) {
|
|
65
62
|
const loaders = [
|
|
66
63
|
new code_file_loader_1.CodeFileLoader({
|
|
@@ -91,9 +88,17 @@ async function loadDocuments(documentPointers, config) {
|
|
|
91
88
|
return loadedFromToolkit;
|
|
92
89
|
}
|
|
93
90
|
catch (error) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
91
|
+
// NoTypeDefinitionsFound from `@graphql-tools/load` already has a message with pointer, so we can just rethrow the error
|
|
92
|
+
if (error instanceof load_1.NoTypeDefinitionsFound) {
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
// For other errors, we need to add an error message with documentPointers, so it's better for DevX
|
|
96
|
+
throw new Error([`Failed to load documents from ${Object.keys(documentPointers).join(',')}:`, printError(error)].join('\n'));
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
-
|
|
99
|
+
const printError = (error) => {
|
|
100
|
+
if (error instanceof graphql_1.GraphQLError) {
|
|
101
|
+
return String(error);
|
|
102
|
+
}
|
|
103
|
+
return [String(error.message || error), String(error.stack)].join('\n');
|
|
104
|
+
};
|
package/cjs/plugins.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPluginByName =
|
|
3
|
+
exports.getPluginByName = getPluginByName;
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
async function getPluginByName(name, pluginLoader) {
|
|
6
6
|
const possibleNames = [
|
|
@@ -41,4 +41,3 @@ async function getPluginByName(name, pluginLoader) {
|
|
|
41
41
|
${possibleNamesMsg}
|
|
42
42
|
`);
|
|
43
43
|
}
|
|
44
|
-
exports.getPluginByName = getPluginByName;
|
package/cjs/presets.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPresetByName =
|
|
3
|
+
exports.getPresetByName = getPresetByName;
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
async function getPresetByName(name, loader) {
|
|
6
6
|
const possibleNames = [
|
|
@@ -48,4 +48,3 @@ async function getPresetByName(name, loader) {
|
|
|
48
48
|
${possibleNamesMsg}
|
|
49
49
|
`);
|
|
50
50
|
}
|
|
51
|
-
exports.getPresetByName = getPresetByName;
|
package/cjs/utils/cli-error.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isListrError = isListrError;
|
|
4
|
+
exports.cliError = cliError;
|
|
4
5
|
function isListrError(err) {
|
|
5
6
|
return err.name === 'ListrError' && Array.isArray(err.errors) && err.errors.length > 0;
|
|
6
7
|
}
|
|
7
|
-
exports.isListrError = isListrError;
|
|
8
8
|
function cliError(err, exitOnError = true) {
|
|
9
9
|
let msg;
|
|
10
10
|
if (err instanceof Error) {
|
|
@@ -22,4 +22,3 @@ function cliError(err, exitOnError = true) {
|
|
|
22
22
|
process.exit(1);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
exports.cliError = cliError;
|
package/cjs/utils/debugging.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.debugLog = debugLog;
|
|
4
|
+
exports.printLogs = printLogs;
|
|
5
|
+
exports.resetLogs = resetLogs;
|
|
4
6
|
const logger_js_1 = require("./logger.js");
|
|
5
7
|
let queue = [];
|
|
6
8
|
function debugLog(message, ...meta) {
|
|
@@ -9,15 +11,12 @@ function debugLog(message, ...meta) {
|
|
|
9
11
|
meta,
|
|
10
12
|
});
|
|
11
13
|
}
|
|
12
|
-
exports.debugLog = debugLog;
|
|
13
14
|
function printLogs() {
|
|
14
15
|
for (const log of queue) {
|
|
15
16
|
(0, logger_js_1.getLogger)().info(log.message, ...log.meta);
|
|
16
17
|
}
|
|
17
18
|
resetLogs();
|
|
18
19
|
}
|
|
19
|
-
exports.printLogs = printLogs;
|
|
20
20
|
function resetLogs() {
|
|
21
21
|
queue = [];
|
|
22
22
|
}
|
|
23
|
-
exports.resetLogs = resetLogs;
|
package/cjs/utils/file-system.js
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.access = access;
|
|
4
|
+
exports.writeFile = writeFile;
|
|
5
|
+
exports.readFile = readFile;
|
|
6
|
+
exports.unlinkFile = unlinkFile;
|
|
7
|
+
exports.mkdirp = mkdirp;
|
|
4
8
|
const fs_1 = require("fs");
|
|
5
9
|
const { access: fsAccess, writeFile: fsWriteFile, readFile: fsReadFile, mkdir } = fs_1.promises;
|
|
6
10
|
function access(...args) {
|
|
7
11
|
return fsAccess(...args);
|
|
8
12
|
}
|
|
9
|
-
exports.access = access;
|
|
10
13
|
function writeFile(filepath, content) {
|
|
11
14
|
return fsWriteFile(filepath, content);
|
|
12
15
|
}
|
|
13
|
-
exports.writeFile = writeFile;
|
|
14
16
|
function readFile(filepath) {
|
|
15
17
|
return fsReadFile(filepath, 'utf-8');
|
|
16
18
|
}
|
|
17
|
-
exports.readFile = readFile;
|
|
18
19
|
function unlinkFile(filePath, cb) {
|
|
19
20
|
(0, fs_1.unlink)(filePath, cb);
|
|
20
21
|
}
|
|
21
|
-
exports.unlinkFile = unlinkFile;
|
|
22
22
|
function mkdirp(filePath) {
|
|
23
23
|
return mkdir(filePath, { recursive: true });
|
|
24
24
|
}
|
|
25
|
-
exports.mkdirp = mkdirp;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getLatestVersion =
|
|
3
|
+
exports.getLatestVersion = getLatestVersion;
|
|
4
4
|
const fetch_1 = require("@whatwg-node/fetch");
|
|
5
5
|
/**
|
|
6
6
|
* Fetches the version directly from the registry instead of depending on
|
|
@@ -12,4 +12,3 @@ async function getLatestVersion(packageName) {
|
|
|
12
12
|
.then(res => res.json())
|
|
13
13
|
.then(pkg => pkg.version);
|
|
14
14
|
}
|
|
15
|
-
exports.getLatestVersion = getLatestVersion;
|
package/cjs/utils/logger.js
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getLogger = getLogger;
|
|
4
|
+
exports.setLogger = setLogger;
|
|
5
|
+
exports.setSilentLogger = setSilentLogger;
|
|
6
|
+
exports.useWinstonLogger = useWinstonLogger;
|
|
4
7
|
const ts_log_1 = require("ts-log");
|
|
5
8
|
let logger;
|
|
6
9
|
function getLogger() {
|
|
7
10
|
return logger || ts_log_1.dummyLogger;
|
|
8
11
|
}
|
|
9
|
-
exports.getLogger = getLogger;
|
|
10
12
|
useWinstonLogger();
|
|
11
13
|
function setLogger(newLogger) {
|
|
12
14
|
logger = newLogger;
|
|
13
15
|
}
|
|
14
|
-
exports.setLogger = setLogger;
|
|
15
16
|
function setSilentLogger() {
|
|
16
17
|
logger = ts_log_1.dummyLogger;
|
|
17
18
|
}
|
|
18
|
-
exports.setSilentLogger = setSilentLogger;
|
|
19
19
|
function useWinstonLogger() {
|
|
20
20
|
if (logger?.levels) {
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
23
|
logger = console;
|
|
24
24
|
}
|
|
25
|
-
exports.useWinstonLogger = useWinstonLogger;
|
package/cjs/utils/patterns.js
CHANGED
|
@@ -7,6 +7,7 @@ const utils_1 = require("@graphql-tools/utils");
|
|
|
7
7
|
const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
|
|
8
8
|
const is_glob_1 = tslib_1.__importDefault(require("is-glob"));
|
|
9
9
|
const micromatch_1 = tslib_1.__importDefault(require("micromatch"));
|
|
10
|
+
const helpers_js_1 = require("./helpers.js");
|
|
10
11
|
/**
|
|
11
12
|
* Flatten a list of pattern sets to be a list of only the affirmative patterns
|
|
12
13
|
* are contained in all of them.
|
|
@@ -149,7 +150,7 @@ const makePatternsFromSchemas = (schemas) => {
|
|
|
149
150
|
const patterns = [];
|
|
150
151
|
for (const s of schemas) {
|
|
151
152
|
const schema = s;
|
|
152
|
-
if ((0, is_glob_1.default)(schema) || (0, utils_1.isValidPath)(schema)) {
|
|
153
|
+
if (!(0, helpers_js_1.isURL)(schema) && ((0, is_glob_1.default)(schema) || (0, utils_1.isValidPath)(schema))) {
|
|
153
154
|
patterns.push(schema);
|
|
154
155
|
}
|
|
155
156
|
}
|
package/cjs/utils/watcher.js
CHANGED
|
@@ -39,8 +39,8 @@ const createWatcher = (initialContext, onNext) => {
|
|
|
39
39
|
try {
|
|
40
40
|
parcelWatcher = await Promise.resolve().then(() => tslib_1.__importStar(require('@parcel/watcher')));
|
|
41
41
|
}
|
|
42
|
-
catch
|
|
43
|
-
log(
|
|
42
|
+
catch {
|
|
43
|
+
log('Failed to import @parcel/watcher.\n To use watch mode, install https://www.npmjs.com/package/@parcel/watcher.');
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
46
|
(0, debugging_js_1.debugLog)(`[Watcher] Parcel watcher loaded...`);
|
|
@@ -48,7 +48,7 @@ const createWatcher = (initialContext, onNext) => {
|
|
|
48
48
|
const debouncedExec = (0, debounce_1.default)(() => {
|
|
49
49
|
if (!isShutdown) {
|
|
50
50
|
(0, codegen_js_1.executeCodegen)(initialContext)
|
|
51
|
-
.then(onNext, () => Promise.resolve())
|
|
51
|
+
.then(({ result }) => onNext(result), () => Promise.resolve())
|
|
52
52
|
.then(() => emitWatching(watchDirectory));
|
|
53
53
|
}
|
|
54
54
|
}, 100);
|
|
@@ -85,7 +85,7 @@ const createWatcher = (initialContext, onNext) => {
|
|
|
85
85
|
try {
|
|
86
86
|
delete require.cache[path];
|
|
87
87
|
}
|
|
88
|
-
catch
|
|
88
|
+
catch { }
|
|
89
89
|
if (eventName === 'update' && config.configFilePath && path === config.configFilePath) {
|
|
90
90
|
log(`${log_symbols_1.default.info} Config file has changed, reloading...`);
|
|
91
91
|
const context = await (0, config_js_1.loadContext)(config.configFilePath);
|
|
@@ -146,7 +146,7 @@ const createWatcher = (initialContext, onNext) => {
|
|
|
146
146
|
*/
|
|
147
147
|
stopWatching.runningWatcher = new Promise((resolve, reject) => {
|
|
148
148
|
(0, codegen_js_1.executeCodegen)(initialContext)
|
|
149
|
-
.then(onNext, () => Promise.resolve())
|
|
149
|
+
.then(({ result }) => onNext(result), () => Promise.resolve())
|
|
150
150
|
.then(() => runWatcher(abortController.signal))
|
|
151
151
|
.catch(err => {
|
|
152
152
|
watcherSubscription.unsubscribe();
|
package/esm/cli.js
CHANGED
|
@@ -27,7 +27,7 @@ export async function ensureGraphQlPackage() {
|
|
|
27
27
|
try {
|
|
28
28
|
await import('graphql');
|
|
29
29
|
}
|
|
30
|
-
catch
|
|
30
|
+
catch {
|
|
31
31
|
throw new Error(`Unable to load "graphql" package. Please make sure to install "graphql" as a dependency! \n
|
|
32
32
|
To install "graphql", run:
|
|
33
33
|
yarn add graphql
|
package/esm/codegen.js
CHANGED
|
@@ -4,6 +4,7 @@ import { cpus } from 'os';
|
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import { codegen } from '@graphql-codegen/core';
|
|
6
6
|
import { getCachedDocumentNodeFromSchema, normalizeConfig, normalizeInstanceOrArray, normalizeOutputParam, } from '@graphql-codegen/plugin-helpers';
|
|
7
|
+
import { NoTypeDefinitionsFound } from '@graphql-tools/load';
|
|
7
8
|
import { GraphQLError } from 'graphql';
|
|
8
9
|
import { Listr } from 'listr2';
|
|
9
10
|
import { ensureContext, shouldEmitLegacyCommonJSImports } from './config.js';
|
|
@@ -217,7 +218,7 @@ export async function executeCodegen(input) {
|
|
|
217
218
|
};
|
|
218
219
|
}
|
|
219
220
|
catch (error) {
|
|
220
|
-
if (config.ignoreNoDocuments) {
|
|
221
|
+
if (error instanceof NoTypeDefinitionsFound && config.ignoreNoDocuments) {
|
|
221
222
|
return {
|
|
222
223
|
documents: [],
|
|
223
224
|
};
|
|
@@ -312,6 +313,8 @@ export async function executeCodegen(input) {
|
|
|
312
313
|
rendererOptions: {
|
|
313
314
|
clearOutput: false,
|
|
314
315
|
collapse: true,
|
|
316
|
+
formatOutput: 'wrap',
|
|
317
|
+
removeEmptyLines: false,
|
|
315
318
|
},
|
|
316
319
|
renderer: config.verbose ? 'verbose' : 'default',
|
|
317
320
|
ctx: { errors: [] },
|
|
@@ -325,12 +328,12 @@ export async function executeCodegen(input) {
|
|
|
325
328
|
// if we have debug logs, make sure to print them before throwing the errors
|
|
326
329
|
printLogs();
|
|
327
330
|
}
|
|
331
|
+
let error = null;
|
|
328
332
|
if (executedContext.errors.length > 0) {
|
|
329
333
|
const errors = executedContext.errors.map(subErr => subErr.message || subErr.toString());
|
|
330
|
-
|
|
334
|
+
error = new AggregateError(executedContext.errors, String(errors.join('\n\n')));
|
|
331
335
|
// Best-effort to all stack traces for debugging
|
|
332
|
-
|
|
333
|
-
throw newErr;
|
|
336
|
+
error.stack = `${error.stack}\n\n${executedContext.errors.map(subErr => subErr.stack).join('\n\n')}`;
|
|
334
337
|
}
|
|
335
|
-
return result;
|
|
338
|
+
return { result, error };
|
|
336
339
|
}
|
package/esm/generate-and-save.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { createHash } from 'crypto';
|
|
2
2
|
import { dirname, isAbsolute, join } from 'path';
|
|
3
|
+
import logSymbols from 'log-symbols';
|
|
3
4
|
import { executeCodegen } from './codegen.js';
|
|
4
5
|
import { ensureContext } from './config.js';
|
|
5
6
|
import { lifecycleHooks } from './hooks.js';
|
|
6
7
|
import { debugLog } from './utils/debugging.js';
|
|
7
8
|
import { mkdirp, readFile, unlinkFile, writeFile } from './utils/file-system.js';
|
|
8
9
|
import { createWatcher } from './utils/watcher.js';
|
|
10
|
+
import { getLogger } from './utils/logger.js';
|
|
9
11
|
const hash = (content) => createHash('sha1').update(content).digest('base64');
|
|
10
12
|
export async function generate(input, saveToFile = true) {
|
|
11
13
|
const context = ensureContext(input);
|
|
@@ -96,7 +98,16 @@ export async function generate(input, saveToFile = true) {
|
|
|
96
98
|
if (config.watch) {
|
|
97
99
|
return createWatcher(context, writeOutput).runningWatcher;
|
|
98
100
|
}
|
|
99
|
-
const outputFiles = await context.profiler.run(() => executeCodegen(context), 'executeCodegen');
|
|
101
|
+
const { result: outputFiles, error } = await context.profiler.run(() => executeCodegen(context), 'executeCodegen');
|
|
102
|
+
if (error) {
|
|
103
|
+
if (config.writeOnPartialSuccess) {
|
|
104
|
+
getLogger().warn(` ${logSymbols.warning} One or more errors occurred. Successful generation wrote to files.`);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
getLogger().error(` ${logSymbols.error} One or more errors occurred. No output was written to files.`);
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
100
111
|
await context.profiler.run(() => writeOutput(outputFiles), 'writeOutput');
|
|
101
112
|
await context.profiler.run(() => lifecycleHooks(config.hooks).beforeDone(), 'Lifecycle: beforeDone');
|
|
102
113
|
if (context.profilerOutput) {
|
package/esm/graphql-config.js
CHANGED
|
@@ -48,7 +48,7 @@ function isGraphQLConfig(config) {
|
|
|
48
48
|
try {
|
|
49
49
|
return config.getDefault().hasExtension('codegen');
|
|
50
50
|
}
|
|
51
|
-
catch
|
|
51
|
+
catch { }
|
|
52
52
|
try {
|
|
53
53
|
for (const projectName in config.projects) {
|
|
54
54
|
if (Object.prototype.hasOwnProperty.call(config.projects, projectName)) {
|
|
@@ -59,6 +59,6 @@ function isGraphQLConfig(config) {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
-
catch
|
|
62
|
+
catch { }
|
|
63
63
|
return false;
|
|
64
64
|
}
|
package/esm/init/questions.js
CHANGED
|
@@ -16,7 +16,7 @@ export function getQuestions(possibleTargets) {
|
|
|
16
16
|
name: 'schema',
|
|
17
17
|
message: 'Where is your schema?:',
|
|
18
18
|
suffix: grey(' (path or url)'),
|
|
19
|
-
default: 'http://localhost:4000',
|
|
19
|
+
default: 'http://localhost:4000', // matches Apollo Server's default
|
|
20
20
|
validate: (str) => str.length > 0,
|
|
21
21
|
},
|
|
22
22
|
{
|
package/esm/load.js
CHANGED
|
@@ -5,9 +5,10 @@ import { GitLoader } from '@graphql-tools/git-loader';
|
|
|
5
5
|
import { GithubLoader } from '@graphql-tools/github-loader';
|
|
6
6
|
import { GraphQLFileLoader } from '@graphql-tools/graphql-file-loader';
|
|
7
7
|
import { JsonFileLoader } from '@graphql-tools/json-file-loader';
|
|
8
|
-
import { loadDocuments as loadDocumentsToolkit, loadSchema as loadSchemaToolkit, } from '@graphql-tools/load';
|
|
8
|
+
import { loadDocuments as loadDocumentsToolkit, loadSchema as loadSchemaToolkit, NoTypeDefinitionsFound, } from '@graphql-tools/load';
|
|
9
9
|
import { PrismaLoader } from '@graphql-tools/prisma-loader';
|
|
10
10
|
import { UrlLoader } from '@graphql-tools/url-loader';
|
|
11
|
+
import { GraphQLError } from 'graphql';
|
|
11
12
|
export const defaultSchemaLoadOptions = {
|
|
12
13
|
assumeValidSDL: true,
|
|
13
14
|
sort: true,
|
|
@@ -39,22 +40,17 @@ export async function loadSchema(schemaPointers, config) {
|
|
|
39
40
|
return schema;
|
|
40
41
|
}
|
|
41
42
|
catch (e) {
|
|
42
|
-
throw new Error(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
- String in config file
|
|
54
|
-
|
|
55
|
-
Try to use one of above options and run codegen again.
|
|
56
|
-
|
|
57
|
-
`);
|
|
43
|
+
throw new Error([
|
|
44
|
+
`Failed to load schema from ${Object.keys(schemaPointers).join(',')}:`,
|
|
45
|
+
printError(e),
|
|
46
|
+
'\nGraphQL Code Generator supports:',
|
|
47
|
+
'\n- ES Modules and CommonJS exports (export as default or named export "schema")',
|
|
48
|
+
'- Introspection JSON File',
|
|
49
|
+
'- URL of GraphQL endpoint',
|
|
50
|
+
'- Multiple files with type definitions (glob expression)',
|
|
51
|
+
'- String in config file',
|
|
52
|
+
'\nTry to use one of above options and run codegen again.\n',
|
|
53
|
+
].join('\n'));
|
|
58
54
|
}
|
|
59
55
|
}
|
|
60
56
|
export async function loadDocuments(documentPointers, config) {
|
|
@@ -87,8 +83,17 @@ export async function loadDocuments(documentPointers, config) {
|
|
|
87
83
|
return loadedFromToolkit;
|
|
88
84
|
}
|
|
89
85
|
catch (error) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
86
|
+
// NoTypeDefinitionsFound from `@graphql-tools/load` already has a message with pointer, so we can just rethrow the error
|
|
87
|
+
if (error instanceof NoTypeDefinitionsFound) {
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
// For other errors, we need to add an error message with documentPointers, so it's better for DevX
|
|
91
|
+
throw new Error([`Failed to load documents from ${Object.keys(documentPointers).join(',')}:`, printError(error)].join('\n'));
|
|
93
92
|
}
|
|
94
93
|
}
|
|
94
|
+
const printError = (error) => {
|
|
95
|
+
if (error instanceof GraphQLError) {
|
|
96
|
+
return String(error);
|
|
97
|
+
}
|
|
98
|
+
return [String(error.message || error), String(error.stack)].join('\n');
|
|
99
|
+
};
|
package/esm/utils/patterns.js
CHANGED
|
@@ -3,6 +3,7 @@ import { isValidPath } from '@graphql-tools/utils';
|
|
|
3
3
|
import { normalizeInstanceOrArray } from '@graphql-codegen/plugin-helpers';
|
|
4
4
|
import isGlob from 'is-glob';
|
|
5
5
|
import mm from 'micromatch';
|
|
6
|
+
import { isURL } from './helpers.js';
|
|
6
7
|
/**
|
|
7
8
|
* Flatten a list of pattern sets to be a list of only the affirmative patterns
|
|
8
9
|
* are contained in all of them.
|
|
@@ -141,7 +142,7 @@ const makePatternsFromSchemas = (schemas) => {
|
|
|
141
142
|
const patterns = [];
|
|
142
143
|
for (const s of schemas) {
|
|
143
144
|
const schema = s;
|
|
144
|
-
if (isGlob(schema) || isValidPath(schema)) {
|
|
145
|
+
if (!isURL(schema) && (isGlob(schema) || isValidPath(schema))) {
|
|
145
146
|
patterns.push(schema);
|
|
146
147
|
}
|
|
147
148
|
}
|
package/esm/utils/watcher.js
CHANGED
|
@@ -35,8 +35,8 @@ export const createWatcher = (initialContext, onNext) => {
|
|
|
35
35
|
try {
|
|
36
36
|
parcelWatcher = await import('@parcel/watcher');
|
|
37
37
|
}
|
|
38
|
-
catch
|
|
39
|
-
log(
|
|
38
|
+
catch {
|
|
39
|
+
log('Failed to import @parcel/watcher.\n To use watch mode, install https://www.npmjs.com/package/@parcel/watcher.');
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
42
|
debugLog(`[Watcher] Parcel watcher loaded...`);
|
|
@@ -44,7 +44,7 @@ export const createWatcher = (initialContext, onNext) => {
|
|
|
44
44
|
const debouncedExec = debounce(() => {
|
|
45
45
|
if (!isShutdown) {
|
|
46
46
|
executeCodegen(initialContext)
|
|
47
|
-
.then(onNext, () => Promise.resolve())
|
|
47
|
+
.then(({ result }) => onNext(result), () => Promise.resolve())
|
|
48
48
|
.then(() => emitWatching(watchDirectory));
|
|
49
49
|
}
|
|
50
50
|
}, 100);
|
|
@@ -81,7 +81,7 @@ export const createWatcher = (initialContext, onNext) => {
|
|
|
81
81
|
try {
|
|
82
82
|
delete require.cache[path];
|
|
83
83
|
}
|
|
84
|
-
catch
|
|
84
|
+
catch { }
|
|
85
85
|
if (eventName === 'update' && config.configFilePath && path === config.configFilePath) {
|
|
86
86
|
log(`${logSymbols.info} Config file has changed, reloading...`);
|
|
87
87
|
const context = await loadContext(config.configFilePath);
|
|
@@ -142,7 +142,7 @@ export const createWatcher = (initialContext, onNext) => {
|
|
|
142
142
|
*/
|
|
143
143
|
stopWatching.runningWatcher = new Promise((resolve, reject) => {
|
|
144
144
|
executeCodegen(initialContext)
|
|
145
|
-
.then(onNext, () => Promise.resolve())
|
|
145
|
+
.then(({ result }) => onNext(result), () => Promise.resolve())
|
|
146
146
|
.then(() => runWatcher(abortController.signal))
|
|
147
147
|
.catch(err => {
|
|
148
148
|
watcherSubscription.unsubscribe();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-alpha-20250627120029-c0ce0575208040dec5264c93cb830e7038549d66",
|
|
4
4
|
"peerDependenciesMeta": {
|
|
5
5
|
"@parcel/watcher": {
|
|
6
6
|
"optional": true
|
|
@@ -14,25 +14,25 @@
|
|
|
14
14
|
"@babel/generator": "^7.18.13",
|
|
15
15
|
"@babel/template": "^7.18.10",
|
|
16
16
|
"@babel/types": "^7.18.13",
|
|
17
|
-
"@graphql-codegen/client-preset": "4.
|
|
18
|
-
"@graphql-codegen/core": "4.0.
|
|
19
|
-
"@graphql-codegen/plugin-helpers": "
|
|
17
|
+
"@graphql-codegen/client-preset": "4.8.4-alpha-20250627120029-c0ce0575208040dec5264c93cb830e7038549d66",
|
|
18
|
+
"@graphql-codegen/core": "4.0.3-alpha-20250627120029-c0ce0575208040dec5264c93cb830e7038549d66",
|
|
19
|
+
"@graphql-codegen/plugin-helpers": "6.0.0-alpha-20250627120029-c0ce0575208040dec5264c93cb830e7038549d66",
|
|
20
20
|
"@graphql-tools/apollo-engine-loader": "^8.0.0",
|
|
21
21
|
"@graphql-tools/code-file-loader": "^8.0.0",
|
|
22
22
|
"@graphql-tools/git-loader": "^8.0.0",
|
|
23
23
|
"@graphql-tools/github-loader": "^8.0.0",
|
|
24
24
|
"@graphql-tools/graphql-file-loader": "^8.0.0",
|
|
25
25
|
"@graphql-tools/json-file-loader": "^8.0.0",
|
|
26
|
-
"@graphql-tools/load": "^8.
|
|
26
|
+
"@graphql-tools/load": "^8.1.0",
|
|
27
27
|
"@graphql-tools/prisma-loader": "^8.0.0",
|
|
28
28
|
"@graphql-tools/url-loader": "^8.0.0",
|
|
29
29
|
"@graphql-tools/utils": "^10.0.0",
|
|
30
|
-
"@whatwg-node/fetch": "^0.
|
|
30
|
+
"@whatwg-node/fetch": "^0.10.0",
|
|
31
31
|
"chalk": "^4.1.0",
|
|
32
32
|
"cosmiconfig": "^8.1.3",
|
|
33
33
|
"debounce": "^1.2.0",
|
|
34
34
|
"detect-indent": "^6.0.0",
|
|
35
|
-
"graphql-config": "^5.
|
|
35
|
+
"graphql-config": "^5.1.1",
|
|
36
36
|
"inquirer": "^8.0.0",
|
|
37
37
|
"is-glob": "^4.0.1",
|
|
38
38
|
"jiti": "^1.17.1",
|
|
@@ -72,6 +72,9 @@
|
|
|
72
72
|
],
|
|
73
73
|
"author": "Dotan Simha <dotansimha@gmail.com>",
|
|
74
74
|
"license": "MIT",
|
|
75
|
+
"engines": {
|
|
76
|
+
"node": ">=16"
|
|
77
|
+
},
|
|
75
78
|
"main": "cjs/index.js",
|
|
76
79
|
"module": "esm/index.js",
|
|
77
80
|
"typings": "typings/index.d.ts",
|
package/typings/codegen.d.cts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { Types } from '@graphql-codegen/plugin-helpers';
|
|
2
2
|
import { CodegenContext } from './config.cjs';
|
|
3
|
-
export declare function executeCodegen(input: CodegenContext | Types.Config): Promise<
|
|
3
|
+
export declare function executeCodegen(input: CodegenContext | Types.Config): Promise<{
|
|
4
|
+
result: Types.FileOutput[];
|
|
5
|
+
error: Error | null;
|
|
6
|
+
}>;
|
package/typings/codegen.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { Types } from '@graphql-codegen/plugin-helpers';
|
|
2
2
|
import { CodegenContext } from './config.js';
|
|
3
|
-
export declare function executeCodegen(input: CodegenContext | Types.Config): Promise<
|
|
3
|
+
export declare function executeCodegen(input: CodegenContext | Types.Config): Promise<{
|
|
4
|
+
result: Types.FileOutput[];
|
|
5
|
+
error: Error | null;
|
|
6
|
+
}>;
|
package/typings/config.d.cts
CHANGED
|
@@ -133,7 +133,7 @@ export declare class CodegenContext {
|
|
|
133
133
|
getPluginContext(): {
|
|
134
134
|
[key: string]: any;
|
|
135
135
|
};
|
|
136
|
-
loadSchema(pointer: Types.Schema): Promise<GraphQLSchema>;
|
|
136
|
+
loadSchema(pointer: Types.Schema | Types.Schema[]): Promise<GraphQLSchema>;
|
|
137
137
|
loadDocuments(pointer: Types.OperationDocument[]): Promise<Types.DocumentFile[]>;
|
|
138
138
|
}
|
|
139
139
|
export declare function ensureContext(input: CodegenContext | Types.Config): CodegenContext;
|
package/typings/config.d.ts
CHANGED
|
@@ -133,7 +133,7 @@ export declare class CodegenContext {
|
|
|
133
133
|
getPluginContext(): {
|
|
134
134
|
[key: string]: any;
|
|
135
135
|
};
|
|
136
|
-
loadSchema(pointer: Types.Schema): Promise<GraphQLSchema>;
|
|
136
|
+
loadSchema(pointer: Types.Schema | Types.Schema[]): Promise<GraphQLSchema>;
|
|
137
137
|
loadDocuments(pointer: Types.OperationDocument[]): Promise<Types.DocumentFile[]>;
|
|
138
138
|
}
|
|
139
139
|
export declare function ensureContext(input: CodegenContext | Types.Config): CodegenContext;
|
package/typings/load.d.cts
CHANGED
|
@@ -11,5 +11,5 @@ export declare const defaultDocumentsLoadOptions: {
|
|
|
11
11
|
sort: boolean;
|
|
12
12
|
skipGraphQLImport: boolean;
|
|
13
13
|
};
|
|
14
|
-
export declare function loadSchema(schemaPointers: UnnormalizedTypeDefPointer, config: Types.Config): Promise<GraphQLSchema>;
|
|
14
|
+
export declare function loadSchema(schemaPointers: UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[], config: Types.Config): Promise<GraphQLSchema>;
|
|
15
15
|
export declare function loadDocuments(documentPointers: UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[], config: Types.Config): Promise<Types.DocumentFile[]>;
|
package/typings/load.d.ts
CHANGED
|
@@ -11,5 +11,5 @@ export declare const defaultDocumentsLoadOptions: {
|
|
|
11
11
|
sort: boolean;
|
|
12
12
|
skipGraphQLImport: boolean;
|
|
13
13
|
};
|
|
14
|
-
export declare function loadSchema(schemaPointers: UnnormalizedTypeDefPointer, config: Types.Config): Promise<GraphQLSchema>;
|
|
14
|
+
export declare function loadSchema(schemaPointers: UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[], config: Types.Config): Promise<GraphQLSchema>;
|
|
15
15
|
export declare function loadDocuments(documentPointers: UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[], config: Types.Config): Promise<Types.DocumentFile[]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isURL(str: string): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isURL(str: string): boolean;
|
|
@@ -63,7 +63,7 @@ export declare const makeLocalPatternSet: (conf: Types.ConfiguredOutput) => {
|
|
|
63
63
|
*
|
|
64
64
|
* @param patterns List of micromatch patterns
|
|
65
65
|
*/
|
|
66
|
-
export declare const sortPatterns: <P extends string>(patterns: P[]) => SortedPatterns<P>;
|
|
66
|
+
export declare const sortPatterns: <P extends string | NegatedPattern>(patterns: P[]) => SortedPatterns<P>;
|
|
67
67
|
/**
|
|
68
68
|
* A type that "sorts" (or "groups") patterns. For a given list of `patterns`,
|
|
69
69
|
* this type will include the original list in `patterns`, all of its
|
|
@@ -63,7 +63,7 @@ export declare const makeLocalPatternSet: (conf: Types.ConfiguredOutput) => {
|
|
|
63
63
|
*
|
|
64
64
|
* @param patterns List of micromatch patterns
|
|
65
65
|
*/
|
|
66
|
-
export declare const sortPatterns: <P extends string>(patterns: P[]) => SortedPatterns<P>;
|
|
66
|
+
export declare const sortPatterns: <P extends string | NegatedPattern>(patterns: P[]) => SortedPatterns<P>;
|
|
67
67
|
/**
|
|
68
68
|
* A type that "sorts" (or "groups") patterns. For a given list of `patterns`,
|
|
69
69
|
* this type will include the original list in `patterns`, all of its
|