Skip to content

Commit 11c08f7

Browse files
gauravmkjnwng
authored andcommitted
Add Named Operations Validation Rule to README (#49)
1 parent 843b09f commit 11c08f7

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,46 @@ The full list of available validators is:
241241
- `UniqueVariableNames`
242242
- `VariablesAreInputTypes`
243243
- `VariablesInAllowedPosition`
244+
245+
### Named Operations Validation Rule
246+
247+
The Named Operation rule validates that all operations are named. Naming operations is valuable for including in server-side logs and debugging.
248+
249+
**Pass**
250+
```
251+
query FetchUsername {
252+
viewer {
253+
name
254+
}
255+
}
256+
```
257+
258+
**Fail**
259+
```
260+
query {
261+
viewer {
262+
name
263+
}
264+
}
265+
```
266+
267+
The rule is defined as `graphql/named-operations` and requires a `schema` and optional `tagName`
268+
269+
```js
270+
// In a file called .eslintrc.js
271+
module.exports = {
272+
parser: "babel-eslint",
273+
rules: {
274+
"graphql/template-strings": ['error', {
275+
env: 'apollo',
276+
schemaJson: require('./schema.json'),
277+
}],
278+
"graphql/named-operations": ['warning' {
279+
schemaJson: require('./schema.json'),
280+
}],
281+
},
282+
plugins: [
283+
'graphql'
284+
]
285+
}
286+
```

0 commit comments

Comments
 (0)