Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added 'literal' option to env #36

Merged
merged 5 commits into from
Dec 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### vNEXT

- ...
- Added `'literal'` option to `env` for when working with `.graphql` and `.gql` files, by [jtmthf in

### v0.4.1

Expand Down
37 changes: 32 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ Note: the linter rule could be extended to identify calls to various specific AP
### GraphQL literal files

This plugin also lints GraphQL literal files ending on `.gql` or `.graphql`.
In order to do so just tell eslint to check these files as well.
In order to do so set `env` to `'literal'` in your `.eslintrc.js` and tell eslint to check these files as well.

```BASH
eslint . --ext js,gql,graphql
eslint . --ext .js --ext .gql --ext .graphql
```

### Example config for Apollo
Expand All @@ -67,7 +67,7 @@ module.exports = {
rules: {
"graphql/template-strings": ['error', {
// Import default settings for your GraphQL client. Supported values:
// 'apollo', 'relay', 'lokka'
// 'apollo', 'relay', 'lokka', 'literal'
env: 'apollo',

// Import your schema JSON here
Expand All @@ -94,7 +94,7 @@ module.exports = {
rules: {
"graphql/template-strings": ['error', {
// Import default settings for your GraphQL client. Supported values:
// 'apollo', 'relay', 'lokka'
// 'apollo', 'relay', 'lokka', 'literal'
env: 'relay',

// Import your schema JSON here
Expand All @@ -121,7 +121,7 @@ module.exports = {
rules: {
"graphql/template-strings": ['error', {
// Import default settings for your GraphQL client. Supported values:
// 'apollo', 'relay', 'lokka'
// 'apollo', 'relay', 'lokka', 'literal'
env: 'lokka',

// Import your schema JSON here
Expand All @@ -140,6 +140,33 @@ module.exports = {
}
```

### Example config for literal graphql files

```js
// In a file called .eslintrc.js
module.exports = {
parser: "babel-eslint",
rules: {
"graphql/template-strings": ['error', {
// Import default settings for your GraphQL client. Supported values:
// 'apollo', 'relay', 'lokka', 'literal'
env: 'literal',

// Import your schema JSON here
schemaJson: require('./schema.json'),

// OR provide absolute path to your schema JSON
// schemaJsonFilepath: path.resolve(__dirname, './schema.json'),

// tagName is set automatically
}]
},
plugins: [
'graphql'
]
}
```

### Additional Schemas or Tags

This plugin can be used to validate against multiple schemas by identifying them with different tags. This is useful for applications interacting with multiple GraphQL systems. Additional schemas can simply be appended to the options list:
Expand Down
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ function parseOptions(optionGroup) {
}

// Validate env
if (env && env !== 'lokka' && env !== 'relay' && env !== 'apollo') {
throw new Error('Invalid option for env, only `apollo`, `lokka`, and `relay` supported.')
if (env && env !== 'lokka' && env !== 'relay' && env !== 'apollo' && env !== 'literal') {
throw new Error('Invalid option for env, only `apollo`, `lokka`, `relay`, and `literal` supported.')
}

// Validate tagName and set default
Expand All @@ -145,6 +145,8 @@ function parseOptions(optionGroup) {
tagName = tagNameOption;
} else if (env === 'relay') {
tagName = 'Relay.QL';
} else if (env === 'literal') {
tagName = internalTag;
} else {
tagName = 'gql';
}
Expand Down