@graphql-codegen/cli 2.2.1-alpha-a09853373.0 → 2.3.0-alpha-f3053e3b7.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/bin.js +13 -8
- package/config.d.ts +30 -0
- package/index.js +14 -8
- package/index.mjs +15 -10
- package/package.json +3 -3
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,38 +580,42 @@ function customLoader(ext) {
|
|
|
579
580
|
}
|
|
580
581
|
return loader;
|
|
581
582
|
}
|
|
582
|
-
async function
|
|
583
|
-
const moduleName = 'codegen';
|
|
583
|
+
async function loadCodegenConfig({ configFilePath = process.cwd(), moduleName = 'codegen', searchPlaces: additionalSearchPlaces = [], packageProp = moduleName, loaders: customLoaders = {}, }) {
|
|
584
584
|
const cosmi = cosmiconfig.cosmiconfig(moduleName, {
|
|
585
|
-
searchPlaces: generateSearchPlaces(moduleName),
|
|
586
|
-
packageProp
|
|
585
|
+
searchPlaces: generateSearchPlaces(moduleName).concat(additionalSearchPlaces),
|
|
586
|
+
packageProp,
|
|
587
587
|
loaders: {
|
|
588
588
|
'.json': customLoader('json'),
|
|
589
589
|
'.yaml': customLoader('yaml'),
|
|
590
590
|
'.yml': customLoader('yaml'),
|
|
591
591
|
'.js': customLoader('js'),
|
|
592
592
|
noExt: customLoader('yaml'),
|
|
593
|
+
...customLoaders,
|
|
593
594
|
},
|
|
594
595
|
});
|
|
596
|
+
const pathStats = await lstat(configFilePath);
|
|
597
|
+
return pathStats.isDirectory ? cosmi.search(configFilePath) : cosmi.load(configFilePath);
|
|
598
|
+
}
|
|
599
|
+
async function loadContext(configFilePath) {
|
|
595
600
|
const graphqlConfig = await findAndLoadGraphQLConfig(configFilePath);
|
|
596
601
|
if (graphqlConfig) {
|
|
597
602
|
return new CodegenContext({
|
|
598
603
|
graphqlConfig,
|
|
599
604
|
});
|
|
600
605
|
}
|
|
601
|
-
const result = await (
|
|
606
|
+
const result = await loadCodegenConfig({ configFilePath });
|
|
602
607
|
if (!result) {
|
|
603
608
|
if (configFilePath) {
|
|
604
609
|
throw new pluginHelpers.DetailedError(`Config ${configFilePath} does not exist`, `
|
|
605
610
|
Config ${configFilePath} does not exist.
|
|
606
|
-
|
|
611
|
+
|
|
607
612
|
$ graphql-codegen --config ${configFilePath}
|
|
608
|
-
|
|
613
|
+
|
|
609
614
|
Please make sure the --config points to a correct file.
|
|
610
615
|
`);
|
|
611
616
|
}
|
|
612
617
|
throw new pluginHelpers.DetailedError(`Unable to find Codegen config file!`, `
|
|
613
|
-
Please make sure that you have a configuration file under the current directory!
|
|
618
|
+
Please make sure that you have a configuration file under the current directory!
|
|
614
619
|
`);
|
|
615
620
|
}
|
|
616
621
|
if (result.isEmpty) {
|
package/config.d.ts
CHANGED
|
@@ -10,6 +10,36 @@ export declare type YamlCliFlags = {
|
|
|
10
10
|
silent: boolean;
|
|
11
11
|
errorsOnly: boolean;
|
|
12
12
|
};
|
|
13
|
+
export interface LoadCodegenConfigOptions {
|
|
14
|
+
/**
|
|
15
|
+
* The path to the config file or directory contains the config file.
|
|
16
|
+
* @default process.cwd()
|
|
17
|
+
*/
|
|
18
|
+
configFilePath?: string;
|
|
19
|
+
/**
|
|
20
|
+
* The name of the config file
|
|
21
|
+
* @default codegen
|
|
22
|
+
*/
|
|
23
|
+
moduleName?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Additional search paths for the config file you want to check
|
|
26
|
+
*/
|
|
27
|
+
searchPlaces?: string[];
|
|
28
|
+
/**
|
|
29
|
+
* @default codegen
|
|
30
|
+
*/
|
|
31
|
+
packageProp?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Overrides or extends the loaders for specific file extensions
|
|
34
|
+
*/
|
|
35
|
+
loaders?: Record<string, (filepath: string, content: string) => Promise<Types.Config> | Types.Config>;
|
|
36
|
+
}
|
|
37
|
+
export interface LoadCodegenConfigResult {
|
|
38
|
+
filepath: string;
|
|
39
|
+
config: Types.Config;
|
|
40
|
+
isEmpty?: boolean;
|
|
41
|
+
}
|
|
42
|
+
export declare function loadCodegenConfig({ configFilePath, moduleName, searchPlaces: additionalSearchPlaces, packageProp, loaders: customLoaders, }: LoadCodegenConfigOptions): Promise<LoadCodegenConfigResult>;
|
|
13
43
|
export declare function loadContext(configFilePath?: string): Promise<CodegenContext> | never;
|
|
14
44
|
export declare function buildOptions(): {
|
|
15
45
|
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,38 +498,42 @@ function customLoader(ext) {
|
|
|
497
498
|
}
|
|
498
499
|
return loader;
|
|
499
500
|
}
|
|
500
|
-
async function
|
|
501
|
-
const moduleName = 'codegen';
|
|
501
|
+
async function loadCodegenConfig({ configFilePath = process.cwd(), moduleName = 'codegen', searchPlaces: additionalSearchPlaces = [], packageProp = moduleName, loaders: customLoaders = {}, }) {
|
|
502
502
|
const cosmi = cosmiconfig.cosmiconfig(moduleName, {
|
|
503
|
-
searchPlaces: generateSearchPlaces(moduleName),
|
|
504
|
-
packageProp
|
|
503
|
+
searchPlaces: generateSearchPlaces(moduleName).concat(additionalSearchPlaces),
|
|
504
|
+
packageProp,
|
|
505
505
|
loaders: {
|
|
506
506
|
'.json': customLoader('json'),
|
|
507
507
|
'.yaml': customLoader('yaml'),
|
|
508
508
|
'.yml': customLoader('yaml'),
|
|
509
509
|
'.js': customLoader('js'),
|
|
510
510
|
noExt: customLoader('yaml'),
|
|
511
|
+
...customLoaders,
|
|
511
512
|
},
|
|
512
513
|
});
|
|
514
|
+
const pathStats = await lstat(configFilePath);
|
|
515
|
+
return pathStats.isDirectory ? cosmi.search(configFilePath) : cosmi.load(configFilePath);
|
|
516
|
+
}
|
|
517
|
+
async function loadContext(configFilePath) {
|
|
513
518
|
const graphqlConfig = await findAndLoadGraphQLConfig(configFilePath);
|
|
514
519
|
if (graphqlConfig) {
|
|
515
520
|
return new CodegenContext({
|
|
516
521
|
graphqlConfig,
|
|
517
522
|
});
|
|
518
523
|
}
|
|
519
|
-
const result = await (
|
|
524
|
+
const result = await loadCodegenConfig({ configFilePath });
|
|
520
525
|
if (!result) {
|
|
521
526
|
if (configFilePath) {
|
|
522
527
|
throw new pluginHelpers.DetailedError(`Config ${configFilePath} does not exist`, `
|
|
523
528
|
Config ${configFilePath} does not exist.
|
|
524
|
-
|
|
529
|
+
|
|
525
530
|
$ graphql-codegen --config ${configFilePath}
|
|
526
|
-
|
|
531
|
+
|
|
527
532
|
Please make sure the --config points to a correct file.
|
|
528
533
|
`);
|
|
529
534
|
}
|
|
530
535
|
throw new pluginHelpers.DetailedError(`Unable to find Codegen config file!`, `
|
|
531
|
-
Please make sure that you have a configuration file under the current directory!
|
|
536
|
+
Please make sure that you have a configuration file under the current directory!
|
|
532
537
|
`);
|
|
533
538
|
}
|
|
534
539
|
if (result.isEmpty) {
|
|
@@ -1779,6 +1784,7 @@ exports.executeCodegen = executeCodegen;
|
|
|
1779
1784
|
exports.findAndLoadGraphQLConfig = findAndLoadGraphQLConfig;
|
|
1780
1785
|
exports.generate = generate;
|
|
1781
1786
|
exports.init = init;
|
|
1787
|
+
exports.loadCodegenConfig = loadCodegenConfig;
|
|
1782
1788
|
exports.loadContext = loadContext;
|
|
1783
1789
|
exports.parseArgv = parseArgv;
|
|
1784
1790
|
exports.runCli = runCli;
|
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,38 +471,42 @@ function customLoader(ext) {
|
|
|
470
471
|
}
|
|
471
472
|
return loader;
|
|
472
473
|
}
|
|
473
|
-
async function
|
|
474
|
-
const moduleName = 'codegen';
|
|
474
|
+
async function loadCodegenConfig({ configFilePath = process.cwd(), moduleName = 'codegen', searchPlaces: additionalSearchPlaces = [], packageProp = moduleName, loaders: customLoaders = {}, }) {
|
|
475
475
|
const cosmi = cosmiconfig(moduleName, {
|
|
476
|
-
searchPlaces: generateSearchPlaces(moduleName),
|
|
477
|
-
packageProp
|
|
476
|
+
searchPlaces: generateSearchPlaces(moduleName).concat(additionalSearchPlaces),
|
|
477
|
+
packageProp,
|
|
478
478
|
loaders: {
|
|
479
479
|
'.json': customLoader('json'),
|
|
480
480
|
'.yaml': customLoader('yaml'),
|
|
481
481
|
'.yml': customLoader('yaml'),
|
|
482
482
|
'.js': customLoader('js'),
|
|
483
483
|
noExt: customLoader('yaml'),
|
|
484
|
+
...customLoaders,
|
|
484
485
|
},
|
|
485
486
|
});
|
|
487
|
+
const pathStats = await lstat(configFilePath);
|
|
488
|
+
return pathStats.isDirectory ? cosmi.search(configFilePath) : cosmi.load(configFilePath);
|
|
489
|
+
}
|
|
490
|
+
async function loadContext(configFilePath) {
|
|
486
491
|
const graphqlConfig = await findAndLoadGraphQLConfig(configFilePath);
|
|
487
492
|
if (graphqlConfig) {
|
|
488
493
|
return new CodegenContext({
|
|
489
494
|
graphqlConfig,
|
|
490
495
|
});
|
|
491
496
|
}
|
|
492
|
-
const result = await (
|
|
497
|
+
const result = await loadCodegenConfig({ configFilePath });
|
|
493
498
|
if (!result) {
|
|
494
499
|
if (configFilePath) {
|
|
495
500
|
throw new DetailedError(`Config ${configFilePath} does not exist`, `
|
|
496
501
|
Config ${configFilePath} does not exist.
|
|
497
|
-
|
|
502
|
+
|
|
498
503
|
$ graphql-codegen --config ${configFilePath}
|
|
499
|
-
|
|
504
|
+
|
|
500
505
|
Please make sure the --config points to a correct file.
|
|
501
506
|
`);
|
|
502
507
|
}
|
|
503
508
|
throw new DetailedError(`Unable to find Codegen config file!`, `
|
|
504
|
-
Please make sure that you have a configuration file under the current directory!
|
|
509
|
+
Please make sure that you have a configuration file under the current directory!
|
|
505
510
|
`);
|
|
506
511
|
}
|
|
507
512
|
if (result.isEmpty) {
|
|
@@ -1741,4 +1746,4 @@ async function ensureGraphQlPackage() {
|
|
|
1741
1746
|
}
|
|
1742
1747
|
}
|
|
1743
1748
|
|
|
1744
|
-
export { CodegenContext, CodegenExtension, buildOptions, cliError, createContext, ensureContext, ensureGraphQlPackage, executeCodegen, findAndLoadGraphQLConfig, generate, init, loadContext, parseArgv, runCli, updateContextWithCliFlags };
|
|
1749
|
+
export { CodegenContext, CodegenExtension, buildOptions, cliError, createContext, ensureContext, ensureGraphQlPackage, executeCodegen, findAndLoadGraphQLConfig, generate, 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
|
+
"version": "2.3.0-alpha-f3053e3b7.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"
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@graphql-codegen/core": "2.2.0
|
|
9
|
-
"@graphql-codegen/plugin-helpers": "2.2.0
|
|
8
|
+
"@graphql-codegen/core": "2.2.0",
|
|
9
|
+
"@graphql-codegen/plugin-helpers": "^2.2.0",
|
|
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",
|