Skip to content

Commit

Permalink
New GraphQL Config (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela authored Oct 24, 2019
1 parent fbebeb8 commit 45c1640
Show file tree
Hide file tree
Showing 58 changed files with 1,677 additions and 4,395 deletions.
19 changes: 19 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
"no-console": "error",
"no-debugger": "error",
"no-invalid-regexp": "error",
"no-extra-boolean-cast": "warn",
"no-unreachable": "error",
"eqeqeq": "error",
"no-global-assign": "error",
"no-redeclare": "error",
"no-delete-var": "warn",
"no-shadow-restricted-names": "warn"
}
}
4 changes: 3 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ jobs:
- name: Use Node.js ${{ matrix.node_version }}
uses: actions/setup-node@master
with:
version: ${{ matrix.node_version }}
node-version: ${{ matrix.node_version }}
- name: Install
run: yarn
- name: Test
run: yarn test
- name: Lint
run: yarn lint
- name: Build
run: yarn build
12 changes: 5 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
.rts2_cache_cjs
.rts2_cache_esm
.rts2_cache_umd
.DS_Store
.idea
node_modules
.DS_Store/
.idea/
node_modules/
coverage/
dist/
*.map
dist
12 changes: 0 additions & 12 deletions .npmignore

This file was deleted.

1 change: 0 additions & 1 deletion .npmrc

This file was deleted.

4 changes: 1 addition & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"dist": true,
".rts2_cache_cjs": true,
".rts2_cache_esm": true
"coverage": true
}
}
1 change: 1 addition & 0 deletions .yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--add.exact true
127 changes: 22 additions & 105 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# graphql-config

[![Build Status](https://travis-ci.org/prisma/graphql-config.svg?branch=master)](https://travis-ci.org/prisma/graphql-config) [![npm version](https://badge.fury.io/js/graphql-config.svg)](https://badge.fury.io/js/graphql-config)
[![Discord Chat](https://img.shields.io/discord/625400653321076807)](https://discord.gg/xud7bH9)

> The README reflects the new [graphql-config protocol](specification.md).
> Old graphql-config-parser documentation [can be found here](https://github.com/graphcool/graphql-config/tree/graphql-config-parser)
The easiest way to configure your development environment with your GraphQL schema (supported by most tools, editors & IDEs)
The easiest way to configure your development environment with your GraphQL schema (supported by most tools, editors & IDEs)

## Supported by...

Expand All @@ -25,35 +23,38 @@ The easiest way to configure your development environment with your GraphQL sche
* [eslint-plugin-graphql](https://github.com/apollostack/eslint-plugin-graphql) - An ESLint plugin that checks tagged template strings against a GraphQL schema (_pending_)
* [webpack-plugin-graphql-schema-hot](https://github.com/nodkz/webpack-plugin-graphql-schema-hot) - Webpack plugin which tracks changes in your schema and generates its introspection in `json` and `txt` formats (_pending_)

> Did we forget a tool/editor? Please [add it here](https://github.com/graphcool/graphql-config/issues/new).
> Did we forget a tool/editor? Please [add it here](https://github.com/kamilkisiela/graphql-config/issues/new).
**[Go to `graphql-config` library docs](#graphql-config-api)**

## Usage

**tl;dr**
### Possible config files

Install [`graphql-cli`](https://github.com/graphcool/graphql-cli) and run `graphql init`. Answer a few simple questions and you are set up!

You can either configure your GraphQL endpoint via a configuration file `.graphqlconfig`
(or `.graphqlconfig.yaml`) which should be put into the root of your project
- `.graphqlrc` _(YAML and JSON)_
- `.graphqlrc.json`
- `.graphqlrc.yaml`
- `.graphqlrc.yml`
- `.graphqlrc.js`
- `graphql.config.js`
- `graphql` property in `package.json`

### Simplest use case

The simplest config specifies only `schemaPath` which is path to the file with introspection
The simplest config specifies only `schema` which is path to the file with introspection
results or corresponding SDL document

```json
{
"schemaPath": "schema.graphql"
"schema": "schema.graphql"
}
```

or

```json
{
"schemaPath": "schema.json"
"schema": "schema.json"
}
```

Expand All @@ -63,7 +64,7 @@ You can specify which files are included/excluded using the corresponding option

```json
{
"schemaPath": "schema.graphql",
"schema": "schema.graphql",
"includes": ["*.graphql"],
"excludes": ["temp/**"]
}
Expand All @@ -73,73 +74,6 @@ You can specify which files are included/excluded using the corresponding option
> So, just `temp` or `temp/` won't match all files inside the directory.
> That's why the example uses `temp/**`
#### Specifying endpoint info

You may specify your endpoints info in `.graphqlconfig` which may be used by some tools.
The simplest case:

```json
{
"schemaPath": "schema.graphql",
"extensions": {
"endpoints": {
"dev": "https://example.com/graphql"
}
}
}
```

In case you need provide additional information, for example headers to authenticate your GraphQL endpoint or
an endpoint for subscription, you can use expanded version:

```json
{
"schemaPath": "schema.graphql",
"extensions": {
"endpoints": {
"dev": {
"url": "https://example.com/graphql",
"headers": {
"Authorization": "Bearer ${env:AUTH_TOKEN_ENV}"
},
"subscription": {
"url": "ws://example.com/graphql",
"connectionParams": {
"Token": "${env:YOUR_APP_TOKEN}"
}
}
}
}
}
}
```

> Note: do not save secure information in .graphqlconfig file. Use [Environment variables](specification.md#referencing-environment-variables) for that like in the example above.
In case if you have multiple endpoints use the following syntax:

```json
{
"schemaPath": "schema.graphql",
"extensions": {
"endpoints": {
"prod": {
"url": "https://your-app.com/graphql",
"subscription": {
"url": "wss://subscriptions.graph.cool/v1/instagram"
}
},
"dev": {
"url": "http://localhost:3000/graphql",
"subscription": {
"url": "ws://localhost:3001"
}
}
}
}
}
```

### Multi-project configuration (advanced)
> TBD
Expand All @@ -158,36 +92,19 @@ Here are very basic examples of how to use `graphql-config` library.

You can find **[the detailed documentation here](docs/)**

### getGraphQLProjectConfig

**NOTE:** if your tool works on per-file basis (e.g. editor plugin, linter, etc) use
[`getGraphQLConfig`](#getGraphQLConfig) function

`getGraphQLProjectConfig` should be used by tools that do not work on per-file basis

```js
import { getGraphQLProjectConfig } from 'graphql-config'

const config = getGraphQLProjectConfig('./optionalProjectDir', 'optionalProjectName')
const schema = config.getSchema()
// use schema for your tool/plugin
```

### getGraphQLConfig

`getGraphQLConfig` should be used by tools that work on per-file basis (editor plugins,
linters, etc.)
### loadConfig

```js
import { getGraphQLConfig } from 'graphql-config'
import { loadConfig } from 'graphql-config'

const config = getGraphQLConfig('./optionalProjectDir')
const schema = config.getConfigForFile(filename).getSchema()
const config = loadConfig({
rootDir: './optionalProjectDir'
})
const schema = config.getProjectForFile(filename).getSchema()
// use schema for your tool/plugin
```

## Help & Community [![Slack Status](https://slack.graph.cool/badge.svg)](https://slack.graph.cool)
## Help & Community [![Discord Chat](https://img.shields.io/discord/625400653321076807)](https://discord.gg/xud7bH9)

Join our [Slack community](http://slack.graph.cool/) if you run into issues or have questions. We love talking to you!
Join our [Discord chat](https://discord.gg/xud7bH9) if you run into issues or have questions. We love talking to you!

![](http://i.imgur.com/5RHR6Ku.png)
Loading

0 comments on commit 45c1640

Please sign in to comment.