Skip to content

Commit

Permalink
Add env option to required-fields rule config
Browse files Browse the repository at this point in the history
Allows .graphql and .gql literal files to be linted with the required-fields rule.
  • Loading branch information
Justin Schulz committed Jun 1, 2017
1 parent 26c63eb commit 934fad4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,6 +1,7 @@
# Change log

### vNEXT
- Add env config option for required-fields rule [Justin Schulz](https://github.com/PepperTeasdale) in

### v1.0.0
- Fix template env for older runtimes (eg. node 5 and earlier) [Justin Schulz](https://github.com/PepperTeasdale) in [#73](https://github.com/apollographql/eslint-plugin-graphql/pull/73)
Expand Down
9 changes: 5 additions & 4 deletions README.md
Expand Up @@ -222,12 +222,12 @@ The full list of available validators is:
- `FragmentsOnCompositeTypes`
- `KnownArgumentNames`
- `KnownDirectives` (*disabled by default in `relay`*)
- `KnownFragmentNames` (*disabled by default in `apollo`, `lokka`, and `relay`*)
- `KnownFragmentNames` (*disabled by default in all envs*)
- `KnownTypeNames`
- `LoneAnonymousOperation`
- `NoFragmentCycles`
- `NoUndefinedVariables` (*disabled by default in `relay`*)
- `NoUnusedFragments` (*disabled by default in `apollo`, `lokka`, and `relay`*)
- `NoUnusedFragments` (*disabled by default in all envs*)
- `NoUnusedVariables`
- `OverlappingFieldsCanBeMerged`
- `PossibleFragmentSpreads`
Expand Down Expand Up @@ -347,7 +347,7 @@ query ViewerName {
}
```

The rule is defined as `graphql/required-fields` and requires a `schema` and `requiredFields`, with an optional `tagName`.
The rule is defined as `graphql/required-fields` and requires a `schema` and `requiredFields`, with an optional `tagName` and `env`.

```js
// In a file called .eslintrc.js
Expand All @@ -356,7 +356,8 @@ module.exports = {
'graphql/required-fields': [
'error',
{
schemaJsonFilepath: require('./schema.json'),
env: 'apollo',
schemaJsonFilepath: path.resolve(__dirname, './schema.json'),
requiredFields: ['uuid'],
},
],
Expand Down
8 changes: 8 additions & 0 deletions src/index.js
Expand Up @@ -161,6 +161,14 @@ const rules = {
additionalProperties: false,
properties: {
...defaultRuleProperties,
env: {
enum: [
'lokka',
'relay',
'apollo',
'literal',
],
},
requiredFields: {
type: 'array',
items: {
Expand Down
1 change: 1 addition & 0 deletions test/makeRule.js
Expand Up @@ -879,6 +879,7 @@ const requiredFieldsTestCases = {
// Validate the required-fields rule
options = [{
schemaJson,
env: 'apollo',
tagName: 'gql',
requiredFields: ['id'],
}];
Expand Down

0 comments on commit 934fad4

Please sign in to comment.