@graphql-codegen/cli 2.7.0 → 2.7.1-alpha-223b75f49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/bin.js +13 -0
- package/cjs/cli.js +60 -0
- package/cjs/codegen.js +319 -0
- package/cjs/config.js +303 -0
- package/cjs/generate-and-save.js +110 -0
- package/cjs/graphql-config.js +69 -0
- package/cjs/hooks.js +87 -0
- package/cjs/index.js +13 -0
- package/cjs/init/helpers.js +64 -0
- package/cjs/init/index.js +60 -0
- package/cjs/init/plugins.js +163 -0
- package/cjs/init/questions.js +147 -0
- package/cjs/init/targets.js +44 -0
- package/cjs/init/types.js +14 -0
- package/cjs/load.js +93 -0
- package/cjs/package.json +1 -0
- package/cjs/plugins.js +45 -0
- package/cjs/presets.js +50 -0
- package/cjs/utils/cli-error.js +25 -0
- package/cjs/utils/debugging.js +27 -0
- package/cjs/utils/file-system.js +26 -0
- package/cjs/utils/logger.js +25 -0
- package/cjs/utils/watcher.js +140 -0
- package/esm/bin.js +11 -0
- package/esm/cli.js +32 -0
- package/esm/codegen.js +314 -0
- package/esm/config.js +290 -0
- package/esm/generate-and-save.js +105 -0
- package/esm/graphql-config.js +64 -0
- package/esm/hooks.js +83 -0
- package/esm/index.js +7 -0
- package/esm/init/helpers.js +55 -0
- package/esm/init/index.js +55 -0
- package/esm/init/plugins.js +160 -0
- package/esm/init/questions.js +140 -0
- package/esm/init/targets.js +40 -0
- package/esm/init/types.js +11 -0
- package/esm/load.js +88 -0
- package/esm/plugins.js +41 -0
- package/esm/presets.js +46 -0
- package/esm/utils/cli-error.js +20 -0
- package/esm/utils/debugging.js +21 -0
- package/esm/utils/file-system.js +19 -0
- package/esm/utils/logger.js +18 -0
- package/esm/utils/watcher.js +135 -0
- package/package.json +33 -29
- package/typings/bin.d.ts +2 -0
- package/{cli.d.ts → typings/cli.d.ts} +0 -0
- package/{codegen.d.ts → typings/codegen.d.ts} +1 -1
- package/{config.d.ts → typings/config.d.ts} +0 -0
- package/{generate-and-save.d.ts → typings/generate-and-save.d.ts} +1 -1
- package/{graphql-config.d.ts → typings/graphql-config.d.ts} +0 -0
- package/{hooks.d.ts → typings/hooks.d.ts} +0 -0
- package/typings/index.d.ts +7 -0
- package/{init → typings/init}/helpers.d.ts +1 -1
- package/{init → typings/init}/index.d.ts +0 -0
- package/{init → typings/init}/plugins.d.ts +1 -1
- package/{init → typings/init}/questions.d.ts +1 -1
- package/{init → typings/init}/targets.d.ts +1 -1
- package/{init → typings/init}/types.d.ts +0 -0
- package/{load.d.ts → typings/load.d.ts} +0 -0
- package/{plugins.d.ts → typings/plugins.d.ts} +0 -0
- package/{presets.d.ts → typings/presets.d.ts} +0 -0
- package/{utils → typings/utils}/cli-error.d.ts +0 -0
- package/{utils → typings/utils}/debugging.d.ts +0 -0
- package/{utils → typings/utils}/file-system.d.ts +0 -0
- package/{utils → typings/utils}/logger.d.ts +0 -0
- package/{utils → typings/utils}/watcher.d.ts +1 -1
- package/bin.d.ts +0 -1
- package/bin.js +0 -1891
- package/index.d.ts +0 -7
- package/index.js +0 -1902
- package/index.mjs +0 -1858
- package/utils/indentString.d.ts +0 -26
- package/utils/listr-renderer.d.ts +0 -18
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { executeCodegen } from '../codegen.js';
|
|
2
|
+
import { normalizeInstanceOrArray, normalizeOutputParam } from '@graphql-codegen/plugin-helpers';
|
|
3
|
+
import isGlob from 'is-glob';
|
|
4
|
+
import debounce from 'debounce';
|
|
5
|
+
import logSymbols from 'log-symbols';
|
|
6
|
+
import { debugLog } from './debugging.js';
|
|
7
|
+
import { getLogger } from './logger.js';
|
|
8
|
+
import { join } from 'path';
|
|
9
|
+
import { lifecycleHooks } from '../hooks.js';
|
|
10
|
+
import { loadContext } from '../config.js';
|
|
11
|
+
import { isValidPath } from '@graphql-tools/utils';
|
|
12
|
+
function log(msg) {
|
|
13
|
+
// double spaces to inline the message with Listr
|
|
14
|
+
getLogger().info(` ${msg}`);
|
|
15
|
+
}
|
|
16
|
+
function emitWatching() {
|
|
17
|
+
log(`${logSymbols.info} Watching for changes...`);
|
|
18
|
+
}
|
|
19
|
+
export const createWatcher = (initalContext, onNext) => {
|
|
20
|
+
debugLog(`[Watcher] Starting watcher...`);
|
|
21
|
+
let config = initalContext.getConfig();
|
|
22
|
+
const files = [initalContext.filepath].filter(a => a);
|
|
23
|
+
const documents = normalizeInstanceOrArray(config.documents);
|
|
24
|
+
const schemas = normalizeInstanceOrArray(config.schema);
|
|
25
|
+
// Add schemas and documents from "generates"
|
|
26
|
+
Object.keys(config.generates)
|
|
27
|
+
.map(filename => normalizeOutputParam(config.generates[filename]))
|
|
28
|
+
.forEach(conf => {
|
|
29
|
+
schemas.push(...normalizeInstanceOrArray(conf.schema));
|
|
30
|
+
documents.push(...normalizeInstanceOrArray(conf.documents));
|
|
31
|
+
});
|
|
32
|
+
if (documents) {
|
|
33
|
+
documents.forEach(doc => {
|
|
34
|
+
if (typeof doc === 'string') {
|
|
35
|
+
files.push(doc);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
files.push(...Object.keys(doc));
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
schemas.forEach((schema) => {
|
|
43
|
+
if (isGlob(schema) || isValidPath(schema)) {
|
|
44
|
+
files.push(schema);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
if (typeof config.watch !== 'boolean') {
|
|
48
|
+
files.push(...normalizeInstanceOrArray(config.watch));
|
|
49
|
+
}
|
|
50
|
+
let watcher;
|
|
51
|
+
const runWatcher = async () => {
|
|
52
|
+
var _a, _b;
|
|
53
|
+
const chokidar = await import('chokidar');
|
|
54
|
+
let isShutdown = false;
|
|
55
|
+
const debouncedExec = debounce(() => {
|
|
56
|
+
if (!isShutdown) {
|
|
57
|
+
executeCodegen(initalContext)
|
|
58
|
+
.then(onNext, () => Promise.resolve())
|
|
59
|
+
.then(() => emitWatching());
|
|
60
|
+
}
|
|
61
|
+
}, 100);
|
|
62
|
+
emitWatching();
|
|
63
|
+
const ignored = [];
|
|
64
|
+
Object.keys(config.generates)
|
|
65
|
+
.map(filename => ({ filename, config: normalizeOutputParam(config.generates[filename]) }))
|
|
66
|
+
.forEach(entry => {
|
|
67
|
+
if (entry.config.preset) {
|
|
68
|
+
const extension = entry.config.presetConfig && entry.config.presetConfig.extension;
|
|
69
|
+
if (extension) {
|
|
70
|
+
ignored.push(join(entry.filename, '**', '*' + extension));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
ignored.push(entry.filename);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
watcher = chokidar.watch(files, {
|
|
78
|
+
persistent: true,
|
|
79
|
+
ignoreInitial: true,
|
|
80
|
+
followSymlinks: true,
|
|
81
|
+
cwd: process.cwd(),
|
|
82
|
+
disableGlobbing: false,
|
|
83
|
+
usePolling: (_a = config.watchConfig) === null || _a === void 0 ? void 0 : _a.usePolling,
|
|
84
|
+
interval: (_b = config.watchConfig) === null || _b === void 0 ? void 0 : _b.interval,
|
|
85
|
+
depth: 99,
|
|
86
|
+
awaitWriteFinish: true,
|
|
87
|
+
ignorePermissionErrors: false,
|
|
88
|
+
atomic: true,
|
|
89
|
+
ignored,
|
|
90
|
+
});
|
|
91
|
+
debugLog(`[Watcher] Started`);
|
|
92
|
+
const shutdown = () => {
|
|
93
|
+
isShutdown = true;
|
|
94
|
+
debugLog(`[Watcher] Shutting down`);
|
|
95
|
+
log(`Shutting down watch...`);
|
|
96
|
+
watcher.close();
|
|
97
|
+
lifecycleHooks(config.hooks).beforeDone();
|
|
98
|
+
};
|
|
99
|
+
// it doesn't matter what has changed, need to run whole process anyway
|
|
100
|
+
watcher.on('all', async (eventName, path) => {
|
|
101
|
+
lifecycleHooks(config.hooks).onWatchTriggered(eventName, path);
|
|
102
|
+
debugLog(`[Watcher] triggered due to a file ${eventName} event: ${path}`);
|
|
103
|
+
const fullPath = join(process.cwd(), path);
|
|
104
|
+
// In ESM require is not defined
|
|
105
|
+
try {
|
|
106
|
+
delete require.cache[fullPath];
|
|
107
|
+
}
|
|
108
|
+
catch (err) { }
|
|
109
|
+
if (eventName === 'change' && config.configFilePath && fullPath === config.configFilePath) {
|
|
110
|
+
log(`${logSymbols.info} Config file has changed, reloading...`);
|
|
111
|
+
const context = await loadContext(config.configFilePath);
|
|
112
|
+
const newParsedConfig = context.getConfig();
|
|
113
|
+
newParsedConfig.watch = config.watch;
|
|
114
|
+
newParsedConfig.silent = config.silent;
|
|
115
|
+
newParsedConfig.overwrite = config.overwrite;
|
|
116
|
+
newParsedConfig.configFilePath = config.configFilePath;
|
|
117
|
+
config = newParsedConfig;
|
|
118
|
+
initalContext.updateConfig(config);
|
|
119
|
+
}
|
|
120
|
+
debouncedExec();
|
|
121
|
+
});
|
|
122
|
+
process.once('SIGINT', shutdown);
|
|
123
|
+
process.once('SIGTERM', shutdown);
|
|
124
|
+
};
|
|
125
|
+
// the promise never resolves to keep process running
|
|
126
|
+
return new Promise((resolve, reject) => {
|
|
127
|
+
executeCodegen(initalContext)
|
|
128
|
+
.then(onNext, () => Promise.resolve())
|
|
129
|
+
.then(runWatcher)
|
|
130
|
+
.catch(err => {
|
|
131
|
+
watcher.close();
|
|
132
|
+
reject(err);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/cli",
|
|
3
|
-
"version": "2.7.0",
|
|
3
|
+
"version": "2.7.1-alpha-223b75f49.0",
|
|
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,35 +8,31 @@
|
|
|
8
8
|
"@graphql-codegen/core": "2.5.1",
|
|
9
9
|
"@graphql-codegen/plugin-helpers": "^2.4.1",
|
|
10
10
|
"@graphql-tools/apollo-engine-loader": "^7.3.1",
|
|
11
|
-
"@graphql-tools/code-file-loader": "^7.0
|
|
12
|
-
"@graphql-tools/git-loader": "^7.0
|
|
13
|
-
"@graphql-tools/github-loader": "^7.
|
|
14
|
-
"@graphql-tools/graphql-file-loader": "^7.0
|
|
15
|
-
"@graphql-tools/json-file-loader": "^7.
|
|
16
|
-
"@graphql-tools/load": "^7.
|
|
11
|
+
"@graphql-tools/code-file-loader": "^7.3.0",
|
|
12
|
+
"@graphql-tools/git-loader": "^7.2.0",
|
|
13
|
+
"@graphql-tools/github-loader": "^7.3.1",
|
|
14
|
+
"@graphql-tools/graphql-file-loader": "^7.4.0",
|
|
15
|
+
"@graphql-tools/json-file-loader": "^7.4.0",
|
|
16
|
+
"@graphql-tools/load": "^7.7.0",
|
|
17
17
|
"@graphql-tools/prisma-loader": "^7.2.2",
|
|
18
18
|
"@graphql-tools/url-loader": "^7.12.1",
|
|
19
|
-
"@graphql-tools/utils": "^8.
|
|
19
|
+
"@graphql-tools/utils": "^8.8.0",
|
|
20
20
|
"ansi-escapes": "^4.3.1",
|
|
21
21
|
"chalk": "^4.1.0",
|
|
22
|
-
"change-case-all": "1.0.14",
|
|
23
22
|
"chokidar": "^3.5.2",
|
|
24
|
-
"common-tags": "^1.8.0",
|
|
25
23
|
"cosmiconfig": "^7.0.0",
|
|
26
24
|
"debounce": "^1.2.0",
|
|
27
25
|
"detect-indent": "^6.0.0",
|
|
28
|
-
"graphql-config": "^4.1
|
|
26
|
+
"graphql-config": "^4.3.1",
|
|
29
27
|
"inquirer": "^8.0.0",
|
|
30
28
|
"is-glob": "^4.0.1",
|
|
31
29
|
"json-to-pretty-yaml": "^1.2.2",
|
|
32
30
|
"latest-version": "5.1.0",
|
|
33
|
-
"
|
|
34
|
-
"listr-update-renderer": "^0.5.0",
|
|
31
|
+
"listr2": "^4.0.5",
|
|
35
32
|
"log-symbols": "^4.0.0",
|
|
36
33
|
"mkdirp": "^1.0.4",
|
|
37
34
|
"string-env-interpolation": "^1.0.1",
|
|
38
35
|
"ts-log": "^2.2.3",
|
|
39
|
-
"wrap-ansi": "^7.0.0",
|
|
40
36
|
"yaml": "^1.10.0",
|
|
41
37
|
"yargs": "^17.0.0"
|
|
42
38
|
},
|
|
@@ -65,26 +61,34 @@
|
|
|
65
61
|
],
|
|
66
62
|
"author": "Dotan Simha <dotansimha@gmail.com>",
|
|
67
63
|
"license": "MIT",
|
|
68
|
-
"main": "index.js",
|
|
69
|
-
"module": "index.
|
|
70
|
-
"typings": "index.d.ts",
|
|
64
|
+
"main": "cjs/index.js",
|
|
65
|
+
"module": "esm/index.js",
|
|
66
|
+
"typings": "typings/index.d.ts",
|
|
71
67
|
"typescript": {
|
|
72
|
-
"definition": "index.d.ts"
|
|
68
|
+
"definition": "typings/index.d.ts"
|
|
73
69
|
},
|
|
70
|
+
"type": "module",
|
|
74
71
|
"exports": {
|
|
75
|
-
"./package.json": "./package.json",
|
|
76
72
|
".": {
|
|
77
|
-
"require":
|
|
78
|
-
|
|
73
|
+
"require": {
|
|
74
|
+
"types": "./typings/index.d.ts",
|
|
75
|
+
"default": "./cjs/index.js"
|
|
76
|
+
},
|
|
77
|
+
"import": {
|
|
78
|
+
"types": "./typings/index.d.ts",
|
|
79
|
+
"default": "./esm/index.js"
|
|
80
|
+
},
|
|
81
|
+
"default": {
|
|
82
|
+
"types": "./typings/index.d.ts",
|
|
83
|
+
"default": "./esm/index.js"
|
|
84
|
+
}
|
|
79
85
|
},
|
|
80
|
-
"
|
|
81
|
-
"require": "./*.js",
|
|
82
|
-
"import": "./*.mjs"
|
|
83
|
-
}
|
|
86
|
+
"./package.json": "./package.json"
|
|
84
87
|
},
|
|
85
88
|
"bin": {
|
|
86
|
-
"gql-gen": "bin.js",
|
|
87
|
-
"graphql-codegen": "bin.js",
|
|
88
|
-
"graphql-code-generator": "bin.js"
|
|
89
|
+
"gql-gen": "cjs/bin.js",
|
|
90
|
+
"graphql-codegen": "cjs/bin.js",
|
|
91
|
+
"graphql-code-generator": "cjs/bin.js",
|
|
92
|
+
"graphql-codegen-esm": "esm/bin.js"
|
|
89
93
|
}
|
|
90
|
-
}
|
|
94
|
+
}
|
package/typings/bin.d.ts
ADDED
|
File without changes
|
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Types } from '@graphql-codegen/plugin-helpers';
|
|
2
|
-
import { CodegenContext } from './config';
|
|
2
|
+
import { CodegenContext } from './config.js';
|
|
3
3
|
export declare function generate(input: CodegenContext | (Types.Config & {
|
|
4
4
|
cwd?: string;
|
|
5
5
|
}), saveToFile?: boolean): Promise<Types.FileOutput[] | any>;
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { executeCodegen } from './codegen.js';
|
|
2
|
+
export { generate } from './generate-and-save.js';
|
|
3
|
+
export * from './config.js';
|
|
4
|
+
export * from './init/index.js';
|
|
5
|
+
export * from './utils/cli-error.js';
|
|
6
|
+
export * from './cli.js';
|
|
7
|
+
export * from './graphql-config.js';
|
|
File without changes
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PluginOption } from './types';
|
|
1
|
+
import { PluginOption } from './types.js';
|
|
2
2
|
export declare const plugins: Array<PluginOption>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import inquirer from 'inquirer';
|
|
2
|
-
import { Tags, Answers } from './types';
|
|
2
|
+
import { Tags, Answers } from './types.js';
|
|
3
3
|
export declare function getQuestions(possibleTargets: Record<Tags, boolean>): inquirer.QuestionCollection;
|
|
4
4
|
export declare function getApplicationTypeChoices(possibleTargets: Record<Tags, boolean>): {
|
|
5
5
|
name: string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Tags } from './types';
|
|
1
|
+
import { Tags } from './types.js';
|
|
2
2
|
export declare function guessTargets(): Promise<Record<Tags, boolean>>;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Types } from '@graphql-codegen/plugin-helpers';
|
|
2
|
-
import { CodegenContext } from '../config';
|
|
2
|
+
import { CodegenContext } from '../config.js';
|
|
3
3
|
export declare const createWatcher: (initalContext: CodegenContext, onNext: (result: Types.FileOutput[]) => Promise<Types.FileOutput[]>) => Promise<void>;
|
package/bin.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|