Skip to content

Commit d2f1164

Browse files
committed
aa
1 parent 99b0703 commit d2f1164

File tree

5 files changed

+59
-0
lines changed

5 files changed

+59
-0
lines changed

.changeset/strong-otters-mate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-eslint/eslint-plugin': patch
3+
---
4+
5+
add an example with custom graphql rules
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import graphqlPlugin from '@graphql-eslint/eslint-plugin';
2+
import { rule } from './my-rule.js'
3+
4+
export default [
5+
{
6+
files: ['**/*.graphql'],
7+
languageOptions: {
8+
parser: graphqlPlugin.parser,
9+
},
10+
plugins: {
11+
'@internal': {
12+
rules: {
13+
'my-rule': rule
14+
}
15+
},
16+
},
17+
rules: {
18+
'@internal/my-rule': 'error',
19+
},
20+
},
21+
];

examples/custom-rule/my-rule.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export const rule = {
2+
create(context) {
3+
return {
4+
OperationDefinition(node) {
5+
if (!node.name?.value) {
6+
context.report({
7+
node,
8+
message: 'Oops, name is required!'
9+
})
10+
}
11+
}
12+
}
13+
}
14+
}

examples/custom-rule/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "@graphql-eslint/example-custom-rule",
3+
"version": "0.0.0",
4+
"type": "module",
5+
"repository": "https://github.com/dimaMachina/graphql-eslint",
6+
"author": "Dimitri POSTOLOV <[email protected]>",
7+
"private": true,
8+
"scripts": {
9+
"lint": "eslint --cache ."
10+
},
11+
"dependencies": {
12+
"graphql": "16.9.0"
13+
},
14+
"devDependencies": {
15+
"@graphql-eslint/eslint-plugin": "4.1.0",
16+
"eslint": "9.15.0"
17+
}
18+
}

examples/custom-rule/test.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
query { foo }

0 commit comments

Comments
 (0)