Skip to content

Commit ccb959c

Browse files
authored
chore: add monorepo example (#1084)
* chore: add monorepo example * add helpful comment in examples eslintrc configs
1 parent 0d48603 commit ccb959c

File tree

24 files changed

+1221
-951
lines changed

24 files changed

+1221
-951
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ See [docs/deprecated-rules.md](docs/deprecated-rules.md).
192192

193193
> If you are in a project that develops GraphQL operations (query/mutation/subscription), you'll need `operations` rules.
194194

195-
> If you are in a monorepo project, you probably need both sets of rules.
195+
> If you are in a monorepo project, you probably need both sets of rules, see [example of configuration](examples/monorepo/.eslintrc.cjs).
196196

197197
### Config usage
198198

examples/basic/.eslintrc.cjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
module.exports = {
22
root: true,
3+
// ❗️ It's very important that you don't have any rules configured at the top-level config,
4+
// and to move all configurations into the overrides section. Since JavaScript rules
5+
// can't run on GraphQL files and vice versa, if you have rules configured at the top level,
6+
// they will try to also execute for all overrides, as ESLint's configs cascade
37
overrides: [
48
{
59
files: ['*.js'],

examples/basic/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
},
1414
"devDependencies": {
1515
"@graphql-eslint/eslint-plugin": "3.10.4",
16-
"eslint": "8.14.0"
16+
"eslint": "8.17.0"
1717
}
1818
}

examples/code-file/.eslintrc.cjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
module.exports = {
22
root: true,
3+
// ❗️ It's very important that you don't have any rules configured at the top-level config,
4+
// and to move all configurations into the overrides section. Since JavaScript rules
5+
// can't run on GraphQL files and vice versa, if you have rules configured at the top level,
6+
// they will try to also execute for all overrides, as ESLint's configs cascade
37
overrides: [
48
{
59
files: ['*.js'],

examples/code-file/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
},
1414
"devDependencies": {
1515
"@graphql-eslint/eslint-plugin": "3.10.4",
16-
"eslint": "8.14.0"
16+
"eslint": "8.17.0"
1717
}
1818
}

examples/graphql-config-code-file/.eslintrc.cjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
module.exports = {
22
root: true,
3+
// ❗️ It's very important that you don't have any rules configured at the top-level config,
4+
// and to move all configurations into the overrides section. Since JavaScript rules
5+
// can't run on GraphQL files and vice versa, if you have rules configured at the top level,
6+
// they will try to also execute for all overrides, as ESLint's configs cascade
37
overrides: [
48
{
59
files: ['*.js'],

examples/graphql-config-code-file/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
},
1515
"devDependencies": {
1616
"@graphql-eslint/eslint-plugin": "3.10.4",
17-
"eslint": "8.14.0"
17+
"eslint": "8.17.0"
1818
}
1919
}

examples/graphql-config/.eslintrc.cjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
module.exports = {
22
root: true,
3+
// ❗️ It's very important that you don't have any rules configured at the top-level config,
4+
// and to move all configurations into the overrides section. Since JavaScript rules
5+
// can't run on GraphQL files and vice versa, if you have rules configured at the top level,
6+
// they will try to also execute for all overrides, as ESLint's configs cascade
37
overrides: [
48
{
59
files: ['*.js'],

examples/graphql-config/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
},
1414
"devDependencies": {
1515
"@graphql-eslint/eslint-plugin": "3.10.4",
16-
"eslint": "8.14.0"
16+
"eslint": "8.17.0"
1717
}
1818
}

examples/monorepo/.eslintrc.cjs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/* eslint-env node */
2+
const SCHEMA_PATH = 'server/**/*.gql';
3+
const OPERATIONS_PATH = 'client/**/*.{tsx,gql}';
4+
5+
module.exports = {
6+
root: true,
7+
// ❗️ It's very important that you don't have any rules configured at the top-level config,
8+
// and to move all configurations into the overrides section. Since JavaScript rules
9+
// can't run on GraphQL files and vice versa, if you have rules configured at the top level,
10+
// they will try to also execute for all overrides, as ESLint's configs cascade
11+
overrides: [
12+
{
13+
files: '*.{cjs,tsx}',
14+
extends: 'eslint:recommended',
15+
env: {
16+
es2022: true,
17+
},
18+
},
19+
{
20+
files: 'client/**/*.tsx',
21+
parserOptions: {
22+
sourceType: 'module',
23+
ecmaFeatures: {
24+
jsx: true,
25+
},
26+
},
27+
},
28+
{
29+
// Setup GraphQL Parser
30+
files: '*.{graphql,gql}',
31+
parser: '@graphql-eslint/eslint-plugin',
32+
plugins: ['@graphql-eslint'],
33+
parserOptions: {
34+
schema: SCHEMA_PATH,
35+
operations: OPERATIONS_PATH,
36+
},
37+
},
38+
{
39+
// Setup processor for operations/fragments definitions on code-files
40+
files: 'client/**/*.tsx',
41+
processor: '@graphql-eslint/graphql',
42+
},
43+
{
44+
// Setup recommended config for schema files
45+
files: SCHEMA_PATH,
46+
extends: 'plugin:@graphql-eslint/schema-recommended',
47+
rules: {
48+
// Override graphql-eslint rules for schema files
49+
},
50+
},
51+
{
52+
// Setup recommended config for operations files
53+
files: 'client/**/*.{graphql,gql}',
54+
extends: 'plugin:@graphql-eslint/operations-recommended',
55+
rules: {
56+
// Override graphql-eslint rules for operations files
57+
},
58+
},
59+
],
60+
};

0 commit comments

Comments
 (0)