@graphql-codegen/cli 2.13.8-alpha-20221025134913-ec8a36be2 → 2.13.8-alpha-20221027114749-e39e1c05f
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 +7 -5
- package/cjs/codegen.js +8 -5
- package/cjs/config.js +3 -3
- package/cjs/plugins.js +3 -2
- package/esm/cli.js +7 -5
- package/esm/codegen.js +9 -6
- package/esm/config.js +4 -4
- package/esm/plugins.js +3 -2
- package/package.json +4 -4
- package/typings/utils/cli-error.d.cts +2 -1
- package/typings/utils/cli-error.d.ts +2 -1
package/cjs/cli.js
CHANGED
|
@@ -28,6 +28,7 @@ const generate_and_save_js_1 = require("./generate-and-save.js");
|
|
|
28
28
|
const index_js_1 = require("./init/index.js");
|
|
29
29
|
const config_js_1 = require("./config.js");
|
|
30
30
|
const hooks_js_1 = require("./hooks.js");
|
|
31
|
+
const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
|
|
31
32
|
async function runCli(cmd) {
|
|
32
33
|
await ensureGraphQlPackage();
|
|
33
34
|
if (cmd === 'init') {
|
|
@@ -55,11 +56,12 @@ async function ensureGraphQlPackage() {
|
|
|
55
56
|
await Promise.resolve().then(() => __importStar(require('graphql')));
|
|
56
57
|
}
|
|
57
58
|
catch (e) {
|
|
58
|
-
throw new
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
throw new plugin_helpers_1.DetailedError(`Unable to load "graphql" package. Please make sure to install "graphql" as a dependency!`, `
|
|
60
|
+
To install "graphql", run:
|
|
61
|
+
yarn add graphql
|
|
62
|
+
Or, with NPM:
|
|
63
|
+
npm install --save graphql
|
|
64
|
+
`);
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
exports.ensureGraphQlPackage = ensureGraphQlPackage;
|
package/cjs/codegen.js
CHANGED
|
@@ -92,7 +92,7 @@ async function executeCodegen(input) {
|
|
|
92
92
|
/* Normalize "generators" field */
|
|
93
93
|
const generateKeys = Object.keys(config.generates || {});
|
|
94
94
|
if (generateKeys.length === 0) {
|
|
95
|
-
throw new
|
|
95
|
+
throw new plugin_helpers_1.DetailedError('Invalid Codegen Configuration!', `
|
|
96
96
|
Please make sure that your codegen config file contains the "generates" field, with a specification for the plugins you need.
|
|
97
97
|
|
|
98
98
|
It should looks like that:
|
|
@@ -103,12 +103,13 @@ async function executeCodegen(input) {
|
|
|
103
103
|
my-file.ts:
|
|
104
104
|
- plugin1
|
|
105
105
|
- plugin2
|
|
106
|
-
- plugin3
|
|
106
|
+
- plugin3
|
|
107
|
+
`);
|
|
107
108
|
}
|
|
108
109
|
for (const filename of generateKeys) {
|
|
109
110
|
const output = (generates[filename] = (0, plugin_helpers_1.normalizeOutputParam)(config.generates[filename]));
|
|
110
111
|
if (!output.preset && (!output.plugins || output.plugins.length === 0)) {
|
|
111
|
-
throw new
|
|
112
|
+
throw new plugin_helpers_1.DetailedError('Invalid Codegen Configuration!', `
|
|
112
113
|
Please make sure that your codegen config file has defined plugins list for output "${filename}".
|
|
113
114
|
|
|
114
115
|
It should looks like that:
|
|
@@ -127,7 +128,7 @@ async function executeCodegen(input) {
|
|
|
127
128
|
Object.keys(generates).some(filename => !generates[filename].schema ||
|
|
128
129
|
(Array.isArray(generates[filename].schema === 'object') &&
|
|
129
130
|
generates[filename].schema.length === 0))) {
|
|
130
|
-
throw new
|
|
131
|
+
throw new plugin_helpers_1.DetailedError('Invalid Codegen Configuration!', `
|
|
131
132
|
Please make sure that your codegen config file contains either the "schema" field
|
|
132
133
|
or every generated file has its own "schema" field.
|
|
133
134
|
|
|
@@ -319,7 +320,9 @@ async function executeCodegen(input) {
|
|
|
319
320
|
(0, debugging_js_1.printLogs)();
|
|
320
321
|
}
|
|
321
322
|
if (executedContext.errors.length > 0) {
|
|
322
|
-
const errors = executedContext.errors.map(subErr =>
|
|
323
|
+
const errors = executedContext.errors.map(subErr => (0, plugin_helpers_1.isDetailedError)(subErr)
|
|
324
|
+
? `${subErr.message} for "${subErr.source}"${subErr.details}`
|
|
325
|
+
: subErr.message || subErr.toString());
|
|
323
326
|
const newErr = new utils_1.AggregateError(executedContext.errors, `${errors.join('\n\n')}`);
|
|
324
327
|
// Best-effort to all stack traces for debugging
|
|
325
328
|
newErr.stack = `${newErr.stack}\n\n${executedContext.errors.map(subErr => subErr.stack).join('\n\n')}`;
|
package/cjs/config.js
CHANGED
|
@@ -85,7 +85,7 @@ async function loadContext(configFilePath) {
|
|
|
85
85
|
const result = await loadCodegenConfig({ configFilePath });
|
|
86
86
|
if (!result) {
|
|
87
87
|
if (configFilePath) {
|
|
88
|
-
throw new
|
|
88
|
+
throw new plugin_helpers_1.DetailedError(`Config ${configFilePath} does not exist`, `
|
|
89
89
|
Config ${configFilePath} does not exist.
|
|
90
90
|
|
|
91
91
|
$ graphql-codegen --config ${configFilePath}
|
|
@@ -93,12 +93,12 @@ async function loadContext(configFilePath) {
|
|
|
93
93
|
Please make sure the --config points to a correct file.
|
|
94
94
|
`);
|
|
95
95
|
}
|
|
96
|
-
throw new
|
|
96
|
+
throw new plugin_helpers_1.DetailedError(`Unable to find Codegen config file!`, `
|
|
97
97
|
Please make sure that you have a configuration file under the current directory!
|
|
98
98
|
`);
|
|
99
99
|
}
|
|
100
100
|
if (result.isEmpty) {
|
|
101
|
-
throw new
|
|
101
|
+
throw new plugin_helpers_1.DetailedError(`Found Codegen config file but it was empty!`, `
|
|
102
102
|
Please make sure that you have a valid configuration file under the current directory!
|
|
103
103
|
`);
|
|
104
104
|
}
|
package/cjs/plugins.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getPluginByName = void 0;
|
|
4
|
+
const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
|
|
4
5
|
const path_1 = require("path");
|
|
5
6
|
async function getPluginByName(name, pluginLoader) {
|
|
6
7
|
const possibleNames = [
|
|
@@ -21,7 +22,7 @@ async function getPluginByName(name, pluginLoader) {
|
|
|
21
22
|
}
|
|
22
23
|
catch (err) {
|
|
23
24
|
if (err.code !== 'MODULE_NOT_FOUND' && err.code !== 'ERR_MODULE_NOT_FOUND') {
|
|
24
|
-
throw new
|
|
25
|
+
throw new plugin_helpers_1.DetailedError(`Unable to load template plugin matching ${name}`, `
|
|
25
26
|
Unable to load template plugin matching '${name}'.
|
|
26
27
|
Reason:
|
|
27
28
|
${err.message}
|
|
@@ -34,7 +35,7 @@ async function getPluginByName(name, pluginLoader) {
|
|
|
34
35
|
- ${name}
|
|
35
36
|
`.trimRight())
|
|
36
37
|
.join('');
|
|
37
|
-
throw new
|
|
38
|
+
throw new plugin_helpers_1.DetailedError(`Unable to find template plugin matching ${name}`, `
|
|
38
39
|
Unable to find template plugin matching '${name}'
|
|
39
40
|
Install one of the following packages:
|
|
40
41
|
|
package/esm/cli.js
CHANGED
|
@@ -2,6 +2,7 @@ import { generate } from './generate-and-save.js';
|
|
|
2
2
|
import { init } from './init/index.js';
|
|
3
3
|
import { createContext } from './config.js';
|
|
4
4
|
import { lifecycleHooks } from './hooks.js';
|
|
5
|
+
import { DetailedError } from '@graphql-codegen/plugin-helpers';
|
|
5
6
|
export async function runCli(cmd) {
|
|
6
7
|
await ensureGraphQlPackage();
|
|
7
8
|
if (cmd === 'init') {
|
|
@@ -28,10 +29,11 @@ export async function ensureGraphQlPackage() {
|
|
|
28
29
|
await import('graphql');
|
|
29
30
|
}
|
|
30
31
|
catch (e) {
|
|
31
|
-
throw new
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
throw new DetailedError(`Unable to load "graphql" package. Please make sure to install "graphql" as a dependency!`, `
|
|
33
|
+
To install "graphql", run:
|
|
34
|
+
yarn add graphql
|
|
35
|
+
Or, with NPM:
|
|
36
|
+
npm install --save graphql
|
|
37
|
+
`);
|
|
36
38
|
}
|
|
37
39
|
}
|
package/esm/codegen.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { normalizeOutputParam, normalizeInstanceOrArray, normalizeConfig, getCachedDocumentNodeFromSchema, } from '@graphql-codegen/plugin-helpers';
|
|
1
|
+
import { DetailedError, normalizeOutputParam, normalizeInstanceOrArray, normalizeConfig, getCachedDocumentNodeFromSchema, isDetailedError, } from '@graphql-codegen/plugin-helpers';
|
|
2
2
|
import { codegen } from '@graphql-codegen/core';
|
|
3
3
|
import { AggregateError } from '@graphql-tools/utils';
|
|
4
4
|
import { GraphQLError } from 'graphql';
|
|
@@ -88,7 +88,7 @@ export async function executeCodegen(input) {
|
|
|
88
88
|
/* Normalize "generators" field */
|
|
89
89
|
const generateKeys = Object.keys(config.generates || {});
|
|
90
90
|
if (generateKeys.length === 0) {
|
|
91
|
-
throw new
|
|
91
|
+
throw new DetailedError('Invalid Codegen Configuration!', `
|
|
92
92
|
Please make sure that your codegen config file contains the "generates" field, with a specification for the plugins you need.
|
|
93
93
|
|
|
94
94
|
It should looks like that:
|
|
@@ -99,12 +99,13 @@ export async function executeCodegen(input) {
|
|
|
99
99
|
my-file.ts:
|
|
100
100
|
- plugin1
|
|
101
101
|
- plugin2
|
|
102
|
-
- plugin3
|
|
102
|
+
- plugin3
|
|
103
|
+
`);
|
|
103
104
|
}
|
|
104
105
|
for (const filename of generateKeys) {
|
|
105
106
|
const output = (generates[filename] = normalizeOutputParam(config.generates[filename]));
|
|
106
107
|
if (!output.preset && (!output.plugins || output.plugins.length === 0)) {
|
|
107
|
-
throw new
|
|
108
|
+
throw new DetailedError('Invalid Codegen Configuration!', `
|
|
108
109
|
Please make sure that your codegen config file has defined plugins list for output "${filename}".
|
|
109
110
|
|
|
110
111
|
It should looks like that:
|
|
@@ -123,7 +124,7 @@ export async function executeCodegen(input) {
|
|
|
123
124
|
Object.keys(generates).some(filename => !generates[filename].schema ||
|
|
124
125
|
(Array.isArray(generates[filename].schema === 'object') &&
|
|
125
126
|
generates[filename].schema.length === 0))) {
|
|
126
|
-
throw new
|
|
127
|
+
throw new DetailedError('Invalid Codegen Configuration!', `
|
|
127
128
|
Please make sure that your codegen config file contains either the "schema" field
|
|
128
129
|
or every generated file has its own "schema" field.
|
|
129
130
|
|
|
@@ -315,7 +316,9 @@ export async function executeCodegen(input) {
|
|
|
315
316
|
printLogs();
|
|
316
317
|
}
|
|
317
318
|
if (executedContext.errors.length > 0) {
|
|
318
|
-
const errors = executedContext.errors.map(subErr => subErr
|
|
319
|
+
const errors = executedContext.errors.map(subErr => isDetailedError(subErr)
|
|
320
|
+
? `${subErr.message} for "${subErr.source}"${subErr.details}`
|
|
321
|
+
: subErr.message || subErr.toString());
|
|
319
322
|
const newErr = new AggregateError(executedContext.errors, `${errors.join('\n\n')}`);
|
|
320
323
|
// Best-effort to all stack traces for debugging
|
|
321
324
|
newErr.stack = `${newErr.stack}\n\n${executedContext.errors.map(subErr => subErr.stack).join('\n\n')}`;
|
package/esm/config.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { cosmiconfig, defaultLoaders } from 'cosmiconfig';
|
|
2
2
|
import { TypeScriptLoader } from 'cosmiconfig-typescript-loader';
|
|
3
3
|
import { resolve } from 'path';
|
|
4
|
-
import { createProfiler, createNoopProfiler, getCachedDocumentNodeFromSchema, } from '@graphql-codegen/plugin-helpers';
|
|
4
|
+
import { DetailedError, createProfiler, createNoopProfiler, getCachedDocumentNodeFromSchema, } from '@graphql-codegen/plugin-helpers';
|
|
5
5
|
import { env } from 'string-env-interpolation';
|
|
6
6
|
import yargs from 'yargs';
|
|
7
7
|
import { findAndLoadGraphQLConfig } from './graphql-config.js';
|
|
@@ -79,7 +79,7 @@ export async function loadContext(configFilePath) {
|
|
|
79
79
|
const result = await loadCodegenConfig({ configFilePath });
|
|
80
80
|
if (!result) {
|
|
81
81
|
if (configFilePath) {
|
|
82
|
-
throw new
|
|
82
|
+
throw new DetailedError(`Config ${configFilePath} does not exist`, `
|
|
83
83
|
Config ${configFilePath} does not exist.
|
|
84
84
|
|
|
85
85
|
$ graphql-codegen --config ${configFilePath}
|
|
@@ -87,12 +87,12 @@ export async function loadContext(configFilePath) {
|
|
|
87
87
|
Please make sure the --config points to a correct file.
|
|
88
88
|
`);
|
|
89
89
|
}
|
|
90
|
-
throw new
|
|
90
|
+
throw new DetailedError(`Unable to find Codegen config file!`, `
|
|
91
91
|
Please make sure that you have a configuration file under the current directory!
|
|
92
92
|
`);
|
|
93
93
|
}
|
|
94
94
|
if (result.isEmpty) {
|
|
95
|
-
throw new
|
|
95
|
+
throw new DetailedError(`Found Codegen config file but it was empty!`, `
|
|
96
96
|
Please make sure that you have a valid configuration file under the current directory!
|
|
97
97
|
`);
|
|
98
98
|
}
|
package/esm/plugins.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DetailedError } from '@graphql-codegen/plugin-helpers';
|
|
1
2
|
import { resolve } from 'path';
|
|
2
3
|
export async function getPluginByName(name, pluginLoader) {
|
|
3
4
|
const possibleNames = [
|
|
@@ -18,7 +19,7 @@ export async function getPluginByName(name, pluginLoader) {
|
|
|
18
19
|
}
|
|
19
20
|
catch (err) {
|
|
20
21
|
if (err.code !== 'MODULE_NOT_FOUND' && err.code !== 'ERR_MODULE_NOT_FOUND') {
|
|
21
|
-
throw new
|
|
22
|
+
throw new DetailedError(`Unable to load template plugin matching ${name}`, `
|
|
22
23
|
Unable to load template plugin matching '${name}'.
|
|
23
24
|
Reason:
|
|
24
25
|
${err.message}
|
|
@@ -31,7 +32,7 @@ export async function getPluginByName(name, pluginLoader) {
|
|
|
31
32
|
- ${name}
|
|
32
33
|
`.trimRight())
|
|
33
34
|
.join('');
|
|
34
|
-
throw new
|
|
35
|
+
throw new DetailedError(`Unable to find template plugin matching ${name}`, `
|
|
35
36
|
Unable to find template plugin matching '${name}'
|
|
36
37
|
Install one of the following packages:
|
|
37
38
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/cli",
|
|
3
|
-
"version": "2.13.8-alpha-
|
|
3
|
+
"version": "2.13.8-alpha-20221027114749-e39e1c05f",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
6
6
|
},
|
|
@@ -8,15 +8,15 @@
|
|
|
8
8
|
"@babel/generator": "^7.18.13",
|
|
9
9
|
"@babel/template": "^7.18.10",
|
|
10
10
|
"@babel/types": "^7.18.13",
|
|
11
|
-
"@graphql-codegen/core": "2.6.
|
|
12
|
-
"@graphql-codegen/plugin-helpers": "2.
|
|
11
|
+
"@graphql-codegen/core": "2.6.2",
|
|
12
|
+
"@graphql-codegen/plugin-helpers": "^2.6.2",
|
|
13
13
|
"@graphql-tools/apollo-engine-loader": "^7.3.6",
|
|
14
14
|
"@graphql-tools/code-file-loader": "^7.3.1",
|
|
15
15
|
"@graphql-tools/git-loader": "^7.2.1",
|
|
16
16
|
"@graphql-tools/github-loader": "^7.3.6",
|
|
17
17
|
"@graphql-tools/graphql-file-loader": "^7.5.0",
|
|
18
18
|
"@graphql-tools/json-file-loader": "^7.4.1",
|
|
19
|
-
"@graphql-tools/load": "
|
|
19
|
+
"@graphql-tools/load": "7.8.0",
|
|
20
20
|
"@graphql-tools/prisma-loader": "^7.2.7",
|
|
21
21
|
"@graphql-tools/url-loader": "^7.13.2",
|
|
22
22
|
"@graphql-tools/utils": "^8.9.0",
|