Skip to content

Commit ab2ad6d

Browse files
authored
add cosmiconfig-toml-loader to peerDependenciesMeta (#1189)
* add `cosmiconfig-toml-loader` to `peerDependenciesMeta` * prettier
1 parent 6962fa5 commit ab2ad6d

File tree

6 files changed

+30
-9
lines changed

6 files changed

+30
-9
lines changed

.changeset/fluffy-kings-applaud.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'graphql-config': minor
3+
---
4+
5+
add `cosmiconfig-toml-loader` to `peerDependenciesMeta`

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,16 @@
4848
"json-schema": "typescript-json-schema src/types.ts IGraphQLConfig --out config-schema.json --ignoreErrors --required --titles && prettier --write config-schema.json"
4949
},
5050
"peerDependencies": {
51+
"cosmiconfig-toml-loader": "^1.0.0",
5152
"cosmiconfig-typescript-loader": "^4.0.0",
5253
"graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
5354
},
5455
"peerDependenciesMeta": {
5556
"cosmiconfig-typescript-loader": {
5657
"optional": true
58+
},
59+
"cosmiconfig-toml-loader": {
60+
"optional": true
5761
}
5862
},
5963
"dependencies": {
@@ -64,7 +68,6 @@
6468
"@graphql-tools/url-loader": "^7.9.7",
6569
"@graphql-tools/utils": "^8.6.5",
6670
"cosmiconfig": "8.0.0",
67-
"cosmiconfig-toml-loader": "1.0.0",
6871
"minimatch": "4.2.1",
6972
"string-env-interpolation": "1.0.1",
7073
"tslib": "^2.4.0"
@@ -76,6 +79,7 @@
7679
"@typescript-eslint/eslint-plugin": "5.47.0",
7780
"@typescript-eslint/parser": "5.47.0",
7881
"bob-the-bundler": "4.2.0-alpha-20221222140753-fcf5286",
82+
"cosmiconfig-toml-loader": "1.0.0",
7983
"cosmiconfig-typescript-loader": "4.3.0",
8084
"del": "6.1.1",
8185
"eslint": "8.25.0",

src/helpers/cosmiconfig.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { cosmiconfig, cosmiconfigSync, Loader, defaultLoaders } from 'cosmiconfig';
2-
import { loadToml } from 'cosmiconfig-toml-loader';
32
import { env } from 'string-env-interpolation';
43

54
export interface ConfigSearchResult {
@@ -43,10 +42,15 @@ export function createCosmiConfigSync(moduleName: string, legacy: boolean) {
4342
const loadTypeScript: Loader = (...args) => {
4443
// eslint-disable-next-line @typescript-eslint/no-var-requires
4544
const { TypeScriptLoader } = require('cosmiconfig-typescript-loader');
46-
4745
return TypeScriptLoader({ transpileOnly: true })(...args);
4846
};
4947

48+
const loadToml: Loader = (...args) => {
49+
// eslint-disable-next-line @typescript-eslint/no-var-requires
50+
const { loadToml } = require('cosmiconfig-toml-loader');
51+
return createCustomLoader(loadToml)(...args);
52+
};
53+
5054
function prepareCosmiconfig(moduleName: string, legacy: boolean) {
5155
const loadYaml = createCustomLoader(defaultLoaders['.yaml']);
5256

@@ -83,7 +87,7 @@ function prepareCosmiconfig(moduleName: string, legacy: boolean) {
8387
'.json': createCustomLoader(defaultLoaders['.json']),
8488
'.yaml': loadYaml,
8589
'.yml': loadYaml,
86-
'.toml': createCustomLoader(loadToml),
90+
'.toml': loadToml,
8791
noExt: loadYaml,
8892
},
8993
};

website/src/pages/docs/index.mdx

+6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ extensions:
4646
schema = "https://localhost:8080"
4747
```
4848

49+
<Callout type="warning">**Note**: This config requires `cosmiconfig-toml-loader` to be installed.</Callout>
50+
4951
### `graphql.config.js` or `.graphqlrc.js`
5052

5153
```js
@@ -66,6 +68,10 @@ const config: IGraphQLConfig = {
6668
export default config
6769
```
6870

71+
<Callout type="warning">
72+
**Note**: This config requires `cosmiconfig-typescript-loader`, `typescript` and `ts-node` to be installed.
73+
</Callout>
74+
6975
### Custom Paths
7076

7177
Custom extension paths with `.mycustomrc.js`, `mycustom.config.yml`, etc. - any filename listed in [usage docs](usage) with `graphql` replaced by the `loadConfig(){:ts}` parameter [`configName`](load-config#configname).

website/src/pages/docs/library/load-config.mdx

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This function is the starting point for using GraphQL Config. It looks for a con
66

77
### A Basic Usage Example (async):
88

9-
```ts filename="ts"
9+
```ts
1010
import { loadConfig } from 'graphql-config'
1111

1212
async function main() {
@@ -16,11 +16,13 @@ async function main() {
1616

1717
### Synchronous Version:
1818

19-
```ts filename="ts"
19+
```ts
2020
import { loadConfigSync } from 'graphql-config'
2121

2222
function main() {
23-
const config = loadConfigSync({ ... }) // an instance of GraphQLConfig
23+
const config = loadConfigSync({
24+
/* ... */
25+
}) // an instance of GraphQLConfig
2426
}
2527
```
2628

website/src/pages/docs/user/documents.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ GraphQL Config supports not only a schema but GraphQL Operations and Fragments t
66

77
You can specify a list of files:
88

9-
```yaml filename="yaml"
9+
```yaml
1010
documents:
1111
- ./documents/foo.graphql
1212
- ./documents/bar.graphql
@@ -15,7 +15,7 @@ documents:
1515
1616
Use a glob pattern to find and include operations and fragments:
1717
18-
```yaml filename="yaml"
18+
```yaml
1919
documents: ./documents/*.graphql
2020
```
2121

0 commit comments

Comments
 (0)