@graphql-codegen/cli 1.19.3 → 1.20.1
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/bin.js +20 -4
- package/index.cjs.js +20 -4
- package/index.cjs.js.map +1 -1
- package/index.esm.js +20 -4
- package/index.esm.js.map +1 -1
- package/package.json +7 -7
package/bin.js
CHANGED
|
@@ -49,6 +49,7 @@ const load = require('@graphql-tools/load');
|
|
|
49
49
|
const graphqlFileLoader = require('@graphql-tools/graphql-file-loader');
|
|
50
50
|
const jsonFileLoader = require('@graphql-tools/json-file-loader');
|
|
51
51
|
const urlLoader = require('@graphql-tools/url-loader');
|
|
52
|
+
const yaml = _interopDefault(require('yaml'));
|
|
52
53
|
const fs = require('fs');
|
|
53
54
|
const fs__default = _interopDefault(fs);
|
|
54
55
|
const module$1 = require('module');
|
|
@@ -115,6 +116,12 @@ function normalizeHooks(_hooks) {
|
|
|
115
116
|
[hookName]: [_hooks[hookName]],
|
|
116
117
|
};
|
|
117
118
|
}
|
|
119
|
+
else if (typeof _hooks[hookName] === 'function') {
|
|
120
|
+
return {
|
|
121
|
+
...prev,
|
|
122
|
+
[hookName]: [_hooks[hookName]],
|
|
123
|
+
};
|
|
124
|
+
}
|
|
118
125
|
else if (Array.isArray(_hooks[hookName])) {
|
|
119
126
|
return {
|
|
120
127
|
...prev,
|
|
@@ -311,7 +318,7 @@ async function getPluginByName(name, pluginLoader) {
|
|
|
311
318
|
return await pluginLoader(moduleName);
|
|
312
319
|
}
|
|
313
320
|
catch (err) {
|
|
314
|
-
if (err.code !== 'MODULE_NOT_FOUND') {
|
|
321
|
+
if (err.code !== 'MODULE_NOT_FOUND' || !err.message.includes(moduleName)) {
|
|
315
322
|
throw new pluginHelpers.DetailedError(`Unable to load template plugin matching ${name}`, `
|
|
316
323
|
Unable to load template plugin matching '${name}'.
|
|
317
324
|
Reason:
|
|
@@ -347,7 +354,7 @@ async function getPresetByName(name, loader) {
|
|
|
347
354
|
return loaded;
|
|
348
355
|
}
|
|
349
356
|
catch (err) {
|
|
350
|
-
if (err.code !== 'MODULE_NOT_FOUND') {
|
|
357
|
+
if (err.code !== 'MODULE_NOT_FOUND' || !err.message.includes(moduleName)) {
|
|
351
358
|
throw new pluginHelpers.DetailedError(`Unable to load preset matching ${name}`, `
|
|
352
359
|
Unable to load preset matching '${name}'.
|
|
353
360
|
Reason:
|
|
@@ -485,7 +492,7 @@ function generateSearchPlaces(moduleName) {
|
|
|
485
492
|
const regular = extensions.map(ext => `${moduleName}.${ext}`);
|
|
486
493
|
// gives .codegenrc.json... but no .codegenrc.config.js
|
|
487
494
|
const dot = extensions.filter(ext => ext !== 'config.js').map(ext => `.${moduleName}rc.${ext}`);
|
|
488
|
-
return regular.concat(dot);
|
|
495
|
+
return [...regular.concat(dot), 'package.json'];
|
|
489
496
|
}
|
|
490
497
|
function customLoader(ext) {
|
|
491
498
|
function loader(filepath, content) {
|
|
@@ -496,7 +503,14 @@ function customLoader(ext) {
|
|
|
496
503
|
return cosmiconfig.defaultLoaders['.json'](filepath, content);
|
|
497
504
|
}
|
|
498
505
|
if (ext === 'yaml') {
|
|
499
|
-
|
|
506
|
+
try {
|
|
507
|
+
const result = yaml.parse(content, { prettyErrors: true, merge: true });
|
|
508
|
+
return result;
|
|
509
|
+
}
|
|
510
|
+
catch (error) {
|
|
511
|
+
error.message = `YAML Error in ${filepath}:\n${error.message}`;
|
|
512
|
+
throw error;
|
|
513
|
+
}
|
|
500
514
|
}
|
|
501
515
|
if (ext === 'js') {
|
|
502
516
|
return cosmiconfig.defaultLoaders['.js'](filepath, content);
|
|
@@ -508,6 +522,7 @@ async function loadContext(configFilePath) {
|
|
|
508
522
|
const moduleName = 'codegen';
|
|
509
523
|
const cosmi = cosmiconfig.cosmiconfig(moduleName, {
|
|
510
524
|
searchPlaces: generateSearchPlaces(moduleName),
|
|
525
|
+
packageProp: moduleName,
|
|
511
526
|
loaders: {
|
|
512
527
|
'.json': customLoader('json'),
|
|
513
528
|
'.yaml': customLoader('yaml'),
|
|
@@ -1052,6 +1067,7 @@ const createWatcher = (initalContext, onNext) => {
|
|
|
1052
1067
|
newParsedConfig.overwrite = config.overwrite;
|
|
1053
1068
|
newParsedConfig.configFilePath = config.configFilePath;
|
|
1054
1069
|
config = newParsedConfig;
|
|
1070
|
+
initalContext.updateConfig(config);
|
|
1055
1071
|
}
|
|
1056
1072
|
debouncedExec();
|
|
1057
1073
|
});
|
package/index.cjs.js
CHANGED
|
@@ -49,6 +49,7 @@ const load = require('@graphql-tools/load');
|
|
|
49
49
|
const graphqlFileLoader = require('@graphql-tools/graphql-file-loader');
|
|
50
50
|
const jsonFileLoader = require('@graphql-tools/json-file-loader');
|
|
51
51
|
const urlLoader = require('@graphql-tools/url-loader');
|
|
52
|
+
const yaml = _interopDefault(require('yaml'));
|
|
52
53
|
const fs = require('fs');
|
|
53
54
|
const fs__default = _interopDefault(fs);
|
|
54
55
|
const module$1 = require('module');
|
|
@@ -235,7 +236,7 @@ async function getPluginByName(name, pluginLoader) {
|
|
|
235
236
|
return await pluginLoader(moduleName);
|
|
236
237
|
}
|
|
237
238
|
catch (err) {
|
|
238
|
-
if (err.code !== 'MODULE_NOT_FOUND') {
|
|
239
|
+
if (err.code !== 'MODULE_NOT_FOUND' || !err.message.includes(moduleName)) {
|
|
239
240
|
throw new pluginHelpers.DetailedError(`Unable to load template plugin matching ${name}`, `
|
|
240
241
|
Unable to load template plugin matching '${name}'.
|
|
241
242
|
Reason:
|
|
@@ -271,7 +272,7 @@ async function getPresetByName(name, loader) {
|
|
|
271
272
|
return loaded;
|
|
272
273
|
}
|
|
273
274
|
catch (err) {
|
|
274
|
-
if (err.code !== 'MODULE_NOT_FOUND') {
|
|
275
|
+
if (err.code !== 'MODULE_NOT_FOUND' || !err.message.includes(moduleName)) {
|
|
275
276
|
throw new pluginHelpers.DetailedError(`Unable to load preset matching ${name}`, `
|
|
276
277
|
Unable to load preset matching '${name}'.
|
|
277
278
|
Reason:
|
|
@@ -409,7 +410,7 @@ function generateSearchPlaces(moduleName) {
|
|
|
409
410
|
const regular = extensions.map(ext => `${moduleName}.${ext}`);
|
|
410
411
|
// gives .codegenrc.json... but no .codegenrc.config.js
|
|
411
412
|
const dot = extensions.filter(ext => ext !== 'config.js').map(ext => `.${moduleName}rc.${ext}`);
|
|
412
|
-
return regular.concat(dot);
|
|
413
|
+
return [...regular.concat(dot), 'package.json'];
|
|
413
414
|
}
|
|
414
415
|
function customLoader(ext) {
|
|
415
416
|
function loader(filepath, content) {
|
|
@@ -420,7 +421,14 @@ function customLoader(ext) {
|
|
|
420
421
|
return cosmiconfig.defaultLoaders['.json'](filepath, content);
|
|
421
422
|
}
|
|
422
423
|
if (ext === 'yaml') {
|
|
423
|
-
|
|
424
|
+
try {
|
|
425
|
+
const result = yaml.parse(content, { prettyErrors: true, merge: true });
|
|
426
|
+
return result;
|
|
427
|
+
}
|
|
428
|
+
catch (error) {
|
|
429
|
+
error.message = `YAML Error in ${filepath}:\n${error.message}`;
|
|
430
|
+
throw error;
|
|
431
|
+
}
|
|
424
432
|
}
|
|
425
433
|
if (ext === 'js') {
|
|
426
434
|
return cosmiconfig.defaultLoaders['.js'](filepath, content);
|
|
@@ -432,6 +440,7 @@ async function loadContext(configFilePath) {
|
|
|
432
440
|
const moduleName = 'codegen';
|
|
433
441
|
const cosmi = cosmiconfig.cosmiconfig(moduleName, {
|
|
434
442
|
searchPlaces: generateSearchPlaces(moduleName),
|
|
443
|
+
packageProp: moduleName,
|
|
435
444
|
loaders: {
|
|
436
445
|
'.json': customLoader('json'),
|
|
437
446
|
'.yaml': customLoader('yaml'),
|
|
@@ -896,6 +905,12 @@ function normalizeHooks(_hooks) {
|
|
|
896
905
|
[hookName]: [_hooks[hookName]],
|
|
897
906
|
};
|
|
898
907
|
}
|
|
908
|
+
else if (typeof _hooks[hookName] === 'function') {
|
|
909
|
+
return {
|
|
910
|
+
...prev,
|
|
911
|
+
[hookName]: [_hooks[hookName]],
|
|
912
|
+
};
|
|
913
|
+
}
|
|
899
914
|
else if (Array.isArray(_hooks[hookName])) {
|
|
900
915
|
return {
|
|
901
916
|
...prev,
|
|
@@ -1053,6 +1068,7 @@ const createWatcher = (initalContext, onNext) => {
|
|
|
1053
1068
|
newParsedConfig.overwrite = config.overwrite;
|
|
1054
1069
|
newParsedConfig.configFilePath = config.configFilePath;
|
|
1055
1070
|
config = newParsedConfig;
|
|
1071
|
+
initalContext.updateConfig(config);
|
|
1056
1072
|
}
|
|
1057
1073
|
debouncedExec();
|
|
1058
1074
|
});
|