Skip to content

Commit

Permalink
add cosmiconfig-toml-loader to peerDependenciesMeta (#1189)
Browse files Browse the repository at this point in the history
* add `cosmiconfig-toml-loader` to `peerDependenciesMeta`

* prettier
  • Loading branch information
dimaMachina committed Dec 23, 2022
1 parent 6962fa5 commit ab2ad6d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/fluffy-kings-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'graphql-config': minor
---

add `cosmiconfig-toml-loader` to `peerDependenciesMeta`
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,16 @@
"json-schema": "typescript-json-schema src/types.ts IGraphQLConfig --out config-schema.json --ignoreErrors --required --titles && prettier --write config-schema.json"
},
"peerDependencies": {
"cosmiconfig-toml-loader": "^1.0.0",
"cosmiconfig-typescript-loader": "^4.0.0",
"graphql": "^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
},
"peerDependenciesMeta": {
"cosmiconfig-typescript-loader": {
"optional": true
},
"cosmiconfig-toml-loader": {
"optional": true
}
},
"dependencies": {
Expand All @@ -64,7 +68,6 @@
"@graphql-tools/url-loader": "^7.9.7",
"@graphql-tools/utils": "^8.6.5",
"cosmiconfig": "8.0.0",
"cosmiconfig-toml-loader": "1.0.0",
"minimatch": "4.2.1",
"string-env-interpolation": "1.0.1",
"tslib": "^2.4.0"
Expand All @@ -76,6 +79,7 @@
"@typescript-eslint/eslint-plugin": "5.47.0",
"@typescript-eslint/parser": "5.47.0",
"bob-the-bundler": "4.2.0-alpha-20221222140753-fcf5286",
"cosmiconfig-toml-loader": "1.0.0",
"cosmiconfig-typescript-loader": "4.3.0",
"del": "6.1.1",
"eslint": "8.25.0",
Expand Down
10 changes: 7 additions & 3 deletions src/helpers/cosmiconfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { cosmiconfig, cosmiconfigSync, Loader, defaultLoaders } from 'cosmiconfig';
import { loadToml } from 'cosmiconfig-toml-loader';
import { env } from 'string-env-interpolation';

export interface ConfigSearchResult {
Expand Down Expand Up @@ -43,10 +42,15 @@ export function createCosmiConfigSync(moduleName: string, legacy: boolean) {
const loadTypeScript: Loader = (...args) => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { TypeScriptLoader } = require('cosmiconfig-typescript-loader');

return TypeScriptLoader({ transpileOnly: true })(...args);
};

const loadToml: Loader = (...args) => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { loadToml } = require('cosmiconfig-toml-loader');
return createCustomLoader(loadToml)(...args);
};

function prepareCosmiconfig(moduleName: string, legacy: boolean) {
const loadYaml = createCustomLoader(defaultLoaders['.yaml']);

Expand Down Expand Up @@ -83,7 +87,7 @@ function prepareCosmiconfig(moduleName: string, legacy: boolean) {
'.json': createCustomLoader(defaultLoaders['.json']),
'.yaml': loadYaml,
'.yml': loadYaml,
'.toml': createCustomLoader(loadToml),
'.toml': loadToml,
noExt: loadYaml,
},
};
Expand Down
6 changes: 6 additions & 0 deletions website/src/pages/docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ extensions:
schema = "https://localhost:8080"
```

<Callout type="warning">**Note**: This config requires `cosmiconfig-toml-loader` to be installed.</Callout>

### `graphql.config.js` or `.graphqlrc.js`

```js
Expand All @@ -66,6 +68,10 @@ const config: IGraphQLConfig = {
export default config
```

<Callout type="warning">
**Note**: This config requires `cosmiconfig-typescript-loader`, `typescript` and `ts-node` to be installed.
</Callout>

### Custom Paths

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).
Expand Down
8 changes: 5 additions & 3 deletions website/src/pages/docs/library/load-config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This function is the starting point for using GraphQL Config. It looks for a con

### A Basic Usage Example (async):

```ts filename="ts"
```ts
import { loadConfig } from 'graphql-config'

async function main() {
Expand All @@ -16,11 +16,13 @@ async function main() {

### Synchronous Version:

```ts filename="ts"
```ts
import { loadConfigSync } from 'graphql-config'

function main() {
const config = loadConfigSync({ ... }) // an instance of GraphQLConfig
const config = loadConfigSync({
/* ... */
}) // an instance of GraphQLConfig
}
```

Expand Down
4 changes: 2 additions & 2 deletions website/src/pages/docs/user/documents.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ GraphQL Config supports not only a schema but GraphQL Operations and Fragments t

You can specify a list of files:

```yaml filename="yaml"
```yaml
documents:
- ./documents/foo.graphql
- ./documents/bar.graphql
Expand All @@ -15,7 +15,7 @@ documents:

Use a glob pattern to find and include operations and fragments:

```yaml filename="yaml"
```yaml
documents: ./documents/*.graphql
```

Expand Down

0 comments on commit ab2ad6d

Please sign in to comment.