@graphql-codegen/cli 2.3.0-alpha-5ed8c1163.0 → 2.3.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 +11 -6
- package/config.d.ts +27 -2
- package/index.js +12 -6
- package/index.mjs +13 -8
- package/package.json +7 -6
package/bin.js
CHANGED
|
@@ -547,6 +547,7 @@ async function loadDocuments(documentPointers, config) {
|
|
|
547
547
|
return loadedFromToolkit;
|
|
548
548
|
}
|
|
549
549
|
|
|
550
|
+
const { lstat } = fs.promises;
|
|
550
551
|
function generateSearchPlaces(moduleName) {
|
|
551
552
|
const extensions = ['json', 'yaml', 'yml', 'js', 'config.js'];
|
|
552
553
|
// gives codegen.json...
|
|
@@ -579,20 +580,24 @@ function customLoader(ext) {
|
|
|
579
580
|
}
|
|
580
581
|
return loader;
|
|
581
582
|
}
|
|
582
|
-
function loadCodegenConfig(configFilePath) {
|
|
583
|
-
|
|
583
|
+
async function loadCodegenConfig({ configFilePath, moduleName, searchPlaces: additionalSearchPlaces, packageProp, loaders: customLoaders, }) {
|
|
584
|
+
configFilePath = configFilePath || process.cwd();
|
|
585
|
+
moduleName = moduleName || 'codegen';
|
|
586
|
+
packageProp = packageProp || moduleName;
|
|
584
587
|
const cosmi = cosmiconfig.cosmiconfig(moduleName, {
|
|
585
|
-
searchPlaces: generateSearchPlaces(moduleName),
|
|
586
|
-
packageProp
|
|
588
|
+
searchPlaces: generateSearchPlaces(moduleName).concat(additionalSearchPlaces || []),
|
|
589
|
+
packageProp,
|
|
587
590
|
loaders: {
|
|
588
591
|
'.json': customLoader('json'),
|
|
589
592
|
'.yaml': customLoader('yaml'),
|
|
590
593
|
'.yml': customLoader('yaml'),
|
|
591
594
|
'.js': customLoader('js'),
|
|
592
595
|
noExt: customLoader('yaml'),
|
|
596
|
+
...customLoaders,
|
|
593
597
|
},
|
|
594
598
|
});
|
|
595
|
-
|
|
599
|
+
const pathStats = await lstat(configFilePath);
|
|
600
|
+
return pathStats.isDirectory() ? cosmi.search(configFilePath) : cosmi.load(configFilePath);
|
|
596
601
|
}
|
|
597
602
|
async function loadContext(configFilePath) {
|
|
598
603
|
const graphqlConfig = await findAndLoadGraphQLConfig(configFilePath);
|
|
@@ -601,7 +606,7 @@ async function loadContext(configFilePath) {
|
|
|
601
606
|
graphqlConfig,
|
|
602
607
|
});
|
|
603
608
|
}
|
|
604
|
-
const result = await loadCodegenConfig(configFilePath);
|
|
609
|
+
const result = await loadCodegenConfig({ configFilePath });
|
|
605
610
|
if (!result) {
|
|
606
611
|
if (configFilePath) {
|
|
607
612
|
throw new pluginHelpers.DetailedError(`Config ${configFilePath} does not exist`, `
|
package/config.d.ts
CHANGED
|
@@ -10,12 +10,37 @@ export declare type YamlCliFlags = {
|
|
|
10
10
|
silent: boolean;
|
|
11
11
|
errorsOnly: boolean;
|
|
12
12
|
};
|
|
13
|
-
export
|
|
13
|
+
export declare function generateSearchPlaces(moduleName: string): string[];
|
|
14
|
+
export interface LoadCodegenConfigOptions {
|
|
15
|
+
/**
|
|
16
|
+
* The path to the config file or directory contains the config file.
|
|
17
|
+
* @default process.cwd()
|
|
18
|
+
*/
|
|
19
|
+
configFilePath?: string;
|
|
20
|
+
/**
|
|
21
|
+
* The name of the config file
|
|
22
|
+
* @default codegen
|
|
23
|
+
*/
|
|
24
|
+
moduleName?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Additional search paths for the config file you want to check
|
|
27
|
+
*/
|
|
28
|
+
searchPlaces?: string[];
|
|
29
|
+
/**
|
|
30
|
+
* @default codegen
|
|
31
|
+
*/
|
|
32
|
+
packageProp?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Overrides or extends the loaders for specific file extensions
|
|
35
|
+
*/
|
|
36
|
+
loaders?: Record<string, (filepath: string, content: string) => Promise<Types.Config> | Types.Config>;
|
|
37
|
+
}
|
|
38
|
+
export interface LoadCodegenConfigResult {
|
|
14
39
|
filepath: string;
|
|
15
40
|
config: Types.Config;
|
|
16
41
|
isEmpty?: boolean;
|
|
17
42
|
}
|
|
18
|
-
export declare function loadCodegenConfig(configFilePath
|
|
43
|
+
export declare function loadCodegenConfig({ configFilePath, moduleName, searchPlaces: additionalSearchPlaces, packageProp, loaders: customLoaders, }: LoadCodegenConfigOptions): Promise<LoadCodegenConfigResult>;
|
|
19
44
|
export declare function loadContext(configFilePath?: string): Promise<CodegenContext> | never;
|
|
20
45
|
export declare function buildOptions(): {
|
|
21
46
|
c: {
|
package/index.js
CHANGED
|
@@ -465,6 +465,7 @@ async function loadDocuments(documentPointers, config) {
|
|
|
465
465
|
return loadedFromToolkit;
|
|
466
466
|
}
|
|
467
467
|
|
|
468
|
+
const { lstat } = fs.promises;
|
|
468
469
|
function generateSearchPlaces(moduleName) {
|
|
469
470
|
const extensions = ['json', 'yaml', 'yml', 'js', 'config.js'];
|
|
470
471
|
// gives codegen.json...
|
|
@@ -497,20 +498,24 @@ function customLoader(ext) {
|
|
|
497
498
|
}
|
|
498
499
|
return loader;
|
|
499
500
|
}
|
|
500
|
-
function loadCodegenConfig(configFilePath) {
|
|
501
|
-
|
|
501
|
+
async function loadCodegenConfig({ configFilePath, moduleName, searchPlaces: additionalSearchPlaces, packageProp, loaders: customLoaders, }) {
|
|
502
|
+
configFilePath = configFilePath || process.cwd();
|
|
503
|
+
moduleName = moduleName || 'codegen';
|
|
504
|
+
packageProp = packageProp || moduleName;
|
|
502
505
|
const cosmi = cosmiconfig.cosmiconfig(moduleName, {
|
|
503
|
-
searchPlaces: generateSearchPlaces(moduleName),
|
|
504
|
-
packageProp
|
|
506
|
+
searchPlaces: generateSearchPlaces(moduleName).concat(additionalSearchPlaces || []),
|
|
507
|
+
packageProp,
|
|
505
508
|
loaders: {
|
|
506
509
|
'.json': customLoader('json'),
|
|
507
510
|
'.yaml': customLoader('yaml'),
|
|
508
511
|
'.yml': customLoader('yaml'),
|
|
509
512
|
'.js': customLoader('js'),
|
|
510
513
|
noExt: customLoader('yaml'),
|
|
514
|
+
...customLoaders,
|
|
511
515
|
},
|
|
512
516
|
});
|
|
513
|
-
|
|
517
|
+
const pathStats = await lstat(configFilePath);
|
|
518
|
+
return pathStats.isDirectory() ? cosmi.search(configFilePath) : cosmi.load(configFilePath);
|
|
514
519
|
}
|
|
515
520
|
async function loadContext(configFilePath) {
|
|
516
521
|
const graphqlConfig = await findAndLoadGraphQLConfig(configFilePath);
|
|
@@ -519,7 +524,7 @@ async function loadContext(configFilePath) {
|
|
|
519
524
|
graphqlConfig,
|
|
520
525
|
});
|
|
521
526
|
}
|
|
522
|
-
const result = await loadCodegenConfig(configFilePath);
|
|
527
|
+
const result = await loadCodegenConfig({ configFilePath });
|
|
523
528
|
if (!result) {
|
|
524
529
|
if (configFilePath) {
|
|
525
530
|
throw new pluginHelpers.DetailedError(`Config ${configFilePath} does not exist`, `
|
|
@@ -1781,6 +1786,7 @@ exports.ensureGraphQlPackage = ensureGraphQlPackage;
|
|
|
1781
1786
|
exports.executeCodegen = executeCodegen;
|
|
1782
1787
|
exports.findAndLoadGraphQLConfig = findAndLoadGraphQLConfig;
|
|
1783
1788
|
exports.generate = generate;
|
|
1789
|
+
exports.generateSearchPlaces = generateSearchPlaces;
|
|
1784
1790
|
exports.init = init;
|
|
1785
1791
|
exports.loadCodegenConfig = loadCodegenConfig;
|
|
1786
1792
|
exports.loadContext = loadContext;
|
package/index.mjs
CHANGED
|
@@ -24,7 +24,7 @@ import { JsonFileLoader } from '@graphql-tools/json-file-loader';
|
|
|
24
24
|
import { UrlLoader } from '@graphql-tools/url-loader';
|
|
25
25
|
import yaml from 'yaml';
|
|
26
26
|
import { createRequire } from 'module';
|
|
27
|
-
import fs, { readFileSync, writeFileSync, statSync, unlink } from 'fs';
|
|
27
|
+
import fs, { promises, readFileSync, writeFileSync, statSync, unlink } from 'fs';
|
|
28
28
|
import Listr from 'listr';
|
|
29
29
|
import { exec } from 'child_process';
|
|
30
30
|
import isGlob from 'is-glob';
|
|
@@ -438,6 +438,7 @@ async function loadDocuments(documentPointers, config) {
|
|
|
438
438
|
return loadedFromToolkit;
|
|
439
439
|
}
|
|
440
440
|
|
|
441
|
+
const { lstat } = promises;
|
|
441
442
|
function generateSearchPlaces(moduleName) {
|
|
442
443
|
const extensions = ['json', 'yaml', 'yml', 'js', 'config.js'];
|
|
443
444
|
// gives codegen.json...
|
|
@@ -470,20 +471,24 @@ function customLoader(ext) {
|
|
|
470
471
|
}
|
|
471
472
|
return loader;
|
|
472
473
|
}
|
|
473
|
-
function loadCodegenConfig(configFilePath) {
|
|
474
|
-
|
|
474
|
+
async function loadCodegenConfig({ configFilePath, moduleName, searchPlaces: additionalSearchPlaces, packageProp, loaders: customLoaders, }) {
|
|
475
|
+
configFilePath = configFilePath || process.cwd();
|
|
476
|
+
moduleName = moduleName || 'codegen';
|
|
477
|
+
packageProp = packageProp || moduleName;
|
|
475
478
|
const cosmi = cosmiconfig(moduleName, {
|
|
476
|
-
searchPlaces: generateSearchPlaces(moduleName),
|
|
477
|
-
packageProp
|
|
479
|
+
searchPlaces: generateSearchPlaces(moduleName).concat(additionalSearchPlaces || []),
|
|
480
|
+
packageProp,
|
|
478
481
|
loaders: {
|
|
479
482
|
'.json': customLoader('json'),
|
|
480
483
|
'.yaml': customLoader('yaml'),
|
|
481
484
|
'.yml': customLoader('yaml'),
|
|
482
485
|
'.js': customLoader('js'),
|
|
483
486
|
noExt: customLoader('yaml'),
|
|
487
|
+
...customLoaders,
|
|
484
488
|
},
|
|
485
489
|
});
|
|
486
|
-
|
|
490
|
+
const pathStats = await lstat(configFilePath);
|
|
491
|
+
return pathStats.isDirectory() ? cosmi.search(configFilePath) : cosmi.load(configFilePath);
|
|
487
492
|
}
|
|
488
493
|
async function loadContext(configFilePath) {
|
|
489
494
|
const graphqlConfig = await findAndLoadGraphQLConfig(configFilePath);
|
|
@@ -492,7 +497,7 @@ async function loadContext(configFilePath) {
|
|
|
492
497
|
graphqlConfig,
|
|
493
498
|
});
|
|
494
499
|
}
|
|
495
|
-
const result = await loadCodegenConfig(configFilePath);
|
|
500
|
+
const result = await loadCodegenConfig({ configFilePath });
|
|
496
501
|
if (!result) {
|
|
497
502
|
if (configFilePath) {
|
|
498
503
|
throw new DetailedError(`Config ${configFilePath} does not exist`, `
|
|
@@ -1744,4 +1749,4 @@ async function ensureGraphQlPackage() {
|
|
|
1744
1749
|
}
|
|
1745
1750
|
}
|
|
1746
1751
|
|
|
1747
|
-
export { CodegenContext, CodegenExtension, buildOptions, cliError, createContext, ensureContext, ensureGraphQlPackage, executeCodegen, findAndLoadGraphQLConfig, generate, init, loadCodegenConfig, loadContext, parseArgv, runCli, updateContextWithCliFlags };
|
|
1752
|
+
export { CodegenContext, CodegenExtension, buildOptions, cliError, createContext, ensureContext, ensureGraphQlPackage, executeCodegen, findAndLoadGraphQLConfig, generate, generateSearchPlaces, init, loadCodegenConfig, loadContext, parseArgv, runCli, updateContextWithCliFlags };
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/cli",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.1",
|
|
4
4
|
"peerDependencies": {
|
|
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"
|
|
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.
|
|
9
|
-
"@graphql-codegen/plugin-helpers": "^2.2
|
|
8
|
+
"@graphql-codegen/core": "2.4.0",
|
|
9
|
+
"@graphql-codegen/plugin-helpers": "^2.3.2",
|
|
10
10
|
"@graphql-tools/apollo-engine-loader": "^7.0.5",
|
|
11
11
|
"@graphql-tools/code-file-loader": "^7.0.6",
|
|
12
12
|
"@graphql-tools/git-loader": "^7.0.5",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"detect-indent": "^6.0.0",
|
|
29
29
|
"glob": "^7.1.6",
|
|
30
30
|
"globby": "^11.0.4",
|
|
31
|
-
"graphql-config": "^4.0
|
|
32
|
-
"inquirer": "^
|
|
31
|
+
"graphql-config": "^4.1.0",
|
|
32
|
+
"inquirer": "^8.0.0",
|
|
33
33
|
"is-glob": "^4.0.1",
|
|
34
34
|
"json-to-pretty-yaml": "^1.2.2",
|
|
35
35
|
"latest-version": "5.1.0",
|
|
@@ -78,6 +78,7 @@
|
|
|
78
78
|
"definition": "index.d.ts"
|
|
79
79
|
},
|
|
80
80
|
"exports": {
|
|
81
|
+
"./package.json": "./package.json",
|
|
81
82
|
".": {
|
|
82
83
|
"require": "./index.js",
|
|
83
84
|
"import": "./index.mjs"
|