@depup/graphql-codegen__cli 6.2.1-depup.2 → 7.2.0-depup.10
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/LICENSE +21 -0
- package/README.md +27 -24
- package/changes.json +44 -32
- package/cjs/cli.js +17 -7
- package/cjs/codegen.js +84 -34
- package/cjs/config.js +55 -20
- package/cjs/documentTransforms.js +5 -1
- package/cjs/generate-and-save.js +1 -1
- package/cjs/graphql-config.js +5 -5
- package/cjs/init/helpers.js +8 -4
- package/cjs/init/index.js +1 -1
- package/cjs/init/plugins.js +3 -1
- package/cjs/init/questions.js +10 -3
- package/cjs/init/targets.js +1 -1
- package/cjs/isESMModule.js +9 -0
- package/cjs/load.js +6 -3
- package/cjs/utils/patterns.js +17 -6
- package/cjs/utils/watcher.js +12 -7
- package/cjs/version.js +4 -0
- package/esm/codegen.js +83 -33
- package/esm/config.js +55 -20
- package/esm/documentTransforms.js +5 -1
- package/esm/generate-and-save.js +1 -1
- package/esm/graphql-config.js +5 -5
- package/esm/init/helpers.js +8 -4
- package/esm/init/index.js +1 -1
- package/esm/init/plugins.js +3 -1
- package/esm/init/questions.js +11 -4
- package/esm/init/targets.js +1 -1
- package/esm/isESMModule.js +6 -0
- package/esm/load.js +6 -3
- package/esm/utils/file-system.js +1 -1
- package/esm/utils/patterns.js +17 -6
- package/esm/utils/watcher.js +12 -7
- package/esm/version.js +1 -0
- package/package.json +77 -64
- package/typings/config.d.cts +3 -2
- package/typings/config.d.ts +3 -2
- package/typings/init/questions.d.cts +1 -1
- package/typings/init/questions.d.ts +1 -1
- package/typings/init/targets.d.cts +1 -1
- package/typings/init/targets.d.ts +1 -1
- package/typings/isESMModule.d.cts +6 -0
- package/typings/isESMModule.d.ts +6 -0
- package/typings/load.d.cts +3 -2
- package/typings/load.d.ts +3 -2
- package/typings/version.d.cts +1 -0
- package/typings/version.d.ts +1 -0
- package/cjs/utils/abort-controller-polyfill.js +0 -99
- package/esm/utils/abort-controller-polyfill.js +0 -96
- package/typings/utils/abort-controller-polyfill.d.cts +0 -5
- package/typings/utils/abort-controller-polyfill.d.ts +0 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 Dotan Simha
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -13,40 +13,43 @@ npm install @depup/graphql-codegen__cli
|
|
|
13
13
|
|
|
14
14
|
| Field | Value |
|
|
15
15
|
|-------|-------|
|
|
16
|
-
| Original | [@graphql-codegen/cli](https://www.npmjs.com/package/@graphql-codegen/cli) @
|
|
17
|
-
| Processed | 2026-
|
|
16
|
+
| Original | [@graphql-codegen/cli](https://www.npmjs.com/package/@graphql-codegen/cli) @ 7.2.0 |
|
|
17
|
+
| Processed | 2026-07-26 |
|
|
18
18
|
| Smoke test | passed |
|
|
19
|
-
| Deps updated |
|
|
19
|
+
| Deps updated | 28 |
|
|
20
20
|
|
|
21
21
|
## Dependency Changes
|
|
22
22
|
|
|
23
23
|
| Dependency | From | To |
|
|
24
24
|
|------------|------|-----|
|
|
25
|
-
| @babel/generator | ^7.18.13 | ^
|
|
26
|
-
| @babel/template | ^7.18.10 | ^
|
|
27
|
-
| @babel/types | ^7.18.13 | ^
|
|
28
|
-
| @graphql-tools/
|
|
29
|
-
| @graphql-tools/
|
|
30
|
-
| @graphql-tools/
|
|
31
|
-
| @graphql-tools/
|
|
32
|
-
| @graphql-tools/
|
|
33
|
-
| @graphql-tools/
|
|
34
|
-
| @
|
|
25
|
+
| @babel/generator | ^7.18.13 | ^8.0.0 |
|
|
26
|
+
| @babel/template | ^7.18.10 | ^8.0.0 |
|
|
27
|
+
| @babel/types | ^7.18.13 | ^8.0.4 |
|
|
28
|
+
| @graphql-tools/apollo-engine-loader | ^8.0.28 | ^8.0.34 |
|
|
29
|
+
| @graphql-tools/code-file-loader | ^8.1.28 | ^8.1.36 |
|
|
30
|
+
| @graphql-tools/git-loader | ^8.0.32 | ^8.0.40 |
|
|
31
|
+
| @graphql-tools/github-loader | ^9.0.6 | ^9.1.6 |
|
|
32
|
+
| @graphql-tools/graphql-file-loader | ^8.1.11 | ^8.1.18 |
|
|
33
|
+
| @graphql-tools/json-file-loader | ^8.0.26 | ^8.0.32 |
|
|
34
|
+
| @graphql-tools/load | ^8.1.8 | ^8.1.15 |
|
|
35
|
+
| @graphql-tools/merge | ^9.0.6 | ^9.2.2 |
|
|
36
|
+
| @graphql-tools/url-loader | ^9.0.6 | ^9.1.6 |
|
|
37
|
+
| @graphql-tools/utils | ^11.2.0 | ^11.2.2 |
|
|
38
|
+
| @inquirer/prompts | ^8.3.2 | ^8.5.2 |
|
|
35
39
|
| @whatwg-node/fetch | ^0.10.0 | ^0.10.13 |
|
|
36
|
-
| chalk | ^
|
|
37
|
-
| cosmiconfig | ^9.0.0 | ^9.0.
|
|
38
|
-
|
|
|
39
|
-
| detect-indent | ^6.0.0 | ^7.0.2 |
|
|
40
|
+
| chalk | ^5.6.0 | ^5.6.2 |
|
|
41
|
+
| cosmiconfig | ^9.0.0 | ^9.0.2 |
|
|
42
|
+
| detect-indent | ^7.0.0 | ^7.0.2 |
|
|
40
43
|
| is-glob | ^4.0.1 | ^4.0.3 |
|
|
41
|
-
| jiti | ^2.3.0 | ^2.
|
|
42
|
-
| listr2 | ^
|
|
43
|
-
| log-symbols | ^
|
|
44
|
+
| jiti | ^2.3.0 | ^2.7.0 |
|
|
45
|
+
| listr2 | ^10.2.1 | ^11.0.0 |
|
|
46
|
+
| log-symbols | ^7.0.0 | ^7.0.1 |
|
|
44
47
|
| micromatch | ^4.0.5 | ^4.0.8 |
|
|
45
|
-
| shell-quote | ^1.7.3 | ^1.
|
|
46
|
-
| ts-log | ^
|
|
48
|
+
| shell-quote | ^1.7.3 | ^1.10.0 |
|
|
49
|
+
| ts-log | ^3.0.0 | ^3.0.2 |
|
|
47
50
|
| tslib | ^2.4.0 | ^2.8.1 |
|
|
48
|
-
| yaml | ^2.3.1 | ^2.
|
|
49
|
-
| yargs | ^
|
|
51
|
+
| yaml | ^2.3.1 | ^2.9.0 |
|
|
52
|
+
| yargs | ^18.0.0 | ^18.1.0 |
|
|
50
53
|
|
|
51
54
|
---
|
|
52
55
|
|
package/changes.json
CHANGED
|
@@ -2,62 +2,74 @@
|
|
|
2
2
|
"bumped": {
|
|
3
3
|
"@babel/generator": {
|
|
4
4
|
"from": "^7.18.13",
|
|
5
|
-
"to": "^
|
|
5
|
+
"to": "^8.0.0"
|
|
6
6
|
},
|
|
7
7
|
"@babel/template": {
|
|
8
8
|
"from": "^7.18.10",
|
|
9
|
-
"to": "^
|
|
9
|
+
"to": "^8.0.0"
|
|
10
10
|
},
|
|
11
11
|
"@babel/types": {
|
|
12
12
|
"from": "^7.18.13",
|
|
13
|
-
"to": "^
|
|
13
|
+
"to": "^8.0.4"
|
|
14
|
+
},
|
|
15
|
+
"@graphql-tools/apollo-engine-loader": {
|
|
16
|
+
"from": "^8.0.28",
|
|
17
|
+
"to": "^8.0.34"
|
|
14
18
|
},
|
|
15
19
|
"@graphql-tools/code-file-loader": {
|
|
16
20
|
"from": "^8.1.28",
|
|
17
|
-
"to": "^8.1.
|
|
21
|
+
"to": "^8.1.36"
|
|
18
22
|
},
|
|
19
23
|
"@graphql-tools/git-loader": {
|
|
20
24
|
"from": "^8.0.32",
|
|
21
|
-
"to": "^8.0.
|
|
25
|
+
"to": "^8.0.40"
|
|
22
26
|
},
|
|
23
27
|
"@graphql-tools/github-loader": {
|
|
24
28
|
"from": "^9.0.6",
|
|
25
|
-
"to": "^9.1.
|
|
29
|
+
"to": "^9.1.6"
|
|
26
30
|
},
|
|
27
31
|
"@graphql-tools/graphql-file-loader": {
|
|
28
32
|
"from": "^8.1.11",
|
|
29
|
-
"to": "^8.1.
|
|
33
|
+
"to": "^8.1.18"
|
|
30
34
|
},
|
|
31
|
-
"@graphql-tools/
|
|
32
|
-
"from": "^
|
|
33
|
-
"to": "^
|
|
35
|
+
"@graphql-tools/json-file-loader": {
|
|
36
|
+
"from": "^8.0.26",
|
|
37
|
+
"to": "^8.0.32"
|
|
38
|
+
},
|
|
39
|
+
"@graphql-tools/load": {
|
|
40
|
+
"from": "^8.1.8",
|
|
41
|
+
"to": "^8.1.15"
|
|
34
42
|
},
|
|
35
43
|
"@graphql-tools/merge": {
|
|
36
44
|
"from": "^9.0.6",
|
|
37
|
-
"to": "^9.
|
|
45
|
+
"to": "^9.2.2"
|
|
46
|
+
},
|
|
47
|
+
"@graphql-tools/url-loader": {
|
|
48
|
+
"from": "^9.0.6",
|
|
49
|
+
"to": "^9.1.6"
|
|
50
|
+
},
|
|
51
|
+
"@graphql-tools/utils": {
|
|
52
|
+
"from": "^11.2.0",
|
|
53
|
+
"to": "^11.2.2"
|
|
38
54
|
},
|
|
39
55
|
"@inquirer/prompts": {
|
|
40
|
-
"from": "^
|
|
41
|
-
"to": "^8.
|
|
56
|
+
"from": "^8.3.2",
|
|
57
|
+
"to": "^8.5.2"
|
|
42
58
|
},
|
|
43
59
|
"@whatwg-node/fetch": {
|
|
44
60
|
"from": "^0.10.0",
|
|
45
61
|
"to": "^0.10.13"
|
|
46
62
|
},
|
|
47
63
|
"chalk": {
|
|
48
|
-
"from": "^
|
|
64
|
+
"from": "^5.6.0",
|
|
49
65
|
"to": "^5.6.2"
|
|
50
66
|
},
|
|
51
67
|
"cosmiconfig": {
|
|
52
68
|
"from": "^9.0.0",
|
|
53
|
-
"to": "^9.0.
|
|
54
|
-
},
|
|
55
|
-
"debounce": {
|
|
56
|
-
"from": "^2.0.0",
|
|
57
|
-
"to": "^3.0.0"
|
|
69
|
+
"to": "^9.0.2"
|
|
58
70
|
},
|
|
59
71
|
"detect-indent": {
|
|
60
|
-
"from": "^
|
|
72
|
+
"from": "^7.0.0",
|
|
61
73
|
"to": "^7.0.2"
|
|
62
74
|
},
|
|
63
75
|
"is-glob": {
|
|
@@ -66,14 +78,14 @@
|
|
|
66
78
|
},
|
|
67
79
|
"jiti": {
|
|
68
80
|
"from": "^2.3.0",
|
|
69
|
-
"to": "^2.
|
|
81
|
+
"to": "^2.7.0"
|
|
70
82
|
},
|
|
71
83
|
"listr2": {
|
|
72
|
-
"from": "^
|
|
73
|
-
"to": "^
|
|
84
|
+
"from": "^10.2.1",
|
|
85
|
+
"to": "^11.0.0"
|
|
74
86
|
},
|
|
75
87
|
"log-symbols": {
|
|
76
|
-
"from": "^
|
|
88
|
+
"from": "^7.0.0",
|
|
77
89
|
"to": "^7.0.1"
|
|
78
90
|
},
|
|
79
91
|
"micromatch": {
|
|
@@ -82,11 +94,11 @@
|
|
|
82
94
|
},
|
|
83
95
|
"shell-quote": {
|
|
84
96
|
"from": "^1.7.3",
|
|
85
|
-
"to": "^1.
|
|
97
|
+
"to": "^1.10.0"
|
|
86
98
|
},
|
|
87
99
|
"ts-log": {
|
|
88
|
-
"from": "^
|
|
89
|
-
"to": "^3.0.
|
|
100
|
+
"from": "^3.0.0",
|
|
101
|
+
"to": "^3.0.2"
|
|
90
102
|
},
|
|
91
103
|
"tslib": {
|
|
92
104
|
"from": "^2.4.0",
|
|
@@ -94,13 +106,13 @@
|
|
|
94
106
|
},
|
|
95
107
|
"yaml": {
|
|
96
108
|
"from": "^2.3.1",
|
|
97
|
-
"to": "^2.
|
|
109
|
+
"to": "^2.9.0"
|
|
98
110
|
},
|
|
99
111
|
"yargs": {
|
|
100
|
-
"from": "^
|
|
101
|
-
"to": "^18.
|
|
112
|
+
"from": "^18.0.0",
|
|
113
|
+
"to": "^18.1.0"
|
|
102
114
|
}
|
|
103
115
|
},
|
|
104
|
-
"timestamp": "2026-
|
|
105
|
-
"totalUpdated":
|
|
116
|
+
"timestamp": "2026-07-26T08:49:32.588Z",
|
|
117
|
+
"totalUpdated": 28
|
|
106
118
|
}
|
package/cjs/cli.js
CHANGED
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.runCli = runCli;
|
|
27
37
|
exports.ensureGraphQlPackage = ensureGraphQlPackage;
|
package/cjs/codegen.js
CHANGED
|
@@ -6,35 +6,32 @@ const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
|
6
6
|
const module_1 = require("module");
|
|
7
7
|
const os_1 = require("os");
|
|
8
8
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
9
|
+
const graphql_1 = require("graphql");
|
|
10
|
+
const listr2_1 = require("listr2");
|
|
9
11
|
const core_1 = require("@graphql-codegen/core");
|
|
10
12
|
const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
|
|
11
13
|
const load_1 = require("@graphql-tools/load");
|
|
12
|
-
const graphql_1 = require("graphql");
|
|
13
14
|
const merge_1 = require("@graphql-tools/merge");
|
|
14
|
-
const listr2_1 = require("listr2");
|
|
15
15
|
const config_js_1 = require("./config.js");
|
|
16
|
+
const documentTransforms_js_1 = require("./documentTransforms.js");
|
|
17
|
+
const isESMModule_js_1 = require("./isESMModule.js");
|
|
16
18
|
const plugins_js_1 = require("./plugins.js");
|
|
17
19
|
const presets_js_1 = require("./presets.js");
|
|
18
20
|
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
21
|
const makeDefaultLoader = (from) => {
|
|
27
22
|
if (fs_1.default.statSync(from).isDirectory()) {
|
|
28
23
|
from = path_1.default.join(from, '__fake.js');
|
|
29
24
|
}
|
|
30
25
|
const relativeRequire = (0, module_1.createRequire)(from);
|
|
31
26
|
return async (mod) => {
|
|
32
|
-
return Promise.resolve(`${isESMModule
|
|
27
|
+
return Promise.resolve(`${isESMModule_js_1.isESMModule
|
|
33
28
|
? /**
|
|
34
29
|
* For ESM we currently have no "resolve path" solution
|
|
35
30
|
* as import.meta is unavailable in a CommonJS context
|
|
36
31
|
* and furthermore unavailable in stable Node.js.
|
|
37
32
|
**/
|
|
33
|
+
// FIXME(pnpm-update): this causes dev-test devDeps to be brought into CLI's package.json, which is not ideal.
|
|
34
|
+
// Note that `relativeRequire.resolve(mod)` seems to work correctly for ESM as well.
|
|
38
35
|
mod
|
|
39
36
|
: relativeRequire.resolve(mod)}`).then(s => tslib_1.__importStar(require(s)));
|
|
40
37
|
};
|
|
@@ -60,6 +57,7 @@ async function executeCodegen(input) {
|
|
|
60
57
|
let rootConfig = {};
|
|
61
58
|
let rootSchemas;
|
|
62
59
|
let rootDocuments;
|
|
60
|
+
let rootExternalDocuments;
|
|
63
61
|
const generates = {};
|
|
64
62
|
const cache = createCache();
|
|
65
63
|
// We need a simple string to uniqually identify the provided GraphQLSchema objects for the above cache.
|
|
@@ -101,6 +99,8 @@ async function executeCodegen(input) {
|
|
|
101
99
|
rootSchemas = (0, plugin_helpers_1.normalizeInstanceOrArray)(config.schema);
|
|
102
100
|
/* Normalize root "documents" field */
|
|
103
101
|
rootDocuments = (0, plugin_helpers_1.normalizeInstanceOrArray)(config.documents);
|
|
102
|
+
/* Normalize root "externalDocuments" field */
|
|
103
|
+
rootExternalDocuments = (0, plugin_helpers_1.normalizeInstanceOrArray)(config.externalDocuments);
|
|
104
104
|
/* Normalize "generators" field */
|
|
105
105
|
const generateKeys = Object.keys(config.generates || {});
|
|
106
106
|
if (generateKeys.length === 0) {
|
|
@@ -173,9 +173,10 @@ async function executeCodegen(input) {
|
|
|
173
173
|
let outputSchemaAst;
|
|
174
174
|
let outputSchema;
|
|
175
175
|
const outputFileTemplateConfig = outputConfig.config || {};
|
|
176
|
-
|
|
176
|
+
const outputDocuments = [];
|
|
177
177
|
const outputSpecificSchemas = (0, plugin_helpers_1.normalizeInstanceOrArray)(outputConfig.schema);
|
|
178
178
|
let outputSpecificDocuments = (0, plugin_helpers_1.normalizeInstanceOrArray)(outputConfig.documents);
|
|
179
|
+
let outputSpecificExternalDocuments = (0, plugin_helpers_1.normalizeInstanceOrArray)(outputConfig.externalDocuments);
|
|
179
180
|
const preset = hasPreset
|
|
180
181
|
? typeof outputConfig.preset === 'string'
|
|
181
182
|
? await (0, presets_js_1.getPresetByName)(outputConfig.preset, makeDefaultLoader(context.cwd))
|
|
@@ -183,6 +184,7 @@ async function executeCodegen(input) {
|
|
|
183
184
|
: null;
|
|
184
185
|
if (preset?.prepareDocuments) {
|
|
185
186
|
outputSpecificDocuments = await preset.prepareDocuments(filename, outputSpecificDocuments);
|
|
187
|
+
outputSpecificExternalDocuments = await preset.prepareDocuments(filename, outputSpecificExternalDocuments);
|
|
186
188
|
}
|
|
187
189
|
return subTask.newListr([
|
|
188
190
|
{
|
|
@@ -191,7 +193,10 @@ async function executeCodegen(input) {
|
|
|
191
193
|
(0, debugging_js_1.debugLog)(`[CLI] Loading Schemas`);
|
|
192
194
|
const schemaPointerMap = {};
|
|
193
195
|
const parsedSchemas = [];
|
|
194
|
-
const allSchemaDenormalizedPointers = [
|
|
196
|
+
const allSchemaDenormalizedPointers = [
|
|
197
|
+
...rootSchemas,
|
|
198
|
+
...outputSpecificSchemas,
|
|
199
|
+
];
|
|
195
200
|
for (const denormalizedPtr of allSchemaDenormalizedPointers) {
|
|
196
201
|
if ((0, graphql_1.isSchema)(denormalizedPtr)) {
|
|
197
202
|
parsedSchemas.push(denormalizedPtr);
|
|
@@ -203,7 +208,8 @@ async function executeCodegen(input) {
|
|
|
203
208
|
Object.assign(schemaPointerMap, denormalizedPtr);
|
|
204
209
|
}
|
|
205
210
|
}
|
|
206
|
-
const hash = JSON.stringify(schemaPointerMap) +
|
|
211
|
+
const hash = JSON.stringify(schemaPointerMap) +
|
|
212
|
+
parsedSchemas.map(getJsObjectId).join(',');
|
|
207
213
|
const result = await cache('schema', hash, async () => {
|
|
208
214
|
// collect parsed schemas
|
|
209
215
|
const schemasToMerge = [...parsedSchemas];
|
|
@@ -229,34 +235,74 @@ async function executeCodegen(input) {
|
|
|
229
235
|
title: 'Load GraphQL documents',
|
|
230
236
|
task: wrapTask(async () => {
|
|
231
237
|
(0, debugging_js_1.debugLog)(`[CLI] Loading Documents`);
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
238
|
+
const populateDocumentPointerMap = (allDocumentsDenormalizedPointers) => {
|
|
239
|
+
const pointer = {};
|
|
240
|
+
for (const denormalizedPtr of allDocumentsDenormalizedPointers) {
|
|
241
|
+
if (typeof denormalizedPtr === 'string') {
|
|
242
|
+
pointer[denormalizedPtr] = {};
|
|
243
|
+
}
|
|
244
|
+
else if (typeof denormalizedPtr === 'object') {
|
|
245
|
+
Object.assign(pointer, denormalizedPtr);
|
|
246
|
+
}
|
|
240
247
|
}
|
|
241
|
-
|
|
248
|
+
return pointer;
|
|
249
|
+
};
|
|
250
|
+
const allDocumentsDenormalizedPointers = [
|
|
251
|
+
...rootDocuments,
|
|
252
|
+
...outputSpecificDocuments,
|
|
253
|
+
];
|
|
254
|
+
const documentPointerMap = populateDocumentPointerMap(allDocumentsDenormalizedPointers);
|
|
242
255
|
const hash = JSON.stringify(documentPointerMap);
|
|
243
|
-
const
|
|
256
|
+
const outputDocumentsStandard = await cache('documents', hash, async () => {
|
|
244
257
|
try {
|
|
245
|
-
const documents = await context.loadDocuments(documentPointerMap);
|
|
246
|
-
return
|
|
247
|
-
documents,
|
|
248
|
-
};
|
|
258
|
+
const documents = await context.loadDocuments(documentPointerMap, 'standard');
|
|
259
|
+
return documents;
|
|
249
260
|
}
|
|
250
261
|
catch (error) {
|
|
251
|
-
if (error instanceof load_1.NoTypeDefinitionsFound &&
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
};
|
|
262
|
+
if (error instanceof load_1.NoTypeDefinitionsFound &&
|
|
263
|
+
config.ignoreNoDocuments) {
|
|
264
|
+
return [];
|
|
255
265
|
}
|
|
256
266
|
throw error;
|
|
257
267
|
}
|
|
258
268
|
});
|
|
259
|
-
|
|
269
|
+
const allExternalDocumentsDenormalizedPointers = [
|
|
270
|
+
...rootExternalDocuments,
|
|
271
|
+
...outputSpecificExternalDocuments,
|
|
272
|
+
];
|
|
273
|
+
const externalDocumentsPointerMap = populateDocumentPointerMap(allExternalDocumentsDenormalizedPointers);
|
|
274
|
+
const externalDocumentHash = JSON.stringify(externalDocumentsPointerMap);
|
|
275
|
+
const outputExternalDocuments = await cache('documents', externalDocumentHash, async () => {
|
|
276
|
+
try {
|
|
277
|
+
const documents = await context.loadDocuments(externalDocumentsPointerMap, 'external');
|
|
278
|
+
return documents;
|
|
279
|
+
}
|
|
280
|
+
catch (error) {
|
|
281
|
+
if (error instanceof load_1.NoTypeDefinitionsFound &&
|
|
282
|
+
config.ignoreNoDocuments) {
|
|
283
|
+
return [];
|
|
284
|
+
}
|
|
285
|
+
throw error;
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
/**
|
|
289
|
+
* Merging `standard` and `external` documents here,
|
|
290
|
+
* so they can be processed the same way,
|
|
291
|
+
* before passed into presets and plugins
|
|
292
|
+
*/
|
|
293
|
+
const processedFile = {};
|
|
294
|
+
const mergedDocuments = [
|
|
295
|
+
...outputDocumentsStandard,
|
|
296
|
+
...outputExternalDocuments,
|
|
297
|
+
];
|
|
298
|
+
for (const file of mergedDocuments) {
|
|
299
|
+
const fileIdentifier = (file.location || '') + (file.hash || '');
|
|
300
|
+
if (processedFile[fileIdentifier]) {
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
outputDocuments.push(file);
|
|
304
|
+
processedFile[fileIdentifier] = true;
|
|
305
|
+
}
|
|
260
306
|
}, filename, `Load GraphQL documents: ${filename}`, ctx),
|
|
261
307
|
},
|
|
262
308
|
{
|
|
@@ -355,7 +401,9 @@ async function executeCodegen(input) {
|
|
|
355
401
|
exitOnError: false,
|
|
356
402
|
};
|
|
357
403
|
});
|
|
358
|
-
return task.newListr(generateTasks, {
|
|
404
|
+
return task.newListr(generateTasks, {
|
|
405
|
+
concurrent: (0, os_1.cpus)().length || 1,
|
|
406
|
+
});
|
|
359
407
|
},
|
|
360
408
|
},
|
|
361
409
|
], {
|
|
@@ -382,7 +430,9 @@ async function executeCodegen(input) {
|
|
|
382
430
|
const errors = executedContext.errors.map(subErr => subErr.message || subErr.toString());
|
|
383
431
|
error = new AggregateError(executedContext.errors, String(errors.join('\n\n')));
|
|
384
432
|
// Best-effort to all stack traces for debugging
|
|
385
|
-
error.stack = `${error.stack}\n\n${executedContext.errors
|
|
433
|
+
error.stack = `${error.stack}\n\n${executedContext.errors
|
|
434
|
+
.map(subErr => subErr.stack)
|
|
435
|
+
.join('\n\n')}`;
|
|
386
436
|
}
|
|
387
437
|
return { result, error };
|
|
388
438
|
}
|
package/cjs/config.js
CHANGED
|
@@ -13,16 +13,19 @@ const tslib_1 = require("tslib");
|
|
|
13
13
|
const crypto_1 = require("crypto");
|
|
14
14
|
const fs_1 = require("fs");
|
|
15
15
|
const module_1 = require("module");
|
|
16
|
+
const url = tslib_1.__importStar(require("node:url"));
|
|
16
17
|
const path_1 = require("path");
|
|
17
|
-
const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
|
|
18
18
|
const cosmiconfig_1 = require("cosmiconfig");
|
|
19
|
-
const jiti_1 = require("jiti");
|
|
20
19
|
const graphql_1 = require("graphql");
|
|
20
|
+
const jiti_1 = require("jiti");
|
|
21
21
|
const string_env_interpolation_1 = require("string-env-interpolation");
|
|
22
22
|
const yaml_1 = tslib_1.__importDefault(require("yaml"));
|
|
23
23
|
const yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
24
|
+
const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
|
|
24
25
|
const graphql_config_js_1 = require("./graphql-config.js");
|
|
26
|
+
const isESMModule_js_1 = require("./isESMModule.js");
|
|
25
27
|
const load_js_1 = require("./load.js");
|
|
28
|
+
const version_js_1 = require("./version.js");
|
|
26
29
|
const { lstat } = fs_1.promises;
|
|
27
30
|
function generateSearchPlaces(moduleName) {
|
|
28
31
|
const extensions = ['json', 'yaml', 'yml', 'js', 'ts', 'config.js'];
|
|
@@ -192,14 +195,14 @@ function buildOptions() {
|
|
|
192
195
|
};
|
|
193
196
|
}
|
|
194
197
|
function parseArgv(argv = process.argv) {
|
|
195
|
-
return (0, yargs_1.default)(argv).options(buildOptions()).parse(argv);
|
|
198
|
+
return (0, yargs_1.default)(argv).version(version_js_1.version).options(buildOptions()).parse(argv);
|
|
196
199
|
}
|
|
197
200
|
async function createContext(cliFlags = parseArgv(process.argv)) {
|
|
198
201
|
if (cliFlags.require && cliFlags.require.length > 0) {
|
|
199
202
|
const relativeRequire = (0, module_1.createRequire)(process.cwd());
|
|
200
|
-
await Promise.all(cliFlags.require.map(mod =>
|
|
203
|
+
await Promise.all(cliFlags.require.map(mod => safeDynamicImport(relativeRequire.resolve(mod, {
|
|
201
204
|
paths: [process.cwd()],
|
|
202
|
-
})
|
|
205
|
+
}))));
|
|
203
206
|
}
|
|
204
207
|
const customConfigPath = getCustomConfigPath(cliFlags);
|
|
205
208
|
const context = await loadContext(customConfigPath);
|
|
@@ -266,7 +269,7 @@ class CodegenContext {
|
|
|
266
269
|
this._config = config;
|
|
267
270
|
this._graphqlConfig = graphqlConfig;
|
|
268
271
|
this.filepath = this._graphqlConfig ? this._graphqlConfig.filepath : filepath;
|
|
269
|
-
this.cwd = this._graphqlConfig ? this._graphqlConfig.dirpath : process.cwd();
|
|
272
|
+
this.cwd = this._graphqlConfig ? this._graphqlConfig.dirpath : config?.cwd || process.cwd();
|
|
270
273
|
this.profiler = (0, plugin_helpers_1.createNoopProfiler)();
|
|
271
274
|
}
|
|
272
275
|
useProject(name) {
|
|
@@ -287,10 +290,18 @@ class CodegenContext {
|
|
|
287
290
|
this.config = { ...this._config, pluginContext: this._pluginContext };
|
|
288
291
|
}
|
|
289
292
|
}
|
|
290
|
-
|
|
293
|
+
const config = {
|
|
294
|
+
noSilentErrors: true, // When a `documents` pattern matches multiple files e.g. `*` exists in filename like `src/something.*.ts`, and some files fail but some pass syntax error check, the failed files will silently fail if `noSilentErrors: false`. So, `noSilentErrors: true` is turned on by default to help users detect errors faster.
|
|
291
295
|
...extraConfig,
|
|
292
296
|
...this.config,
|
|
293
297
|
};
|
|
298
|
+
if (this._graphqlConfig) {
|
|
299
|
+
return config;
|
|
300
|
+
}
|
|
301
|
+
return {
|
|
302
|
+
...config,
|
|
303
|
+
cwd: this.cwd,
|
|
304
|
+
};
|
|
294
305
|
}
|
|
295
306
|
updateConfig(config) {
|
|
296
307
|
this.config = {
|
|
@@ -324,13 +335,15 @@ class CodegenContext {
|
|
|
324
335
|
}
|
|
325
336
|
return addHashToSchema((0, load_js_1.loadSchema)(pointer, config));
|
|
326
337
|
}
|
|
327
|
-
async loadDocuments(pointer) {
|
|
338
|
+
async loadDocuments(pointer, type) {
|
|
328
339
|
const config = this.getConfig(load_js_1.defaultDocumentsLoadOptions);
|
|
329
340
|
if (this._graphqlConfig) {
|
|
330
341
|
// TODO: pointer won't work here
|
|
331
|
-
return
|
|
342
|
+
return addMetadataToSources(this._graphqlConfig
|
|
343
|
+
.getProject(this._project)
|
|
344
|
+
.loadDocuments(pointer, { ...config, ...config.config }), type);
|
|
332
345
|
}
|
|
333
|
-
return
|
|
346
|
+
return addMetadataToSources((0, load_js_1.loadDocuments)(pointer, config), type);
|
|
334
347
|
}
|
|
335
348
|
}
|
|
336
349
|
exports.CodegenContext = CodegenContext;
|
|
@@ -353,18 +366,40 @@ function addHashToSchema(schemaPromise) {
|
|
|
353
366
|
return schema;
|
|
354
367
|
});
|
|
355
368
|
}
|
|
356
|
-
function
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
369
|
+
async function addMetadataToSources(documentFilesPromise, type) {
|
|
370
|
+
function hashDocument(doc) {
|
|
371
|
+
if (doc.rawSDL) {
|
|
372
|
+
return hashContent(doc.rawSDL);
|
|
373
|
+
}
|
|
374
|
+
if (doc.document) {
|
|
375
|
+
return hashContent((0, graphql_1.print)(doc.document));
|
|
376
|
+
}
|
|
377
|
+
return null;
|
|
362
378
|
}
|
|
363
|
-
return
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
return documentFilesPromise.then(documentFiles => documentFiles.map(doc => {
|
|
379
|
+
return documentFilesPromise.then(documentFiles =>
|
|
380
|
+
// Note: `doc` here is technically `Source`, but by the end of the funciton it's `Types.DocumentFile`. This re-declaration makes TypeScript happy.
|
|
381
|
+
documentFiles.map((doc) => {
|
|
367
382
|
doc.hash = hashDocument(doc);
|
|
383
|
+
doc.type = type;
|
|
368
384
|
return doc;
|
|
369
385
|
}));
|
|
370
386
|
}
|
|
387
|
+
/**
|
|
388
|
+
* `safeDynamicImport` is a wrapper of dynamic `import()`
|
|
389
|
+
* to work across Linux and Windows
|
|
390
|
+
*
|
|
391
|
+
* CJS:
|
|
392
|
+
* `import()` seems to work well in CJS when given resolved filename
|
|
393
|
+
*
|
|
394
|
+
* ESM:
|
|
395
|
+
* On native Windows (i.e. no WSL or CI), filename may look like this: `C:\\Users\\path\\to\\file.ts`
|
|
396
|
+
* If used directly with `import()`, we'll see `ERR_UNSUPPORTED_ESM_URL_SCHEME` error because `c:` is not a valid protocol
|
|
397
|
+
* `url.pathToFileURL` turns the filename to `file:///C:/Users/path/to/file.ts`, which is import-able
|
|
398
|
+
*/
|
|
399
|
+
const safeDynamicImport = (absoluteFilename) => {
|
|
400
|
+
if (isESMModule_js_1.isESMModule) {
|
|
401
|
+
const { href: fileUrl } = url.pathToFileURL(absoluteFilename);
|
|
402
|
+
return Promise.resolve(`${fileUrl}`).then(s => tslib_1.__importStar(require(s)));
|
|
403
|
+
}
|
|
404
|
+
return Promise.resolve(`${absoluteFilename}`).then(s => tslib_1.__importStar(require(s)));
|
|
405
|
+
};
|
|
@@ -14,7 +14,11 @@ async function getDocumentTransform(documentTransform, loader, defaultName) {
|
|
|
14
14
|
if (isTransformFileConfig(documentTransform)) {
|
|
15
15
|
const name = Object.keys(documentTransform)[0];
|
|
16
16
|
const transformObject = await getDocumentTransformByName(name, loader);
|
|
17
|
-
return {
|
|
17
|
+
return {
|
|
18
|
+
name,
|
|
19
|
+
transformObject,
|
|
20
|
+
config: Object.values(documentTransform)[0],
|
|
21
|
+
};
|
|
18
22
|
}
|
|
19
23
|
throw new Error(`
|
|
20
24
|
An unknown format document transform: '${defaultName}'.
|
package/cjs/generate-and-save.js
CHANGED
|
@@ -10,8 +10,8 @@ const config_js_1 = require("./config.js");
|
|
|
10
10
|
const hooks_js_1 = require("./hooks.js");
|
|
11
11
|
const debugging_js_1 = require("./utils/debugging.js");
|
|
12
12
|
const file_system_js_1 = require("./utils/file-system.js");
|
|
13
|
-
const watcher_js_1 = require("./utils/watcher.js");
|
|
14
13
|
const logger_js_1 = require("./utils/logger.js");
|
|
14
|
+
const watcher_js_1 = require("./utils/watcher.js");
|
|
15
15
|
const hash = (content) => (0, crypto_1.createHash)('sha1').update(content).digest('base64');
|
|
16
16
|
async function generate(input, saveToFile = true) {
|
|
17
17
|
const context = (0, config_js_1.ensureContext)(input);
|