Skip to content

Commit 0e9ddb5

Browse files
authoredDec 16, 2020
feat(graphql-codegen-cli): adds YAML merge (<<) syntax for configuration files (#5160)
1 parent 6f3cd39 commit 0e9ddb5

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed
 

‎.changeset/chatty-buttons-greet.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-codegen/cli': minor
3+
---
4+
5+
Add `merge` (`<<`) syntax for `yaml` configurations

‎packages/graphql-codegen-cli/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
"upper-case": "^2.0.2",
8484
"valid-url": "^1.0.9",
8585
"wrap-ansi": "^7.0.0",
86+
"yaml": "^1.10.0",
8687
"yargs": "^16.1.1"
8788
},
8889
"devDependencies": {

‎packages/graphql-codegen-cli/src/config.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { GraphQLConfig } from 'graphql-config';
77
import { findAndLoadGraphQLConfig } from './graphql-config';
88
import { loadSchema, loadDocuments, defaultSchemaLoadOptions, defaultDocumentsLoadOptions } from './load';
99
import { GraphQLSchema } from 'graphql';
10+
import yaml from 'yaml';
1011

1112
export type YamlCliFlags = {
1213
config: string;
@@ -39,7 +40,13 @@ function customLoader(ext: 'json' | 'yaml' | 'js') {
3940
}
4041

4142
if (ext === 'yaml') {
42-
return defaultLoaders['.yaml'](filepath, content);
43+
try {
44+
const result = yaml.parse(content, { prettyErrors: true, merge: true });
45+
return result;
46+
} catch (error) {
47+
error.message = `YAML Error in ${filepath}:\n${error.message}`;
48+
throw error;
49+
}
4350
}
4451

4552
if (ext === 'js') {

0 commit comments

Comments
 (0)
Please sign in to comment.