@graphql-codegen/cli 2.8.0-alpha-0b48ad1f9.0 → 2.8.0-alpha-2ada7b533.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/config.js CHANGED
@@ -179,7 +179,7 @@ function updateContextWithCliFlags(context, cliFlags) {
179
179
  const config = {
180
180
  configFilePath: context.filepath,
181
181
  };
182
- if (cliFlags.watch) {
182
+ if (cliFlags.watch !== undefined) {
183
183
  config.watch = cliFlags.watch;
184
184
  }
185
185
  if (cliFlags.overwrite === true) {
@@ -191,6 +191,10 @@ function updateContextWithCliFlags(context, cliFlags) {
191
191
  if (cliFlags.errorsOnly === true) {
192
192
  config.errorsOnly = cliFlags.errorsOnly;
193
193
  }
194
+ if (cliFlags['ignore-no-documents'] !== undefined) {
195
+ // for some reason parsed value is `'false'` string so this ensure it always is a boolean.
196
+ config.ignoreNoDocuments = cliFlags['ignore-no-documents'] === true;
197
+ }
194
198
  if (cliFlags.project) {
195
199
  context.useProject(cliFlags.project);
196
200
  }
@@ -6,7 +6,7 @@ const chalk_1 = tslib_1.__importDefault(require("chalk"));
6
6
  const path_1 = require("path");
7
7
  const fs_1 = require("fs");
8
8
  const detect_indent_1 = tslib_1.__importDefault(require("detect-indent"));
9
- const latest_version_1 = tslib_1.__importDefault(require("latest-version"));
9
+ const get_latest_version_js_1 = require("../utils/get-latest-version.js");
10
10
  // Parses config and writes it to a file
11
11
  async function writeConfig(answers, config) {
12
12
  const YAML = await Promise.resolve().then(() => tslib_1.__importStar(require('json-to-pretty-yaml'))).then(m => ('default' in m ? m.default : m));
@@ -41,12 +41,12 @@ async function writePackage(answers, configLocation) {
41
41
  pkg.devDependencies = {};
42
42
  }
43
43
  await Promise.all(answers.plugins.map(async (plugin) => {
44
- pkg.devDependencies[plugin.package] = await (0, latest_version_1.default)(plugin.package);
44
+ pkg.devDependencies[plugin.package] = await (0, get_latest_version_js_1.getLatestVersion)(plugin.package);
45
45
  }));
46
46
  if (answers.introspection) {
47
- pkg.devDependencies['@graphql-codegen/introspection'] = await (0, latest_version_1.default)('@graphql-codegen/introspection');
47
+ pkg.devDependencies['@graphql-codegen/introspection'] = await (0, get_latest_version_js_1.getLatestVersion)('@graphql-codegen/introspection');
48
48
  }
49
- pkg.devDependencies['@graphql-codegen/cli'] = await (0, latest_version_1.default)('@graphql-codegen/cli');
49
+ pkg.devDependencies['@graphql-codegen/cli'] = await (0, get_latest_version_js_1.getLatestVersion)('@graphql-codegen/cli');
50
50
  (0, fs_1.writeFileSync)(pkgPath, JSON.stringify(pkg, null, indent));
51
51
  }
52
52
  exports.writePackage = writePackage;
package/cjs/load.js CHANGED
@@ -48,16 +48,16 @@ async function loadSchema(schemaPointers, config) {
48
48
 
49
49
  ${e.message || e}
50
50
  ${e.stack || ''}
51
-
51
+
52
52
  GraphQL Code Generator supports:
53
53
  - ES Modules and CommonJS exports (export as default or named export "schema")
54
54
  - Introspection JSON File
55
55
  - URL of GraphQL endpoint
56
56
  - Multiple files with type definitions (glob expression)
57
57
  - String in config file
58
-
58
+
59
59
  Try to use one of above options and run codegen again.
60
-
60
+
61
61
  `);
62
62
  }
63
63
  }
@@ -81,13 +81,20 @@ async function loadDocuments(documentPointers, config) {
81
81
  }
82
82
  ignore.push((0, path_1.join)(process.cwd(), generatePath));
83
83
  }
84
- const loadedFromToolkit = await (0, load_1.loadDocuments)(documentPointers, {
85
- ...exports.defaultDocumentsLoadOptions,
86
- ignore,
87
- loaders,
88
- ...config,
89
- ...config.config,
90
- });
91
- return loadedFromToolkit;
84
+ try {
85
+ const loadedFromToolkit = await (0, load_1.loadDocuments)(documentPointers, {
86
+ ...exports.defaultDocumentsLoadOptions,
87
+ ignore,
88
+ loaders,
89
+ ...config,
90
+ ...config.config,
91
+ });
92
+ return loadedFromToolkit;
93
+ }
94
+ catch (error) {
95
+ if (config.ignoreNoDocuments)
96
+ return [];
97
+ throw error;
98
+ }
92
99
  }
93
100
  exports.loadDocuments = loadDocuments;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLatestVersion = void 0;
4
+ const cross_undici_fetch_1 = require("cross-undici-fetch");
5
+ /**
6
+ * Fetches the version directly from the registry instead of depending on
7
+ * an ESM only module as latest-version does.
8
+ * @param packageName
9
+ */
10
+ async function getLatestVersion(packageName) {
11
+ return (0, cross_undici_fetch_1.fetch)(`https://unpkg.com/${packageName}/package.json`)
12
+ .then(res => res.json())
13
+ .then(pkg => pkg.version);
14
+ }
15
+ exports.getLatestVersion = getLatestVersion;
package/esm/config.js CHANGED
@@ -169,7 +169,7 @@ export function updateContextWithCliFlags(context, cliFlags) {
169
169
  const config = {
170
170
  configFilePath: context.filepath,
171
171
  };
172
- if (cliFlags.watch) {
172
+ if (cliFlags.watch !== undefined) {
173
173
  config.watch = cliFlags.watch;
174
174
  }
175
175
  if (cliFlags.overwrite === true) {
@@ -181,6 +181,10 @@ export function updateContextWithCliFlags(context, cliFlags) {
181
181
  if (cliFlags.errorsOnly === true) {
182
182
  config.errorsOnly = cliFlags.errorsOnly;
183
183
  }
184
+ if (cliFlags['ignore-no-documents'] !== undefined) {
185
+ // for some reason parsed value is `'false'` string so this ensure it always is a boolean.
186
+ config.ignoreNoDocuments = cliFlags['ignore-no-documents'] === true;
187
+ }
184
188
  if (cliFlags.project) {
185
189
  context.useProject(cliFlags.project);
186
190
  }
@@ -2,7 +2,7 @@ import chalk from 'chalk';
2
2
  import { resolve, relative } from 'path';
3
3
  import { writeFileSync, readFileSync } from 'fs';
4
4
  import detectIndent from 'detect-indent';
5
- import getLatestVersion from 'latest-version';
5
+ import { getLatestVersion } from '../utils/get-latest-version.js';
6
6
  // Parses config and writes it to a file
7
7
  export async function writeConfig(answers, config) {
8
8
  const YAML = await import('json-to-pretty-yaml').then(m => ('default' in m ? m.default : m));
package/esm/load.js CHANGED
@@ -45,16 +45,16 @@ export async function loadSchema(schemaPointers, config) {
45
45
 
46
46
  ${e.message || e}
47
47
  ${e.stack || ''}
48
-
48
+
49
49
  GraphQL Code Generator supports:
50
50
  - ES Modules and CommonJS exports (export as default or named export "schema")
51
51
  - Introspection JSON File
52
52
  - URL of GraphQL endpoint
53
53
  - Multiple files with type definitions (glob expression)
54
54
  - String in config file
55
-
55
+
56
56
  Try to use one of above options and run codegen again.
57
-
57
+
58
58
  `);
59
59
  }
60
60
  }
@@ -77,12 +77,19 @@ export async function loadDocuments(documentPointers, config) {
77
77
  }
78
78
  ignore.push(join(process.cwd(), generatePath));
79
79
  }
80
- const loadedFromToolkit = await loadDocumentsToolkit(documentPointers, {
81
- ...defaultDocumentsLoadOptions,
82
- ignore,
83
- loaders,
84
- ...config,
85
- ...config.config,
86
- });
87
- return loadedFromToolkit;
80
+ try {
81
+ const loadedFromToolkit = await loadDocumentsToolkit(documentPointers, {
82
+ ...defaultDocumentsLoadOptions,
83
+ ignore,
84
+ loaders,
85
+ ...config,
86
+ ...config.config,
87
+ });
88
+ return loadedFromToolkit;
89
+ }
90
+ catch (error) {
91
+ if (config.ignoreNoDocuments)
92
+ return [];
93
+ throw error;
94
+ }
88
95
  }
@@ -0,0 +1,11 @@
1
+ import { fetch } from 'cross-undici-fetch';
2
+ /**
3
+ * Fetches the version directly from the registry instead of depending on
4
+ * an ESM only module as latest-version does.
5
+ * @param packageName
6
+ */
7
+ export async function getLatestVersion(packageName) {
8
+ return fetch(`https://unpkg.com/${packageName}/package.json`)
9
+ .then(res => res.json())
10
+ .then(pkg => pkg.version);
11
+ }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@graphql-codegen/cli",
3
- "version": "2.8.0-alpha-0b48ad1f9.0",
3
+ "version": "2.8.0-alpha-2ada7b533.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
  },
7
7
  "dependencies": {
8
- "@graphql-codegen/core": "2.6.0-alpha-0b48ad1f9.0",
9
- "@graphql-codegen/plugin-helpers": "^2.5.0-alpha-0b48ad1f9.0",
8
+ "@graphql-codegen/core": "2.5.2-alpha-2ada7b533.0",
9
+ "@graphql-codegen/plugin-helpers": "^2.5.0-alpha-2ada7b533.0",
10
10
  "@graphql-tools/apollo-engine-loader": "^7.3.1",
11
11
  "@graphql-tools/code-file-loader": "^7.3.0",
12
12
  "@graphql-tools/git-loader": "^7.2.0",
@@ -23,13 +23,13 @@
23
23
  "chokidar": "^3.5.2",
24
24
  "common-tags": "^1.8.0",
25
25
  "cosmiconfig": "^7.0.0",
26
+ "cross-undici-fetch": "^0.4.11",
26
27
  "debounce": "^1.2.0",
27
28
  "detect-indent": "^6.0.0",
28
29
  "graphql-config": "^4.3.1",
29
30
  "inquirer": "^8.0.0",
30
31
  "is-glob": "^4.0.1",
31
32
  "json-to-pretty-yaml": "^1.2.2",
32
- "latest-version": "5.1.0",
33
33
  "listr": "^0.14.3",
34
34
  "listr-update-renderer": "^0.5.0",
35
35
  "log-symbols": "^4.0.0",
@@ -10,6 +10,7 @@ export declare type YamlCliFlags = {
10
10
  silent: boolean;
11
11
  errorsOnly: boolean;
12
12
  profile: boolean;
13
+ ignoreNoDocuments?: boolean;
13
14
  };
14
15
  export declare function generateSearchPlaces(moduleName: string): string[];
15
16
  export interface LoadCodegenConfigOptions {
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Fetches the version directly from the registry instead of depending on
3
+ * an ESM only module as latest-version does.
4
+ * @param packageName
5
+ */
6
+ export declare function getLatestVersion(packageName: string): Promise<string>;