@graphql-codegen/cli 2.11.9-alpha-20220830121640-07b2ea5e6 → 2.12.0-alpha-20220830124514-58ba5a8be

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/codegen.js CHANGED
@@ -153,18 +153,26 @@ async function executeCodegen(input) {
153
153
  const generateTasks = Object.keys(generates).map(filename => {
154
154
  const outputConfig = generates[filename];
155
155
  const hasPreset = !!outputConfig.preset;
156
- const title = hasPreset
157
- ? `Generate to ${filename} (using EXPERIMENTAL preset "${outputConfig.preset}")`
158
- : `Generate ${filename}`;
156
+ const title = `Generate to ${filename}`;
159
157
  return {
160
158
  title,
161
- task: (_, subTask) => {
159
+ task: async (_, subTask) => {
162
160
  let outputSchemaAst;
163
161
  let outputSchema;
164
162
  const outputFileTemplateConfig = outputConfig.config || {};
165
163
  let outputDocuments = [];
166
164
  const outputSpecificSchemas = (0, plugin_helpers_1.normalizeInstanceOrArray)(outputConfig.schema);
167
- const outputSpecificDocuments = (0, plugin_helpers_1.normalizeInstanceOrArray)(outputConfig.documents);
165
+ let outputSpecificDocuments = (0, plugin_helpers_1.normalizeInstanceOrArray)(outputConfig.documents);
166
+ const preset = hasPreset
167
+ ? typeof outputConfig.preset === 'string'
168
+ ? await (0, presets_js_1.getPresetByName)(outputConfig.preset, makeDefaultLoader(context.cwd))
169
+ : outputConfig.preset
170
+ : null;
171
+ if (preset) {
172
+ if (preset.prepareDocuments) {
173
+ outputSpecificDocuments = await preset.prepareDocuments(filename, outputSpecificDocuments);
174
+ }
175
+ }
168
176
  return subTask.newListr([
169
177
  {
170
178
  title: 'Load GraphQL schemas',
@@ -224,11 +232,6 @@ async function executeCodegen(input) {
224
232
  const normalizedPluginsArray = (0, plugin_helpers_1.normalizeConfig)(outputConfig.plugins);
225
233
  const pluginLoader = config.pluginLoader || makeDefaultLoader(context.cwd);
226
234
  const pluginPackages = await Promise.all(normalizedPluginsArray.map(plugin => (0, plugins_js_1.getPluginByName)(Object.keys(plugin)[0], pluginLoader)));
227
- const preset = hasPreset
228
- ? typeof outputConfig.preset === 'string'
229
- ? await (0, presets_js_1.getPresetByName)(outputConfig.preset, makeDefaultLoader(context.cwd))
230
- : outputConfig.preset
231
- : null;
232
235
  const pluginMap = Object.fromEntries(pluginPackages.map((pkg, i) => {
233
236
  const plugin = normalizedPluginsArray[i];
234
237
  const name = Object.keys(plugin)[0];
@@ -241,7 +244,7 @@ async function executeCodegen(input) {
241
244
  : outputFileTemplateConfig),
242
245
  emitLegacyCommonJSImports: (0, config_js_1.shouldEmitLegacyCommonJSImports)(config, filename),
243
246
  };
244
- const outputs = hasPreset
247
+ const outputs = preset
245
248
  ? await context.profiler.run(async () => preset.buildGeneratesSection({
246
249
  baseOutputDir: filename,
247
250
  presetConfig: outputConfig.presetConfig || {},
package/cjs/config.js CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.shouldEmitLegacyCommonJSImports = exports.ensureContext = exports.CodegenContext = exports.updateContextWithCliFlags = exports.createContext = exports.parseArgv = exports.buildOptions = exports.loadContext = exports.loadCodegenConfig = exports.generateSearchPlaces = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const cosmiconfig_1 = require("cosmiconfig");
6
+ const cosmiconfig_typescript_loader_1 = require("cosmiconfig-typescript-loader");
6
7
  const path_1 = require("path");
7
8
  const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
8
9
  const string_env_interpolation_1 = require("string-env-interpolation");
@@ -16,7 +17,7 @@ const fs_1 = require("fs");
16
17
  const crypto_1 = require("crypto");
17
18
  const { lstat } = fs_1.promises;
18
19
  function generateSearchPlaces(moduleName) {
19
- const extensions = ['json', 'yaml', 'yml', 'js', 'config.js'];
20
+ const extensions = ['json', 'yaml', 'yml', 'js', 'ts', 'config.js'];
20
21
  // gives codegen.json...
21
22
  const regular = extensions.map(ext => `${moduleName}.${ext}`);
22
23
  // gives .codegenrc.json... but no .codegenrc.config.js
@@ -45,6 +46,9 @@ function customLoader(ext) {
45
46
  if (ext === 'js') {
46
47
  return cosmiconfig_1.defaultLoaders['.js'](filepath, content);
47
48
  }
49
+ if (ext === 'ts') {
50
+ return (0, cosmiconfig_typescript_loader_1.TypeScriptLoader)()(filepath, content);
51
+ }
48
52
  }
49
53
  return loader;
50
54
  }
@@ -60,6 +64,7 @@ async function loadCodegenConfig({ configFilePath, moduleName, searchPlaces: add
60
64
  '.yaml': customLoader('yaml'),
61
65
  '.yml': customLoader('yaml'),
62
66
  '.js': customLoader('js'),
67
+ '.ts': customLoader('ts'),
63
68
  noExt: customLoader('yaml'),
64
69
  ...customLoaders,
65
70
  },
package/cjs/presets.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getPresetByName = void 0;
4
- const plugin_helpers_1 = require("@graphql-codegen/plugin-helpers");
5
4
  const path_1 = require("path");
6
5
  async function getPresetByName(name, loader) {
7
6
  const possibleNames = [
@@ -27,7 +26,8 @@ async function getPresetByName(name, loader) {
27
26
  err.code !== 'MODULE_NOT_FOUND' &&
28
27
  /** ESM Error code */
29
28
  err.code !== 'ERR_MODULE_NOT_FOUND') {
30
- throw new plugin_helpers_1.DetailedError(`Unable to load preset matching ${name}`, `
29
+ throw new Error(`Unable to load preset matching ${name}
30
+
31
31
  Unable to load preset matching '${name}'.
32
32
  Reason:
33
33
  ${err.message}
@@ -40,7 +40,8 @@ async function getPresetByName(name, loader) {
40
40
  - ${name}
41
41
  `.trimRight())
42
42
  .join('');
43
- throw new plugin_helpers_1.DetailedError(`Unable to find preset matching ${name}`, `
43
+ throw new Error(`Unable to find preset matching ${name}
44
+
44
45
  Unable to find preset matching '${name}'
45
46
  Install one of the following packages:
46
47
 
package/esm/codegen.js CHANGED
@@ -149,18 +149,26 @@ export async function executeCodegen(input) {
149
149
  const generateTasks = Object.keys(generates).map(filename => {
150
150
  const outputConfig = generates[filename];
151
151
  const hasPreset = !!outputConfig.preset;
152
- const title = hasPreset
153
- ? `Generate to ${filename} (using EXPERIMENTAL preset "${outputConfig.preset}")`
154
- : `Generate ${filename}`;
152
+ const title = `Generate to ${filename}`;
155
153
  return {
156
154
  title,
157
- task: (_, subTask) => {
155
+ task: async (_, subTask) => {
158
156
  let outputSchemaAst;
159
157
  let outputSchema;
160
158
  const outputFileTemplateConfig = outputConfig.config || {};
161
159
  let outputDocuments = [];
162
160
  const outputSpecificSchemas = normalizeInstanceOrArray(outputConfig.schema);
163
- const outputSpecificDocuments = normalizeInstanceOrArray(outputConfig.documents);
161
+ let outputSpecificDocuments = normalizeInstanceOrArray(outputConfig.documents);
162
+ const preset = hasPreset
163
+ ? typeof outputConfig.preset === 'string'
164
+ ? await getPresetByName(outputConfig.preset, makeDefaultLoader(context.cwd))
165
+ : outputConfig.preset
166
+ : null;
167
+ if (preset) {
168
+ if (preset.prepareDocuments) {
169
+ outputSpecificDocuments = await preset.prepareDocuments(filename, outputSpecificDocuments);
170
+ }
171
+ }
164
172
  return subTask.newListr([
165
173
  {
166
174
  title: 'Load GraphQL schemas',
@@ -220,11 +228,6 @@ export async function executeCodegen(input) {
220
228
  const normalizedPluginsArray = normalizeConfig(outputConfig.plugins);
221
229
  const pluginLoader = config.pluginLoader || makeDefaultLoader(context.cwd);
222
230
  const pluginPackages = await Promise.all(normalizedPluginsArray.map(plugin => getPluginByName(Object.keys(plugin)[0], pluginLoader)));
223
- const preset = hasPreset
224
- ? typeof outputConfig.preset === 'string'
225
- ? await getPresetByName(outputConfig.preset, makeDefaultLoader(context.cwd))
226
- : outputConfig.preset
227
- : null;
228
231
  const pluginMap = Object.fromEntries(pluginPackages.map((pkg, i) => {
229
232
  const plugin = normalizedPluginsArray[i];
230
233
  const name = Object.keys(plugin)[0];
@@ -237,7 +240,7 @@ export async function executeCodegen(input) {
237
240
  : outputFileTemplateConfig),
238
241
  emitLegacyCommonJSImports: shouldEmitLegacyCommonJSImports(config, filename),
239
242
  };
240
- const outputs = hasPreset
243
+ const outputs = preset
241
244
  ? await context.profiler.run(async () => preset.buildGeneratesSection({
242
245
  baseOutputDir: filename,
243
246
  presetConfig: outputConfig.presetConfig || {},
package/esm/config.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { cosmiconfig, defaultLoaders } from 'cosmiconfig';
2
+ import { TypeScriptLoader } from 'cosmiconfig-typescript-loader';
2
3
  import { resolve } from 'path';
3
4
  import { DetailedError, createProfiler, createNoopProfiler, getCachedDocumentNodeFromSchema, } from '@graphql-codegen/plugin-helpers';
4
5
  import { env } from 'string-env-interpolation';
@@ -12,7 +13,7 @@ import { promises } from 'fs';
12
13
  import { createHash } from 'crypto';
13
14
  const { lstat } = promises;
14
15
  export function generateSearchPlaces(moduleName) {
15
- const extensions = ['json', 'yaml', 'yml', 'js', 'config.js'];
16
+ const extensions = ['json', 'yaml', 'yml', 'js', 'ts', 'config.js'];
16
17
  // gives codegen.json...
17
18
  const regular = extensions.map(ext => `${moduleName}.${ext}`);
18
19
  // gives .codegenrc.json... but no .codegenrc.config.js
@@ -40,6 +41,9 @@ function customLoader(ext) {
40
41
  if (ext === 'js') {
41
42
  return defaultLoaders['.js'](filepath, content);
42
43
  }
44
+ if (ext === 'ts') {
45
+ return TypeScriptLoader()(filepath, content);
46
+ }
43
47
  }
44
48
  return loader;
45
49
  }
@@ -55,6 +59,7 @@ export async function loadCodegenConfig({ configFilePath, moduleName, searchPlac
55
59
  '.yaml': customLoader('yaml'),
56
60
  '.yml': customLoader('yaml'),
57
61
  '.js': customLoader('js'),
62
+ '.ts': customLoader('ts'),
58
63
  noExt: customLoader('yaml'),
59
64
  ...customLoaders,
60
65
  },
package/esm/presets.js CHANGED
@@ -1,4 +1,3 @@
1
- import { DetailedError } from '@graphql-codegen/plugin-helpers';
2
1
  import { resolve } from 'path';
3
2
  export async function getPresetByName(name, loader) {
4
3
  const possibleNames = [
@@ -24,7 +23,8 @@ export async function getPresetByName(name, loader) {
24
23
  err.code !== 'MODULE_NOT_FOUND' &&
25
24
  /** ESM Error code */
26
25
  err.code !== 'ERR_MODULE_NOT_FOUND') {
27
- throw new DetailedError(`Unable to load preset matching ${name}`, `
26
+ throw new Error(`Unable to load preset matching ${name}
27
+
28
28
  Unable to load preset matching '${name}'.
29
29
  Reason:
30
30
  ${err.message}
@@ -37,7 +37,8 @@ export async function getPresetByName(name, loader) {
37
37
  - ${name}
38
38
  `.trimRight())
39
39
  .join('');
40
- throw new DetailedError(`Unable to find preset matching ${name}`, `
40
+ throw new Error(`Unable to find preset matching ${name}
41
+
41
42
  Unable to find preset matching '${name}'
42
43
  Install one of the following packages:
43
44
 
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@graphql-codegen/cli",
3
- "version": "2.11.9-alpha-20220830121640-07b2ea5e6",
3
+ "version": "2.12.0-alpha-20220830124514-58ba5a8be",
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
8
  "@graphql-codegen/core": "2.6.2",
9
- "@graphql-codegen/plugin-helpers": "^2.6.2",
9
+ "@graphql-codegen/plugin-helpers": "2.7.0-alpha-20220830124514-58ba5a8be",
10
10
  "@graphql-tools/apollo-engine-loader": "^7.3.6",
11
11
  "@graphql-tools/code-file-loader": "^7.3.1",
12
12
  "@graphql-tools/git-loader": "^7.2.1",
@@ -22,6 +22,7 @@
22
22
  "chalk": "^4.1.0",
23
23
  "chokidar": "^3.5.2",
24
24
  "cosmiconfig": "^7.0.0",
25
+ "cosmiconfig-typescript-loader": "^4.0.0",
25
26
  "debounce": "^1.2.0",
26
27
  "detect-indent": "^6.0.0",
27
28
  "graphql-config": "^4.3.5",
@@ -1,6 +1,7 @@
1
1
  import { Types, Profiler } from '@graphql-codegen/plugin-helpers';
2
2
  import { GraphQLConfig } from 'graphql-config';
3
3
  import { GraphQLSchema } from 'graphql';
4
+ export declare type CodegenConfig = Types.Config;
4
5
  export declare type YamlCliFlags = {
5
6
  config: string;
6
7
  watch: boolean | string | string[];
@@ -1,6 +1,7 @@
1
1
  import { Types, Profiler } from '@graphql-codegen/plugin-helpers';
2
2
  import { GraphQLConfig } from 'graphql-config';
3
3
  import { GraphQLSchema } from 'graphql';
4
+ export declare type CodegenConfig = Types.Config;
4
5
  export declare type YamlCliFlags = {
5
6
  config: string;
6
7
  watch: boolean | string | string[];
@@ -5,3 +5,4 @@ export * from './init/index.cjs';
5
5
  export * from './utils/cli-error.cjs';
6
6
  export * from './cli.cjs';
7
7
  export * from './graphql-config.cjs';
8
+ export { CodegenConfig } from './config.cjs';
@@ -5,3 +5,4 @@ export * from './init/index.js';
5
5
  export * from './utils/cli-error.js';
6
6
  export * from './cli.js';
7
7
  export * from './graphql-config.js';
8
+ export { CodegenConfig } from './config.js';