@graphql-codegen/cli 6.2.1 → 6.2.2-alpha-20260405034159-39fcc54cea95aedd7dbb252bb8d3602db33669bc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/cjs/codegen.js +21 -9
- package/cjs/config.js +5 -3
- package/cjs/documentTransforms.js +5 -1
- package/cjs/generate-and-save.js +1 -1
- package/cjs/graphql-config.js +1 -1
- package/cjs/init/helpers.js +8 -4
- package/cjs/init/plugins.js +3 -1
- package/cjs/init/questions.js +10 -3
- package/cjs/load.js +5 -2
- package/cjs/utils/patterns.js +17 -6
- package/cjs/utils/watcher.js +12 -6
- package/esm/codegen.js +21 -9
- package/esm/config.js +6 -4
- package/esm/documentTransforms.js +5 -1
- package/esm/generate-and-save.js +1 -1
- package/esm/graphql-config.js +1 -1
- package/esm/init/helpers.js +8 -4
- package/esm/init/plugins.js +3 -1
- package/esm/init/questions.js +11 -4
- package/esm/load.js +5 -2
- package/esm/utils/file-system.js +1 -1
- package/esm/utils/patterns.js +17 -6
- package/esm/utils/watcher.js +13 -7
- package/package.json +6 -6
- package/typings/config.d.cts +1 -1
- package/typings/config.d.ts +1 -1
- package/typings/init/questions.d.cts +1 -1
- package/typings/init/questions.d.ts +1 -1
- package/typings/load.d.cts +1 -1
- package/typings/load.d.ts +1 -1
package/README.md
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
<img src="https://github.com/dotansimha/graphql-code-generator/blob/master/logo.png?raw=true" />
|
|
5
5
|
</p>
|
|
6
6
|
|
|
7
|
-
Live demo and full documentation:
|
|
7
|
+
Live demo and full documentation:
|
|
8
|
+
[the-guild.dev/graphql/codegen](https://the-guild.dev/graphql/codegen)
|
|
8
9
|
|
|
9
10
|
Project repository: [graphql-code-generator](https://github.com/dotansimha/graphql-code-generator)
|
package/cjs/codegen.js
CHANGED
|
@@ -6,17 +6,17 @@ 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");
|
|
16
17
|
const plugins_js_1 = require("./plugins.js");
|
|
17
18
|
const presets_js_1 = require("./presets.js");
|
|
18
19
|
const debugging_js_1 = require("./utils/debugging.js");
|
|
19
|
-
const documentTransforms_js_1 = require("./documentTransforms.js");
|
|
20
20
|
/**
|
|
21
21
|
* Poor mans ESM detection.
|
|
22
22
|
* Looking at this and you have a better method?
|
|
@@ -191,7 +191,10 @@ async function executeCodegen(input) {
|
|
|
191
191
|
(0, debugging_js_1.debugLog)(`[CLI] Loading Schemas`);
|
|
192
192
|
const schemaPointerMap = {};
|
|
193
193
|
const parsedSchemas = [];
|
|
194
|
-
const allSchemaDenormalizedPointers = [
|
|
194
|
+
const allSchemaDenormalizedPointers = [
|
|
195
|
+
...rootSchemas,
|
|
196
|
+
...outputSpecificSchemas,
|
|
197
|
+
];
|
|
195
198
|
for (const denormalizedPtr of allSchemaDenormalizedPointers) {
|
|
196
199
|
if ((0, graphql_1.isSchema)(denormalizedPtr)) {
|
|
197
200
|
parsedSchemas.push(denormalizedPtr);
|
|
@@ -203,7 +206,8 @@ async function executeCodegen(input) {
|
|
|
203
206
|
Object.assign(schemaPointerMap, denormalizedPtr);
|
|
204
207
|
}
|
|
205
208
|
}
|
|
206
|
-
const hash = JSON.stringify(schemaPointerMap) +
|
|
209
|
+
const hash = JSON.stringify(schemaPointerMap) +
|
|
210
|
+
parsedSchemas.map(getJsObjectId).join(',');
|
|
207
211
|
const result = await cache('schema', hash, async () => {
|
|
208
212
|
// collect parsed schemas
|
|
209
213
|
const schemasToMerge = [...parsedSchemas];
|
|
@@ -230,7 +234,10 @@ async function executeCodegen(input) {
|
|
|
230
234
|
task: wrapTask(async () => {
|
|
231
235
|
(0, debugging_js_1.debugLog)(`[CLI] Loading Documents`);
|
|
232
236
|
const documentPointerMap = {};
|
|
233
|
-
const allDocumentsDenormalizedPointers = [
|
|
237
|
+
const allDocumentsDenormalizedPointers = [
|
|
238
|
+
...rootDocuments,
|
|
239
|
+
...outputSpecificDocuments,
|
|
240
|
+
];
|
|
234
241
|
for (const denormalizedPtr of allDocumentsDenormalizedPointers) {
|
|
235
242
|
if (typeof denormalizedPtr === 'string') {
|
|
236
243
|
documentPointerMap[denormalizedPtr] = {};
|
|
@@ -248,7 +255,8 @@ async function executeCodegen(input) {
|
|
|
248
255
|
};
|
|
249
256
|
}
|
|
250
257
|
catch (error) {
|
|
251
|
-
if (error instanceof load_1.NoTypeDefinitionsFound &&
|
|
258
|
+
if (error instanceof load_1.NoTypeDefinitionsFound &&
|
|
259
|
+
config.ignoreNoDocuments) {
|
|
252
260
|
return {
|
|
253
261
|
documents: [],
|
|
254
262
|
};
|
|
@@ -355,7 +363,9 @@ async function executeCodegen(input) {
|
|
|
355
363
|
exitOnError: false,
|
|
356
364
|
};
|
|
357
365
|
});
|
|
358
|
-
return task.newListr(generateTasks, {
|
|
366
|
+
return task.newListr(generateTasks, {
|
|
367
|
+
concurrent: (0, os_1.cpus)().length || 1,
|
|
368
|
+
});
|
|
359
369
|
},
|
|
360
370
|
},
|
|
361
371
|
], {
|
|
@@ -382,7 +392,9 @@ async function executeCodegen(input) {
|
|
|
382
392
|
const errors = executedContext.errors.map(subErr => subErr.message || subErr.toString());
|
|
383
393
|
error = new AggregateError(executedContext.errors, String(errors.join('\n\n')));
|
|
384
394
|
// Best-effort to all stack traces for debugging
|
|
385
|
-
error.stack = `${error.stack}\n\n${executedContext.errors
|
|
395
|
+
error.stack = `${error.stack}\n\n${executedContext.errors
|
|
396
|
+
.map(subErr => subErr.stack)
|
|
397
|
+
.join('\n\n')}`;
|
|
386
398
|
}
|
|
387
399
|
return { result, error };
|
|
388
400
|
}
|
package/cjs/config.js
CHANGED
|
@@ -14,13 +14,13 @@ const crypto_1 = require("crypto");
|
|
|
14
14
|
const fs_1 = require("fs");
|
|
15
15
|
const module_1 = require("module");
|
|
16
16
|
const path_1 = require("path");
|
|
17
|
-
const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
|
|
18
17
|
const cosmiconfig_1 = require("cosmiconfig");
|
|
19
|
-
const jiti_1 = require("jiti");
|
|
20
18
|
const graphql_1 = require("graphql");
|
|
19
|
+
const jiti_1 = require("jiti");
|
|
21
20
|
const string_env_interpolation_1 = require("string-env-interpolation");
|
|
22
21
|
const yaml_1 = tslib_1.__importDefault(require("yaml"));
|
|
23
22
|
const yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
23
|
+
const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
|
|
24
24
|
const graphql_config_js_1 = require("./graphql-config.js");
|
|
25
25
|
const load_js_1 = require("./load.js");
|
|
26
26
|
const { lstat } = fs_1.promises;
|
|
@@ -328,7 +328,9 @@ class CodegenContext {
|
|
|
328
328
|
const config = this.getConfig(load_js_1.defaultDocumentsLoadOptions);
|
|
329
329
|
if (this._graphqlConfig) {
|
|
330
330
|
// TODO: pointer won't work here
|
|
331
|
-
return addHashToDocumentFiles(this._graphqlConfig
|
|
331
|
+
return addHashToDocumentFiles(this._graphqlConfig
|
|
332
|
+
.getProject(this._project)
|
|
333
|
+
.loadDocuments(pointer, { ...config, ...config.config }));
|
|
332
334
|
}
|
|
333
335
|
return addHashToDocumentFiles((0, load_js_1.loadDocuments)(pointer, config));
|
|
334
336
|
}
|
|
@@ -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);
|
package/cjs/graphql-config.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CodegenExtension = void 0;
|
|
4
4
|
exports.findAndLoadGraphQLConfig = findAndLoadGraphQLConfig;
|
|
5
|
+
const graphql_config_1 = require("graphql-config");
|
|
5
6
|
const apollo_engine_loader_1 = require("@graphql-tools/apollo-engine-loader");
|
|
6
7
|
const code_file_loader_1 = require("@graphql-tools/code-file-loader");
|
|
7
8
|
const git_loader_1 = require("@graphql-tools/git-loader");
|
|
8
9
|
const github_loader_1 = require("@graphql-tools/github-loader");
|
|
9
|
-
const graphql_config_1 = require("graphql-config");
|
|
10
10
|
const CodegenExtension = (api) => {
|
|
11
11
|
// Schema
|
|
12
12
|
api.loaders.schema.register(new code_file_loader_1.CodeFileLoader({
|
package/cjs/init/helpers.js
CHANGED
|
@@ -8,21 +8,25 @@ exports.italic = italic;
|
|
|
8
8
|
const tslib_1 = require("tslib");
|
|
9
9
|
const fs_1 = require("fs");
|
|
10
10
|
const path_1 = require("path");
|
|
11
|
+
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
12
|
+
const detect_indent_1 = tslib_1.__importDefault(require("detect-indent"));
|
|
11
13
|
const generator_1 = tslib_1.__importDefault(require("@babel/generator"));
|
|
12
14
|
const template_1 = tslib_1.__importDefault(require("@babel/template"));
|
|
13
15
|
const t = tslib_1.__importStar(require("@babel/types"));
|
|
14
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
15
|
-
const detect_indent_1 = tslib_1.__importDefault(require("detect-indent"));
|
|
16
16
|
const get_latest_version_js_1 = require("../utils/get-latest-version.js");
|
|
17
17
|
const types_js_1 = require("./types.js");
|
|
18
18
|
function jsObjectToBabelObjectExpression(obj) {
|
|
19
19
|
const objExp = t.objectExpression([]);
|
|
20
20
|
for (const [key, val] of Object.entries(obj)) {
|
|
21
21
|
if (Array.isArray(val)) {
|
|
22
|
-
objExp.properties.push(t.objectProperty(/^[a-zA-Z0-9]+$/.test(key) ? t.identifier(key) : t.stringLiteral(key), t.arrayExpression(val.map(v =>
|
|
22
|
+
objExp.properties.push(t.objectProperty(/^[a-zA-Z0-9]+$/.test(key) ? t.identifier(key) : t.stringLiteral(key), t.arrayExpression(val.map(v => typeof v === 'object'
|
|
23
|
+
? jsObjectToBabelObjectExpression(v)
|
|
24
|
+
: t.valueToNode(v)))));
|
|
23
25
|
}
|
|
24
26
|
else {
|
|
25
|
-
objExp.properties.push(t.objectProperty(/^[a-zA-Z0-9]+$/.test(key) ? t.identifier(key) : t.stringLiteral(key), typeof val === 'object'
|
|
27
|
+
objExp.properties.push(t.objectProperty(/^[a-zA-Z0-9]+$/.test(key) ? t.identifier(key) : t.stringLiteral(key), typeof val === 'object'
|
|
28
|
+
? jsObjectToBabelObjectExpression(val)
|
|
29
|
+
: t.valueToNode(val)));
|
|
26
30
|
}
|
|
27
31
|
}
|
|
28
32
|
return objExp;
|
package/cjs/init/plugins.js
CHANGED
|
@@ -10,7 +10,9 @@ exports.plugins = [
|
|
|
10
10
|
value: 'typescript',
|
|
11
11
|
pathInRepo: 'typescript/typescript',
|
|
12
12
|
available: hasTag(types_js_1.Tags.typescript),
|
|
13
|
-
shouldBeSelected: tags => oneOf(tags, types_js_1.Tags.angular, types_js_1.Tags.stencil) ||
|
|
13
|
+
shouldBeSelected: tags => oneOf(tags, types_js_1.Tags.angular, types_js_1.Tags.stencil) ||
|
|
14
|
+
allOf(tags, types_js_1.Tags.typescript, types_js_1.Tags.react) ||
|
|
15
|
+
noneOf(tags, types_js_1.Tags.flow),
|
|
14
16
|
defaultExtension: '.ts',
|
|
15
17
|
},
|
|
16
18
|
{
|
package/cjs/init/questions.js
CHANGED
|
@@ -21,7 +21,9 @@ async function getAnswers(possibleTargets) {
|
|
|
21
21
|
validate: str => str.length > 0,
|
|
22
22
|
});
|
|
23
23
|
let documents;
|
|
24
|
-
if (targets.includes(types_js_1.Tags.client) ||
|
|
24
|
+
if (targets.includes(types_js_1.Tags.client) ||
|
|
25
|
+
targets.includes(types_js_1.Tags.angular) ||
|
|
26
|
+
targets.includes(types_js_1.Tags.stencil))
|
|
25
27
|
documents = await (0, prompts_1.input)({
|
|
26
28
|
message: 'Where are your operations and fragments?:',
|
|
27
29
|
default: getDocumentsDefaultValue(targets),
|
|
@@ -46,7 +48,9 @@ async function getAnswers(possibleTargets) {
|
|
|
46
48
|
});
|
|
47
49
|
const config = await (0, prompts_1.input)({
|
|
48
50
|
message: 'How to name the config file?',
|
|
49
|
-
default: (() => targets.includes(types_js_1.Tags.client) ||
|
|
51
|
+
default: (() => targets.includes(types_js_1.Tags.client) ||
|
|
52
|
+
targets.includes(types_js_1.Tags.typescript) ||
|
|
53
|
+
targets.includes(types_js_1.Tags.angular)
|
|
50
54
|
? 'codegen.ts'
|
|
51
55
|
: 'codegen.yml')(),
|
|
52
56
|
validate: str => {
|
|
@@ -136,7 +140,10 @@ function getApplicationTypeChoices(possibleTargets) {
|
|
|
136
140
|
name: 'Application built with other framework or vanilla JS',
|
|
137
141
|
key: 'client',
|
|
138
142
|
value: [types_js_1.Tags.typescript, types_js_1.Tags.flow],
|
|
139
|
-
checked: possibleTargets.Browser &&
|
|
143
|
+
checked: possibleTargets.Browser &&
|
|
144
|
+
!possibleTargets.Angular &&
|
|
145
|
+
!possibleTargets.React &&
|
|
146
|
+
!possibleTargets.Stencil,
|
|
140
147
|
},
|
|
141
148
|
];
|
|
142
149
|
}
|
package/cjs/load.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.defaultDocumentsLoadOptions = exports.defaultSchemaLoadOptions = void 0;
|
|
|
4
4
|
exports.loadSchema = loadSchema;
|
|
5
5
|
exports.loadDocuments = loadDocuments;
|
|
6
6
|
const path_1 = require("path");
|
|
7
|
+
const graphql_1 = require("graphql");
|
|
7
8
|
const apollo_engine_loader_1 = require("@graphql-tools/apollo-engine-loader");
|
|
8
9
|
const code_file_loader_1 = require("@graphql-tools/code-file-loader");
|
|
9
10
|
const git_loader_1 = require("@graphql-tools/git-loader");
|
|
@@ -12,7 +13,6 @@ const graphql_file_loader_1 = require("@graphql-tools/graphql-file-loader");
|
|
|
12
13
|
const json_file_loader_1 = require("@graphql-tools/json-file-loader");
|
|
13
14
|
const load_1 = require("@graphql-tools/load");
|
|
14
15
|
const url_loader_1 = require("@graphql-tools/url-loader");
|
|
15
|
-
const graphql_1 = require("graphql");
|
|
16
16
|
exports.defaultSchemaLoadOptions = {
|
|
17
17
|
assumeValidSDL: true,
|
|
18
18
|
sort: true,
|
|
@@ -91,7 +91,10 @@ async function loadDocuments(documentPointers, config) {
|
|
|
91
91
|
throw error;
|
|
92
92
|
}
|
|
93
93
|
// For other errors, we need to add an error message with documentPointers, so it's better for DevX
|
|
94
|
-
throw new Error([
|
|
94
|
+
throw new Error([
|
|
95
|
+
`Failed to load documents from ${Object.keys(documentPointers).join(',')}:`,
|
|
96
|
+
printError(error),
|
|
97
|
+
].join('\n'));
|
|
95
98
|
}
|
|
96
99
|
}
|
|
97
100
|
const printError = (error) => {
|
package/cjs/utils/patterns.js
CHANGED
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.sortPatterns = exports.makeLocalPatternSet = exports.makeGlobalPatternSet = exports.makeShouldRebuild = exports.allAffirmativePatternsFromPatternSets = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const path_1 = require("path");
|
|
6
|
-
const utils_1 = require("@graphql-tools/utils");
|
|
7
|
-
const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
|
|
8
6
|
const is_glob_1 = tslib_1.__importDefault(require("is-glob"));
|
|
9
7
|
const micromatch_1 = tslib_1.__importDefault(require("micromatch"));
|
|
8
|
+
const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
|
|
9
|
+
const utils_1 = require("@graphql-tools/utils");
|
|
10
10
|
const helpers_js_1 = require("./helpers.js");
|
|
11
11
|
/**
|
|
12
12
|
* Flatten a list of pattern sets to be a list of only the affirmative patterns
|
|
@@ -44,7 +44,10 @@ const makeShouldRebuild = ({ globalPatternSet, localPatternSets, }) => {
|
|
|
44
44
|
const localMatchers = localPatternSets.map(localPatternSet => {
|
|
45
45
|
return (path) => {
|
|
46
46
|
// Is path negated by any negating watch pattern?
|
|
47
|
-
if (matchesAnyNegatedPattern(path, [
|
|
47
|
+
if (matchesAnyNegatedPattern(path, [
|
|
48
|
+
...globalPatternSet.watch.negated,
|
|
49
|
+
...localPatternSet.watch.negated,
|
|
50
|
+
])) {
|
|
48
51
|
// Short circut: negations in watch patterns take priority
|
|
49
52
|
return false;
|
|
50
53
|
}
|
|
@@ -61,7 +64,10 @@ const makeShouldRebuild = ({ globalPatternSet, localPatternSets, }) => {
|
|
|
61
64
|
...globalPatternSet.documents.affirmative,
|
|
62
65
|
...localPatternSet.documents.affirmative,
|
|
63
66
|
]) &&
|
|
64
|
-
!matchesAnyNegatedPattern(path, [
|
|
67
|
+
!matchesAnyNegatedPattern(path, [
|
|
68
|
+
...globalPatternSet.documents.negated,
|
|
69
|
+
...localPatternSet.documents.negated,
|
|
70
|
+
])) {
|
|
65
71
|
return true;
|
|
66
72
|
}
|
|
67
73
|
// Does path match schemas patterns (without being negated)?
|
|
@@ -69,7 +75,10 @@ const makeShouldRebuild = ({ globalPatternSet, localPatternSets, }) => {
|
|
|
69
75
|
...globalPatternSet.schemas.affirmative,
|
|
70
76
|
...localPatternSet.schemas.affirmative,
|
|
71
77
|
]) &&
|
|
72
|
-
!matchesAnyNegatedPattern(path, [
|
|
78
|
+
!matchesAnyNegatedPattern(path, [
|
|
79
|
+
...globalPatternSet.schemas.negated,
|
|
80
|
+
...localPatternSet.schemas.negated,
|
|
81
|
+
])) {
|
|
73
82
|
return true;
|
|
74
83
|
}
|
|
75
84
|
// Otherwise, there is no match
|
|
@@ -100,7 +109,9 @@ const makeGlobalPatternSet = (initialContext) => {
|
|
|
100
109
|
const config = initialContext.getConfig();
|
|
101
110
|
return {
|
|
102
111
|
watch: (0, exports.sortPatterns)([
|
|
103
|
-
...(typeof config.watch === 'boolean'
|
|
112
|
+
...(typeof config.watch === 'boolean'
|
|
113
|
+
? []
|
|
114
|
+
: (0, plugin_helpers_1.normalizeInstanceOrArray)(config.watch ?? [])),
|
|
104
115
|
(0, path_1.relative)(process.cwd(), initialContext.filepath),
|
|
105
116
|
]),
|
|
106
117
|
schemas: (0, exports.sortPatterns)(makePatternsFromSchemas((0, plugin_helpers_1.normalizeInstanceOrArray)(config.schema))),
|
package/cjs/utils/watcher.js
CHANGED
|
@@ -3,18 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createWatcher = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const path_1 = require("path");
|
|
6
|
-
const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
|
|
7
6
|
const debounce_1 = tslib_1.__importDefault(require("debounce"));
|
|
8
|
-
const micromatch_1 = tslib_1.__importDefault(require("micromatch"));
|
|
9
7
|
const log_symbols_1 = tslib_1.__importDefault(require("log-symbols"));
|
|
8
|
+
const micromatch_1 = tslib_1.__importDefault(require("micromatch"));
|
|
9
|
+
const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
|
|
10
10
|
const codegen_js_1 = require("../codegen.js");
|
|
11
11
|
const config_js_1 = require("../config.js");
|
|
12
12
|
const hooks_js_1 = require("../hooks.js");
|
|
13
|
-
const
|
|
13
|
+
const abort_controller_polyfill_js_1 = require("./abort-controller-polyfill.js");
|
|
14
14
|
const debugging_js_1 = require("./debugging.js");
|
|
15
|
+
const file_system_js_1 = require("./file-system.js");
|
|
15
16
|
const logger_js_1 = require("./logger.js");
|
|
16
17
|
const patterns_js_1 = require("./patterns.js");
|
|
17
|
-
const abort_controller_polyfill_js_1 = require("./abort-controller-polyfill.js");
|
|
18
18
|
function log(msg) {
|
|
19
19
|
// double spaces to inline the message with Listr
|
|
20
20
|
(0, logger_js_1.getLogger)().info(` ${msg}`);
|
|
@@ -29,8 +29,14 @@ const createWatcher = (initialContext, onNext) => {
|
|
|
29
29
|
const localPatternSets = Object.keys(config.generates)
|
|
30
30
|
.map(filename => (0, plugin_helpers_1.normalizeOutputParam)(config.generates[filename]))
|
|
31
31
|
.map(conf => (0, patterns_js_1.makeLocalPatternSet)(conf));
|
|
32
|
-
const allAffirmativePatterns = (0, patterns_js_1.allAffirmativePatternsFromPatternSets)([
|
|
33
|
-
|
|
32
|
+
const allAffirmativePatterns = (0, patterns_js_1.allAffirmativePatternsFromPatternSets)([
|
|
33
|
+
globalPatternSet,
|
|
34
|
+
...localPatternSets,
|
|
35
|
+
]);
|
|
36
|
+
const shouldRebuild = (0, patterns_js_1.makeShouldRebuild)({
|
|
37
|
+
globalPatternSet,
|
|
38
|
+
localPatternSets,
|
|
39
|
+
});
|
|
34
40
|
let watcherSubscription;
|
|
35
41
|
const runWatcher = async (abortSignal) => {
|
|
36
42
|
const watchDirectory = await findHighestCommonDirectory(allAffirmativePatterns);
|
package/esm/codegen.js
CHANGED
|
@@ -2,17 +2,17 @@ import fs from 'fs';
|
|
|
2
2
|
import { createRequire } from 'module';
|
|
3
3
|
import { cpus } from 'os';
|
|
4
4
|
import path from 'path';
|
|
5
|
+
import { buildASTSchema, GraphQLError, isSchema } from 'graphql';
|
|
6
|
+
import { Listr } from 'listr2';
|
|
5
7
|
import { codegen } from '@graphql-codegen/core';
|
|
6
8
|
import { getCachedDocumentNodeFromSchema, normalizeConfig, normalizeImportExtension, normalizeInstanceOrArray, normalizeOutputParam, } from '@graphql-codegen/plugin-helpers';
|
|
7
9
|
import { NoTypeDefinitionsFound } from '@graphql-tools/load';
|
|
8
|
-
import { buildASTSchema, GraphQLError, isSchema } from 'graphql';
|
|
9
10
|
import { mergeTypeDefs } from '@graphql-tools/merge';
|
|
10
|
-
import { Listr } from 'listr2';
|
|
11
11
|
import { ensureContext } from './config.js';
|
|
12
|
+
import { getDocumentTransform } from './documentTransforms.js';
|
|
12
13
|
import { getPluginByName } from './plugins.js';
|
|
13
14
|
import { getPresetByName } from './presets.js';
|
|
14
15
|
import { debugLog, printLogs } from './utils/debugging.js';
|
|
15
|
-
import { getDocumentTransform } from './documentTransforms.js';
|
|
16
16
|
/**
|
|
17
17
|
* Poor mans ESM detection.
|
|
18
18
|
* Looking at this and you have a better method?
|
|
@@ -187,7 +187,10 @@ export async function executeCodegen(input) {
|
|
|
187
187
|
debugLog(`[CLI] Loading Schemas`);
|
|
188
188
|
const schemaPointerMap = {};
|
|
189
189
|
const parsedSchemas = [];
|
|
190
|
-
const allSchemaDenormalizedPointers = [
|
|
190
|
+
const allSchemaDenormalizedPointers = [
|
|
191
|
+
...rootSchemas,
|
|
192
|
+
...outputSpecificSchemas,
|
|
193
|
+
];
|
|
191
194
|
for (const denormalizedPtr of allSchemaDenormalizedPointers) {
|
|
192
195
|
if (isSchema(denormalizedPtr)) {
|
|
193
196
|
parsedSchemas.push(denormalizedPtr);
|
|
@@ -199,7 +202,8 @@ export async function executeCodegen(input) {
|
|
|
199
202
|
Object.assign(schemaPointerMap, denormalizedPtr);
|
|
200
203
|
}
|
|
201
204
|
}
|
|
202
|
-
const hash = JSON.stringify(schemaPointerMap) +
|
|
205
|
+
const hash = JSON.stringify(schemaPointerMap) +
|
|
206
|
+
parsedSchemas.map(getJsObjectId).join(',');
|
|
203
207
|
const result = await cache('schema', hash, async () => {
|
|
204
208
|
// collect parsed schemas
|
|
205
209
|
const schemasToMerge = [...parsedSchemas];
|
|
@@ -226,7 +230,10 @@ export async function executeCodegen(input) {
|
|
|
226
230
|
task: wrapTask(async () => {
|
|
227
231
|
debugLog(`[CLI] Loading Documents`);
|
|
228
232
|
const documentPointerMap = {};
|
|
229
|
-
const allDocumentsDenormalizedPointers = [
|
|
233
|
+
const allDocumentsDenormalizedPointers = [
|
|
234
|
+
...rootDocuments,
|
|
235
|
+
...outputSpecificDocuments,
|
|
236
|
+
];
|
|
230
237
|
for (const denormalizedPtr of allDocumentsDenormalizedPointers) {
|
|
231
238
|
if (typeof denormalizedPtr === 'string') {
|
|
232
239
|
documentPointerMap[denormalizedPtr] = {};
|
|
@@ -244,7 +251,8 @@ export async function executeCodegen(input) {
|
|
|
244
251
|
};
|
|
245
252
|
}
|
|
246
253
|
catch (error) {
|
|
247
|
-
if (error instanceof NoTypeDefinitionsFound &&
|
|
254
|
+
if (error instanceof NoTypeDefinitionsFound &&
|
|
255
|
+
config.ignoreNoDocuments) {
|
|
248
256
|
return {
|
|
249
257
|
documents: [],
|
|
250
258
|
};
|
|
@@ -351,7 +359,9 @@ export async function executeCodegen(input) {
|
|
|
351
359
|
exitOnError: false,
|
|
352
360
|
};
|
|
353
361
|
});
|
|
354
|
-
return task.newListr(generateTasks, {
|
|
362
|
+
return task.newListr(generateTasks, {
|
|
363
|
+
concurrent: cpus().length || 1,
|
|
364
|
+
});
|
|
355
365
|
},
|
|
356
366
|
},
|
|
357
367
|
], {
|
|
@@ -378,7 +388,9 @@ export async function executeCodegen(input) {
|
|
|
378
388
|
const errors = executedContext.errors.map(subErr => subErr.message || subErr.toString());
|
|
379
389
|
error = new AggregateError(executedContext.errors, String(errors.join('\n\n')));
|
|
380
390
|
// Best-effort to all stack traces for debugging
|
|
381
|
-
error.stack = `${error.stack}\n\n${executedContext.errors
|
|
391
|
+
error.stack = `${error.stack}\n\n${executedContext.errors
|
|
392
|
+
.map(subErr => subErr.stack)
|
|
393
|
+
.join('\n\n')}`;
|
|
382
394
|
}
|
|
383
395
|
return { result, error };
|
|
384
396
|
}
|
package/esm/config.js
CHANGED
|
@@ -2,15 +2,15 @@ import { createHash } from 'crypto';
|
|
|
2
2
|
import { promises } from 'fs';
|
|
3
3
|
import { createRequire } from 'module';
|
|
4
4
|
import { resolve } from 'path';
|
|
5
|
-
import { createNoopProfiler, createProfiler, getCachedDocumentNodeFromSchema, } from '@graphql-codegen/plugin-helpers';
|
|
6
5
|
import { cosmiconfig, defaultLoaders } from 'cosmiconfig';
|
|
7
|
-
import { createJiti } from 'jiti';
|
|
8
6
|
import { print } from 'graphql';
|
|
7
|
+
import { createJiti } from 'jiti';
|
|
9
8
|
import { env } from 'string-env-interpolation';
|
|
10
9
|
import yaml from 'yaml';
|
|
11
10
|
import yargs from 'yargs';
|
|
11
|
+
import { createNoopProfiler, createProfiler, getCachedDocumentNodeFromSchema, } from '@graphql-codegen/plugin-helpers';
|
|
12
12
|
import { findAndLoadGraphQLConfig } from './graphql-config.js';
|
|
13
|
-
import { defaultDocumentsLoadOptions, defaultSchemaLoadOptions, loadDocuments, loadSchema } from './load.js';
|
|
13
|
+
import { defaultDocumentsLoadOptions, defaultSchemaLoadOptions, loadDocuments, loadSchema, } from './load.js';
|
|
14
14
|
const { lstat } = promises;
|
|
15
15
|
export function generateSearchPlaces(moduleName) {
|
|
16
16
|
const extensions = ['json', 'yaml', 'yml', 'js', 'ts', 'config.js'];
|
|
@@ -316,7 +316,9 @@ export class CodegenContext {
|
|
|
316
316
|
const config = this.getConfig(defaultDocumentsLoadOptions);
|
|
317
317
|
if (this._graphqlConfig) {
|
|
318
318
|
// TODO: pointer won't work here
|
|
319
|
-
return addHashToDocumentFiles(this._graphqlConfig
|
|
319
|
+
return addHashToDocumentFiles(this._graphqlConfig
|
|
320
|
+
.getProject(this._project)
|
|
321
|
+
.loadDocuments(pointer, { ...config, ...config.config }));
|
|
320
322
|
}
|
|
321
323
|
return addHashToDocumentFiles(loadDocuments(pointer, config));
|
|
322
324
|
}
|
|
@@ -10,7 +10,11 @@ export async function getDocumentTransform(documentTransform, loader, defaultNam
|
|
|
10
10
|
if (isTransformFileConfig(documentTransform)) {
|
|
11
11
|
const name = Object.keys(documentTransform)[0];
|
|
12
12
|
const transformObject = await getDocumentTransformByName(name, loader);
|
|
13
|
-
return {
|
|
13
|
+
return {
|
|
14
|
+
name,
|
|
15
|
+
transformObject,
|
|
16
|
+
config: Object.values(documentTransform)[0],
|
|
17
|
+
};
|
|
14
18
|
}
|
|
15
19
|
throw new Error(`
|
|
16
20
|
An unknown format document transform: '${defaultName}'.
|
package/esm/generate-and-save.js
CHANGED
|
@@ -6,8 +6,8 @@ import { ensureContext } from './config.js';
|
|
|
6
6
|
import { lifecycleHooks } from './hooks.js';
|
|
7
7
|
import { debugLog } from './utils/debugging.js';
|
|
8
8
|
import { mkdirp, readFile, unlinkFile, writeFile } from './utils/file-system.js';
|
|
9
|
-
import { createWatcher } from './utils/watcher.js';
|
|
10
9
|
import { getLogger } from './utils/logger.js';
|
|
10
|
+
import { createWatcher } from './utils/watcher.js';
|
|
11
11
|
const hash = (content) => createHash('sha1').update(content).digest('base64');
|
|
12
12
|
export async function generate(input, saveToFile = true) {
|
|
13
13
|
const context = ensureContext(input);
|
package/esm/graphql-config.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { loadConfig } from 'graphql-config';
|
|
1
2
|
import { ApolloEngineLoader } from '@graphql-tools/apollo-engine-loader';
|
|
2
3
|
import { CodeFileLoader } from '@graphql-tools/code-file-loader';
|
|
3
4
|
import { GitLoader } from '@graphql-tools/git-loader';
|
|
4
5
|
import { GithubLoader } from '@graphql-tools/github-loader';
|
|
5
|
-
import { loadConfig } from 'graphql-config';
|
|
6
6
|
export const CodegenExtension = (api) => {
|
|
7
7
|
// Schema
|
|
8
8
|
api.loaders.schema.register(new CodeFileLoader({
|
package/esm/init/helpers.js
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import { readFileSync, writeFileSync } from 'fs';
|
|
2
2
|
import { relative, resolve } from 'path';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import detectIndent from 'detect-indent';
|
|
3
5
|
import generate from '@babel/generator';
|
|
4
6
|
import template from '@babel/template';
|
|
5
7
|
import * as t from '@babel/types';
|
|
6
|
-
import chalk from 'chalk';
|
|
7
|
-
import detectIndent from 'detect-indent';
|
|
8
8
|
import { getLatestVersion } from '../utils/get-latest-version.js';
|
|
9
9
|
import { Tags } from './types.js';
|
|
10
10
|
function jsObjectToBabelObjectExpression(obj) {
|
|
11
11
|
const objExp = t.objectExpression([]);
|
|
12
12
|
for (const [key, val] of Object.entries(obj)) {
|
|
13
13
|
if (Array.isArray(val)) {
|
|
14
|
-
objExp.properties.push(t.objectProperty(/^[a-zA-Z0-9]+$/.test(key) ? t.identifier(key) : t.stringLiteral(key), t.arrayExpression(val.map(v =>
|
|
14
|
+
objExp.properties.push(t.objectProperty(/^[a-zA-Z0-9]+$/.test(key) ? t.identifier(key) : t.stringLiteral(key), t.arrayExpression(val.map(v => typeof v === 'object'
|
|
15
|
+
? jsObjectToBabelObjectExpression(v)
|
|
16
|
+
: t.valueToNode(v)))));
|
|
15
17
|
}
|
|
16
18
|
else {
|
|
17
|
-
objExp.properties.push(t.objectProperty(/^[a-zA-Z0-9]+$/.test(key) ? t.identifier(key) : t.stringLiteral(key), typeof val === 'object'
|
|
19
|
+
objExp.properties.push(t.objectProperty(/^[a-zA-Z0-9]+$/.test(key) ? t.identifier(key) : t.stringLiteral(key), typeof val === 'object'
|
|
20
|
+
? jsObjectToBabelObjectExpression(val)
|
|
21
|
+
: t.valueToNode(val)));
|
|
18
22
|
}
|
|
19
23
|
}
|
|
20
24
|
return objExp;
|
package/esm/init/plugins.js
CHANGED
|
@@ -7,7 +7,9 @@ export const plugins = [
|
|
|
7
7
|
value: 'typescript',
|
|
8
8
|
pathInRepo: 'typescript/typescript',
|
|
9
9
|
available: hasTag(Tags.typescript),
|
|
10
|
-
shouldBeSelected: tags => oneOf(tags, Tags.angular, Tags.stencil) ||
|
|
10
|
+
shouldBeSelected: tags => oneOf(tags, Tags.angular, Tags.stencil) ||
|
|
11
|
+
allOf(tags, Tags.typescript, Tags.react) ||
|
|
12
|
+
noneOf(tags, Tags.flow),
|
|
11
13
|
defaultExtension: '.ts',
|
|
12
14
|
},
|
|
13
15
|
{
|
package/esm/init/questions.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { checkbox, input, select
|
|
1
|
+
import { checkbox, confirm, input, select } from '@inquirer/prompts';
|
|
2
2
|
import { grey } from './helpers.js';
|
|
3
3
|
import { plugins } from './plugins.js';
|
|
4
4
|
import { Tags } from './types.js';
|
|
@@ -16,7 +16,9 @@ export async function getAnswers(possibleTargets) {
|
|
|
16
16
|
validate: str => str.length > 0,
|
|
17
17
|
});
|
|
18
18
|
let documents;
|
|
19
|
-
if (targets.includes(Tags.client) ||
|
|
19
|
+
if (targets.includes(Tags.client) ||
|
|
20
|
+
targets.includes(Tags.angular) ||
|
|
21
|
+
targets.includes(Tags.stencil))
|
|
20
22
|
documents = await input({
|
|
21
23
|
message: 'Where are your operations and fragments?:',
|
|
22
24
|
default: getDocumentsDefaultValue(targets),
|
|
@@ -41,7 +43,9 @@ export async function getAnswers(possibleTargets) {
|
|
|
41
43
|
});
|
|
42
44
|
const config = await input({
|
|
43
45
|
message: 'How to name the config file?',
|
|
44
|
-
default: (() => targets.includes(Tags.client) ||
|
|
46
|
+
default: (() => targets.includes(Tags.client) ||
|
|
47
|
+
targets.includes(Tags.typescript) ||
|
|
48
|
+
targets.includes(Tags.angular)
|
|
45
49
|
? 'codegen.ts'
|
|
46
50
|
: 'codegen.yml')(),
|
|
47
51
|
validate: str => {
|
|
@@ -131,7 +135,10 @@ export function getApplicationTypeChoices(possibleTargets) {
|
|
|
131
135
|
name: 'Application built with other framework or vanilla JS',
|
|
132
136
|
key: 'client',
|
|
133
137
|
value: [Tags.typescript, Tags.flow],
|
|
134
|
-
checked: possibleTargets.Browser &&
|
|
138
|
+
checked: possibleTargets.Browser &&
|
|
139
|
+
!possibleTargets.Angular &&
|
|
140
|
+
!possibleTargets.React &&
|
|
141
|
+
!possibleTargets.Stencil,
|
|
135
142
|
},
|
|
136
143
|
];
|
|
137
144
|
}
|
package/esm/load.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { extname, join } from 'path';
|
|
2
|
+
import { GraphQLError } from 'graphql';
|
|
2
3
|
import { ApolloEngineLoader } from '@graphql-tools/apollo-engine-loader';
|
|
3
4
|
import { CodeFileLoader } from '@graphql-tools/code-file-loader';
|
|
4
5
|
import { GitLoader } from '@graphql-tools/git-loader';
|
|
@@ -7,7 +8,6 @@ import { GraphQLFileLoader } from '@graphql-tools/graphql-file-loader';
|
|
|
7
8
|
import { JsonFileLoader } from '@graphql-tools/json-file-loader';
|
|
8
9
|
import { loadDocuments as loadDocumentsToolkit, loadSchema as loadSchemaToolkit, NoTypeDefinitionsFound, } from '@graphql-tools/load';
|
|
9
10
|
import { UrlLoader } from '@graphql-tools/url-loader';
|
|
10
|
-
import { GraphQLError } from 'graphql';
|
|
11
11
|
export const defaultSchemaLoadOptions = {
|
|
12
12
|
assumeValidSDL: true,
|
|
13
13
|
sort: true,
|
|
@@ -86,7 +86,10 @@ export async function loadDocuments(documentPointers, config) {
|
|
|
86
86
|
throw error;
|
|
87
87
|
}
|
|
88
88
|
// For other errors, we need to add an error message with documentPointers, so it's better for DevX
|
|
89
|
-
throw new Error([
|
|
89
|
+
throw new Error([
|
|
90
|
+
`Failed to load documents from ${Object.keys(documentPointers).join(',')}:`,
|
|
91
|
+
printError(error),
|
|
92
|
+
].join('\n'));
|
|
90
93
|
}
|
|
91
94
|
}
|
|
92
95
|
const printError = (error) => {
|
package/esm/utils/file-system.js
CHANGED
package/esm/utils/patterns.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { isAbsolute, relative } from 'path';
|
|
2
|
-
import { isValidPath } from '@graphql-tools/utils';
|
|
3
|
-
import { normalizeInstanceOrArray } from '@graphql-codegen/plugin-helpers';
|
|
4
2
|
import isGlob from 'is-glob';
|
|
5
3
|
import mm from 'micromatch';
|
|
4
|
+
import { normalizeInstanceOrArray } from '@graphql-codegen/plugin-helpers';
|
|
5
|
+
import { isValidPath } from '@graphql-tools/utils';
|
|
6
6
|
import { isURL } from './helpers.js';
|
|
7
7
|
/**
|
|
8
8
|
* Flatten a list of pattern sets to be a list of only the affirmative patterns
|
|
@@ -39,7 +39,10 @@ export const makeShouldRebuild = ({ globalPatternSet, localPatternSets, }) => {
|
|
|
39
39
|
const localMatchers = localPatternSets.map(localPatternSet => {
|
|
40
40
|
return (path) => {
|
|
41
41
|
// Is path negated by any negating watch pattern?
|
|
42
|
-
if (matchesAnyNegatedPattern(path, [
|
|
42
|
+
if (matchesAnyNegatedPattern(path, [
|
|
43
|
+
...globalPatternSet.watch.negated,
|
|
44
|
+
...localPatternSet.watch.negated,
|
|
45
|
+
])) {
|
|
43
46
|
// Short circut: negations in watch patterns take priority
|
|
44
47
|
return false;
|
|
45
48
|
}
|
|
@@ -56,7 +59,10 @@ export const makeShouldRebuild = ({ globalPatternSet, localPatternSets, }) => {
|
|
|
56
59
|
...globalPatternSet.documents.affirmative,
|
|
57
60
|
...localPatternSet.documents.affirmative,
|
|
58
61
|
]) &&
|
|
59
|
-
!matchesAnyNegatedPattern(path, [
|
|
62
|
+
!matchesAnyNegatedPattern(path, [
|
|
63
|
+
...globalPatternSet.documents.negated,
|
|
64
|
+
...localPatternSet.documents.negated,
|
|
65
|
+
])) {
|
|
60
66
|
return true;
|
|
61
67
|
}
|
|
62
68
|
// Does path match schemas patterns (without being negated)?
|
|
@@ -64,7 +70,10 @@ export const makeShouldRebuild = ({ globalPatternSet, localPatternSets, }) => {
|
|
|
64
70
|
...globalPatternSet.schemas.affirmative,
|
|
65
71
|
...localPatternSet.schemas.affirmative,
|
|
66
72
|
]) &&
|
|
67
|
-
!matchesAnyNegatedPattern(path, [
|
|
73
|
+
!matchesAnyNegatedPattern(path, [
|
|
74
|
+
...globalPatternSet.schemas.negated,
|
|
75
|
+
...localPatternSet.schemas.negated,
|
|
76
|
+
])) {
|
|
68
77
|
return true;
|
|
69
78
|
}
|
|
70
79
|
// Otherwise, there is no match
|
|
@@ -94,7 +103,9 @@ export const makeGlobalPatternSet = (initialContext) => {
|
|
|
94
103
|
const config = initialContext.getConfig();
|
|
95
104
|
return {
|
|
96
105
|
watch: sortPatterns([
|
|
97
|
-
...(typeof config.watch === 'boolean'
|
|
106
|
+
...(typeof config.watch === 'boolean'
|
|
107
|
+
? []
|
|
108
|
+
: normalizeInstanceOrArray(config.watch ?? [])),
|
|
98
109
|
relative(process.cwd(), initialContext.filepath),
|
|
99
110
|
]),
|
|
100
111
|
schemas: sortPatterns(makePatternsFromSchemas(normalizeInstanceOrArray(config.schema))),
|
package/esm/utils/watcher.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { normalizeOutputParam } from '@graphql-codegen/plugin-helpers';
|
|
1
|
+
import { isAbsolute, join, relative, resolve, sep } from 'path';
|
|
3
2
|
import debounce from 'debounce';
|
|
4
|
-
import mm from 'micromatch';
|
|
5
3
|
import logSymbols from 'log-symbols';
|
|
4
|
+
import mm from 'micromatch';
|
|
5
|
+
import { normalizeOutputParam } from '@graphql-codegen/plugin-helpers';
|
|
6
6
|
import { executeCodegen } from '../codegen.js';
|
|
7
7
|
import { loadContext } from '../config.js';
|
|
8
8
|
import { lifecycleHooks } from '../hooks.js';
|
|
9
|
-
import {
|
|
9
|
+
import { AbortController } from './abort-controller-polyfill.js';
|
|
10
10
|
import { debugLog } from './debugging.js';
|
|
11
|
+
import { access } from './file-system.js';
|
|
11
12
|
import { getLogger } from './logger.js';
|
|
12
13
|
import { allAffirmativePatternsFromPatternSets, makeGlobalPatternSet, makeLocalPatternSet, makeShouldRebuild, } from './patterns.js';
|
|
13
|
-
import { AbortController } from './abort-controller-polyfill.js';
|
|
14
14
|
function log(msg) {
|
|
15
15
|
// double spaces to inline the message with Listr
|
|
16
16
|
getLogger().info(` ${msg}`);
|
|
@@ -25,8 +25,14 @@ export const createWatcher = (initialContext, onNext) => {
|
|
|
25
25
|
const localPatternSets = Object.keys(config.generates)
|
|
26
26
|
.map(filename => normalizeOutputParam(config.generates[filename]))
|
|
27
27
|
.map(conf => makeLocalPatternSet(conf));
|
|
28
|
-
const allAffirmativePatterns = allAffirmativePatternsFromPatternSets([
|
|
29
|
-
|
|
28
|
+
const allAffirmativePatterns = allAffirmativePatternsFromPatternSets([
|
|
29
|
+
globalPatternSet,
|
|
30
|
+
...localPatternSets,
|
|
31
|
+
]);
|
|
32
|
+
const shouldRebuild = makeShouldRebuild({
|
|
33
|
+
globalPatternSet,
|
|
34
|
+
localPatternSets,
|
|
35
|
+
});
|
|
30
36
|
let watcherSubscription;
|
|
31
37
|
const runWatcher = async (abortSignal) => {
|
|
32
38
|
const watchDirectory = await findHighestCommonDirectory(allAffirmativePatterns);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/cli",
|
|
3
|
-
"version": "6.2.
|
|
3
|
+
"version": "6.2.2-alpha-20260405034159-39fcc54cea95aedd7dbb252bb8d3602db33669bc",
|
|
4
4
|
"peerDependenciesMeta": {
|
|
5
5
|
"@parcel/watcher": {
|
|
6
6
|
"optional": true
|
|
@@ -24,25 +24,25 @@
|
|
|
24
24
|
"@graphql-tools/graphql-file-loader": "^8.1.11",
|
|
25
25
|
"@graphql-tools/json-file-loader": "^8.0.26",
|
|
26
26
|
"@graphql-tools/load": "^8.1.8",
|
|
27
|
-
"@graphql-tools/url-loader": "^9.0.6",
|
|
28
27
|
"@graphql-tools/merge": "^9.0.6",
|
|
28
|
+
"@graphql-tools/url-loader": "^9.0.6",
|
|
29
29
|
"@graphql-tools/utils": "^11.0.0",
|
|
30
|
-
"@inquirer/prompts": "^
|
|
30
|
+
"@inquirer/prompts": "^8.0.0",
|
|
31
31
|
"@whatwg-node/fetch": "^0.10.0",
|
|
32
32
|
"chalk": "^4.1.0",
|
|
33
33
|
"cosmiconfig": "^9.0.0",
|
|
34
|
-
"debounce": "^
|
|
34
|
+
"debounce": "^3.0.0",
|
|
35
35
|
"detect-indent": "^6.0.0",
|
|
36
36
|
"graphql-config": "^5.1.6",
|
|
37
37
|
"is-glob": "^4.0.1",
|
|
38
38
|
"jiti": "^2.3.0",
|
|
39
39
|
"json-to-pretty-yaml": "^1.2.2",
|
|
40
|
-
"listr2": "^
|
|
40
|
+
"listr2": "^10.0.0",
|
|
41
41
|
"log-symbols": "^4.0.0",
|
|
42
42
|
"micromatch": "^4.0.5",
|
|
43
43
|
"shell-quote": "^1.7.3",
|
|
44
44
|
"string-env-interpolation": "^1.0.1",
|
|
45
|
-
"ts-log": "^
|
|
45
|
+
"ts-log": "^3.0.0",
|
|
46
46
|
"tslib": "^2.4.0",
|
|
47
47
|
"yaml": "^2.3.1",
|
|
48
48
|
"yargs": "^17.0.0"
|
package/typings/config.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Profiler, Types } from '@graphql-codegen/plugin-helpers';
|
|
2
1
|
import { GraphQLSchema } from 'graphql';
|
|
3
2
|
import { GraphQLConfig } from 'graphql-config';
|
|
3
|
+
import { Profiler, Types } from '@graphql-codegen/plugin-helpers';
|
|
4
4
|
export type CodegenConfig = Types.Config;
|
|
5
5
|
export type YamlCliFlags = {
|
|
6
6
|
config: string;
|
package/typings/config.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Profiler, Types } from '@graphql-codegen/plugin-helpers';
|
|
2
1
|
import { GraphQLSchema } from 'graphql';
|
|
3
2
|
import { GraphQLConfig } from 'graphql-config';
|
|
3
|
+
import { Profiler, Types } from '@graphql-codegen/plugin-helpers';
|
|
4
4
|
export type CodegenConfig = Types.Config;
|
|
5
5
|
export type YamlCliFlags = {
|
|
6
6
|
config: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Answers, type PluginOption
|
|
1
|
+
import { Tags, type Answers, type PluginOption } from './types.cjs';
|
|
2
2
|
export declare function getAnswers(possibleTargets: Record<Tags, boolean>): Promise<Answers>;
|
|
3
3
|
export declare function getApplicationTypeChoices(possibleTargets: Record<Tags, boolean>): {
|
|
4
4
|
name: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Answers, type PluginOption
|
|
1
|
+
import { Tags, type Answers, type PluginOption } from './types.js';
|
|
2
2
|
export declare function getAnswers(possibleTargets: Record<Tags, boolean>): Promise<Answers>;
|
|
3
3
|
export declare function getApplicationTypeChoices(possibleTargets: Record<Tags, boolean>): {
|
|
4
4
|
name: string;
|
package/typings/load.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { GraphQLSchema } from 'graphql';
|
|
1
2
|
import { Types } from '@graphql-codegen/plugin-helpers';
|
|
2
3
|
import { UnnormalizedTypeDefPointer } from '@graphql-tools/load';
|
|
3
|
-
import { GraphQLSchema } from 'graphql';
|
|
4
4
|
export declare const defaultSchemaLoadOptions: {
|
|
5
5
|
assumeValidSDL: boolean;
|
|
6
6
|
sort: boolean;
|
package/typings/load.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { GraphQLSchema } from 'graphql';
|
|
1
2
|
import { Types } from '@graphql-codegen/plugin-helpers';
|
|
2
3
|
import { UnnormalizedTypeDefPointer } from '@graphql-tools/load';
|
|
3
|
-
import { GraphQLSchema } from 'graphql';
|
|
4
4
|
export declare const defaultSchemaLoadOptions: {
|
|
5
5
|
assumeValidSDL: boolean;
|
|
6
6
|
sort: boolean;
|