@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/index.esm.js CHANGED
@@ -23,6 +23,7 @@ import { loadSchema as loadSchema$1, loadDocuments as loadDocuments$1 } from '@g
23
23
  import { GraphQLFileLoader } from '@graphql-tools/graphql-file-loader';
24
24
  import { JsonFileLoader } from '@graphql-tools/json-file-loader';
25
25
  import { UrlLoader } from '@graphql-tools/url-loader';
26
+ import yaml from 'yaml';
26
27
  import fs, { readFileSync, writeFileSync, statSync, unlink } from 'fs';
27
28
  import { createRequire, createRequireFromPath } from 'module';
28
29
  import { exec } from 'child_process';
@@ -208,7 +209,7 @@ async function getPluginByName(name, pluginLoader) {
208
209
  return await pluginLoader(moduleName);
209
210
  }
210
211
  catch (err) {
211
- if (err.code !== 'MODULE_NOT_FOUND') {
212
+ if (err.code !== 'MODULE_NOT_FOUND' || !err.message.includes(moduleName)) {
212
213
  throw new DetailedError(`Unable to load template plugin matching ${name}`, `
213
214
  Unable to load template plugin matching '${name}'.
214
215
  Reason:
@@ -244,7 +245,7 @@ async function getPresetByName(name, loader) {
244
245
  return loaded;
245
246
  }
246
247
  catch (err) {
247
- if (err.code !== 'MODULE_NOT_FOUND') {
248
+ if (err.code !== 'MODULE_NOT_FOUND' || !err.message.includes(moduleName)) {
248
249
  throw new DetailedError(`Unable to load preset matching ${name}`, `
249
250
  Unable to load preset matching '${name}'.
250
251
  Reason:
@@ -382,7 +383,7 @@ function generateSearchPlaces(moduleName) {
382
383
  const regular = extensions.map(ext => `${moduleName}.${ext}`);
383
384
  // gives .codegenrc.json... but no .codegenrc.config.js
384
385
  const dot = extensions.filter(ext => ext !== 'config.js').map(ext => `.${moduleName}rc.${ext}`);
385
- return regular.concat(dot);
386
+ return [...regular.concat(dot), 'package.json'];
386
387
  }
387
388
  function customLoader(ext) {
388
389
  function loader(filepath, content) {
@@ -393,7 +394,14 @@ function customLoader(ext) {
393
394
  return defaultLoaders['.json'](filepath, content);
394
395
  }
395
396
  if (ext === 'yaml') {
396
- return defaultLoaders['.yaml'](filepath, content);
397
+ try {
398
+ const result = yaml.parse(content, { prettyErrors: true, merge: true });
399
+ return result;
400
+ }
401
+ catch (error) {
402
+ error.message = `YAML Error in ${filepath}:\n${error.message}`;
403
+ throw error;
404
+ }
397
405
  }
398
406
  if (ext === 'js') {
399
407
  return defaultLoaders['.js'](filepath, content);
@@ -405,6 +413,7 @@ async function loadContext(configFilePath) {
405
413
  const moduleName = 'codegen';
406
414
  const cosmi = cosmiconfig(moduleName, {
407
415
  searchPlaces: generateSearchPlaces(moduleName),
416
+ packageProp: moduleName,
408
417
  loaders: {
409
418
  '.json': customLoader('json'),
410
419
  '.yaml': customLoader('yaml'),
@@ -869,6 +878,12 @@ function normalizeHooks(_hooks) {
869
878
  [hookName]: [_hooks[hookName]],
870
879
  };
871
880
  }
881
+ else if (typeof _hooks[hookName] === 'function') {
882
+ return {
883
+ ...prev,
884
+ [hookName]: [_hooks[hookName]],
885
+ };
886
+ }
872
887
  else if (Array.isArray(_hooks[hookName])) {
873
888
  return {
874
889
  ...prev,
@@ -1026,6 +1041,7 @@ const createWatcher = (initalContext, onNext) => {
1026
1041
  newParsedConfig.overwrite = config.overwrite;
1027
1042
  newParsedConfig.configFilePath = config.configFilePath;
1028
1043
  config = newParsedConfig;
1044
+ initalContext.updateConfig(config);
1029
1045
  }
1030
1046
  debouncedExec();
1031
1047
  });